Esempio n. 1
0
 /// <summary>
 /// Renames the given the set of matched references
 /// </summary>
 private void OnFindAllReferencesCompleted(object sender, RefactorCompleteEventArgs <IDictionary <string, List <SearchMatch> > > eventArgs)
 {
     UserInterfaceManager.ProgressDialog.Show();
     UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.UpdatingReferences"));
     MessageBar.Locked = true;
     foreach (var entry in eventArgs.Results)
     {
         UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + entry.Key + "\"");
         // re-open the document and replace all the text
         var doc = AssociatedDocumentHelper.LoadDocument(entry.Key);
         var sci = doc.SciControl;
         // replace matches in the current file with the new name
         RefactoringHelper.ReplaceMatches(entry.Value, sci, NewName);
         //Uncomment if we want to keep modified files
         //if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(entry.Key);
         doc.Save();
     }
     if (newFileName != null)
     {
         RenameFile(eventArgs.Results);
     }
     Results = eventArgs.Results;
     AssociatedDocumentHelper.CloseTemporarilyOpenedDocuments();
     if (OutputResults)
     {
         ReportResults();
     }
     UserInterfaceManager.ProgressDialog.Hide();
     MessageBar.Locked = false;
     FireOnRefactorComplete();
 }
Esempio n. 2
0
        /// <summary>
        /// Renames the given the set of matched references
        /// </summary>
        private void OnFindAllReferencesCompleted(Object sender, RefactorCompleteEventArgs <IDictionary <string, List <SearchMatch> > > eventArgs)
        {
            UserInterfaceManager.ProgressDialog.Show();
            UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.RenamingReferences"));
            PluginCore.Controls.MessageBar.Locked = true;
            foreach (KeyValuePair <String, List <SearchMatch> > entry in eventArgs.Results)
            {
                UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + entry.Key + "\"");
                // re-open the document and replace all the text
                PluginBase.MainForm.OpenEditableDocument(entry.Key);
                ScintillaControl sci = ASContext.CurSciControl;
                // replace matches in the current file with the new name
                RefactoringHelper.ReplaceMatches(entry.Value, sci, this.newName, sci.Text);
                if (sci.IsModify)
                {
                    this.AssociatedDocumentHelper.MarkDocumentToKeep(sci.FileName);
                }
            }
            this.Results = eventArgs.Results;
            if (this.outputResults)
            {
                this.ReportResults();
            }
            UserInterfaceManager.ProgressDialog.Hide();
            PluginCore.Controls.MessageBar.Locked = false;
            this.FireOnRefactorComplete();

            RenameFile();
        }
Esempio n. 3
0
        private void FindFinished(FRResults results)
        {
            UserInterfaceManager.ProgressDialog.Show();
            UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.UpdatingReferences"));
            MessageBar.Locked = true;
            bool   isNotHaxe         = !PluginBase.CurrentProject.Language.StartsWith("haxe");
            bool   packageIsNotEmpty = !string.IsNullOrEmpty(currentTarget.OldFileModel.Package);
            string targetName        = Path.GetFileNameWithoutExtension(currentTarget.OldFilePath);
            string oldType           = (currentTarget.OldFileModel.Package + "." + targetName).Trim('.');
            string newType           = (currentTarget.NewPackage + "." + targetName).Trim('.');

            foreach (KeyValuePair <string, List <SearchMatch> > entry in results)
            {
                List <SearchMatch> matches = entry.Value;
                if (matches.Count == 0)
                {
                    continue;
                }
                string path = entry.Key;
                UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + path + "\"");
                ScintillaControl sci = AssociatedDocumentHelper.LoadDocument(path);
                if (isNotHaxe && path != currentTarget.NewFilePath && ASContext.Context.CurrentModel.Imports.Search(targetName, FlagType.Class & FlagType.Function & FlagType.Namespace, 0) == null)
                {
                    ASGenerator.InsertImport(new MemberModel(targetName, newType, FlagType.Import, 0), false);
                }
                if (packageIsNotEmpty)
                {
                    RefactoringHelper.ReplaceMatches(matches, sci, newType, null);
                }
                else
                {
                    foreach (SearchMatch sm in matches)
                    {
                        if (sm.LineText.TrimStart().StartsWith("import"))
                        {
                            RefactoringHelper.SelectMatch(sci, sm);
                            sci.ReplaceSel(newType);
                        }
                    }
                }
                foreach (SearchMatch match in matches)
                {
                    match.LineText = sci.GetLine(match.Line - 1);
                    match.Value    = newType;
                }
                if (!Results.ContainsKey(path))
                {
                    Results[path] = new List <SearchMatch>();
                }
                Results[path].AddRange(matches.ToArray());
                PluginBase.MainForm.CurrentDocument.Save();
                if (sci.IsModify)
                {
                    AssociatedDocumentHelper.MarkDocumentToKeep(path);
                }
            }
            UserInterfaceManager.ProgressDialog.Hide();
            MessageBar.Locked = false;
            UpdateReferencesNextTarget();
        }
