예제 #1
0
        void DoValueEntering()
        {
            //add value completion list.
            if (!CheckedForValueCompletion)
            {
                //if (char.IsLetterOrDigit(text[text.Length - 1]) || text[text.Length - 1] == ' ')
                //{
                //find attribute (we are within quote)
                string attrib = null;
                int    i      = Content.Document.Text.LastIndexOf(" ", Content.CaretOffset, StringComparison.OrdinalIgnoreCase);
                if (i > -1 && XmlHelper.IsInTag(Content.Document.Text, i))
                {
                    int j = Content.Document.Text.LastIndexOf("=", Content.CaretOffset, StringComparison.OrdinalIgnoreCase);
                    if (j > i)
                    {
                        attrib = Content.Document.Text.Substring(i + 1, j - i - 1).Trim();
                    }
                }
                string nd = XmlHelper.GetNodeName(XmlHelper.GetLastNode(Content.Document.Text, Content.CaretOffset));

                if (Commands.Current.CommandDictionary.ContainsKey(nd))
                {
                    CommandElement cmd1 = Commands.Current.CommandDictionary[nd] as CommandElement;

                    AttributeElement elem = null;
                    foreach (AttributeElement cmd in cmd1.Attributes)
                    {
                        if (cmd.Text == attrib)
                        {
                            elem = cmd;
                            break;
                        }
                    }

                    if (elem != null)
                    {
                        if (elem.AttributeType == AttributeType.ExpressionValue)
                        {
                            List <string> variables = GetVariables();
                            variables.Sort();
                            List <ICompletionData> data = new List <ICompletionData>();
                            string lastVar = string.Empty;
                            foreach (string v in variables)
                            {
                                if (v != lastVar)
                                {
                                    data.Add(new XmlCompletionData(v));
                                    lastVar = v;
                                }
                            }
                            AddCompletionData(data);
                        }
                        else
                        {
                            //If the attribute starts "name", get list of names from <create.
                            if (elem.Text.StartsWith("name", StringComparison.OrdinalIgnoreCase))
                            {
                                List <string> variables = GetNames();
                                variables.Sort();
                                List <ICompletionData> data = new List <ICompletionData>();
                                string lastVar = string.Empty;
                                foreach (string v in variables)
                                {
                                    if (v != lastVar)
                                    {
                                        data.Add(new XmlCompletionData(v));
                                        lastVar = v;
                                    }
                                }
                                AddCompletionData(data);
                            }
                            else if (elem.Values != null)
                            {
                                List <ICompletionData> data = new List <ICompletionData>();
                                foreach (XmlCompletionData value in elem.Values)
                                {
                                    data.Add(value);
                                }
                                AddCompletionData(data);
                            }
                        }
                    }
                }
                //}
                CheckedForValueCompletion = true;
            }
        }
예제 #2
0
        //static readonly ILog _log = LogManager.GetLogger(typeof(Commands));
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); }
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); }

        //Load from mission-file-docs.txt
        void LoadMissionDoc()
        {
            //First load special critical COMMANDS, then load from file.

            //LoadCreate();
            //12/30/2012
            string           txt     = Properties.Resources.mission_file_docs;
            bool             started = false;
            CommandElement   currentActiveCommand   = null;
            AttributeElement currentActiveAttribute = null;

            foreach (string ll in txt.Split('\n'))
            {
                string sline = ll.Replace("\t", string.Empty).Replace("\r", string.Empty).Trim();

                if (!started)
                {
                    if (sline.StartsWith("COMMAND", StringComparison.OrdinalIgnoreCase))
                    {
                        started = true;
                    }
                }

                if (started)
                {
                    switch (DetermineLineType(sline))
                    {
                    case LineType.Command:
                    case LineType.Condition:
                        KeyValuePair <string, string> cmd = GetCommandData(sline);
                        currentActiveCommand = new CommandElement(cmd.Key, cmd.Value);
                        if (!CommandDictionary.ContainsKey(cmd.Key))
                        {
                            CommandDictionary.Add(cmd.Key, currentActiveCommand);
                        }
                        else
                        {
                            currentActiveCommand = CommandDictionary[cmd.Key];
                        }
                        break;

                    case LineType.Attribute:
                        if (currentActiveCommand != null)
                        {
                            bool foundAttrib = false;
                            currentActiveAttribute = new AttributeElement(GetAttributeData(sline));
                            currentActiveAttribute.ParentCommand = currentActiveCommand.Text;
                            foreach (AttributeElement att in currentActiveCommand.Attributes)
                            {
                                if (att.Text == currentActiveAttribute.Text)
                                {
                                    foundAttrib            = true;
                                    currentActiveAttribute = att;
                                    break;
                                }
                            }
                            if (!foundAttrib)
                            {
                                currentActiveCommand.Attributes.Add(currentActiveAttribute);
                            }
                        }
                        break;

                    case LineType.ValueList:
                        ProcessValue(sline, currentActiveAttribute);

                        break;
                    }
                }
            }
        }
