Example #1
0
        public ArrayList FindAll()
        {
            ArrayList results = new ArrayList();

            SearchEngine se = new SearchEngine();

            bool mc = true;

            if (checkBox2.Checked == false)
            {
                mc = false;
            }

            string s = comboBox1.Text;

            //MessageBox.Show("Find " + s);

            VSSolution vs = ef.GetVSSolution();

            if (vs == null)
            {
                return(results);
            }

            int bb = comboBox2.SelectedIndex;

            if (bb == 1)
            {
                MessageBox.Show("Find for All Open Documents");

                ScriptControl.ScriptControl scr = ef.scr;

                VSProject vp = vs.MainVSProject;

                ArrayList L = new ArrayList();//.GetOpenFiles();

                if (BB != bb || patterns != s)
                {
                    Results = null;
                }

                BB = bb;

                patterns = s;

                if (Results == null)
                {
                    {
                        {
                            Finder finders = new Finder();

                            Results = new ArrayList();

                            foreach (string f in L)
                            {
                                string text = File.ReadAllText(f);

                                if (mc == false)
                                {
                                    text = text.ToLower();

                                    s = s.ToLower();
                                }

                                char[] texts = text.ToCharArray();

                                char[] pattern = s.ToCharArray();

                                ArrayList found = null;

                                if (checkBox4.Checked == true)
                                {
                                    found = RegexMatch(text, s, true);
                                }
                                else
                                {
                                    found = finders.TW(pattern, pattern.Length, texts, texts.Length);
                                }

                                if (found.Count == 0)
                                {
                                    continue;
                                }

                                string[] lines = text.Split("\n".ToCharArray());

                                int fp = 0;

                                int pos = (int)found[fp];

                                int r = 0;

                                int n = 0;

                                int i = 0;
                                while (i < lines.Length)
                                {
                                    string line = lines[i];

                                    n = r + line.Length + 1;

                                    if (pos >= r && pos <= n)
                                    {
                                        do
                                        {
                                            if (checkBox3.Checked == true)
                                            {
                                                if (Char.IsLetterOrDigit(texts[pos + patterns.Length]) == false)
                                                {
                                                    if (pos > 0)
                                                    {
                                                        if (Char.IsLetterOrDigit(texts[pos - 1]) == false)
                                                        {
                                                            Results.Add(f + "\t\t" + (pos - r) + " \t" + i);
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Results.Add(f + "\t\t" + (pos - r) + " \t" + i);
                                            }

                                            fp++;

                                            if (fp < found.Count)
                                            {
                                                pos = (int)found[fp];
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }while (pos <= n);
                                    }

                                    r = n;

                                    i++;
                                }
                            }
                            act = 0;
                            return(Results);
                        }
                    }
                }

                if (Results == null)
                {
                    return(null);
                }

                if (act >= Results.Count)
                {
                    return(null);
                }

                string dd = Results[act] as string;

                string[] cc = dd.Split("\t".ToCharArray());

                string file = cc[0];

                int l2 = Convert.ToInt32(cc[2]);

                int c2 = Convert.ToInt32(cc[1]);

                scr = ef.scr;

                string filename = file;

                //VSProject vp = vs.GetProjectbyFileName(filename);

                DomRegion dr = new DomRegion(l2, c2, l2, c2 + patterns.Length);

                scr.OpenDocuments2(filename, vp, dr, true);

                return(null);
            }
            else if (bb == 0)
            {
                MessageBox.Show("Find for Current Block");

                ScriptControl.ScriptControl scr = ef.scr;

                AvalonDocument doc = ef.scr.GetActiveDocument();

                string filename = doc.FileName;

                //Dom.IMember m = scr.GetCurrentBlock();

                //if (m == null)
                //{
                //    Results = null;
                //    return null;
                //}

                //string text = "";// scr.GetCurrentBlockText(m.BodyRegion);

                //TextPoint p = new TextPoint(0, m.Region.BeginLine);

                ////if (BB != bb || patterns != s || filename != filenamedoc)

                //if (m != mb)

                //    Results = null;

                //mb = m;

                filenamedoc = filename;

                BB = bb;

                patterns = s;

                if (Results == null)
                {
                    {
                        {
                            Finder finders = new Finder();

                            Results = new ArrayList();

                            if (mc == false)
                            {
                                //text = text.ToLower();

                                s = s.ToLower();
                            }

                            char[] texts = "text".ToCharArray();

                            char[] pattern = s.ToCharArray();

                            ArrayList found = null;

                            if (checkBox4.Checked == true)
                            {
                                //found = RegexMatch(text, s, true);
                            }
                            else
                            {
                                found = finders.TW(pattern, pattern.Length, texts, texts.Length);
                            }

                            string[] lines = "text".Split("\n".ToCharArray());

                            int fp = 0;

                            int pos = (int)found[fp];

                            int r = 0;

                            int n = 0;

                            int i = 0;
                            while (i < lines.Length)
                            {
                                string line = lines[i];

                                n = r + line.Length + 1;

                                if (pos >= r && pos <= n)
                                {
                                    Results.Add(filename + "\t\t" + (pos - r) + " \t" + (0 /*p.Y*/ + i));

                                    fp++;

                                    if (fp < found.Count)
                                    {
                                        pos = (int)found[fp];
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                r = n;

                                i++;
                            }
                        }

                        act = 0;

                        return(Results);
                    }
                }

                if (Results == null)
                {
                    return(null);
                }

                if (act >= Results.Count)
                {
                    return(null);
                }

                string dd = Results[act] as string;

                string[] cc = dd.Split("\t".ToCharArray());

                int l2 = Convert.ToInt32(cc[2]);

                int c2 = Convert.ToInt32(cc[1]);

                scr = ef.scr;

                filename = doc.FileName;

                VSProject vp = vs.GetProjectbyFileName(filename);

                DomRegion dr = new DomRegion(l2, c2, l2, c2 + patterns.Length);

                scr.OpenDocuments2(filename, vp, dr, true);

                return(null);
            }

            if (bb == 7)
            {
                MessageBox.Show("Find for Current Selection");

                ScriptControl.ScriptControl scr = ef.scr;

                AvalonDocument doc = ef.scr.GetActiveDocument();

                string filename = doc.FileName;

                string text = scr.GetCurrentSelection();

                //TextPoint p = new TextPoint(0, 0); // scr.GetCurrentSelectionStart();

                if (BB != bb || patterns != s || filename != filenamedoc)
                {
                    Results = null;
                }

                filenamedoc = filename;

                BB = bb;

                patterns = s;

                if (Results == null)
                {
                    {
                        {
                            Finder finders = new Finder();

                            Results = new ArrayList();

                            if (mc == false)
                            {
                                text = text.ToLower();

                                s = s.ToLower();
                            }

                            char[] texts = text.ToCharArray();

                            char[] pattern = s.ToCharArray();

                            ArrayList found = null;

                            if (checkBox4.Checked == true)
                            {
                                found = RegexMatch(text, s, true);
                            }
                            else
                            {
                                found = finders.TW(pattern, pattern.Length, texts, texts.Length);
                            }

                            string[] lines = text.Split("\n".ToCharArray());

                            int fp = 0;

                            int pos = (int)found[fp];

                            int r = 0;

                            int n = 0;

                            int i = 0;
                            while (i < lines.Length)
                            {
                                string line = lines[i];

                                n = r + line.Length + 1;

                                if (pos >= r && pos <= n)
                                {
                                    // Results.Add(filename + "\t\t" + (pos - r) + " \t" + (p.Y + i));

                                    fp++;

                                    if (fp < found.Count)
                                    {
                                        pos = (int)found[fp];
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                r = n;

                                i++;
                            }
                        }

                        act = 0;

                        return(Results);
                    }
                }

                if (Results == null)
                {
                    return(null);
                }

                if (act >= Results.Count)
                {
                    return(null);
                }

                string dd = Results[act] as string;

                string[] cc = dd.Split("\t".ToCharArray());

                int l2 = Convert.ToInt32(cc[2]);

                int c2 = Convert.ToInt32(cc[1]);

                scr = ef.scr;

                filename = doc.FileName;

                VSProject vp = vs.GetProjectbyFileName(filename);

                DomRegion dr = new DomRegion(l2, c2, l2, c2 + patterns.Length);

                scr.OpenDocuments2(filename, vp, dr, true);

                return(null);
            }

            if (bb == 3)
            {
                //MessageBox.Show("Find for Project");

                ScriptControl.ScriptControl scr = ef.scr;

                //string filename = doc.FileName;

                VSProject vp = vs.MainVSProject;

                if (vp == null)
                {
                    MessageBox.Show("No project has been selected");
                    Results = new ArrayList();
                    return(Results);
                }

                ArrayList L = vp.GetCompileItems();

                if (BB != bb || patterns != s)
                {
                    Results = null;
                }

                BB = bb;

                patterns = s;

                if (Results == null)
                {
                    {
                        {
                            Finder finders = new Finder();

                            Results = new ArrayList();

                            foreach (string f in L)
                            {
                                string text = File.ReadAllText(f);

                                if (mc == false)
                                {
                                    text = text.ToLower();

                                    s = s.ToLower();
                                }

                                char[] texts = text.ToCharArray();

                                char[] pattern = s.ToCharArray();

                                ArrayList found = null;

                                if (checkBox4.Checked == true)
                                {
                                    found = RegexMatch(text, s, true);
                                }
                                else
                                {
                                    found = finders.TW(pattern, pattern.Length, texts, texts.Length);
                                }

                                if (found.Count == 0)
                                {
                                    continue;
                                }

                                string[] lines = text.Split("\n".ToCharArray());

                                int fp = 0;

                                int pos = (int)found[fp];

                                int r = 0;

                                int n = 0;

                                int i = 0;
                                while (i < lines.Length)
                                {
                                    string line = lines[i];

                                    n = r + line.Length + 1;

                                    if (pos >= r && pos <= n)
                                    {
                                        Results.Add(f + "\t" + (pos - r) + " \t" + i);

                                        fp++;

                                        if (fp < found.Count)
                                        {
                                            pos = (int)found[fp];
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }

                                    r = n;

                                    i++;
                                }
                            }
                            act = 0;
                            return(Results);
                        }
                    }
                }

                if (Results == null)
                {
                    return(null);
                }

                if (act >= Results.Count)
                {
                    return(null);
                }

                string dd = Results[act] as string;

                string[] cc = dd.Split("\t".ToCharArray());

                string file = cc[0];

                int l2 = Convert.ToInt32(cc[2]);

                int c2 = Convert.ToInt32(cc[1]);

                scr = ef.scr;

                string filename = file;

                //VSProject vp = vs.GetProjectbyFileName(filename);

                DomRegion dr = new DomRegion(l2, c2, l2, c2 + patterns.Length);

                scr.OpenDocuments2(filename, vp, dr, true);

                return(null);
            }
            else if (bb == 2)
            {
                //MessageBox.Show("Find for Current Document");

                AvalonDocument doc = ef.scr.GetActiveDocument();

                string filename = doc.FileName;

                string text = "doc.syntaxDocument1.Text";

                if (BB != bb || patterns != s || filename != filenamedoc)
                {
                    Results = null;
                }

                filenamedoc = filename;

                BB = bb;

                patterns = s;

                if (Results == null)
                {
                    {
                        {
                            Finder finders = new Finder();

                            Results = new ArrayList();

                            //text = File.ReadAllText(f);

                            if (mc == false)
                            {
                                text = text.ToLower();

                                s = s.ToLower();
                            }

                            char[] texts = text.ToCharArray();

                            char[] pattern = s.ToCharArray();

                            ArrayList found = null;

                            if (checkBox4.Checked == true)
                            {
                                found = RegexMatch(text, s, true);
                            }
                            else
                            {
                                found = finders.TW(pattern, pattern.Length, texts, texts.Length);
                            }

                            if (found.Count > 0)
                            {
                                string[] lines = text.Split("\n".ToCharArray());

                                int fp = 0;

                                int pos = (int)found[fp];

                                int r = 0;

                                int n = 0;

                                int i = 0;
                                while (i < lines.Length)
                                {
                                    string line = lines[i];

                                    n = r + line.Length + 1;

                                    if (pos >= r && pos <= n)
                                    {
                                        do
                                        {
                                            Results.Add(filename + "\t" + (pos - r) + " \t" + i);

                                            fp++;

                                            if (fp < found.Count)
                                            {
                                                pos = (int)found[fp];
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }while (pos <= n);
                                    }

                                    r = n;

                                    i++;
                                }
                            }
                        }
                        act = 0;

                        return(Results);
                    }
                }

                if (Results == null)
                {
                    return(null);
                }

                if (act >= Results.Count)
                {
                    return(null);
                }

                string dd = Results[act] as string;

                string[] cc = dd.Split("\t".ToCharArray());

                int l2 = Convert.ToInt32(cc[2]);

                int c2 = Convert.ToInt32(cc[1]);

                ScriptControl.ScriptControl scr = ef.scr;

                filename = doc.FileName;

                VSProject vp = vs.GetProjectbyFileName(filename);

                DomRegion dr = new DomRegion(l2, c2, l2, c2 + patterns.Length);

                scr.OpenDocuments2(filename, vp, dr, true);

                return(null);
            }
            Finder finder = new Finder();

            foreach (VSProject p in vs.Projects)
            {
                ArrayList L = p.GetCompileItems();

                foreach (string f in L)
                {
                    string text = File.ReadAllText(f);

                    if (mc == false)
                    {
                        text = text.ToLower();

                        s = s.ToLower();
                    }

                    char[] texts = text.ToCharArray();

                    char[] pattern = s.ToCharArray();

                    ArrayList found = null;

                    if (checkBox4.Checked == true)
                    {
                        found = RegexMatch(text, s, true);
                    }
                    else
                    {
                        found = finder.TW(pattern, pattern.Length, texts, texts.Length);
                    }

                    if (found.Count == 0)
                    {
                        continue;
                    }

                    string[] lines = text.Split("\n".ToCharArray());

                    int fp = 0;

                    int pos = (int)found[fp];

                    int r = 0;

                    int n = 0;

                    int i = 0;
                    while (i < lines.Length)
                    {
                        string line = lines[i];

                        n = r + line.Length + 1;

                        if (pos >= r && pos <= n)
                        {
                            results.Add(f + "\t" + (pos - r) + " \t" + i);

                            fp++;

                            if (fp < found.Count)
                            {
                                pos = (int)found[fp];
                            }
                            else
                            {
                                break;
                            }
                        }

                        r = n;

                        i++;
                    }
                }
            }

            if (checkBox3.Checked == true)
            {
                string pp = comboBox1.Text;

                char[] separators = { '\t', ' ', '\n', '.', '-', '(' };

                ArrayList R = new ArrayList();

                foreach (string sw in results)
                {
                    string[] d = sw.Split(separators);

                    foreach (string b in d)
                    {
                        if (b.Trim().ToLower() == pp.Trim().ToLower())
                        {
                            R.Add(sw);
                        }
                    }
                }

                results = R;
            }

            if (checkBox10.Checked == true)
            {
                ArrayList R = new ArrayList();
                foreach (string sw in results)
                {
                    string[] d = sw.Split(" ".ToCharArray());
                    R.Add(d[0] + "\n");
                }

                results = R;
            }

            return(results);
        }
Example #2
0
        public static ArrayList FindInActiveDocument(string s)
        {
            //                      else if (bb == 2)
            //{
            //MessageBox.Show("Find for Current Document");

            ArrayList Results = new ArrayList();

            ExplorerForms ef = ExplorerForms.ef;

            AvalonDocument doc = ef.scr.GetActiveDocument();

            string filename = doc.FileName;

            string text = "doc.syntaxDocument1.Text";

            string filenamedoc = filename;

            string patterns = s;

            //if (Results == null)
            {
                {
                    {
                        Finder finders = new Finder();

                        Results = new ArrayList();

                        //text = File.ReadAllText(f);

                        //if (mc == false)
                        {
                            //    text = text.ToLower();

                            //    s = s.ToLower();
                        }

                        char[] texts = text.ToCharArray();

                        char[] pattern = s.ToCharArray();

                        ArrayList found = null;

                        //if (checkBox4.Checked == true)
                        //{
                        //    found = RegexMatch(text, s, true);
                        //}
                        //else
                        {
                            found = finders.TW(pattern, pattern.Length, texts, texts.Length);
                        }

                        if (found.Count > 0)
                        {
                            string[] lines = text.Split("\n".ToCharArray());

                            int fp = 0;

                            int pos = (int)found[fp];

                            int r = 0;

                            int n = 0;

                            int i = 0;
                            while (i < lines.Length)
                            {
                                string line = lines[i];

                                n = r + line.Length + 1;

                                if (pos >= r && pos <= n)
                                {
                                    do
                                    {
                                        Results.Add(filename + "\t" + (pos - r) + " \t" + i);

                                        fp++;

                                        if (fp < found.Count)
                                        {
                                            pos = (int)found[fp];
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }while (pos <= n);
                                }

                                r = n;

                                i++;
                            }
                        }
                    }
                    int act = 0;

                    return(Results);
                }
            }

            //}

            return(Results);
        }