Пример #1
0
        private Namespace GetNamespace(TextStream textStream, Document document)
        {
            Namespace ns = null;
            Dictionary <string, Namespace> lookup;

            List <string> parts = new List <string>();

            while (textStream.GoToPreviousToken() && textStream.Token.Key == "DotOperatorToken")
            {
                textStream.GoToPreviousToken();
                IToken token = textStream.PeekToken();
                if (token.Key != "IdentifierToken")
                {
                    break;
                }
                parts.Insert(0, document.GetTokenText(token));
            }
            foreach (string part in parts)
            {
                if (ns == null)
                {
                    lookup = m_scriptEngineDefinition.NamespaceLookup;
                }
                else
                {
                    lookup = ns.NamespaceLookup;
                }

                if (!lookup.TryGetValue(part, out ns))
                {
                    return(null);
                }
            }
            return(ns);
        }
Пример #2
0
        private Function GetFunction(TextStream textStream, Document document)
        {
            int nesting = 0;

            while (nesting != -1)
            {
                if (textStream.TokenIndex == 0)
                {
                    return(null);
                }

                textStream.SeekToken(-1);

                switch (textStream.PeekToken().Key)
                {
                case "OpenParenthesisToken":
                    nesting--;
                    break;

                case "CloseParenthesisToken":
                    nesting++;
                    break;
                }
            }

            if (!textStream.GoToPreviousToken())
            {
                return(null);
            }

            string functionName;

            if (textStream.Token.Key == "IdentifierToken")
            {
                functionName = document.GetTokenText(textStream.Token);
            }
            else
            {
                return(null);
            }

            /*if (textStream.TokenIndex == 0)
             *      return null;
             *
             * textStream.SeekToken(-1);*/

            Namespace ns = GetNamespace(textStream, document);

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

            foreach (Function f in ns.Functions)
            {
                if (f.Name == functionName)
                {
                    return(f);
                }
            }
            return(null);
        }
Пример #3
0
        private void lvAutoComplete_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            this.fIP.Hide();

            if (e.KeyCode == Keys.Escape)
            {
                editor.txtEditor.Focus();
                this.Close();
                this.Dispose();
            }
            else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.PageDown || e.KeyCode == Keys.PageUp || e.KeyCode == Keys.End || e.KeyCode == Keys.Home)
            {
                // Update the side listing
                SelectPrompt();
            }
            else if (e.KeyCode == Keys.Tab || e.KeyCode == Keys.Right)
            {
                // Displays the members of the selected object, if it's a class
                if (this.lvAutoComplete.SelectedItems.Count == 0)
                {
                    return;
                }

                if (!(this.lvAutoComplete.SelectedItems[0].Tag is CAutoComplete.ClassEntry))
                {
                    return;
                }

                this.prevclass = (CAutoComplete.ClassEntry) this.lvAutoComplete.SelectedItems[0].Tag;

                UpdateClassMembers((CAutoComplete.ClassEntry) this.lvAutoComplete.SelectedItems[0].Tag);
            }
            else if (e.KeyCode == Keys.Left)
            {
                // Displays the previous class's information
                if (this.lvAutoComplete.SelectedItems.Count > 0 && this.lvAutoComplete.SelectedItems[0].Tag is CAutoComplete.ClassEntry.FuncEntry)
                {
                    this.prevfunc = (CAutoComplete.ClassEntry.FuncEntry)lvAutoComplete.SelectedItems[0].Tag;
                }

                UpdateMainClassList();
            }
            else if (e.KeyCode == Keys.Enter)
            {
                // Commit an item to the active editor
                if (this.lvAutoComplete.SelectedItems.Count == 0)
                {
                    return;
                }

                if (this.lvAutoComplete.SelectedItems[0].Tag is CAutoComplete.ClassEntry)
                {
                    this.prevclass = (CAutoComplete.ClassEntry)lvAutoComplete.SelectedItems[0].Tag;

                    if (var != "")
                    {
                        int line = editor.txtEditor.SelectedView.Selection.EndPosition.Line;
                        int chr  = editor.txtEditor.SelectedView.Selection.EndPosition.Character;

                        TextStream ts = editor.txtEditor.Document.GetTextStream(editor.txtEditor.SelectedView.Selection.StartOffset);
                        ts.GoToPreviousToken("LineTerminatorToken");

                        editor.txtEditor.SelectedView.Selection.StartOffset = ts.CurrentToken.EndOffset;
                        editor.txtEditor.SelectedView.InsertLineBreak();
                        ts = editor.txtEditor.Document.GetTextStream(ts.CurrentToken.StartOffset);
                        ts.GoToNextToken("LineTerminatorToken");
                        editor.txtEditor.SelectedView.Selection.StartOffset = ts.CurrentToken.EndOffset;

                        editor.txtEditor.SelectedView.Selection.StartOffset = ts.CurrentToken.EndOffset;
                        editor.txtEditor.SelectedView.InsertText("//# DECLARE " + var + " as " + (this.lvAutoComplete.SelectedItems[0].Tag as CAutoComplete.ClassEntry).ClassName);

                        editor.txtEditor.SelectedView.Selection.StartOffset = editor.txtEditor.Document.PositionToOffset(new Position(line + 1, chr));
                    }
                    else
                    {
                        editor.txtEditor.SelectedView.InsertText((this.lvAutoComplete.SelectedItems[0].Tag as CAutoComplete.ClassEntry).ClassName + " ");
                    }
                }
                else if (this.lvAutoComplete.SelectedItems[0].Tag is CAutoComplete.ClassEntry.FuncEntry)
                {
                    this.prevfunc = (CAutoComplete.ClassEntry.FuncEntry)lvAutoComplete.SelectedItems[0].Tag;
                    editor.txtEditor.SelectedView.InsertText((this.lvAutoComplete.SelectedItems[0].Tag as CAutoComplete.ClassEntry.FuncEntry).func_name);
                }
                else if (this.lvAutoComplete.SelectedItems[0].Tag is CAutoComplete.ClassEntry.PropEntry)
                {
                    editor.txtEditor.SelectedView.InsertText((this.lvAutoComplete.SelectedItems[0].Tag as CAutoComplete.ClassEntry.PropEntry).prop_name);
                }
                else
                {
                    return;
                }

                editor.txtEditor.Focus();
                this.Close();
                this.Dispose();

                this.fIP.Close();
                this.fIP.Dispose();
            }
        }
