Пример #1
0
        /// <summary>
        /// Entry point to execute renaming.
        /// </summary>
        protected override void ExecutionImplementation()
        {
            var sci       = PluginBase.MainForm.CurrentDocument.SciControl;
            var fileModel = ASContext.Context.CurrentModel;
            var parser    = new ASFileParser();

            parser.ParseSrc(fileModel, sci.Text);
            var search = new FRSearch(sci.SelText)
            {
                SourceFile = sci.FileName
            };
            var mathes        = search.Matches(sci.Text);
            var currentMember = fileModel.Context.CurrentMember;
            var lineFrom      = currentMember.LineFrom;
            var lineTo        = currentMember.LineTo;

            mathes.RemoveAll(it => it.Line <lineFrom || it.Line> lineTo);
            var target = mathes.FindAll(it => sci.MBSafePosition(it.Index) == sci.SelectionStart);

            if (mathes.Count > 1)
            {
                CompletionList = new List <ICompletionListItem> {
                    new CompletionListItem(target, sci, OnItemClick)
                };
                CompletionList.Insert(0, new CompletionListItem(mathes, sci, OnItemClick));
                sci.DisableAllSciEvents = true;
                PluginCore.Controls.CompletionList.Show(CompletionList, true);
            }
            else
            {
                GenerateExtractVariable(target);
            }
        }
 /// <summary>
 /// Gets search results for a document
 /// </summary>
 private List <SearchMatch> GetResults(ScintillaControl sci, Boolean simple)
 {
     if (this.findComboBox.Text != String.Empty)
     {
         String   pattern = this.findComboBox.Text;
         FRSearch search  = new FRSearch(pattern);
         search.NoCase = !this.matchCaseCheckBox.Checked;
         search.Filter = SearchFilter.None;
         if (!simple)
         {
             search.IsRegex   = this.useRegexCheckBox.Checked;
             search.IsEscaped = this.escapedCheckBox.Checked;
             search.WholeWord = this.wholeWordCheckBox.Checked;
             if (this.lookComboBox.SelectedIndex == 2)
             {
                 search.Filter = SearchFilter.OutsideCodeComments;
             }
             else if (this.lookComboBox.SelectedIndex == 3)
             {
                 search.Filter = SearchFilter.InCodeComments | SearchFilter.OutsideStringLiterals;
             }
             else if (this.lookComboBox.SelectedIndex == 4)
             {
                 search.Filter = SearchFilter.InStringLiterals | SearchFilter.OutsideCodeComments;
             }
         }
         return(search.Matches(sci.Text));
     }
     return(null);
 }
Пример #3
0
        /// <summary>
        /// Gets search results for a sci control
        /// </summary>
        private List <SearchMatch> GetResults(ScintillaControl sci, String text)
        {
            String   pattern = text;
            FRSearch search  = new FRSearch(pattern);

            search.Filter    = SearchFilter.None;
            search.NoCase    = !this.matchCaseCheckBox.Checked;
            search.WholeWord = this.wholeWordCheckBox.Checked;
            return(search.Matches(sci.Text));
        }
Пример #4
0
        private List <SearchMatch> GetResults(ScintillaControl sci, String text)
        {
            String   pattern = text;
            FRSearch search  = new FRSearch(pattern);

            search.Filter    = SearchFilter.OutsideCodeComments;
            search.NoCase    = true;
            search.WholeWord = true;
            return(search.Matches(sci.Text));
        }
Пример #5
0
        static List <SearchMatch> GetResults(ScintillaControl sci, string text)
        {
            FRSearch search = new FRSearch(text)
            {
                Filter    = SearchFilter.OutsideCodeComments,
                NoCase    = true,
                WholeWord = true
            };

            return(search.Matches(sci.Text));
        }
Пример #6
0
 /// <summary>
 /// Gets search results for a document
 /// </summary>
 private List <SearchMatch> GetResults(ScintillaControl sci)
 {
     if (this.searchBox.Text != String.Empty)
     {
         String   pattern = this.searchBox.Text;
         FRSearch search  = new FRSearch(pattern);
         search.IsEscaped = false;
         search.WholeWord = false;
         search.NoCase    = true;
         search.IsRegex   = true;
         search.Filter    = SearchFilter.None;
         return(search.Matches(sci.Text));
     }
     return(null);
 }
