コード例 #1
0
        /// <summary>
        /// Replaces all results specified by user input
        /// </summary>
        private void ReplaceAllButtonClick(Object sender, System.EventArgs e)
        {
            if (Globals.SciControl == null)
            {
                return;
            }
            ScintillaControl   sci           = Globals.SciControl;
            List <SearchMatch> matches       = this.GetResults(sci);
            Boolean            selectionOnly = this.lookComboBox.SelectedIndex == 1 && sci.SelText.Length > 0;

            if (matches != null && selectionOnly)
            {
                Int32 end   = sci.MBSafeCharPosition(sci.SelectionEnd);
                Int32 start = sci.MBSafeCharPosition(sci.SelectionStart);
                matches = FRDialogGenerics.FilterMatches(matches, start, end);
            }
            if (matches != null)
            {
                sci.BeginUndoAction();
                try
                {
                    for (Int32 i = 0, count = matches.Count; i < count; i++)
                    {
                        if (!selectionOnly)
                        {
                            FRDialogGenerics.SelectMatch(sci, matches[i]);
                        }
                        else
                        {
                            FRDialogGenerics.SelectMatchInTarget(sci, matches[i]);
                        }
                        String replaceWith = this.GetReplaceText(matches[i]);
                        FRSearch.PadIndexes(matches, i, matches[i].Value, replaceWith);
                        sci.EnsureVisible(sci.CurrentLine);
                        if (!selectionOnly)
                        {
                            sci.ReplaceSel(replaceWith);
                        }
                        else
                        {
                            sci.ReplaceTarget(sci.MBSafeTextLength(replaceWith), replaceWith);
                        }
                    }
                }
                finally
                {
                    sci.EndUndoAction();
                }
                FRDialogGenerics.UpdateComboBoxItems(this.findComboBox);
                FRDialogGenerics.UpdateComboBoxItems(this.replaceComboBox);
                String message   = TextHelper.GetString("Info.ReplacedMatches");
                String formatted = String.Format(message, matches.Count);
                this.ShowMessage(formatted, 0);
                this.lookupIsDirty = false;
            }
        }
コード例 #2
0
 /// <summary>
 /// Replaces only the matches in the current sci control
 /// </summary>
 public static void ReplaceMatches(IList <SearchMatch> matches, ScintillaControl sci, String replacement, String src)
 {
     if (sci == null || matches == null || matches.Count == 0)
     {
         return;
     }
     sci.BeginUndoAction();
     try
     {
         for (Int32 i = 0; i < matches.Count; i++)
         {
             SelectMatch(sci, matches[i]);
             FRSearch.PadIndexes((List <SearchMatch>)matches, i, matches[i].Value, replacement);
             sci.EnsureVisible(sci.LineFromPosition(sci.MBSafePosition(matches[i].Index)));
             sci.ReplaceSel(replacement);
         }
     }
     finally
     {
         sci.EndUndoAction();
     }
 }
コード例 #3
0
ファイル: Rename.cs プロジェクト: zvoronz/flashdevelop
 /// <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();
 }