Ejemplo n.º 1
0
        /// <summary>
        /// Start a search.
        /// </summary>
        /// <param name="sender">system parameter</param>
        /// <param name="e">system parameter</param>
        private void btnSearch_Clicked(object sender, EventArgs e)
        {
            if (!ValidateInput())
                return;

             // gui state
             SetSearchState(null, new SearchEventArgs(false));
             sbStatus.Pop(1);
             txtViewer.Buffer.Clear();
             (tvFiles.Model as ListStore).Clear();

             alSearchErrors = null;

             AddComboSelectionSpecial(cboSearchStart, cboSearchStart.ActiveText);
             AddComboSelection(cboSearchFilter, cboSearchFilter.ActiveText);
             AddComboSelection(cboSearchText, cboSearchText.ActiveText);

             // search pattern
             gpGrep = new Grep();
             gpGrep.StartDirectory = cboSearchStart.ActiveText;
             gpGrep.FileFilter = cboSearchFilter.ActiveText;
             gpGrep.SearchText = cboSearchText.ActiveText;

             // exclusion list
             string[] extensions = Core.GeneralSettings.ExtensionExcludeList.Split(';');
             foreach (string ext in extensions)
            gpGrep.AddExclusionExtension(ext.ToLower());

             // options
             gpGrep.UseRegularExpressions = chkRegularExpressions.Active;
             gpGrep.UseCaseSensitivity = chkCaseSensitive.Active;
             gpGrep.UseWholeWordMatching = chkWholeWord.Active;
             gpGrep.UseRecursion = chkRecurse.Active;
             gpGrep.ReturnOnlyFileNames = chkFileNamesOnly.Active;
             gpGrep.UseNegation = chkNegation.Active;
             gpGrep.IncludeLineNumbers = chkLineNumbers.Active;
             gpGrep.ContextLines = cboContextLines.Active;

             // events
             gpGrep.SearchingFile += new Grep.SearchingFileHandler(gpGrep_SearchingFile);
             gpGrep.FileHit += new Grep.FileHitHandler(gpGrep_FileHit);
             gpGrep.LineHit += new Grep.LineHitHandler(gpGrep_LineHit);
             gpGrep.SearchCancel += new Grep.SearchCancelHandler(gpGrep_SearchCancel);
             gpGrep.SearchComplete += new Grep.SearchCompleteHandler(gpGrep_SearchComplete);
             gpGrep.SearchError += new Grep.SearchErrorHandler(gpGrep_SearchError);

             gpGrep.BeginExecute();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start the searching
        /// </summary>
        /// <history>
        /// [Curtis_Beard]	   10/17/2005	Created
        /// [Curtis_Beard]	   07/03/2006	FIX: 1516775, Remove trim on the search expression
        /// [Curtis_Beard]	   07/12/2006	CHG: moved thread actions to grep class
        /// [Curtis_Beard]	   11/22/2006	CHG: Remove use of browse in combobox
        /// </history>
        private void StartSearch()
        {
            string _path;
             string _fileName;
             int _index;
             string _expression;

             try
             {
            _fileName = cboFileName.Text;
            _path = cboFilePath.Text.Trim();
            _expression = cboSearchForText.Text;

            // update combo selections
            AddComboSelection(cboSearchForText, _expression);
            AddComboSelection(cboFileName, _fileName);
            AddComboSelection(cboFilePath, _path);

            // Ensure that there is a backslash.
            if (!_path.EndsWith("\\"))
               _path += "\\";

            // update path and fileName if fileName has a path in it
            for (_index = _fileName.Length; _index >= 1; _index--)
            {
               //if (Mid(_fileName, _index, 1) = "\\")
               if (_fileName.Substring(_index-1, 1).Equals("\\"))
               {
                  _path += _fileName.Substring(0, _index);
                  _fileName = _fileName.Substring(_fileName.Length - _index + 1);
                  break;
               }
            }

            // disable gui
            SetSearchState(false);

            // Clear the display
            UpdateStatusBar(string.Empty);
            ClearItems();
            txtHits.Clear();

            // begin searching
            __Grep = new Grep();
            SetGrepOptions();
            __Grep.StartDirectory = _path;
            __Grep.FileFilter = _fileName;
            __Grep.SearchText = _expression;

            // attach events
            __Grep.FileHit += new AstroGrep.AstroGrepBase.Grep.FileHitHandler(ReceiveFileHit);
            __Grep.LineHit += new AstroGrep.AstroGrepBase.Grep.LineHitHandler(ReceiveLineHit);
            __Grep.SearchCancel += new AstroGrep.AstroGrepBase.Grep.SearchCancelHandler(ReceiveSearchCancel);
            __Grep.SearchComplete += new AstroGrep.AstroGrepBase.Grep.SearchCompleteHandler(ReceiveSearchComplete);
            __Grep.SearchError += new AstroGrep.AstroGrepBase.Grep.SearchErrorHandler(ReceiveSearchError);
            __Grep.SearchingFile += new AstroGrep.AstroGrepBase.Grep.SearchingFileHandler(ReceiveSearchingFile);

            __Grep.BeginExecute();
             }
             catch (Exception ex)
             {
            MessageBox.Show(ex.Message);
             }
        }