예제 #3
0
        protected override void OnTextEntered(System.Windows.Input.TextCompositionEventArgs e)
        {
            base.OnTextEntered(e);
            //Code completion here.
            //"<" entered, command completion offered.
            if (e != null)
            {
                if (e.Text.EndsWith("<", StringComparison.OrdinalIgnoreCase))
                {
                    CheckedForValueCompletion = false;
                    if (IsInEvent(Content.CaretOffset))
                    {
                        List <ICompletionData> data = new List <ICompletionData>();
                        foreach (string cmd in Commands.Current.CommandDictionary.Keys)
                        {
                            data.Add(Commands.Current.CommandDictionary[cmd]);
                        }
                        AddCompletionData(data);

                        //buildCommand = new StringBuilder();
                        //caretStart = Content.CaretOffset;
                    }
                    else
                    {
                        List <ICompletionData> data = new List <ICompletionData>();
                        data.Add(new XmlCompletionData("event"));
                        AddCompletionData(data);
                    }
                }
                else
                {
                    if (completionWindow == null && XmlHelper.IsInTag(Content.Document.Text, Content.CaretOffset))
                    {
                        //int iWrk = 0;
                        ////char prevChar = '~';
                        //if (Content.CaretOffset > 0)
                        //{
                        //    iWrk = Content.CaretOffset;
                        //    //prevChar = Content.Document.Text[iWrk - 1];
                        //}


                        if (!XmlHelper.IsWithinQuotes(Content.Document.Text, Content.CaretOffset)) // && caretStart + buildCommand.ToString().Length == Content.CaretOffset)
                        {
                            if (char.IsLetterOrDigit(e.Text[e.Text.Length - 1]) || e.Text[e.Text.Length - 1] == ' ')
                            {
                                //find command and lookup in dictionary.
                                string nd = XmlHelper.GetNodeName(XmlHelper.GetLastNode(Content.Document.Text, Content.CaretOffset));
                                if (Commands.Current.CommandDictionary.ContainsKey(nd))
                                {
                                    CommandElement cmd1 = Commands.Current.CommandDictionary[nd] as CommandElement;

                                    List <ICompletionData> data = new List <ICompletionData>();
                                    foreach (AttributeElement cmd in cmd1.GetSortedAttributes())
                                    {
                                        data.Add(cmd);
                                    }
                                    AddCompletionData(data);
                                    CheckedForValueCompletion = false;
                                }
                            }
                        }
                        else
                        {
                            if (!CheckedForValueCompletion)
                            {
                                if (char.IsLetterOrDigit(e.Text[e.Text.Length - 1]) || e.Text[e.Text.Length - 1] == ' ' ||
                                    ("-+*/^%.".Contains(e.Text[e.Text.Length - 1])))
                                {
                                    NoCodeCompleteCharacters = "-+*/^%.";
                                    DoValueEntering();
                                }
                            }
                        }
                    }
                }
            }
        }