Esempio n. 1
0
        public bool TextArea_DoProcessDialogKey(Keys keyData, EditorControl editor)
        {
            if ((CurrentTemplate != null) && keyData == Keys.Enter)
            {
                foreach (var item in CurrentTemplate.List)
                {
                    if (item.HasChilds)
                    {
                        List <CopyMarker> copyMarkerList = CurrentTemplate.GetChildsOfParent(item.VariableName);
                        if (copyMarkerList.Count > 0)
                        {
                            string currentText = editor.Text.Substring(item.Expression.Offset, item.Expression.Length);
                            foreach (var copyItem in copyMarkerList)
                            {
                                //string copyText
                                editor.Document.Remove(copyItem.Expression.Offset, copyItem.Expression.Length);
                                editor.Document.Insert(copyItem.Expression.Offset, currentText);
                            }
                        }
                    }
                }

                CurrentTemplate.GoToEndMarker(editor);
                ClearMarkers(editor);
                CurrentTemplate = null;
                processTemplate = false;
                return(true);
            }
            if ((keyData == Keys.Tab) && (CurrentTemplate != null))
            {
                bool canSwitch = CurrentTemplate.SwitchBetweenExpressions(editor);

                if (canSwitch)
                {
                    return(canSwitch);
                }
                else
                {
                    CurrentTemplate.GoToEndMarker(editor);
                    return(true);
                }
            }
            else if (keyData == Keys.Tab)
            {
                if (mouseEndPosition != null)
                {
                    editor.Caret.Position = editor.Document.OffsetToPosition(mouseEndPosition.Offset);

                    removeMouseEndPosition(editor);
                    return(true);
                }
                else
                {
                    int    shortcutOffset = TextUtilities.FindPrevWordStart(editor.Document, editor.Caret.Offset);
                    string shortcut       = TextUtilities.GetWordAt(editor.Document, shortcutOffset);
                    switch (HighlighterUtils.GetDocumentLanguage(editor))
                    {
                    case DocumentLanguage.PHP:
                        return(InsertQuickTemplate(shortcut, shortcutOffset, DocumentLanguage.PHP, editor));;

                    case DocumentLanguage.JavaScript:
                        return(InsertQuickTemplate(shortcut, shortcutOffset, DocumentLanguage.JavaScript, editor));
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        public void LoadDefinationFile(string fileName)
        {
            XmlTextReader      reader   = new XmlTextReader(fileName);
            TemplateDefinition template = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:

                    if (reader.Name == "Template")
                    {
                        string           shortCut        = string.Empty;
                        string           templateText    = string.Empty;
                        int              variablesInText = -1;
                        DocumentLanguage docLang         = DocumentLanguage.NULL;

                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.Name)
                            {
                            case "shortcut":
                                shortCut = reader.Value;
                                break;

                            case "text":
                                templateText = ReplaceLineBreak(reader.Value);
                                break;

                            case "variables":
                                variablesInText = int.Parse(reader.Value);
                                break;

                            case "docLang":
                                docLang = (DocumentLanguage)Enum.Parse(typeof(DocumentLanguage), reader.Value);
                                Console.WriteLine(docLang.ToString());
                                break;
                            }
                        }
                        template = AddTemplateDefinition(shortCut, templateText, variablesInText, docLang);
                    }

                    if (reader.Name == "Variable")
                    {
                        if (template != null)
                        {
                            string name  = string.Empty;
                            string value = string.Empty;

                            while (reader.MoveToNextAttribute())
                            {
                                switch (reader.Name)
                                {
                                case "name":
                                    name = reader.Value;
                                    break;

                                case "value":
                                    value = reader.Value;
                                    break;
                                }
                            }
                            template.AddVariable(name, value);
                        }
                    }
                    break;



                case XmlNodeType.EndElement:
                    break;
                }
            }
        }