/// <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; 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; // replace matches in the current file with the new name RefactoringHelper.ReplaceMatches(entry.Value, 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(); }
/// <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.RenamingReferences")); PluginCore.Controls.MessageBar.Locked = true; foreach (KeyValuePair <String, List <SearchMatch> > entry in eventArgs.Results) { UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + entry.Key + "\""); // re-open the document and replace all the text PluginBase.MainForm.OpenEditableDocument(entry.Key); ScintillaControl sci = ASContext.CurSciControl; // replace matches in the current file with the new name RefactoringHelper.ReplaceMatches(entry.Value, sci, this.newName, sci.Text); if (sci.IsModify) { this.AssociatedDocumentHelper.MarkDocumentToKeep(sci.FileName); } } this.Results = eventArgs.Results; if (this.outputResults) { this.ReportResults(); } UserInterfaceManager.ProgressDialog.Hide(); PluginCore.Controls.MessageBar.Locked = false; this.FireOnRefactorComplete(); RenameFile(); }
/// <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(); }
private void OnRenamePackageComplete(object sender, RefactorCompleteEventArgs<IDictionary<string, List<SearchMatch>>> args) { Results = args.Results; FireOnRefactorComplete(); }