示例#1
0
 /// <summary>
 /// Do a synchronous text search/replace
 /// Use RepleaceAsync to run a background thread
 /// </summary>
 /// <param name="configuration">Replace operation parameters</param>
 /// <returns>Search results before replacement</returns>
 public FRResults ReplaceSync(FRConfiguration configuration)
 {
     try
     {
         FRResults     results     = new FRResults();
         List <String> files       = configuration.GetFiles();
         FRSearch      search      = configuration.GetSearch();
         string        replacement = configuration.Replacement;
         if (replacement == null)
         {
             return(results);
         }
         string             src;
         List <SearchMatch> matches;
         foreach (String file in files)
         {
             src = configuration.GetSource(file);
             search.SourceFile = file;
             results[file]     = matches = search.Matches(src);
             foreach (SearchMatch match in matches)
             {
                 src = search.ReplaceAll(src, replacement, matches);
                 configuration.SetSource(file, src);
             }
             matches = null;
         }
         return(results);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message + "\n" + ex.StackTrace);
         return(null);
     }
 }
示例#2
0
 /// <summary>
 /// Do a background text search/replace
 /// NOTE: You need to listen to the runner's events
 /// </summary>
 /// <param name="configuration">Replace operation parameters</param>
 public void ReplaceAsync(FRConfiguration configuration)
 {
     if (this.backgroundWorker == null)
     {
         this.CreateWorker();
     }
     this.backgroundWorker.RunWorkerAsync(configuration);
 }
示例#3
0
 /// <summary>
 /// Do a background text search
 /// NOTE: You need to listen to the runner's events
 /// </summary>
 /// <param name="configuration">Search operation parameters</param>
 public void SearchAsync(FRConfiguration configuration)
 {
     if (this.backgroundWorker == null)
     {
         this.CreateWorker();
     }
     configuration.Replacement = null;
     this.backgroundWorker.RunWorkerAsync(configuration);
 }
示例#4
0
 /// <summary>
 /// Do a synchronous search
 /// Use SearchAsync to run a background thread
 /// </summary>
 /// <param name="configuration">Search operation parameters</param>
 /// <returns>Search results</returns>
 public FRResults SearchSync(FRConfiguration configuration)
 {
     try
     {
         FRResults     results = new FRResults();
         List <String> files   = configuration.GetFiles();
         FRSearch      search  = configuration.GetSearch();
         foreach (String file in files)
         {
             String             src     = configuration.GetSource(file);
             List <SearchMatch> matches = search.Matches(src);
             FRSearch.ExtractResultsLineText(matches, src);
             results[file] = matches;
         }
         return(results);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message + "\n" + ex.StackTrace);
         return(null);
     }
 }
 /// <summary>
 /// Finds the given target in all project files.
 /// If the target is a local variable or function parameter, it will only search the associated file.
 /// Note: if running asynchronously, you must supply a listener to "findFinishedHandler" to retrieve the results.
 /// If running synchronously, do not set listeners and instead use the return value.
 /// </summary>
 /// <param name="target">the source member to find references to</param>
 /// <param name="progressReportHandler">event to fire as search results are compiled</param>
 /// <param name="findFinishedHandler">event to fire once searching is finished</param>
 /// <param name="asynchronous">executes in asynchronous mode</param>
 /// <returns>If "asynchronous" is false, will return the search results, otherwise returns null on bad input or if running in asynchronous mode.</returns>
 public static FRResults FindTargetInFiles(ASResult target, FRProgressReportHandler progressReportHandler, FRFinishedHandler findFinishedHandler, Boolean asynchronous)
 {
     Boolean currentFileOnly = false;
     // checks target is a member
     if (target == null || ((target.Member == null || String.IsNullOrEmpty(target.Member.Name))
         && (target.Type == null || !CheckFlag(target.Type.Flags, FlagType.Class) && !target.Type.IsEnum())))
     {
         return null;
     }
     else
     {
         // if the target we are trying to rename exists as a local variable or a function parameter we only need to search the current file
         if (target.Member != null && (
                 target.Member.Access == Visibility.Private
                 || RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.LocalVar)
                 || RefactoringHelper.CheckFlag(target.Member.Flags, FlagType.ParameterVar))
             )
         {
             currentFileOnly = true;
         }
     }
     FRConfiguration config;
     IProject project = PluginBase.CurrentProject;
     String file = PluginBase.MainForm.CurrentDocument.FileName;
     // This is out of the project, just look for this file...
     if (currentFileOnly || !IsProjectRelatedFile(project, file))
     {
         String mask = Path.GetFileName(file);
         String path = Path.GetDirectoryName(file);
         if (mask.Contains("[model]"))
         {
             if (findFinishedHandler != null)
             {
                 findFinishedHandler(new FRResults());
             }
             return null;
         }
         config = new FRConfiguration(path, mask, false, GetFRSearch(target.Member != null ? target.Member.Name : target.Type.Name));
     }
     else if (target.Member != null && !CheckFlag(target.Member.Flags, FlagType.Constructor))
     {
         config = new FRConfiguration(GetAllProjectRelatedFiles(project), GetFRSearch(target.Member.Name));
     }
     else
     {
         target.Member = null;
         config = new FRConfiguration(GetAllProjectRelatedFiles(project), GetFRSearch(target.Type.Name));
     }
     config.CacheDocuments = true;
     FRRunner runner = new FRRunner();
     if (progressReportHandler != null)
     {
         runner.ProgressReport += progressReportHandler;
     }
     if (findFinishedHandler != null)
     {
         runner.Finished += findFinishedHandler;
     }
     if (asynchronous) runner.SearchAsync(config);
     else return runner.SearchSync(config);
     return null;
 }