Пример #7
0
 /// <summary>
 /// Renames the given the set of matched references
 /// </summary>
 private void OnFindAllReferencesCompleted(object sender, RefactorCompleteEventArgs<IDictionary<string, List<SearchMatch>>> eventArgs)
 {
     UserInterfaceManager.ProgressDialog.Show();
     UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.UpdatingReferences"));
     MessageBar.Locked = true;
     var isParameterVar = (Target.Member?.Flags & FlagType.ParameterVar) > 0;
     foreach (var entry in eventArgs.Results)
     {
         UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + entry.Key + "\"");
         // re-open the document and replace all the text
         var doc = AssociatedDocumentHelper.LoadDocument(entry.Key);
         var sci = doc.SciControl;
         var targetMatches = entry.Value;
         if (isParameterVar)
         {
             var lineFrom = Target.Context.ContextFunction.LineFrom;
             var lineTo = Target.Context.ContextFunction.LineTo;
             var search = new FRSearch(NewName) {WholeWord = true, NoCase = false, SingleLine = true};
             var matches = search.Matches(sci.Text, sci.PositionFromLine(lineFrom), lineFrom);
             matches.RemoveAll(it => it.Line < lineFrom || it.Line > lineTo);
             if (matches.Count != 0)
             {
                 sci.BeginUndoAction();
                 try
                 {
                     for (var i = 0; i < matches.Count; i++)
                     {
                         var match = matches[i];
                         var expr = ASComplete.GetExpressionType(sci, sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value));
                         if (expr.IsNull() || expr.Context.Value != NewName) continue;
                         string replacement;
                         var flags = expr.Member.Flags;
                         if ((flags & FlagType.Static) > 0) replacement = ASContext.Context.CurrentClass.Name + "." + NewName;
                         else if((flags & FlagType.LocalVar) == 0) replacement = "this." + NewName;
                         else continue;
                         RefactoringHelper.SelectMatch(sci, match);
                         sci.EnsureVisible(sci.LineFromPosition(sci.MBSafePosition(match.Index)));
                         sci.ReplaceSel(replacement);
                         for (var j = 0; j < targetMatches.Count; j++)
                         {
                             var targetMatch = targetMatches[j];
                             if (targetMatch.Line <= match.Line) continue;
                             FRSearch.PadIndexes(targetMatches, j, match.Value, replacement);
                             if (targetMatch.Line == match.Line + 1)
                             {
                                 targetMatch.LineText = sci.GetLine(match.Line);
                                 targetMatch.Column += replacement.Length - match.Value.Length;
                             }
                             break;
                         }
                         FRSearch.PadIndexes(matches, i + 1, match.Value, replacement);
                     }
                 }
                 finally
                 {
                     sci.EndUndoAction();
                 }
             }
         }
         // replace matches in the current file with the new name
         RefactoringHelper.ReplaceMatches(targetMatches, sci, NewName);
         //Uncomment if we want to keep modified files
         //if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(entry.Key);
         doc.Save();
     }
     if (newFileName != null) RenameFile(eventArgs.Results);
     Results = eventArgs.Results;
     AssociatedDocumentHelper.CloseTemporarilyOpenedDocuments();
     if (OutputResults) ReportResults();
     UserInterfaceManager.ProgressDialog.Hide();
     MessageBar.Locked = false;
     FireOnRefactorComplete();
 }
Пример #8
0
	public static void Execute()
	{
		if ( Globals.SciControl == null ) return;
		ScintillaControl sci = Globals.SciControl;

		MainForm mainForm = (MainForm) Globals.MainForm;

		ITabbedDocument document = mainForm.CurrentDocument;

		String documentDirectory = Path.GetDirectoryName(document.FileName);

		ASContext context = (ASContext) ASContext.Context;
		string currentPackage = context.CurrentModel.Package;
		List<ClassModel> classes = context.CurrentModel.Classes;
		MemberList imports = context.CurrentModel.Imports;
		
		sci.BeginUndoAction();
		
		String pattern = "}";
		FRSearch search = new FRSearch(pattern);
		search.Filter = SearchFilter.None;
		List<SearchMatch> matches = search.Matches(sci.Text);
		if (matches == null || matches.Count == 0) return;
		if (classes.Count < 2) return;
		
		SearchMatch match = GetNextDocumentMatch(sci, matches, sci.PositionFromLine(classes[0].LineTo + 1));
		
		Int32 packageEnd = sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value); // wchar to byte text length
		
		String strImport = "";
		
		if (imports.Count > 0)
		{
			for (int i=imports.Count-1; i>0; --i ) 
			{
				MemberModel import = imports[i];
				if(packageEnd < sci.PositionFromLine(import.LineFrom)) {
					sci.SelectionStart = sci.PositionFromLine(import.LineFrom);
					sci.SelectionEnd = sci.PositionFromLine(import.LineTo + 1);
					strImport = sci.SelText + strImport;
					sci.Clear();
				}
			}
		}
		
		context.UpdateCurrentFile(true);
		
		Int32 prevClassEnd = packageEnd;
		
		foreach (ClassModel currentClass in classes)
		{
			// 最初のクラスは無視
			if (currentClass == classes[0]) continue;
			
			sci.SelectionStart = prevClassEnd;
			sci.SelectionEnd = sci.PositionFromLine(currentClass.LineTo + 1);
			
			String content = "package "
					   + currentPackage
					   + "\n{\n"
					   + Regex.Replace( strImport, @"^", "\t", RegexOptions.Multiline)
					   + Regex.Replace( sci.SelText, @"^", "\t", RegexOptions.Multiline)
					   + "\n}\n";
					   
			prevClassEnd = sci.PositionFromLine(currentClass.LineTo + 1);
			
			Encoding encoding = sci.Encoding;
			String file = documentDirectory + "\\" + currentClass.Name + ".as";
			FileHelper.WriteFile(file, content, encoding);
		}
		
		sci.SelectionStart = packageEnd;
		sci.Clear();		
		sci.EndUndoAction();
	}
Пример #9
0
        // 文字列検索
        private List <SearchMatch> searchString(ScintillaControl sci, String text)
        {
            FRSearch search = new FRSearch(text);

            return(search.Matches(sci.Text));
        }