Esempio n. 4
0
        void GenerateExtractVariable(List <SearchMatch> matches)
        {
            if (string.IsNullOrEmpty(newName))
            {
                newName = GetNewName();
            }
            if (string.IsNullOrEmpty(newName))
            {
                return;
            }
            var sci = PluginBase.MainForm.CurrentDocument.SciControl;

            sci.BeginUndoAction();
            try
            {
                var expression = sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
                expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
                expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });
                var insertPosition = sci.PositionFromLine(ASContext.Context.CurrentMember.LineTo);
                foreach (var match in matches)
                {
                    var position = sci.MBSafePosition(match.Index);
                    insertPosition = Math.Min(insertPosition, position);
                    match.LineText = sci.GetLine(match.Line - 1);
                }
                insertPosition = sci.LineFromPosition(insertPosition);
                insertPosition = sci.LineIndentPosition(insertPosition);
                RefactoringHelper.ReplaceMatches(matches, sci, newName);
                sci.SetSel(insertPosition, insertPosition);
                var member = new MemberModel(newName, string.Empty, FlagType.LocalVar, 0)
                {
                    Value = expression
                };
                var snippet = TemplateUtils.GetTemplate("Variable");
                snippet  = TemplateUtils.ReplaceTemplateVariable(snippet, "Modifiers", null);
                snippet  = TemplateUtils.ToDeclarationString(member, snippet);
                snippet += "$(Boundary)\n$(Boundary)";
                SnippetHelper.InsertSnippetText(sci, sci.CurrentPos, snippet);
                foreach (var match in matches)
                {
                    match.Line += 1;
                }
                Results = new Dictionary <string, List <SearchMatch> > {
                    { sci.FileName, matches }
                };
                if (outputResults)
                {
                    ReportResults();
                }
            }
            finally
            {
                sci.EndUndoAction();
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Renames the given the set of matched references
 /// </summary>
 private void OnFindAllReferencesCompleted(object sender, RefactorCompleteEventArgs<IDictionary<string, List<SearchMatch>>> eventArgs)
 {
     UserInterfaceManager.ProgressDialog.Show();
     UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.UpdatingReferences"));
     MessageBar.Locked = true;
     var isParameterVar = (Target.Member?.Flags & FlagType.ParameterVar) > 0;
     foreach (var entry in eventArgs.Results)
     {
         UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + entry.Key + "\"");
         // re-open the document and replace all the text
         var doc = AssociatedDocumentHelper.LoadDocument(entry.Key);
         var sci = doc.SciControl;
         var targetMatches = entry.Value;
         if (isParameterVar)
         {
             var lineFrom = Target.Context.ContextFunction.LineFrom;
             var lineTo = Target.Context.ContextFunction.LineTo;
             var search = new FRSearch(NewName) {WholeWord = true, NoCase = false, SingleLine = true};
             var matches = search.Matches(sci.Text, sci.PositionFromLine(lineFrom), lineFrom);
             matches.RemoveAll(it => it.Line < lineFrom || it.Line > lineTo);
             if (matches.Count != 0)
             {
                 sci.BeginUndoAction();
                 try
                 {
                     for (var i = 0; i < matches.Count; i++)
                     {
                         var match = matches[i];
                         var expr = ASComplete.GetExpressionType(sci, sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value));
                         if (expr.IsNull() || expr.Context.Value != NewName) continue;
                         string replacement;
                         var flags = expr.Member.Flags;
                         if ((flags & FlagType.Static) > 0) replacement = ASContext.Context.CurrentClass.Name + "." + NewName;
                         else if((flags & FlagType.LocalVar) == 0) replacement = "this." + NewName;
                         else continue;
                         RefactoringHelper.SelectMatch(sci, match);
                         sci.EnsureVisible(sci.LineFromPosition(sci.MBSafePosition(match.Index)));
                         sci.ReplaceSel(replacement);
                         for (var j = 0; j < targetMatches.Count; j++)
                         {
                             var targetMatch = targetMatches[j];
                             if (targetMatch.Line <= match.Line) continue;
                             FRSearch.PadIndexes(targetMatches, j, match.Value, replacement);
                             if (targetMatch.Line == match.Line + 1)
                             {
                                 targetMatch.LineText = sci.GetLine(match.Line);
                                 targetMatch.Column += replacement.Length - match.Value.Length;
                             }
                             break;
                         }
                         FRSearch.PadIndexes(matches, i + 1, match.Value, replacement);
                     }
                 }
                 finally
                 {
                     sci.EndUndoAction();
                 }
             }
         }
         // replace matches in the current file with the new name
         RefactoringHelper.ReplaceMatches(targetMatches, sci, NewName);
         //Uncomment if we want to keep modified files
         //if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(entry.Key);
         doc.Save();
     }
     if (newFileName != null) RenameFile(eventArgs.Results);
     Results = eventArgs.Results;
     AssociatedDocumentHelper.CloseTemporarilyOpenedDocuments();
     if (OutputResults) ReportResults();
     UserInterfaceManager.ProgressDialog.Hide();
     MessageBar.Locked = false;
     FireOnRefactorComplete();
 }