示例#6
0
        /// <summary>
        /// Background work main loop
        /// </summary>
        private void BackgroundWork(Object sender, DoWorkEventArgs e)
        {
            try
            {
                FRConfiguration configuration = e.Argument as FRConfiguration;
                if (configuration == null)
                {
                    e.Result = null;
                    return;
                }
                // get files
                Int32         count = 0;
                List <string> files = configuration.GetFiles();
                if (files == null || files.Count == 0)
                {
                    e.Result = new FRResults(); // empty results
                    return;
                }

                FRResults results     = new FRResults();
                FRSearch  search      = configuration.GetSearch();
                string    replacement = configuration.Replacement;

                if (this.backgroundWorker.CancellationPending)
                {
                    e.Cancel = true;
                }
                else
                {
                    // do search
                    Int32 total       = files.Count;
                    Int32 lastPercent = 0;
                    List <SearchMatch> matches;
                    string             src;
                    foreach (String file in files)
                    {
                        if (this.backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                        }
                        else
                        {
                            // work
                            src = configuration.GetSource(file);
                            search.SourceFile = file;
                            results[file]     = matches = search.Matches(src);

                            if (matches.Count > 0)
                            {
                                if (replacement != null)
                                {
                                    // replace text
                                    src = search.ReplaceAll(src, replacement, matches);
                                    configuration.SetSource(file, src);
                                }
                                else
                                {
                                    FRSearch.ExtractResultsLineText(matches, src);
                                }
                            }
                            matches = null;

                            // progress
                            count++;
                            Int32 percent = (100 * count) / total;
                            if (lastPercent != percent)
                            {
                                this.backgroundWorker.ReportProgress(percent);
                                lastPercent = percent;
                            }
                        }
                    }
                }
                e.Result = results;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception during background operation:\n" + ex.Message + "\n" + ex.StackTrace);
                e.Result = null;
            }
        }
