コード例 #1
0
        public bool CtrlSpace(ITextEditor editor)
        {
            int elementStartIndex = XmlParser.GetActiveElementStartIndex(editor.Document.Text, editor.Caret.Offset);

            if (elementStartIndex <= -1)
            {
                return(false);
            }
            if (ElementStartsWith("<!", elementStartIndex, editor.Document))
            {
                return(false);
            }
            if (ElementStartsWith("<?", elementStartIndex, editor.Document))
            {
                return(false);
            }

            XmlSchemaCompletion defaultSchema = schemaFileAssociations.GetSchemaCompletion(editor.FileName);

            XmlCompletionItemCollection completionItems = GetCompletionItems(editor, defaultSchema);

            if (completionItems.HasItems)
            {
                completionItems.Sort();
                string identifier = XmlParser.GetXmlIdentifierBeforeIndex(editor.Document, editor.Caret.Offset);
                completionItems.PreselectionLength = identifier.Length;
                ICompletionListWindow completionWindow = editor.ShowCompletionWindow(completionItems);
                if (completionWindow != null)
                {
                    SetCompletionWindowWidth(completionWindow, completionItems);
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
		void SetCompletionWindowWidth(ICompletionListWindow completionWindow, XmlCompletionItemCollection completionItems)
		{
			XmlCompletionItem firstListItem = completionItems[0];
			if (firstListItem.DataType == XmlCompletionItemType.NamespaceUri) {
				completionWindow.Width = double.NaN;
			}
		}
コード例 #3
0
        void SetCompletionWindowWidth(ICompletionListWindow completionWindow, XmlCompletionItemCollection completionItems)
        {
            XmlCompletionItem firstListItem = completionItems[0];

            if (firstListItem.DataType == XmlCompletionItemType.NamespaceUri)
            {
                completionWindow.Width = double.NaN;
            }
        }
コード例 #4
0
        public void CanCheckCompletionWindowFromShowCompletionHasWidthPropertyModified()
        {
            XmlCompletionItemCollection list = new XmlCompletionItemCollection();

            list.Add(new XmlCompletionItem("a"));
            ICompletionListWindow window = editor.ShowCompletionWindow(list);

            window.Width = double.NaN;

            Assert.AreEqual(double.NaN, editor.CompletionWindowDisplayed.Width);
        }
コード例 #5
0
        public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
        {
            XmlSchemaCompletion         defaultSchema   = schemaFileAssociations.GetSchemaCompletion(editor.FileName);
            XmlCompletionItemCollection completionItems = GetCompletionItems(editor, ch, defaultSchema);

            if (completionItems.HasItems)
            {
                completionItems.Sort();
                ICompletionListWindow completionWindow = editor.ShowCompletionWindow(completionItems);
                if (completionWindow != null)
                {
                    SetCompletionWindowWidth(completionWindow, completionItems);
                }
            }

            if ((ch == '<') || (ch == ' ') || (ch == '='))
            {
                return(CodeCompletionKeyPressResult.Completed);
            }
            return(CodeCompletionKeyPressResult.None);
        }
コード例 #6
0
        void DoXmlAttributeCompletion(XamlCompletionContext context, XamlCompletionItemList completionList)
        {
            if (context.Attribute.Name == "xml:space")
            {
                completionList.Items.AddRange(new[] {
                    new XamlCompletionItem("preserve"),
                    new XamlCompletionItem("default")
                });
            }

            if (context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) ||
                context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase))
            {
                completionList.Items.AddRange(generator.CreateListForXmlnsCompletion(compilation));

                ICompletionListWindow window = context.Editor.ShowCompletionWindow(completionList);
                if (window != null)
                {
                    window.Width = 400;
                }
            }
        }
コード例 #7
0
        public bool CtrlSpace(ITextEditor editor)
        {
            XamlCompletionContext context = CompletionDataHelper.ResolveCompletionContext(editor, ' ');

            context.Forced = trackForced;

            if (context.Description == XamlContextDescription.InComment || context.Description == XamlContextDescription.InCData)
            {
                return(false);
            }

            if (context.ActiveElement != null)
            {
                if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset) && context.Description != XamlContextDescription.InAttributeValue)
                {
                    XamlCompletionItemList list = CompletionDataHelper.CreateListForContext(context);
                    string starter = editor.GetWordBeforeCaretExtended().TrimStart('/');
                    if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter))
                    {
                        if (starter.Contains("."))
                        {
                            list.PreselectionLength = starter.Length - starter.IndexOf('.') - 1;
                        }
                        else
                        {
                            list.PreselectionLength = starter.Length;
                        }
                    }
                    editor.ShowCompletionWindow(list);
                    return(true);
                }
                else
                {
                    // DO NOT USE CompletionDataHelper.CreateListForContext here!!! results in endless recursion!!!!
                    if (context.Attribute != null)
                    {
                        if (!DoMarkupExtensionCompletion(context))
                        {
                            var completionList = new XamlCompletionItemList(context);
                            completionList.PreselectionLength = editor.GetWordBeforeCaretExtended().Length;

                            if ((context.ActiveElement.Name == "Setter" || context.ActiveElement.Name == "EventSetter") &&
                                (context.Attribute.Name == "Property" || context.Attribute.Name == "Value"))
                            {
                                DoSetterAndEventSetterCompletion(context, completionList);
                            }
                            else if ((context.ActiveElement.Name.EndsWith("Trigger") || context.ActiveElement.Name == "Condition") && context.Attribute.Name == "Value")
                            {
                                DoTriggerCompletion(context, completionList);
                            }
                            else
                            {
                                if (context.Attribute.Name == "xml:space")
                                {
                                    completionList.Items.AddRange(new[] { new SpecialCompletionItem("preserve"),
                                                                          new SpecialCompletionItem("default") });
                                }

                                var mrr = XamlResolver.Resolve(context.Attribute.Name, context) as MemberResolveResult;
                                if (mrr != null && mrr.ResolvedType != null)
                                {
                                    completionList.Items.AddRange(CompletionDataHelper.MemberCompletion(context, mrr.ResolvedType, string.Empty));
                                    editor.ShowInsightWindow(CompletionDataHelper.MemberInsight(mrr));
                                    if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.PropertyPath")
                                    {
                                        string start = editor.GetWordBeforeCaretExtended();
                                        int    index = start.LastIndexOfAny(PropertyPathTokenizer.ControlChars);
                                        if (index + 1 < start.Length)
                                        {
                                            start = start.Substring(index + 1);
                                        }
                                        else
                                        {
                                            start = "";
                                        }
                                        completionList.PreselectionLength = start.Length;
                                    }
                                    else if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.Media.FontFamily")
                                    {
                                        string text      = context.ValueStartOffset > -1 ? context.RawAttributeValue.Substring(0, Math.Min(context.ValueStartOffset, context.RawAttributeValue.Length)) : "";
                                        int    lastComma = text.LastIndexOf(',');
                                        completionList.PreselectionLength = lastComma == -1 ? context.ValueStartOffset : context.ValueStartOffset - lastComma - 1;
                                    }
                                }
                            }

                            completionList.SortItems();

                            if (context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) ||
                                context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase))
                            {
                                completionList.Items.AddRange(CompletionDataHelper.CreateListForXmlnsCompletion(context.ProjectContent));
                            }

                            ICompletionListWindow window = editor.ShowCompletionWindow(completionList);

                            if ((context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) ||
                                 context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase)) && window != null)
                            {
                                window.Width = 400;
                            }

                            return(completionList.Items.Any());
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }