Пример #1
0
 /// <summary>
 /// Invoked when the user selects the "Rename" command
 /// </summary>
 private void RenameClicked(Object sender, EventArgs e)
 {
     try
     {
         RenamingHelper.AddToQueue(RefactoringHelper.GetDefaultRefactorTarget());
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
     }
 }
Пример #2
0
            static string Common(ScintillaControl sci, string sourceText, string newName)
            {
                SetSrc(sci, sourceText);
                var waitHandle = new AutoResetEvent(false);

                CommandFactoryProvider.GetFactory(sci)
                .CreateRenameCommandAndExecute(RefactoringHelper.GetDefaultRefactorTarget(), false, newName)
                .OnRefactorComplete += (sender, args) => waitHandle.Set();
                var end    = DateTime.Now.AddSeconds(2);
                var result = false;

                while ((!result) && (DateTime.Now < end))
                {
                    context.Send(state => {}, new {});
                    result = waitHandle.WaitOne(0);
                }
                return(sci.Text);
            }
 /// <summary>
 /// A new FindAllReferences refactoring command.
 /// Uses the current text location as the declaration target.
 /// </summary>
 /// <param name="output">If true, will send the found results to the trace log and results panel</param>
 public FindAllReferences(Boolean output) : this(RefactoringHelper.GetDefaultRefactorTarget(), output)
 {
     this.outputResults = output;
 }
Пример #4
0
 /// <summary>
 /// A new Rename refactoring command.
 /// Uses the current text location as the declaration target.
 /// </summary>
 /// <param name="outputResults">If true, will send the found results to the trace log and results panel</param>
 /// <param name="inline">Whether to use inline renaming.</param>
 public Rename(bool outputResults, bool inline = false)
    : this(RefactoringHelper.GetDefaultRefactorTarget(), outputResults, inline) { }
Пример #5
0
 /// <summary>
 /// A new Rename refactoring command.
 /// Uses the current text location as the declaration target.
 /// </summary>
 /// <param name="outputResults">If true, will send the found results to the trace log and results panel</param>
 public Rename(Boolean outputResults) : this(RefactoringHelper.GetDefaultRefactorTarget(), outputResults)
 {
 }
Пример #6
0
        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);
        }