private void PopulateConfig(MultiRenameForm dlg) { if (config != null && config.Count > 0) { dlg.Formula = config.GetString("Formula"); dlg.Counter = new StringHelper.CounterDetails(config.GetUInt("CounterStart", 1), config.GetUInt("CounterStep", 1), (int)config.GetUInt("CounterDigits", 3)); dlg.FormatIndex = (int)config.GetUInt("FormatIndex"); } }
private void StoreConfig(MultiRenameForm dlg) { if (dlg != null) { if (config == null) { config = ObjectFactory.LoadConfiguration(ConfigurationName); } StringHelper.CounterDetails counter = dlg.Counter; config.Add("Formula", dlg.Formula); config.Add("CounterStart", counter.Current); config.Add("CounterStep", counter.Step); config.Add("CounterDigits", (uint)counter.Digits); config.Add("FormatIndex", (uint)dlg.FormatIndex); } }
/// <summary> /// Invokes proper processing assigned to current action. /// </summary> public void Execute(object sender, EventArgs e) { CodeEditPoint editorEditPoint = parent.CurrentEditPoint; CodeEditSelection selectionData; IList <CodeFunction> methods; IList <string> names; int i = 0; if (!editorEditPoint.IsRefactorValid) { return; } // get selected methods inside the code editor: selectionData = EditorHelper.GetSelectedMethods(editorEditPoint, true); if (selectionData != null) { if (dlgRename == null) { dlgRename = new MultiRenameForm(); PopulateConfig(dlgRename); } // show confirmation dialog: dlgRename.InitInterface(EditorHelper.FilterMethods(selectionData.AllMethods, vsCMFunction.vsCMFunctionConstructor, vsCMFunction.vsCMFunctionDestructor), EditorHelper.FilterMethods(selectionData.Methods, vsCMFunction.vsCMFunctionConstructor, vsCMFunction.vsCMFunctionDestructor)); if (dlgRename.ShowDialog() == DialogResult.OK && dlgRename.ReadInterface(out methods, out names)) { // remember the latest settings: StoreConfig(dlgRename); // open the undo-context to combine all the modifications of the source code into one: parent.DTE.UndoContext.Open(SharedStrings.UndoContext_MultiRenameRefactor, true); // update the source code: if (methods != null && names != null) { foreach (CodeFunction m in methods) { try { // update the names: if (m.Name != names[i]) { m.Name = names[i]; } } catch (Exception ex) { Trace.WriteLine(ex.Message); } i++; } } // close the undo-context, so all the changes will be threated as one: parent.DTE.UndoContext.Close(); } } }