Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Source Code Super Search

, 10 Mar 2009 CPOL
A simple solution for searching source code directories
BSCodeGrep.zip
BSCodeGrep
branches
0.9 VS Add-In
BSCodeGrep
Classes
folder_explore copy.ico
Forms
icons
add.png
application_form.png
arrow_right.png
delete.png
find.png
folder.png
folder_explore copy.ico
folder_explore.png
folder_page.png
information.png
lightning.png
magnifier.png
note_edit.png
package_system.png
star.png
Properties
Settings.settings
CodeSearchAddIn
CodeSearchAddIn.AddIn
CodeSearchAddIn.csproj.user
tags
trunk
BSCodeGrep
bin
Classes
folder_explore copy.ico
Forms
icons
add.png
application_form.png
arrow_right.png
delete.png
find.png
folder.png
folder_explore copy.ico
folder_explore.png
folder_page.png
information.png
lightning.png
magnifier.png
note_edit.png
package_system.png
script_go.png
star.png
Properties
Settings.settings
BSCodeGrep_src.zip
Properties
Settings.settings
BSCodeGrep.csproj.user
folder_explore copy.ico
Classes
Forms
icons
add.png
application_form.png
arrow_right.png
BSLogo.jpg
delete.png
exclamation.png
find.png
folder.png
folder_explore copy.ico
folder_explore.png
folder_page.png
information.png
lightning.png
magnifier.png
note_edit.png
package_system.png
page_save.png
script_go.png
star.png
VS2008_Add-In.zip
BSCodeGrep.pdb
CodeSearchAddIn.AddIn
CodeSearchAddIn.dll
BSCodeGrep.exe
// BaileySoft Super Code Search
// Copyright (c) 2008, BSLTD
// nealbailey@hotmail.com - All rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BSCodeGrep
{
    public partial class Form2 : Form
    {
        #region constructors

        public Form2()
        {
            InitializeComponent();
            m_uso = new IOWorker.SearchSettings();
            LoadUserSettings();
        }

        #endregion

        #region public properties

        public IOWorker.SearchSettings Uso
        {
            get { return m_uso; }
        }
        #endregion

        #region private methods

        private void LoadUserSettings()
        {
            _appSettings = new CAppSettings();
            _appSettings.Reload();

            _appSettings.SearchPaths.Reverse();
            _appSettings.SearchFilters.Reverse();
            _appSettings.SearchPatterns.Reverse();
            _appSettings.ReplacementStrings.Reverse();

            comboBox1.Items.AddRange(_appSettings.SearchPaths.ToArray());            
            comboBox2.Items.AddRange(_appSettings.SearchFilters.ToArray());
            comboBox3.Items.AddRange(_appSettings.SearchPatterns.ToArray());
            comboBox4.Items.AddRange(_appSettings.ReplacementStrings.ToArray());
        }

        private bool ValidateAndPersistControls()
        {
            bool isValid = false;

            if (comboBox1.Text != "" || comboBox2.Text != "" || comboBox3.Text != "")
            {

                if (!comboBox1.Items.Contains(comboBox1.Text) && !String.IsNullOrEmpty(comboBox1.Text))
                {
                    comboBox1.Items.Insert(0, comboBox1.Text);
                    _appSettings.SearchPaths.Add(comboBox1.Text);
                    if (comboBox1.Text.Substring(comboBox1.Text.Length - 1) == "\\")
                        comboBox1.Text = comboBox1.Text.Remove(comboBox1.Text.Length - 1);
                }

                if (!comboBox2.Items.Contains(comboBox2.Text) && !String.IsNullOrEmpty(comboBox2.Text))
                {
                    comboBox2.Items.Insert(0, comboBox2.Text);
                    _appSettings.SearchFilters.Add(comboBox2.Text);
                }

                if (!comboBox3.Items.Contains(comboBox3.Text) && !String.IsNullOrEmpty(comboBox3.Text))
                {
                    comboBox3.Items.Insert(0, comboBox3.Text);
                    _appSettings.SearchPatterns.Add(comboBox3.Text);
                }

                if (!comboBox4.Items.Contains(comboBox4.Text) && !String.IsNullOrEmpty(comboBox4.Text))
                {
                    comboBox4.Items.Insert(0, comboBox4.Text);
                    _appSettings.ReplacementStrings.Add(comboBox4.Text);
                }               
                
                _appSettings.Save();
                isValid = true;
            }    
            return isValid;
        }

        #endregion

        #region private events

        //Browse Folder Dialog Button 
        private void button1_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
            folderBrowserDialog1.Description = "Starting Search Location";
            folderBrowserDialog1.ShowNewFolderButton = false;
            DialogResult result = folderBrowserDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                comboBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        //Apply Button Clicked
        private void button2_Click(object sender, EventArgs e)
        {
            if (ValidateAndPersistControls())
            {
                string[] filters;

                if (comboBox2.Text.IndexOf(" ") > -1)
                    filters = comboBox2.Text.Split(' ');
                else
                    filters = new string[] { comboBox2.Text };

                m_uso.SearchPath = comboBox1.Text;
                m_uso.SearchFilters = filters;
                m_uso.SearchPattern = comboBox3.Text;
                m_uso.NamesOnly = false;
                m_uso.CaseInsensative = false;
                m_uso.Replacement = comboBox4.Text;
                m_uso.Scope = IOWorker.RegExSearchScope.SINGLE_LINE;

                if (checkBox1.Checked)
                    m_uso.CaseInsensative = true;

                if (checkBox2.Checked)
                    m_uso.NamesOnly = true;

                if (checkBox3.Checked)
                       m_uso.Scope = IOWorker.RegExSearchScope.MULTI_LINE;
            }
            this.Hide();
        }

        //Clear User Settings History
        private void button3_Click(object sender, EventArgs e)
        {
            _appSettings.SearchPaths.Clear();
            _appSettings.SearchFilters.Clear();
            _appSettings.SearchPatterns.Clear();
            _appSettings.ReplacementStrings.Clear();
            _appSettings.Save();

            comboBox1.Items.Clear();
            comboBox2.Items.Clear();
            comboBox3.Items.Clear();

            comboBox1.Text = "";
            comboBox2.Text = "";
            comboBox3.Text = "";
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                checkBox3.Checked = false;
                checkBox4.Checked = false;
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {
                checkBox4.Checked = false;
                checkBox2.Checked = false;
            }
        }
        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
            {
                checkBox2.Checked = false;
                checkBox3.Checked = false;
            }
        }      
        #endregion

        #region private fields

        private CAppSettings _appSettings = null;
        private IOWorker.SearchSettings m_uso;
        #endregion
       
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

thund3rstruck
Software Developer
United States United States
I'm a typical 30 year old generation X guy that likes video games, NFL football, and comic style art. I have an insatiable passion for programming and doing what ever it takes to become a better programmer.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 10 Mar 2009
Article Copyright 2008 by thund3rstruck
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid