Exemplo n.º 1
0
 public void HandleTextEntered(EditorControl control, string insertText)
 {
     if (_isInitialized)
       {
     switch (insertText)
     {
       case "\"":
       case " ":
       case "<":
       case ",":
       case "(":
     int overlap;
     var completionItems = this.GetCompletions(control.Editor.Text.Substring(0, control.Editor.CaretOffset), this.SoapAction, out overlap).Select(c => new BasicCompletionData(c));
     control.ShowCompletionWindow(completionItems, overlap);
     break;
       case ">":
     var endTag = this.LastOpenTag(control.Editor.Text.Substring(0, control.Editor.CaretOffset));
     if (!string.IsNullOrEmpty(endTag))
     {
       var insert = "</" + endTag + ">";
       if (!control.Editor.Text.Substring(control.Editor.CaretOffset).StartsWith(insert))
       {
         control.Editor.Document.Insert(control.Editor.CaretOffset, insert, AnchorMovementType.BeforeInsertion);
       }
     }
     break;
     }
       }
 }
        public virtual void HandleTextEntered(EditorControl control, string insertText)
        {
            var text = control.Editor.Text.Substring(0, control.Editor.CaretOffset);

            ICompletionData[]            result = null;
            XmlElementPath               parentPath;
            IEnumerable <XmlElementPath> parentPaths;

            switch (insertText)
            {
            case "=":
                // Namespace intellisense.
                if (XmlParser.IsNamespaceDeclaration(text, text.Length))
                {
                    result = schemaCompletionDataItems.GetNamespaceCompletionData();
                }
                break;

            case "<":
                // Child element intellisense.
                parentPaths = XmlParser.GetParentElementPaths(text);
                if (parentPaths.Any())
                {
                    foreach (var path in parentPaths)
                    {
                        result = GetChildElementCompletionData(path);
                        if (result.Any())
                        {
                            break;
                        }
                    }
                }
                else if (defaultSchemaCompletionData != null)
                {
                    result = defaultSchemaCompletionData.GetElementCompletionData(defaultNamespacePrefix);
                }
                break;

            case " ":
                // Attribute intellisense.
                if (!XmlParser.IsInsideAttributeValue(text, text.Length))
                {
                    XmlElementPath path = XmlParser.GetActiveElementStartPath(text, text.Length);
                    if (path.Elements.Count > 0)
                    {
                        result = GetAttributeCompletionData(path);
                    }
                }
                break;

            case ">":
                var elementName = XmlParser.GetOpenElement(text);
                if (!string.IsNullOrEmpty(elementName))
                {
                    var insert = "</" + elementName + ">";
                    if (!control.Editor.Text.Substring(control.Editor.CaretOffset).Trim().StartsWith(insert))
                    {
                        control.Editor.Document.Insert(control.Editor.CaretOffset, insert, AnchorMovementType.BeforeInsertion);
                    }
                }
                break;

            default:

                // Attribute value intellisense.
                if (XmlParser.IsAttributeValueChar(insertText[0]))
                {
                    string attributeName = XmlParser.GetAttributeName(text, text.Length);
                    if (attributeName.Length > 0)
                    {
                        XmlElementPath elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
                        if (elementPath.Elements.Count > 0)
                        {
                            //preSelection = insertText.ToString();
                            result = GetAttributeValueCompletionData(elementPath, attributeName);
                        }
                    }
                }
                break;
            }

            if (result != null)
            {
                Array.Sort(result, (x, y) => x.Text.CompareTo(y.Text));
                control.ShowCompletionWindow(result, 0);
            }
        }
        public virtual void HandleTextEntered(EditorControl control, string insertText)
        {
            var text = control.Editor.Text.Substring(0, control.Editor.CaretOffset);
              ICompletionData[] result = null;
              XmlElementPath parentPath;
              IEnumerable<XmlElementPath> parentPaths;
              switch (insertText)
              {
            case "=":
              // Namespace intellisense.
              if (XmlParser.IsNamespaceDeclaration(text, text.Length))
              {
            result = schemaCompletionDataItems.GetNamespaceCompletionData();
              }
              break;
            case "<":
              // Child element intellisense.
              parentPaths = XmlParser.GetParentElementPaths(text);
              if (parentPaths.Any())
              {
            foreach (var path in parentPaths)
            {
              result = GetChildElementCompletionData(path);
              if (result.Any()) break;
            }
              }
              else if (defaultSchemaCompletionData != null)
              {
            result = defaultSchemaCompletionData.GetElementCompletionData(defaultNamespacePrefix);
              }
              break;

            case " ":
              // Attribute intellisense.
              if (!XmlParser.IsInsideAttributeValue(text, text.Length))
              {
            XmlElementPath path = XmlParser.GetActiveElementStartPath(text, text.Length);
            if (path.Elements.Count > 0)
            {
              result = GetAttributeCompletionData(path);
            }
              }
              break;
            case ">":
              var elementName = XmlParser.GetOpenElement(text);
              if (!string.IsNullOrEmpty(elementName))
              {
            var insert = "</" + elementName + ">";
            if (!control.Editor.Text.Substring(control.Editor.CaretOffset).Trim().StartsWith(insert))
            {
              control.Editor.Document.Insert(control.Editor.CaretOffset, insert, AnchorMovementType.BeforeInsertion);
            }
              }
              break;
            default:

              // Attribute value intellisense.
              if (XmlParser.IsAttributeValueChar(insertText[0]))
              {
            string attributeName = XmlParser.GetAttributeName(text, text.Length);
            if (attributeName.Length > 0)
            {
              XmlElementPath elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
              if (elementPath.Elements.Count > 0)
              {
                //preSelection = insertText.ToString();
                result = GetAttributeValueCompletionData(elementPath, attributeName);
              }
            }
              }
              break;
              }

              if (result != null)
              {
            Array.Sort(result, (x, y) => x.Text.CompareTo(y.Text));
            control.ShowCompletionWindow(result, 0);
              }
        }