/// <summary> /// Begins the process of renaming. /// </summary> private void StartRename(bool useInline, string oldName, string newName) { if (!string.IsNullOrEmpty(newName)) { OnApply(null, oldName, newName); return; } if (useInline) { var sci = PluginBase.MainForm.CurrentDocument.SciControl; int position = sci.WordEndPosition(sci.CurrentPos, true); var inlineRename = new InlineRename(sci, oldName, position, null, null, isRenamePackage ? new bool?() : new bool?(true), Target); inlineRename.Apply += OnApply; inlineRename.Cancel += OnCancel; } else { string title = " " + string.Format(TextHelper.GetString("Title.RenameDialog"), oldName); string label = TextHelper.GetString("Label.NewName"); var dialog = new LineEntryDialog(title, label, oldName); switch (dialog.ShowDialog()) { case DialogResult.OK: OnApply(null, oldName, dialog.Line.Trim()); break; case DialogResult.Cancel: OnCancel(null); break; } } }
/// <summary> /// Add this <see cref="InlineRename"/> object as a message filter and handle internal /// messages and handle <see cref="ScintillaControl"/> events. /// </summary> private void AddMessageFilter() { Application.AddMessageFilter(this); sci.SelectionChanged += Sci_SelectionChanged; sci.TextInserted += Sci_TextInserted; sci.TextDeleted += Sci_TextDeleted; Current = this; }
/// <summary> /// Update the default flags and clean up. /// </summary> private void UpdateDefaultFlags(InlineRename inlineRename) { if (inlineRename != null) { inlineRename.Apply -= OnApply; inlineRename.Cancel -= OnCancel; } }
/// <summary> /// Cancel renaming and clean up. /// </summary> private void OnCancel(InlineRename sender) { UpdateDefaultFlags(sender); if (findAllReferencesCommand != null) { findAllReferencesCommand.OnRefactorComplete -= OnFindAllReferencesCompleted; } }
/// <summary> /// Apply the new name. /// </summary> private void OnApply(InlineRename sender, string oldName, string newName) { UpdateDefaultFlags(sender); if (newName.Length == 0 || oldName == newName) return; if (isRenamePackage) { renamePackage = new Move(new Dictionary<string, string> { { renamePackagePath, newName } }, true, true); } OldName = oldName; NewName = newName; RenamingHelper.AddToQueue(this); }
/// <summary> /// Remove this <see cref="InlineRename"/> from the system message filters, dispose any /// resources used, and re-enable controls from <see cref="IMainForm"/>. /// </summary> void IDisposable.Dispose() { Application.RemoveMessageFilter(this); sci.SelectionChanged -= Sci_SelectionChanged; sci.TextInserted -= Sci_TextInserted; sci.TextDeleted -= Sci_TextDeleted; Current = null; currentDoc = null; currentRef = null; refs = null; history.Clear(); history = null; PluginBase.MainForm.MenuStrip.Enabled = true; PluginBase.MainForm.ToolStrip.Enabled = true; PluginBase.MainForm.EditorMenu.Enabled = true; UITools.Manager.DisableEvents = false; }