示例#1
0
 public FRConfiguration(String fileName, String source, FRSearch search)
 {
     this.type = OperationType.FindInSource;
     this.path = fileName;
     this.search = search;
     this.source = source;
 }
示例#2
0
 public FRConfiguration(String path, String fileMask, Boolean recursive, FRSearch search)
 {
     this.path = path;
     this.type = OperationType.FindInPath;
     this.recursive = recursive;
     this.mask = fileMask;
     this.search = search;
 }
示例#3
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);
     }
 }
示例#4
0
 /// <summary>
 /// Constructor of the class 
 /// </summary> 
 public FRConfiguration(List<String> files, FRSearch search)
 {
     this.type = OperationType.FindInRange;
     this.search = search;
     this.files = files;
 }
示例#5
0
 /// <summary>
 /// Gets search results for a document
 /// </summary>
 private List<SearchMatch> GetResults(ScintillaControl sci, Boolean simple)
 {
     if (this.findComboBox.Text != String.Empty)
     {
         String pattern = this.findComboBox.Text;
         FRSearch search = new FRSearch(pattern);
         search.NoCase = !this.matchCaseCheckBox.Checked;
         search.Filter = SearchFilter.None;
         if (!simple)
         {
             search.IsRegex = this.useRegexCheckBox.Checked;
             search.IsEscaped = this.escapedCheckBox.Checked;
             search.WholeWord = this.wholeWordCheckBox.Checked;
             if (this.lookComboBox.SelectedIndex == 2)
             {
                 search.Filter = SearchFilter.OutsideCodeComments;
             }
             else if (this.lookComboBox.SelectedIndex == 3)
             {
                 search.Filter = SearchFilter.InCodeComments | SearchFilter.OutsideStringLiterals;
             }
             else if (this.lookComboBox.SelectedIndex == 4)
             {
                 search.Filter = SearchFilter.InStringLiterals | SearchFilter.OutsideCodeComments;
             }
         }
         return search.Matches(sci.Text);
     }
     return null;
 }
示例#6
0
 /// <summary>
 /// Gets search results for a document
 /// </summary>
 private List<SearchMatch> GetResults(ScintillaControl sci)
 {
     if (this.searchBox.Text != String.Empty)
     {
         String pattern = this.searchBox.Text;
         FRSearch search = new FRSearch(pattern);
         search.IsEscaped = false;
         search.WholeWord = false;
         search.NoCase = true;
         search.IsRegex = true;
         search.Filter = SearchFilter.None;
         return search.Matches(sci.Text);
     }
     return null;
 }
示例#7
0
 /// <summary>
 /// Gets search results for a document
 /// </summary>
 private List<SearchMatch> GetResults( ScintillaControl sci, String text )
 {
     String pattern = text;
     FRSearch search = new FRSearch(pattern);
     search.Filter = SearchFilter.None;
     search.NoCase = true;
     return search.Matches(sci.Text);
 }
示例#8
0
 /// <summary>
 /// Provides basic highlighting of selected text
 /// </summary>
 private void OnSelectHighlight(ScintillaControl sci)
 {
     sci.RemoveHighlights();
     if (Control.ModifierKeys == Keys.Control && sci.SelText.Length != 0)
     {
         Language language = Configuration.GetLanguage(sci.ConfigurationLanguage);
         Int32 color = language.editorstyle.HighlightBackColor;
         String pattern = sci.SelText.Trim();
         FRSearch search = new FRSearch(pattern);
         search.WholeWord = true; search.NoCase = false;
         search.Filter = SearchFilter.None; // Everywhere
         sci.AddHighlights(search.Matches(sci.Text), color);
         sci.hasHighlights = true;
     }
 }
示例#9
0
 public FRConfiguration(String fileName, FRSearch search)
 {
     this.type   = OperationType.FindInFile;
     this.path   = fileName;
     this.search = search;
 }
示例#10
0
 // 文字列検索
 private List<SearchMatch> searchString(ScintillaControl sci, String text)
 {
     FRSearch search = new FRSearch(text);
     return search.Matches(sci.Text);
 }