示例#7
0
 private static void Replace(List<String> path, String search, String replace)
 {
     FRConfiguration config = new FRConfiguration(path, GetFRSearch(search));
     config.Replacement = replace;
     runner = new FRRunner();
     runner.ProgressReport += new FRProgressReportHandler(RunnerProgress);
     runner.Finished += new FRFinishedHandler(ReplaceFinished);
     runner.ReplaceAsync(config);
 }
 /// <summary>
 /// Finds the given target in all project files.
 /// If the target is a local variable or function parameter, it will only search the associated file.
 /// Note: if running asynchronously, you must supply a listener to "findFinishedHandler" to retrieve the results.
 /// If running synchronously, do not set listeners and instead use the return value.
 /// </summary>
 /// <param name="target">the source member to find references to</param>
 /// <param name="progressReportHandler">event to fire as search results are compiled</param>
 /// <param name="findFinishedHandler">event to fire once searching is finished</param>
 /// <param name="asynchronous">executes in asynchronous mode</param>
 /// <returns>If "asynchronous" is false, will return the search results, otherwise returns null on bad input or if running in asynchronous mode.</returns>
 public static FRResults FindTargetInFiles(ASResult target, FRProgressReportHandler progressReportHandler, FRFinishedHandler findFinishedHandler, Boolean asynchronous)
 {
     Boolean currentFileOnly = false;
     // checks target is a member
     if (target == null || ((target.Member == null || target.Member.Name == null || target.Member.Name == String.Empty) && (target.Type == null || CheckFlag(FlagType.Class, target.Type.Flags))))
     {
         return null;
     }
     else
     {
         // if the target we are trying to rename exists as a local variable or a function parameter we only need to search the current file
         if (target.Member != null && (RefactoringHelpera.CheckFlag(target.Member.Flags, FlagType.LocalVar) || RefactoringHelpera.CheckFlag(target.Member.Flags, FlagType.ParameterVar)))
         {
             currentFileOnly = true;
         }
     }
     // sets the FindInFiles settings to the project root, *.as files, and recursive
     String path = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath);
     if (!PluginBase.MainForm.CurrentDocument.FileName.StartsWith(path))
     {
         // This is out of the project, just look for this file...
         currentFileOnly = true;
     }
     String mask = "*.as;*.hx";
     Boolean recursive = true;
     // but if it's only the current file, let's just search that!
     if (currentFileOnly)
     {
         path = Path.GetDirectoryName(PluginBase.MainForm.CurrentDocument.FileName);
         mask = Path.GetFileName(PluginBase.MainForm.CurrentDocument.FileName);
         recursive = false;
     }
     FRConfiguration config = new FRConfiguration(path, mask, recursive, GetFRSearch(target.Member.Name));
     config.CacheDocuments = true;
     FRRunner runner = new FRRunner();
     if (progressReportHandler != null)
     {
         runner.ProgressReport += progressReportHandler;
     }
     if (findFinishedHandler != null)
     {
         runner.Finished += findFinishedHandler;
     }
     if (asynchronous) runner.SearchAsync(config);
     else return runner.SearchSync(config);
     return null;
 }
示例#9
0
 /// <summary>
 /// Runs the replace based on the user specified arguments
 /// </summary>
 private void ReplaceButtonClick(Object sender, EventArgs e)
 {
     String path = this.folderComboBox.Text;
     String mask = this.extensionComboBox.Text;
     Boolean recursive = this.subDirectoriesCheckBox.Checked;
     if (this.findComboBox.Text.Trim() != "")
     {
         if (!Globals.Settings.DisableReplaceFilesConfirm)
         {
             String caption = TextHelper.GetString("Title.ConfirmDialog");
             String message = TextHelper.GetString("Info.AreYouSureToReplaceInFiles");
             DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
             if (result == DialogResult.Cancel) return;
         }
         this.UpdateUIState(true);
         FRConfiguration config = new FRConfiguration(path, mask, recursive, this.GetFRSearch());
         config.Replacement = this.replaceComboBox.Text;
         this.runner = new FRRunner();
         this.runner.ProgressReport += new FRProgressReportHandler(this.RunnerProgress);
         this.runner.Finished += new FRFinishedHandler(this.ReplaceFinished);
         this.runner.ReplaceAsync(config);
         //
         FRDialogGenerics.UpdateComboBoxItems(this.folderComboBox);
         FRDialogGenerics.UpdateComboBoxItems(this.extensionComboBox);
         FRDialogGenerics.UpdateComboBoxItems(this.replaceComboBox);
         FRDialogGenerics.UpdateComboBoxItems(this.findComboBox);
     }
 }
示例#10
0
 /// <summary>
 /// Runs the find based on the user specified arguments
 /// </summary>
 private void FindButtonClick(Object sender, EventArgs e)
 {
     String path = this.folderComboBox.Text;
     String mask = this.extensionComboBox.Text;
     Boolean recursive = this.subDirectoriesCheckBox.Checked;
     if (this.findComboBox.Text.Trim() != "")
     {
         this.UpdateUIState(true);
         FRConfiguration config = new FRConfiguration(path, mask, recursive, this.GetFRSearch());
         this.runner = new FRRunner();
         this.runner.ProgressReport += new FRProgressReportHandler(this.RunnerProgress);
         this.runner.Finished += new FRFinishedHandler(this.FindFinished);
         this.runner.SearchAsync(config);
         //
         FRDialogGenerics.UpdateComboBoxItems(this.folderComboBox);
         FRDialogGenerics.UpdateComboBoxItems(this.extensionComboBox);
         FRDialogGenerics.UpdateComboBoxItems(this.findComboBox);
     }
 }