Ejemplo n.º 1
0
        /// <summary>
        /// Find the next term
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnFindNext(object sender, EventArgs e)
        {
            if (document == null)
            {
                return;
            }

            if (textBoxFind.Text == "")
            {
                return;
            }

            ScintillaNET.SearchFlags flags = ScintillaNET.SearchFlags.Empty;
            if (checkboxCase.Checked)
            {
                flags |= ScintillaNET.SearchFlags.MatchCase;
            }
            if (checkBoxWord.Checked)
            {
                flags |= ScintillaNET.SearchFlags.WholeWord;
            }
            if (checkBoxRegex.Checked)
            {
                flags |= ScintillaNET.SearchFlags.RegExp;
            }

            ScintillaNET.Range range = document.Scintilla.FindReplace.FindNext(textBoxFind.Text, true, flags);
            if (range != null)
            {
                range.GotoStart();
                range.Select();
            }
        }
Ejemplo n.º 2
0
        public void SetSel(ScintillaNET.Range range, bool makeVisible = false)
        {
            range.Select();

            /*Editor.ClearSelections();
             * Editor.Selection.Start = range.Start;
             * Editor.Selection.End = range.End;
             * if (makeVisible)
             * {
             *  Editor.NativeInterface.SetSelection(range.Start, range.End);
             * }*/
        }
Ejemplo n.º 3
0
        public List <FindItem> FindAll(string searchText, bool matchWholeWord, bool matchCase, int searchMode)
        {
            List <FindItem> items = new List <FindItem>();

            int searchFlags = (int)ScintillaNET.SearchFlags.Empty;

            if (matchWholeWord)
            {
                searchFlags += (int)ScintillaNET.SearchFlags.WholeWord;
            }
            if (matchCase)
            {
                searchFlags += (int)ScintillaNET.SearchFlags.MatchCase;
            }
            if (searchMode == 3)
            {
                searchFlags += (int)ScintillaNET.SearchFlags.RegExp;
            }


            // Handles escaping a search string.
            if (searchMode == 2)
            {
                searchText = searchText.Escapes();
            }

            int Last         = Editor.Text.Length;
            int searchLength = searchText.Length;
            int Pos          = 0;



            ScintillaNET.Range range = new ScintillaNET.Range(Pos, Last, Editor);
            while (Pos > -1)
            {
                range.Start = Pos;
                range.End   = Last;
                ScintillaNET.Range find = Editor.FindReplace.Find(range, searchText, (ScintillaNET.SearchFlags)searchFlags);
                if (find != null)
                {
                    int    line = Editor.NativeInterface.LineFromPosition(find.Start);
                    string text = Editor.Lines[line].Text;
                    items.Add(new FindItem(text, this, this._FileName, find.Start, find.End, Editor.GetColumn(find.Start), Editor.NativeInterface.GetTabWidth()));
                    Pos = find.End;
                }
                else
                {
                    Pos = -1;
                }
            }
            return(items);
        }
Ejemplo n.º 4
0
 public IntelluaSource(Intellua intellua, bool copy = false)
 {
     m_copy = copy;
     pos = intellua.CurrentPos;
     m_intellua = intellua;
     m_filepath = m_intellua.FilePath;
     if (copy)
     {
         m_text = intellua.Text;
         rawText = intellua.RawText;
         ScintillaNET.Range range = new ScintillaNET.Range(0, rawText.Length, intellua);
         styledText = range.StyledText;
     }
 }
Ejemplo n.º 5
0
 public IntelluaSource(Intellua intellua, bool copy = false)
 {
     m_copy     = copy;
     pos        = intellua.CurrentPos;
     m_intellua = intellua;
     m_filepath = m_intellua.FilePath;
     if (copy)
     {
         m_text  = intellua.Text;
         rawText = intellua.RawText;
         ScintillaNET.Range range = new ScintillaNET.Range(0, rawText.Length, intellua);
         styledText = range.StyledText;
     }
 }
Ejemplo n.º 6
0
        public IntelluaSource(string filename, Intellua parent)
        {
            m_copy = true;
            pos = 0;
            m_intellua = new Intellua();
            m_intellua.Parse = false;
            m_intellua.AutoCompleteData.setParent(parent.AutoCompleteData.getParent());
            m_intellua.Text = System.IO.File.ReadAllText(filename);
            m_intellua.FilePath = filename;
            m_filepath = m_intellua.FilePath;

            m_text = m_intellua.Text;
            rawText = m_intellua.RawText;
            ScintillaNET.Range range = new ScintillaNET.Range(0, rawText.Length, m_intellua);
            styledText = range.StyledText;
        }