示例#11
0
 /// <summary>
 /// Gets seartch object for find and replace
 /// </summary>
 private static FRSearch GetFRSearch(String pattern)
 {
     FRSearch search = new FRSearch(pattern);
     search.WholeWord = true;
     search.NoCase = !true;
     search.Filter = SearchFilter.None;
     search.Filter |= SearchFilter.OutsideCodeComments;
     search.Filter |= SearchFilter.OutsideStringLiterals;
     return search;
 }
示例#12
0
        /// <summary>
        /// Gets search results for a sci control
        /// </summary>
        private List<SearchMatch> GetResults(ScintillaControl sci, String text)
        {
            if (text != String.Empty && IsAlphaNumeric(text))
            {
                String pattern = text;
                FRSearch search = new FRSearch(pattern);
                search.WholeWord = this.settingObject.wholeWords;
                search.NoCase = !this.settingObject.matchCase;
                search.Filter = SearchFilter.None;
                return search.Matches(sci.Text);
            }

            return null;
        }
示例#13
0
 static List<SearchMatch> GetResults(ScintillaControl sci, string text)
 {
     FRSearch search = new FRSearch(text)
     {
         Filter = SearchFilter.OutsideCodeComments,
         NoCase = true,
         WholeWord = true
     };
     return search.Matches(sci.Text);
 }
 /// <summary>
 /// Gets search results for a sci control
 /// </summary>
 private List<SearchMatch> GetResults(ScintillaControl sci, string text)
 {
     if (string.IsNullOrEmpty(text) || Regex.IsMatch(text, "[^a-zA-Z0-9_$]")) return null;
     FRSearch search = new FRSearch(text);
     search.WholeWord = settings.WholeWords;
     search.NoCase = !settings.MatchCase;
     search.Filter = SearchFilter.None;
     return search.Matches(sci.Text);
 }
示例#15
0
    public static void Execute()
    {
        if ( Globals.SciControl == null ) return;
        ScintillaControl sci = Globals.SciControl;

        MainForm mainForm = (MainForm) Globals.MainForm;

        ITabbedDocument document = mainForm.CurrentDocument;

        String documentDirectory = Path.GetDirectoryName(document.FileName);

        ASContext context = (ASContext) ASContext.Context;
        string currentPackage = context.CurrentModel.Package;
        List<ClassModel> classes = context.CurrentModel.Classes;
        MemberList imports = context.CurrentModel.Imports;

        sci.BeginUndoAction();

        String pattern = "}";
        FRSearch search = new FRSearch(pattern);
        search.Filter = SearchFilter.None;
        List<SearchMatch> matches = search.Matches(sci.Text);
        if (matches == null || matches.Count == 0) return;
        if (classes.Count < 2) return;

        SearchMatch match = GetNextDocumentMatch(sci, matches, sci.PositionFromLine(classes[0].LineTo + 1));

        Int32 packageEnd = sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value); // wchar to byte text length

        String strImport = "";

        if (imports.Count > 0)
        {
            for (int i=imports.Count-1; i>0; --i )
            {
                MemberModel import = imports[i];
                if(packageEnd < sci.PositionFromLine(import.LineFrom)) {
                    sci.SelectionStart = sci.PositionFromLine(import.LineFrom);
                    sci.SelectionEnd = sci.PositionFromLine(import.LineTo + 1);
                    strImport = sci.SelText + strImport;
                    sci.Clear();
                }
            }
        }

        context.UpdateCurrentFile(true);

        Int32 prevClassEnd = packageEnd;

        foreach (ClassModel currentClass in classes)
        {
            // 最初のクラスは無視
            if (currentClass == classes[0]) continue;

            sci.SelectionStart = prevClassEnd;
            sci.SelectionEnd = sci.PositionFromLine(currentClass.LineTo + 1);

            String content = "package "
                       + currentPackage
                       + "\n{\n"
                       + Regex.Replace( strImport, @"^", "\t", RegexOptions.Multiline)
                       + Regex.Replace( sci.SelText, @"^", "\t", RegexOptions.Multiline)
                       + "\n}\n";

            prevClassEnd = sci.PositionFromLine(currentClass.LineTo + 1);

            Encoding encoding = sci.Encoding;
            String file = documentDirectory + "\\" + currentClass.Name + ".as";
            FileHelper.WriteFile(file, content, encoding);
        }

        sci.SelectionStart = packageEnd;
        sci.Clear();
        sci.EndUndoAction();
    }