Esempio n. 6
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();
     }
 }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 private void UpdateReferencesNextTarget()
 {
     if (targets.Count > 0)
     {
         currentTarget = targets[0];
         targets.Remove(currentTarget);
         FileModel oldFileModel = currentTarget.OldFileModel;
         FRSearch  search;
         string    newType;
         if (string.IsNullOrEmpty(oldFileModel.Package))
         {
             search  = new FRSearch("(package)+\\s*");
             newType = Path.GetFileNameWithoutExtension(currentTarget.OldFilePath);
         }
         else
         {
             search  = new FRSearch("(package)+\\s+(" + oldFileModel.Package + ")\\s*");
             newType = oldFileModel.Package + "." + Path.GetFileNameWithoutExtension(currentTarget.OldFilePath);
         }
         search.IsRegex    = true;
         search.Filter     = SearchFilter.None;
         newType           = newType.Trim('.');
         MessageBar.Locked = true;
         string             newFilePath = currentTarget.NewFilePath;
         ScintillaControl   sci         = AssociatedDocumentHelper.LoadDocument(newFilePath);
         List <SearchMatch> matches     = search.Matches(sci.Text);
         RefactoringHelper.ReplaceMatches(matches, sci, "package " + currentTarget.NewPackage + " ", null);
         int offset = "package ".Length;
         foreach (SearchMatch match in matches)
         {
             match.Column  += offset;
             match.LineText = sci.GetLine(match.Line - 1);
             match.Value    = currentTarget.NewPackage;
         }
         if (!Results.ContainsKey(newFilePath))
         {
             Results[newFilePath] = new List <SearchMatch>();
         }
         Results[newFilePath].AddRange(matches.ToArray());
         PluginBase.MainForm.CurrentDocument.Save();
         if (sci.IsModify)
         {
             AssociatedDocumentHelper.MarkDocumentToKeep(currentTarget.OldFilePath);
         }
         MessageBar.Locked = false;
         UserInterfaceManager.ProgressDialog.Show();
         UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.FindingReferences"));
         UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.SearchingFiles"));
         ASResult target = new ASResult()
         {
             Member = new MemberModel(newType, newType, FlagType.Import, 0)
         };
         RefactoringHelper.FindTargetInFiles(target, UserInterfaceManager.ProgressDialog.UpdateProgress, FindFinished, true);
     }
     else
     {
         if (outputResults)
         {
             ReportResults();
         }
         FireOnRefactorComplete();
     }
 }