Exemple #1
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();
        }
Exemple #2
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();
     }
 }