Ejemplo n.º 7
0
        public IntelluaSource(string filename, Intellua parent)
        {
            m_copy           = true;
            pos              = 0;
            m_intellua       = new Intellua();
            m_intellua.Parse = false;
            m_intellua.AutoCompleteData.setParent(parent.AutoCompleteData.getParent());
            m_intellua.Text     = System.IO.File.ReadAllText(filename);
            m_intellua.FilePath = filename;
            m_filepath          = m_intellua.FilePath;

            m_text  = m_intellua.Text;
            rawText = m_intellua.RawText;
            ScintillaNET.Range range = new ScintillaNET.Range(0, rawText.Length, m_intellua);
            styledText = range.StyledText;
        }
Ejemplo n.º 8
0
 private void findPreviousToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (scintilla1.Selection.Text != "")
     {
         ScintillaNET.Range range = scintilla1.Selection.Range;
         scintilla1.Selection.Range.GotoStart();
         scintilla1.Selection.Start = range.Start;
         scintilla1.Selection.End   = range.End;
         scintilla1.Selection.Range = scintilla1.FindReplace.FindPrevious(scintilla1.Selection.Text);
     }
     else if (FindWindowAppeared && scintilla1.Selection.Text != "")
     {
         scintilla1.FindReplace.Window.FindPrevious();
     }
     else
     {
         scintilla1.FindReplace.ShowFind();
         FindWindowAppeared = true;
     }
 }