示例#16
0
 public FRConfiguration(String fileName, FRSearch search)
 {
     this.type = OperationType.FindInFile;
     this.path = fileName;
     this.search = search;
 }
示例#17
0
        /// <summary>
        /// Generates an FRSearch to find all instances of the given member name.
        /// Enables WholeWord and Match Case. No comment/string literal, escape characters, or regex searching.
        /// </summary>
        private static FRSearch GetFRSearch(string memberName, bool includeComments, bool includeStrings)
        {
            FRSearch search = new FRSearch(memberName);
            search.IsRegex = false;
            search.IsEscaped = false;
            search.WholeWord = true;
            search.NoCase = false;
            search.Filter = SearchFilter.None;

            if (!includeComments) search.Filter |= SearchFilter.OutsideCodeComments;
            if (!includeStrings) search.Filter |= SearchFilter.OutsideStringLiterals;

            return search;
        }
示例#18
0
 /// <summary>
 /// Constructor of the class
 /// </summary>
 public FRConfiguration(List <String> files, FRSearch search)
 {
     this.type   = OperationType.FindInRange;
     this.search = search;
     this.files  = files;
 }
示例#19
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;
            }
        }
示例#20
0
 /// <summary>
 /// Gets search results for a sci control
 /// </summary>
 private List<SearchMatch> GetResults(ScintillaControl sci, String text)
 {
     String pattern = text;
     FRSearch search = new FRSearch(pattern);
     search.Filter = SearchFilter.None;
     search.NoCase = !this.matchCaseCheckBox.Checked;
     search.WholeWord = this.wholeWordCheckBox.Checked;
     return search.Matches(sci.Text);
 }
 /// <summary>
 /// Provides basic highlighting of selected text
 /// </summary>
 private void HighlightWordsMatchingSelected()
 {
     if (TextLength == 0 || TextLength > 64 * 1024) return;
     Language language = Configuration.GetLanguage(ConfigurationLanguage);
     Int32 color = language.editorstyle.SelectionBackgroundColor;
     String word = GetWordFromPosition(CurrentPos);
     if (String.IsNullOrEmpty(word)) return;
     if (this.PositionIsOnComment(CurrentPos))
     {
         this.RemoveHighlights(1);
         return;
     }
     String pattern = word.Trim();
     FRSearch search = new FRSearch(pattern);
     search.WholeWord = true; 
     search.NoCase = true;
     search.Filter = SearchFilter.OutsideCodeComments | SearchFilter.OutsideStringLiterals;
     search.SourceFile = FileName;
     RemoveHighlights(1);
     List<SearchMatch> test = search.Matches(Text);
     AddHighlights(1, test, color);
     hasHighlights = true;
 }
示例#22
0
 /// <summary>
 /// Generates an FRSearch to find all instances of the given member name.
 /// Enables WholeWord and Match Case. No comment/string literal, escape characters, or regex searching.
 /// </summary>
 private static FRSearch GetFRSearch(string memberName)
 {
     String pattern = memberName;
     FRSearch search = new FRSearch(pattern);
     search.IsRegex = false;
     search.IsEscaped = false;
     search.WholeWord = true;
     search.NoCase = false;
     search.Filter = SearchFilter.None | SearchFilter.OutsideCodeComments | SearchFilter.OutsideStringLiterals;
     return search;
 }
示例#23
0
 /// <summary>
 /// Gets search object for find and replace
 /// </summary>
 private FRSearch GetFRSearch()
 {
     String pattern = this.findComboBox.Text;
     FRSearch search = new FRSearch(pattern);
     search.IsRegex = this.regexCheckBox.Checked;
     search.IsEscaped = this.escapedCheckBox.Checked;
     search.WholeWord = this.wholeWordCheckBox.Checked;
     search.NoCase = !this.matchCaseCheckBox.Checked;
     search.Filter = SearchFilter.None;
     if (!this.commentsCheckBox.Checked)
     {
         search.Filter |= SearchFilter.OutsideCodeComments;
     }
     if (!this.stringsCheckBox.Checked)
     {
         search.Filter |= SearchFilter.OutsideStringLiterals;
     }
     return search;
 }