Ejemplo n.º 1
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)
            {
                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);
            }
        }
Ejemplo n.º 2
0
 private void UpdateReferencesNextTarget()
 {
     if (currentTargetIndex < targets.Count)
     {
         var       currentTarget = targets[currentTargetIndex];
         FileModel oldFileModel  = currentTarget.OldFileModel;
         FRSearch  search;
         string    oldType;
         if (string.IsNullOrEmpty(oldFileModel.Package))
         {
             search           = new FRSearch("package");
             search.WholeWord = true;
             oldType          = Path.GetFileNameWithoutExtension(currentTarget.OldFilePath);
         }
         else
         {
             search  = new FRSearch("package\\s+(" + oldFileModel.Package + ")");
             oldType = oldFileModel.Package + "." + Path.GetFileNameWithoutExtension(currentTarget.OldFilePath);
         }
         search.IsRegex    = true;
         search.Filter     = SearchFilter.None;
         oldType           = oldType.Trim('.');
         MessageBar.Locked = true;
         string           newFilePath = currentTarget.NewFilePath;
         var              doc         = AssociatedDocumentHelper.LoadDocument(currentTarget.TmpFilePath ?? newFilePath);
         ScintillaControl sci         = doc.SciControl;
         search.SourceFile = sci.FileName;
         List <SearchMatch> matches            = search.Matches(sci.Text);
         string             packageReplacement = "package";
         if (currentTarget.NewPackage != "")
         {
             packageReplacement += " " + currentTarget.NewPackage;
         }
         RefactoringHelper.ReplaceMatches(matches, sci, packageReplacement);
         int offset = "package ".Length;
         foreach (SearchMatch match in matches)
         {
             match.Column  += offset;
             match.LineText = sci.GetLine(match.Line - 1);
             match.Value    = currentTarget.NewPackage;
         }
         if (matches.Count > 0)
         {
             if (!Results.ContainsKey(newFilePath))
             {
                 Results[newFilePath] = new List <SearchMatch>();
             }
             Results[newFilePath].AddRange(matches);
         }
         else if (sci.ConfigurationLanguage == "haxe")
         {
             // haxe modules don't need to specify a package if it's empty
             sci.InsertText(0, packageReplacement + ";\n\n");
         }
         //Do we want to open modified files?
         //if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(file);
         doc.Save();
         MessageBar.Locked = false;
         UserInterfaceManager.ProgressDialog.Show();
         UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.FindingReferences"));
         UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.SearchingFiles"));
         currentTargetResult = RefactoringHelper.GetRefactorTargetFromFile(oldFileModel.FileName, AssociatedDocumentHelper);
         if (currentTargetResult != null)
         {
             RefactoringHelper.FindTargetInFiles(currentTargetResult, UserInterfaceManager.ProgressDialog.UpdateProgress, FindFinished, true, true, true);
         }
         else
         {
             currentTargetIndex++;
             UserInterfaceManager.ProgressDialog.Hide();
             UpdateReferencesNextTarget();
         }
     }
     else
     {
         MoveRefactoredFiles();
         ReopenInitialFiles();
         FireOnRefactorComplete();
     }
 }