Пример #4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Completes the element tag at the specified offset.
        /// </summary>
        /// <param name="syntaxEditor">The <see cref="SyntaxEditor"/> to examine.</param>
        /// <param name="offset">The offset at which to base the context.</param>
        private void CompleteElementTag(SyntaxEditor syntaxEditor, int offset)
        {
            string elementName = null;

            // Ensure the previous token is a > and not a />
            TextStream stream = syntaxEditor.Document.GetTextStream(offset);

            if (!stream.GoToPreviousToken())
            {
                return;
            }
            if ((stream.Token.Key != "StartTagEndToken") || (offset - stream.Offset != 1))
            {
                return;
            }

            // Search backward for a start element name
            bool exitLoop = false;

            while (stream.GoToPreviousToken())
            {
                switch (stream.Token.Key)
                {
                case "StartTagNameToken":
                    elementName = stream.TokenText.Trim();
                    exitLoop    = true;
                    break;

                case "StartTagStartToken":
                case "EndTagEndToken":
                    return;
                }
                if (exitLoop)
                {
                    break;
                }
            }

            // Quit if no element name was found
            if (elementName == null)
            {
                return;
            }

            // Search forward to ensure that the next element is not an end element for the same element
            stream.Offset = offset;
            exitLoop      = false;
            while (!stream.IsAtDocumentEnd)
            {
                switch (stream.Token.Key)
                {
                case "EndTagDefaultToken":
                    if (elementName == stream.TokenText.Trim())
                    {
                        return;
                    }
                    else
                    {
                        exitLoop = true;
                    }
                    break;

                case "StartTagStartToken":
                case "EndTagEndToken":
                    exitLoop = true;
                    break;
                }
                if (exitLoop)
                {
                    break;
                }
                stream.GoToNextToken();
            }

            // Insert the end element text
            syntaxEditor.SelectedView.InsertSurroundingText(DocumentModificationType.AutoComplete, null, "</" + elementName + ">");
        }
        private void CompleteElementTag(ActiproSoftware.SyntaxEditor.SyntaxEditor syntaxEditor, int offset)
        {
            string     str        = null;
            TextStream textStream = syntaxEditor.get_Document().GetTextStream(offset);

            if (textStream.GoToPreviousToken() && ((textStream.get_Token().get_Key() == "StartTagEndToken") && ((offset - textStream.get_Offset()) == 1)))
            {
                bool flag = false;
                while (textStream.GoToPreviousToken())
                {
                    string str2 = textStream.get_Token().get_Key();
                    if (str2 != null)
                    {
                        if (!(str2 == "StartTagNameToken"))
                        {
                            if ((str2 == "StartTagStartToken") || (str2 == "EndTagEndToken"))
                            {
                                return;
                            }
                        }
                        else
                        {
                            str  = textStream.get_TokenText().Trim();
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                if (str != null)
                {
                    textStream.set_Offset(offset);
                    flag = false;
                    while (!textStream.get_IsAtDocumentEnd())
                    {
                        switch (textStream.get_Token().get_Key())
                        {
                        case "EndTagDefaultToken":
                            if (str == textStream.get_TokenText().Trim())
                            {
                                return;
                            }
                            flag = true;
                            break;

                        case "StartTagStartToken":
                        case "EndTagEndToken":
                            flag = true;
                            break;
                        }
                        if (flag)
                        {
                            break;
                        }
                        textStream.GoToNextToken();
                    }
                    syntaxEditor.get_SelectedView().InsertSurroundingText(0, null, "</" + str + ">");
                }
            }
        }