Exemplo n.º 1
0
        public void LoadFromXml(string content)
        {
            // Parse Xml spec for symbols
            XqlParser parser = new XqlParser();

            parser.LoadData(content);

            // Search for keyword definitions
            List <Hashtable> results = parser.Query("SELECT name, type FROM Keyword");

            foreach (Hashtable result in results)
            {
                ScriptingSymbol newSymbol = new ScriptingSymbol();
                newSymbol.Name    = result["name"].ToString();
                newSymbol.Type    = LuaSymbolType.Keyword;
                newSymbol.Enabled = true;
                _symbols.Add(newSymbol);
            }

            // Search for class definitions and symbols within each class scope
            results = parser.Query("SELECT name, _outerXml FROM Class");
            XqlParser subParser = new XqlParser();

            foreach (Hashtable result in results)
            {
                ScriptingSymbol newSymbol = new ScriptingSymbol();
                newSymbol.Name    = result["name"].ToString();
                newSymbol.Type    = LuaSymbolType.Class;
                newSymbol.Enabled = true;
                _symbols.Add(newSymbol);

                // Add method and member symbols within this class scope (disabled until scope opened)
                subParser.LoadData(result["_outerXml"].ToString());
                List <Hashtable> subResults = subParser.Query("SELECT name, type FROM Method");
                foreach (Hashtable subResult in subResults)
                {
                    ScriptingSymbol classMethod = new ScriptingSymbol();
                    classMethod.Name         = subResult["name"].ToString();
                    classMethod.Type         = LuaSymbolType.Function;
                    classMethod.Enabled      = false;
                    classMethod.ParentSymbol = newSymbol;
                    _symbols.Add(classMethod);
                }
                subResults = subParser.Query("SELECT name, type FROM Property");
                foreach (Hashtable subResult in subResults)
                {
                    ScriptingSymbol classProperty = new ScriptingSymbol();
                    classProperty.Name         = subResult["name"].ToString();
                    classProperty.Type         = LuaSymbolType.Local;
                    classProperty.Enabled      = false;
                    classProperty.ParentSymbol = newSymbol;
                    _symbols.Add(classProperty);
                }
            }

            // Sort all symbols and update listbox content
            SortSymbols();
            UpdateItems();
        }
Exemplo n.º 2
0
        public void HighlightBestGuess(string guess)
        {
            // Highlights the closest match symbol to the current word
            SymbolListItem currItem;
            int            bestGuess  = -1;
            int            compResult = 0;

            for (int i = 0; i < Items.Count; i++)
            {
                try
                {
                    currItem = (SymbolListItem)Items[i];
                    ScriptingSymbol sym = FindSymbol(currItem.Name);
                    if (sym.Enabled)
                    {
                        compResult = guess.CompareTo(sym.Name);
                        if (compResult < 0)
                        {
                            if (sym.Name.Contains(guess))
                            {
                                // Partial match; select and break
                                SelectedIndex = i;
                                return;
                            }
                            else
                            {
                                // Too far; deselect and break
                                UnselectAll();
                                return;
                            }
                        }
                        else if (compResult == 0)
                        {
                            // Perfect match; select and break
                            SelectedIndex = i;
                            return;
                        }
                        else
                        {
                            // Not there yet; continue
                            bestGuess = i;
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    // Wasn't a symbol list item; shouldn't happen!
                    MessageBox.Show("What happened!?");
                }
            }

            // If we haven't set a match by this point, don't select anything
            UnselectAll();
        }
        private void addNodeButton_Click(object sender, EventArgs e)
        {
            // Check for location
            TreeNode currentNode = subsystemTreeView.SelectedNode;

            if (currentNode == SubsystemNode)
            {
                // Do nothing to add to head node
                return;
            }
            if (currentNode.Parent != SubsystemNode)
            {
                // Shift to right level
                currentNode = currentNode.Parent;
            }
            if (currentNode.Text == "Scripted Functions")
            {
                // Create new function with name from textbox dialog
                ScriptedFunction newFunction = new ScriptedFunction();
                TextboxDialog    dialog      = new TextboxDialog("Create new function", "New function name");
                dialog.ShowDialog();
                if (dialog.Cancelled)
                {
                    return;
                }
                newFunction.Name = dialog.StringValue;

                // Add function node
                TreeNode newNode = new TreeNode(newFunction.Name + "()");
                newNode.Tag = newFunction;
                currentNode.Nodes.Add(newNode);
                currentNode.Expand();

                // Add function text at bottom, set cursor position to function parameters
                string header = "function " + newFunction.Name + "()";
                scriptingEditor.InsertLine("", -1);
                scriptingEditor.InsertLine(header, -1);
                scriptingEditor.InsertLine("end", -1);
                scriptingEditor.Focus();
                int focusCol = header.Length - 1;
                int focusRow = scriptingEditor.Lines.Length - 2;
                scriptingEditor.CursorPosition = new Point(focusCol, focusRow);

                // Add function to subsystem script
                Script.Functions.Add(newFunction);
            }
            if (currentNode.Text == "State Variables")
            {
                // Create new variable with name from textbox dialog
                StateVariable newVar = new StateVariable();
                TextboxDialog dialog = new TextboxDialog("Create new state variable", "New variable name");
                dialog.ShowDialog();
                if (dialog.Cancelled)
                {
                    return;
                }
                newVar.Name = dialog.StringValue;

                // Add variable node
                TreeNode newNode = new TreeNode(newVar.Name);
                newNode.Tag = newVar;
                currentNode.Nodes.Add(newNode);
                currentNode.Expand();

                // Add variable to global symbols
                ScriptingSymbol varSymb = new ScriptingSymbol();
                varSymb.Enabled = true;
                varSymb.Name    = newVar.Name;
                varSymb.Type    = LuaSymbolType.Global;
                scriptingEditor.ScriptingSymbolListbox.Symbols.Add(varSymb);
                scriptingEditor.ScriptingSymbolListbox.SortSymbols();

                // Add function to subsystem script
                Script.States.Add(newVar);
            }
            if (currentNode.Text == "Subsystem Parameters")
            {
                // Create new parameter with name from textbox dialog
                SubsystemParameter newParam = new SubsystemParameter();
                TextboxDialog      dialog   = new TextboxDialog("Create new parameter", "New parameter name");
                dialog.ShowDialog();
                if (dialog.Cancelled)
                {
                    return;
                }
                newParam.Name = dialog.StringValue;

                // Add parameter node
                TreeNode newNode = new TreeNode(newParam.Name);
                newNode.Tag = newParam;
                currentNode.Nodes.Add(newNode);
                currentNode.Expand();

                // Add parameter to global symbols
                ScriptingSymbol varSymb = new ScriptingSymbol();
                varSymb.Enabled = true;
                varSymb.Name    = newParam.Name;
                varSymb.Type    = LuaSymbolType.Global;
                scriptingEditor.ScriptingSymbolListbox.Symbols.Add(varSymb);
                scriptingEditor.ScriptingSymbolListbox.SortSymbols();

                // Add parameter to subsystem script
                Script.Parameters.Add(newParam);
            }
        }