Exemplo n.º 1
0
        public void DoSyntaxHightlight_CurrentLine(CodeTextBox codeTextbox)
        {
            #region Compile regexs if necessary
            if (!compiled)
            {
                Update(codeTextbox);
            }
            #endregion

            string line      = RichTextboxHelper.GetCurrentLine(codeTextbox);
            int    lineStart = RichTextboxHelper.GetCurrentLineStartIndex(codeTextbox);

            ProcessLine(codeTextbox, line, lineStart);
        }
Exemplo n.º 2
0
        public void DoIntellisense_CurrentLine(CodeTextBox codeTextbox, TreeView m_IntellisenseTree)
        {
            #region Compile regexs if necessary
            if (!compiled)
            {
                Update(codeTextbox);
            }
            #endregion

            string line      = RichTextboxHelper.GetCurrentLine(codeTextbox);
            int    lineStart = RichTextboxHelper.GetCurrentLineStartIndex(codeTextbox);

            ProcessLine(codeTextbox, line, lineStart, m_IntellisenseTree);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the position of the last word. Position searching takes care of scope operators!
        /// </summary>
        /// <param name="richTextbox"></param>
        /// <param name="scopeOperators"></param>
        /// <returns></returns>
        public int GetLastWordStartPosition(RichTextBox richTextbox, List <string> scopeOperators)
        {
            int           pos = richTextbox.SelectionStart - 1;
            List <string> lastScopeOperatorChars = GetLastCharsOfScopeOperators();

            //If the last char was a scope separator, we need the current position...
            if (m_LastCharWasAScopeOperator)
            {
                return(richTextbox.SelectionStart);
            }
            try
            {
                //If we deleted the last char, and arrive at a scope operator...
                string lastWord = RichTextboxHelper.GetLastWord(m_CodeTextBox);
                string lastChar = lastWord.Substring(lastWord.Length - 1, 1);
                if (lastScopeOperatorChars.Contains(lastChar))
                {
                    return(richTextbox.SelectionStart);;
                }
            }
            catch { }

            while (pos > 1)
            {
                string substr = richTextbox.Text.Substring(pos - 1, 1);

                if (Char.IsWhiteSpace(substr, 0))
                {
                    return(pos);
                }
                else if (lastScopeOperatorChars.Contains(substr))
                {
                    return(pos);
                }

                pos--;
            }

            return(0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calls, when a non-alphanumerical character typed.
        /// </summary>
        /// <param name="c"></param>
        public void TypeNonAlphaNumerical(char c)
        {
            CheckScopeOperator(c);

            //Search the last letter(s) for separator, and update if found...
            string lastWord = RichTextboxHelper.GetLastWord(m_CodeTextBox);

            //last word doesn't contains the processed char yet...
            lastWord += c;

            foreach (string separator in m_CodeTextBox.CodeWords_ScopeOperators)
            {
                int index = lastWord.LastIndexOf(separator);
                if (index > -1)
                {
                    if (index == (lastWord.Length - separator.Length))
                    {
                        //found...
                        UpdateIntellisense(true, lastWord.Substring(0, index), c.ToString());
                        return;
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates the intellisense box's elements to show the right object list.
        /// </summary>
        /// <param name="forceNextLevel"></param>
        /// <param name="word"></param>
        /// <param name="justRead"></param>
        /// <returns></returns>
        public bool UpdateIntellisense(bool forceNextLevel, string word, string justRead)
        {
            //Clear all elements
            m_CodeTextBox.IntellisenseBox.Items.Clear();

            //Get the actual line
            if (word == "")
            {
                word = RichTextboxHelper.GetLastWord(m_CodeTextBox);
            }

            if (justRead == "\b")
            {
                if (!String.IsNullOrEmpty(word))
                {
                    word = word.Substring(0, word.Length - 1);
                }
            }
            else
            {
                word += justRead;
            }


            //Get subwords
            string[] words = word.Split(
                m_CodeTextBox.CodeWords_ScopeOperators.ToArray <string>(),
                StringSplitOptions.None);

            //if none, return...
            if (words.Length < 1)
            {
                //Hide intellisense...
                return(false);
            }

            string lastWord = words[words.Length - 1];

            if (words.Length == 1 && !forceNextLevel)
            {
                #region Search in the root level
                foreach (TreeNode n in m_CodeTextBox.IntellisenseTree.Nodes)
                {
                    if (!Like(n, lastWord))
                    {
                        continue;
                    }

                    ImageListItem li = new ImageListItem();
                    li.Text  = n.Name;
                    li.Image = AssociateImage(n);

                    m_CodeTextBox.IntellisenseBox.Items.Add(li);
                }

                //Not show, when no elements available...
                if (m_CodeTextBox.IntellisenseBox.Items.Count > 0)
                {
                    m_CodeTextBox.IntellisenseBox.SelectedIndex = 0;
                    return(true);
                }
                return(false);

                #endregion
            }


            int      i    = 1;
            TreeNode node = null;

            //Find the root node
            node = m_CodeTextBox.IntellisenseTree.Nodes[words[0]];

            //Search the tree for the last node - before the one we actually type in
            while (node != null && i < words.Length - 1)
            {
                node = node.Nodes[words[i]];
                i++;
            }

            //Couldn't find one of the sub words...
            if (node == null)
            {
                return(false);
            }

            if (forceNextLevel)
            {
                lastWord = "";
            }

            //Add it's nodes to the intellisense list
            foreach (TreeNode n in node.Nodes)
            {
                if (!Like(n, lastWord))
                {
                    continue;
                }

                ImageListItem li = new ImageListItem();
                li.Text  = n.Name;
                li.Image = AssociateImage(n);

                m_CodeTextBox.IntellisenseBox.Items.Add(li);
            }

            //Show box
            ShowIntellisenseBoxWithoutUpdate();
            return(true);
        }