Ejemplo n.º 9
0
        public GrammarBrowser(string text, List <string> kwords, string start_pos, Form1 main_f)
        {
            InitializeComponent();

            main_form = main_f;

            saveFileDialog1.InitialDirectory = Application.StartupPath;

            scintilla1.Text       = text;
            scintilla1.IsReadOnly = true;

            //setting styles
            set_sci_styles();

            scintilla1.GetRange().SetStyle(scintilla1.Styles.Default.Index);

            //Lexing and coloring our view
            for (int i = 0; i < scintilla1.Lines.Count; i++)
            {
                if (scintilla1.Lines[i].Text == "")
                {
                    continue;
                }

                string word = scintilla1.Lines[i].Text.Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];
                if (keywords.ContainsKey(word) || kwords.Contains(word))
                {
                    var x     = scintilla1.Lines[i].Text.IndexOf(word);
                    var range = new ScintillaNET.Range(scintilla1.Lines[i].Range.Start + x, scintilla1.Lines[i].Range.Start + x + word.Length, scintilla1);
                    range.SetStyle(hotspot_style);
                }

                if (scintilla1.Lines[i].Text[0] == '\t' || scintilla1.Lines[i].Text[0] == ' ')
                {
                    continue;
                }
                for (int j = 0; j < kwords.Count; j++)
                {
                    if (scintilla1.Lines[i].Text.StartsWith(kwords[j])) //if starts with a keyword and NO tabs, means, that this is a definition
                    {
                        //adding keyword
                        keywords.Add(kwords[j], i);

                        //applying styles
                        var range = new ScintillaNET.Range(scintilla1.Lines[i].Range.Start, scintilla1.Lines[i].Range.Start + kwords[j].Length, scintilla1);
                        range.SetStyle(definition_style);

                        int x = scintilla1.Lines[i].Text.IndexOf("->");
                        if (x >= 0)
                        {
                            x          += scintilla1.Lines[i].Range.Start;
                            range.Start = x;
                            range.End   = x + 2;
                            range.SetStyle(heritage_style);

                            range.Start = x + 3;
                            range.End   = scintilla1.Lines[i].Range.End;
                            range.SetStyle(parent_style);
                        }

                        kwords.RemoveAt(j);
                        break;
                    }
                }
            }

            //moving to the starting pos
            if (keywords.ContainsKey(start_pos))
            {
                move_sci_to_line(keywords[start_pos]);
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Clean up
 /// </summary>
 public void Dispose()
 {
     this.document = null;
     this.range    = null;
     this.file     = null;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Simple constuctor
 /// </summary>
 /// <param name="range"></param>
 /// <param name="file"></param>
 public SearchResult(ScintillaNET.Range range, string file, Document doc)
 {
     this.document = doc;
     this.range    = range;
     this.file     = file;
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Performs a find operation and sets the cursor at the found position if found
        /// Returns true if the text is found or false if not.
        /// </summary>
        /// <param name="findText"></param>
        /// <param name="matchWholeWord"></param>
        /// <param name="matchCase"></param>
        /// <param name="wrapAround"></param>
        /// <param name="searchMode"></param>
        /// <param name="direction"></param>
        /// <returns>True/False</returns>
        public bool Find(string findText, bool matchWholeWord, bool matchCase, bool wrapAround, int searchMode, bool moveNext, bool startZero = false)
        {
            try
            {
                // Can't find nothing.
                if (String.IsNullOrEmpty(findText))
                {
                    return(false);
                }
                int selStart    = Editor.Selection.Start;
                int selEnd      = Editor.Selection.End;
                int searchFlags = (int)ScintillaNET.SearchFlags.Empty;
                if (matchWholeWord)
                {
                    searchFlags += (int)ScintillaNET.SearchFlags.WholeWord;
                }
                if (matchCase)
                {
                    searchFlags += (int)ScintillaNET.SearchFlags.MatchCase;
                }
                if (searchMode == 3)
                {
                    searchFlags += (int)ScintillaNET.SearchFlags.RegExp;
                }

                // Handles escaping a search string.
                if (searchMode == 2)
                {
                    findText = findText.Escapes();
                }

                _MatchWholeWord = matchWholeWord;
                _MatchCase      = matchCase;

                _FindText = findText;
                // Don't store the wrap mode at this point because we are
                // dealing with a zero start which occurs when it's find in all
                // open documents which forces wrapAround to false so as to not
                // keep finding in the same document.
                if (!startZero)
                {
                    _Wrap = wrapAround;
                }
                _SearchMode = searchMode;

                // Create a base range to search
                ScintillaNET.Range range = new ScintillaNET.Range(Editor.CurrentPos, Editor.TextLength, Editor);
                if (!moveNext)
                {
                    // Direction is up so swap the range which causes the editor to search up
                    range.Start = Editor.Selection.Start;
                    range.End   = 0;
                }

                // Here specifically to deal with document searches.
                if (startZero)
                {
                    range.Start = 0;
                    range.End   = Editor.TextLength;
                }

                ScintillaNET.Range findRange = Editor.FindReplace.Find(range, findText, (ScintillaNET.SearchFlags)searchFlags);
                if (findRange != null)
                {
                    SetSel(findRange);
                    return(true);
                }
                else
                {
                    // Check wrapmode
                    if (wrapAround)
                    {
                        // Wrap mode is true and no find occurred so just adjust the range to search the entire document and
                        // try again
                        if (moveNext)
                        {
                            range.Start = 0;
                            range.End   = Editor.TextLength;
                        }
                        else
                        {
                            range.Start = Editor.Text.Length;
                            range.End   = 0;
                        }
                        findRange = Editor.FindReplace.Find(range, findText, (ScintillaNET.SearchFlags)searchFlags);
                        if (findRange != null)
                        {
                            SetSel(findRange);
                            return(true);
                        }
                    }
                }

                /*Editor.ClearSelections();
                 * Editor.CurrentPos = selStart;
                 * Editor.Selection.Start = selStart;
                 * Editor.Selection.End = selEnd;*/
            }
            catch { }   // Fail silently. Can cause an exception on the SendMessageDirect here.
            return(false);
        }
Ejemplo n.º 13
0
        public GrammarBrowser(string text, List<string> kwords, string start_pos, Form1 main_f)
        {
            InitializeComponent();

            main_form = main_f;

            saveFileDialog1.InitialDirectory = Application.StartupPath;
        
            scintilla1.Text = text;
            scintilla1.IsReadOnly = true;

            //setting styles
            set_sci_styles();

            scintilla1.GetRange().SetStyle(scintilla1.Styles.Default.Index);

            //Lexing and coloring our view
            for (int i = 0; i < scintilla1.Lines.Count; i++)
            {
                if (scintilla1.Lines[i].Text == "") continue;
                
                string word = scintilla1.Lines[i].Text.Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries)[0];
                if (keywords.ContainsKey(word) || kwords.Contains(word))
                {
                    var x = scintilla1.Lines[i].Text.IndexOf(word);
                    var range = new ScintillaNET.Range(scintilla1.Lines[i].Range.Start + x, scintilla1.Lines[i].Range.Start + x + word.Length, scintilla1);
                    range.SetStyle(hotspot_style);
                }

                if (scintilla1.Lines[i].Text[0] == '\t' || scintilla1.Lines[i].Text[0] == ' ') continue;
                for (int j = 0; j < kwords.Count; j++)
                {
                    if (scintilla1.Lines[i].Text.StartsWith(kwords[j])) //if starts with a keyword and NO tabs, means, that this is a definition
                    {
                        //adding keyword
                        keywords.Add(kwords[j], i);

                        //applying styles
                        var range = new ScintillaNET.Range(scintilla1.Lines[i].Range.Start, scintilla1.Lines[i].Range.Start + kwords[j].Length, scintilla1);
                        range.SetStyle(definition_style);

                        int x = scintilla1.Lines[i].Text.IndexOf("->");
                        if (x >= 0)
                        {
                            x += scintilla1.Lines[i].Range.Start;
                            range.Start = x;
                            range.End = x + 2;
                            range.SetStyle(heritage_style);

                            range.Start = x + 3;
                            range.End = scintilla1.Lines[i].Range.End;
                            range.SetStyle(parent_style);
                        }

                        kwords.RemoveAt(j);
                        break;
                    }
                }
            }

            //moving to the starting pos
            if (keywords.ContainsKey(start_pos))
                move_sci_to_line(keywords[start_pos]);
        }