protected override void ExecutionImplementation() { String oldFileName = Path.GetFileNameWithoutExtension(oldPath); String newFileName = Path.GetFileNameWithoutExtension(newPath); String msg = TextHelper.GetString("Info.RenamingFile"); String title = String.Format(TextHelper.GetString("Title.RenameDialog"), oldFileName); if (MessageBox.Show(msg, title, MessageBoxButtons.YesNo) == DialogResult.Yes) { var target = RefactoringHelper.GetRefactorTargetFromFile(oldPath, AssociatedDocumentHelper); if (target != null) { Rename command = new Rename(target, true, newFileName); command.RegisterDocumentHelper(AssociatedDocumentHelper); command.Execute(); return; } } // refactor failed or was refused if (Path.GetFileName(oldPath).Equals(newPath, StringComparison.OrdinalIgnoreCase)) { // name casing changed string tmpPath = oldPath + "$renaming$"; File.Move(oldPath, tmpPath); oldPath = tmpPath; } if (!Path.IsPathRooted(newPath)) { newPath = Path.Combine(Path.GetDirectoryName(oldPath), newPath); } if (FileHelper.ConfirmOverwrite(newPath)) { FileHelper.ForceMove(oldPath, newPath); PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath); } }
protected override void ExecutionImplementation() { String oldFileName = Path.GetFileNameWithoutExtension(oldPath); String newFileName = Path.GetFileNameWithoutExtension(newPath); String msg = TextHelper.GetString("Info.RenamingFile"); String title = String.Format(TextHelper.GetString("Title.RenameDialog"), oldFileName); if (MessageBox.Show(msg, title, MessageBoxButtons.YesNo) == DialogResult.Yes) { Int32 line = 0; PluginBase.MainForm.OpenEditableDocument(oldPath, false); ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; if (sci == null) { return; // Should not happen... } List <ClassModel> classes = ASContext.Context.CurrentModel.Classes; if (classes.Count > 0) { foreach (ClassModel classModel in classes) { if (classModel.Name.Equals(oldFileName)) { line = classModel.LineFrom; } } } else { MemberList members = ASContext.Context.CurrentModel.Members; foreach (MemberModel member in members) { if (member.Name.Equals(oldFileName)) { line = member.LineFrom; } } } if (line > 0) { sci.SelectText(oldFileName, sci.PositionFromLine(line)); Rename command = new Rename(RefactoringHelper.GetDefaultRefactorTarget(), true, newFileName); command.Execute(); return; } } // refactor failed or was refused if (Path.GetFileName(oldPath).Equals(newPath, StringComparison.OrdinalIgnoreCase)) { // name casing changed string tmpPath = oldPath + "$renaming$"; File.Move(oldPath, tmpPath); oldPath = tmpPath; } if (!Path.IsPathRooted(newPath)) { newPath = Path.Combine(Path.GetDirectoryName(oldPath), newPath); } File.Move(oldPath, newPath); PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath); }