Example #1
0
        public SharpDevelopCompletionWindow(ITextEditor editor, TextArea textArea, ICompletionItemList itemList)
            : base(textArea)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            if (itemList == null)
            {
                throw new ArgumentNullException("itemList");
            }

            if (!itemList.ContainsAllAvailableItems)
            {
                // If more items are available (Ctrl+Space wasn't pressed), show this hint
                EmptyText = "Empty";
            }

            Editor        = editor;
            this.itemList = itemList;
            ICompletionItem suggestedItem = itemList.SuggestedItem;

            foreach (var item in itemList.Items)
            {
                ICompletionData adapter = new CodeCompletionDataAdapter(this, item);
                CompletionList.CompletionData.Add(adapter);
                if (item == suggestedItem)
                {
                    CompletionList.SelectedItem = adapter;
                }
            }
            StartOffset -= itemList.PreselectionLength;
            Width        = 250;
        }
		protected void TestTextInsert(string file, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset)
		{
			int insertionPoint = file.IndexOf('|');
			
			if (insertionPoint < 0)
				Assert.Fail("insertionPoint not found in text!");
			
			this.textEditor.Document.Text = file.Replace("|", "");
			this.textEditor.Caret.Offset = insertionPoint;
			this.textEditor.CreateParseInformation();
			
			CompletionContext context = new CompletionContext() {
				Editor = this.textEditor,
				CompletionChar = completionChar,
				StartOffset = textEditor.Caret.Offset,
				EndOffset = textEditor.Caret.Offset
			};
			
			list.Complete(context, item);
			
			if (!context.CompletionCharHandled && context.CompletionChar != '\n')
				this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + "");
			
			string insertedText = this.textEditor.Document.GetText(insertionPoint, this.textEditor.Document.TextLength - file.Length + 1);
			
			Assert.AreEqual(expectedOutput, insertedText);
			Assert.AreEqual(insertionPoint + expectedOffset, textEditor.Caret.Offset);
		}
		public SharpDevelopCompletionWindow(ITextEditor editor, TextArea textArea, ICompletionItemList itemList) : base(textArea)
		{
			if (editor == null)
				throw new ArgumentNullException("editor");
			if (itemList == null)
				throw new ArgumentNullException("itemList");
			
			if (!itemList.ContainsAllAvailableItems) {
				// If more items are available (Ctrl+Space wasn't pressed), show this hint
				this.EmptyText = StringParser.Parse("${res:ICSharpCode.AvalonEdit.AddIn.SharpDevelopCompletionWindow.EmptyText}");
			}
			
			InitializeComponent();
			this.Editor = editor;
			this.itemList = itemList;
			ICompletionItem suggestedItem = itemList.SuggestedItem;
			foreach (ICompletionItem item in itemList.Items) {
				ICompletionData adapter = new CodeCompletionDataAdapter(this, item);
				this.CompletionList.CompletionData.Add(adapter);
				if (item == suggestedItem)
					this.CompletionList.SelectedItem = adapter;
			}
			this.StartOffset -= itemList.PreselectionLength;
			this.EndOffset += itemList.PostselectionLength;
		}
        public CodeCompletionWindow(ITextEditor editor, TextArea textArea, ICompletionItemList itemList)
            : base(textArea)
        {
            if (editor == null)
                throw new ArgumentNullException("editor");
            if (itemList == null)
                throw new ArgumentNullException("itemList");

            if (!itemList.ContainsAllAvailableItems) {
                // If more items are available (Ctrl+Space wasn't pressed), show this hint
                this.EmptyText = "Press Ctrl+Space to show items from all namespaces";
            }

            //InitializeComponent();
            this.Editor = editor;
            this.itemList = itemList;
            ICompletionItem suggestedItem = itemList.SuggestedItem;
            foreach (ICompletionItem item in itemList.Items) {
                ICompletionData adapter = new CodeCompletionDataAdapter(this, item);
                this.CompletionList.CompletionData.Add(adapter);
                if (item == suggestedItem)
                    this.CompletionList.SelectedItem = adapter;
            }
            this.StartOffset -= itemList.PreselectionLength;
        }
Example #5
0
        public SharpDevelopCompletionWindow(TextEditor editor, TextArea textArea, ICompletionItemList itemList) : base(textArea)
        {
            if (editor == null)
            {
                throw new ArgumentNullException(nameof(editor));
            }
            if (itemList == null)
            {
                throw new ArgumentNullException(nameof(itemList));
            }

            Editor    = editor;
            _itemList = itemList;
            var suggestedItem = itemList.SuggestedItem;

            foreach (var item in itemList.Items)
            {
                ICompletionData adapter = new CodeCompletionDataAdapter(this, item);
                CompletionList.CompletionData.Add(adapter);
                if (item == suggestedItem)
                {
                    CompletionList.SelectedItem = adapter;
                }
            }
            StartOffset -= itemList.PreselectionLength;
            EndOffset   += itemList.PostselectionLength;
        }
        public CodeSnippetCompletionWindow(ITextEditor editor, ICompletionItemList list)
            : base(editor, editor.GetService(typeof(TextArea)) as TextArea, list)
        {
            this.snippetInput = new TextBox();

            DockPanel panel = new DockPanel()
            {
                Children =
                {
                    snippetInput
                }
            };

            this.Content = panel;

            panel.Children.Add(CompletionList);

            snippetInput.SetValue(DockPanel.DockProperty, Dock.Top);

            this.Width  = 150;
            this.Height = 200;

            this.Loaded += delegate { Keyboard.Focus(snippetInput); };
            this.snippetInput.PreviewKeyDown += new KeyEventHandler(CodeSnippetCompletionWindowPreviewKeyDown);
            this.snippetInput.TextChanged    += new TextChangedEventHandler(CodeSnippetCompletionWindow_TextChanged);
        }
Example #7
0
        public CodeCompletionWindow(ITextEditor editor, TextArea textArea, ICompletionItemList itemList) : base(textArea)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            if (itemList == null)
            {
                throw new ArgumentNullException("itemList");
            }

            if (!itemList.ContainsAllAvailableItems)
            {
                // If more items are available (Ctrl+Space wasn't pressed), show this hint
                this.EmptyText = "Press Ctrl+Space to show items from all namespaces";
            }

            //InitializeComponent();
            this.Editor   = editor;
            this.itemList = itemList;
            ICompletionItem suggestedItem = itemList.SuggestedItem;

            foreach (ICompletionItem item in itemList.Items)
            {
                ICompletionData adapter = new CodeCompletionDataAdapter(this, item);
                this.CompletionList.CompletionData.Add(adapter);
                if (item == suggestedItem)
                {
                    this.CompletionList.SelectedItem = adapter;
                }
            }
            this.StartOffset -= itemList.PreselectionLength;
        }
        public SharpDevelopCompletionWindow(ITextEditor editor, TextArea textArea, ICompletionItemList itemList) : base(textArea)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            if (itemList == null)
            {
                throw new ArgumentNullException("itemList");
            }

            if (!itemList.ContainsAllAvailableItems)
            {
                // If more items are available (Ctrl+Space wasn't pressed), show this hint
                this.EmptyText = StringParser.Parse("${res:ICSharpCode.AvalonEdit.AddIn.SharpDevelopCompletionWindow.EmptyText}");
            }

            InitializeComponent();
            this.Editor   = editor;
            this.itemList = itemList;
            ICompletionItem suggestedItem = itemList.SuggestedItem;

            foreach (ICompletionItem item in itemList.Items)
            {
                ICompletionData adapter = new CodeCompletionDataAdapter(this, item);
                this.CompletionList.CompletionData.Add(adapter);
                if (item == suggestedItem)
                {
                    this.CompletionList.SelectedItem = adapter;
                }
            }
            this.StartOffset -= itemList.PreselectionLength;
        }
        protected void TestTextInsert(string file, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset)
        {
            int insertionPoint = file.IndexOf('|');

            if (insertionPoint < 0)
            {
                Assert.Fail("insertionPoint not found in text!");
            }

            this.textEditor.Document.Text = file.Replace("|", "");
            this.textEditor.Caret.Offset  = insertionPoint;
            this.textEditor.CreateParseInformation();

            CompletionContext context = new CompletionContext()
            {
                Editor         = this.textEditor,
                CompletionChar = completionChar,
                StartOffset    = textEditor.Caret.Offset,
                EndOffset      = textEditor.Caret.Offset
            };

            list.Complete(context, item);

            if (!context.CompletionCharHandled && context.CompletionChar != '\n')
            {
                this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + "");
            }

            string insertedText = this.textEditor.Document.GetText(insertionPoint, this.textEditor.Document.TextLength - file.Length + 1);

            Assert.AreEqual(expectedOutput, insertedText);
            Assert.AreEqual(insertionPoint + expectedOffset, textEditor.Caret.Offset);
        }
		public override ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
		{
			if (data == null || !data.Items.Any())
				return null;
			SharpDevelopCompletionWindow window = new SharpDevelopCompletionWindow(this, this.TextEditor.TextArea, data);
			textEditor.ShowCompletionWindow(window);
			return window;
		}
Example #11
0
        public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
        {
            ICompletionItemList list = GenerateCompletionListCore(editor);

            if (ShowTemplates)
            {
                AddTemplates(editor, list as DefaultCompletionItemList);
            }
            return(list);
        }
Example #12
0
        public override ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
        {
            if (data == null || !data.Items.Any())
            {
                return(null);
            }
            SharpDevelopCompletionWindow window = new SharpDevelopCompletionWindow(this, this.TextEditor.TextArea, data);

            textEditor.ShowCompletionWindow(window);
            return(window);
        }
Example #13
0
        protected void TestKeyPress(string fileHeader, string fileFooter, char keyPressed, CodeCompletionKeyPressResult keyPressResult, Action <ICompletionItemList> constraint)
        {
            SetUpWithCode(fileHeader + fileFooter, fileHeader.Length);
            CodeCompletionKeyPressResult result = new XamlCodeCompletionBinding().HandleKeyPress(textEditor, keyPressed);

            Assert.AreEqual(keyPressResult, result);

            ICompletionItemList list = this.textEditor.LastCompletionItemList;

            constraint(list);
        }
Example #14
0
        public ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
        {
            if (data == null || !data.Items.Any())
            {
                return(null);
            }
            SharpDevelopCompletionWindow window = new SharpDevelopCompletionWindow(this, TextArea, data);

            ShowCompletionWindow(window);
            return(window);
        }
        public override ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
        {
            if (data == null || !data.Items.Any())
            {
                return(null);
            }
            var window = new WabbitcodeCompletionWindow(this, textEditor.TextArea, data);

            textEditor.ShowCompletionWindow(window);
            return(window);
        }
Example #16
0
        protected void TestCtrlSpace(string fileHeader, string fileFooter, bool expected, Action <ICompletionItemList> constraint)
        {
            SetUpWithCode(fileHeader + fileFooter, fileHeader.Length);
            bool invoked = new XamlCodeCompletionBinding().CtrlSpace(textEditor);

            Assert.AreEqual(expected, invoked);
            ICompletionItemList list = textEditor.LastCompletionItemList;

            Assert.NotNull(list);
            constraint(list);
        }
Example #17
0
        public bool ShowCompletion(ITextEditor editor, bool memberCompletion)
        {
            this.memberCompletion = memberCompletion;
            ICompletionItemList list = GenerateCompletionList(editor);

            if (list.Items.Any())
            {
                editor.ShowCompletionWindow(list);
                return(true);
            }
            return(false);
        }
Example #18
0
        internal static VBNetCompletionItemList ToVBCCList(this ICompletionItemList list)
        {
            var result = new VBNetCompletionItemList()
            {
                SuggestedItem      = list.SuggestedItem,
                PreselectionLength = list.PreselectionLength
            };

            result.Items.AddRange(list.Items);

            return(result);
        }
        /// <summary>
        /// Shows code completion for the specified editor.
        /// </summary>
        public virtual void ShowCompletion(ITextEditor editor)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            ICompletionItemList itemList = GenerateCompletionList(editor);

            if (itemList != null)
            {
                editor.ShowCompletionWindow(itemList);
            }
        }
        /// <summary>
        /// Shows code completion for the specified editor.
        /// </summary>
        protected void ShowCompletion(ICompletionItemProvider completionItemProvider, ITextEditor editor, IProjectContent projectContent)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            ICompletionItemList itemList = completionItemProvider.GenerateCompletionList(editor, projectContent);

            if (itemList != null)
            {
                editor.ShowCompletionWindow(FilterList(itemList));
            }
        }
Example #21
0
        protected override ICompletionItemList FilterList(ICompletionItemList itemList)
        {
            if (FilterStrategy == null)
            {
                return(itemList);
            }
            var defaultCompletionItemList = new DefaultCompletionItemList
            {
                SuggestedItem = itemList.SuggestedItem, PreselectionLength = itemList.PreselectionLength
            };

            defaultCompletionItemList.Items.AddRange(FilterStrategy.Filter(itemList.Items));
            return(defaultCompletionItemList);
        }
Example #22
0
        protected void TestCtrlSpace(string fileHeader, string fileFooter, bool expected, Action <ICompletionItemList> constraint)
        {
            this.textEditor.Document.Text = fileHeader + fileFooter;
            this.textEditor.Caret.Offset  = fileHeader.Length;
            this.textEditor.CreateParseInformation();

            bool invoked = new XamlCodeCompletionBinding().CtrlSpace(textEditor);

            Assert.AreEqual(expected, invoked);

            ICompletionItemList list = this.textEditor.LastCompletionItemList;

            constraint(list);
        }
Example #23
0
        protected void TestKeyPress(string fileHeader, string fileFooter, char keyPressed, CodeCompletionKeyPressResult keyPressResult, Action <ICompletionItemList> constraint)
        {
            this.textEditor.Document.Text = fileHeader + fileFooter;
            this.textEditor.Caret.Offset  = fileHeader.Length;
            this.textEditor.CreateParseInformation();

            CodeCompletionKeyPressResult result = new XamlCodeCompletionBinding().HandleKeyPress(textEditor, keyPressed);

            Assert.AreEqual(keyPressResult, result);

            ICompletionItemList list = this.textEditor.LastCompletionItemList;

            constraint(list);
        }
        public ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
        {
            completionItemsDisplayed         = data;
            showCompletionWindowMethodCalled = true;

            if (showCompletionWindowReturnsNull)
            {
                completionWindowDisplayed = null;
            }
            else
            {
                completionWindowDisplayed = new MockCompletionListWindow();
            }
            return(completionWindowDisplayed);
        }
Example #25
0
        public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
        {
            ICompletionItemList list = baseProvider.GenerateCompletionList(editor);

            if (this.RemoveAttributeSuffix && list != null)
            {
                foreach (CodeCompletionItem d in list.Items.OfType <CodeCompletionItem>())
                {
                    if (d.Text.EndsWith("Attribute"))
                    {
                        d.Text = d.Text.Substring(0, d.Text.Length - 9);
                    }
                }
            }
            return(list);
        }
        protected void TestKeyPress(string file, char keyPressed, CodeCompletionKeyPressResult keyPressResult, Action <ICompletionItemList> constraint)
        {
            int insertionPoint = file.IndexOf('|');

            if (insertionPoint < 0)
            {
                Assert.Fail("insertionPoint not found in text!");
            }

            this.textEditor.Document.Text = file.Replace("|", "");
            this.textEditor.Caret.Offset  = insertionPoint;
            this.textEditor.CreateParseInformation();

            CodeCompletionKeyPressResult result = new VBNetCompletionBinding().HandleKeyPress(textEditor, keyPressed);

            Assert.AreEqual(keyPressResult, result);

            ICompletionItemList list = this.textEditor.LastCompletionItemList;

            constraint(list);
        }
        protected void TestCtrlSpace(string file, bool expected, Action <ICompletionItemList> constraint)
        {
            int insertionPoint = file.IndexOf('|');

            if (insertionPoint < 0)
            {
                Assert.Fail("insertionPoint not found in text!");
            }

            this.textEditor.Document.Text = file.Replace("|", "");
            this.textEditor.Caret.Offset  = insertionPoint;
            this.textEditor.CreateParseInformation();

            bool invoked = new VBNetCompletionBinding().CtrlSpace(textEditor);

            Assert.AreEqual(expected, invoked);

            ICompletionItemList list = this.textEditor.LastCompletionItemList;

            constraint(list);
        }
		protected void TestTextInsert(string fileHeader, string fileFooter, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset)
		{
			this.textEditor.Document.Text = fileHeader + fileFooter;
			this.textEditor.Caret.Offset = fileHeader.Length;
			this.textEditor.CreateParseInformation();
			
			CompletionContext context = new CompletionContext() {
				Editor = this.textEditor,
				CompletionChar = completionChar,
				StartOffset = textEditor.Caret.Offset,
				EndOffset = textEditor.Caret.Offset
			};
			
			list.Complete(context, item);
			
			if (!context.CompletionCharHandled && context.CompletionChar != '\n')
				this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + "");
			
			string insertedText = this.textEditor.Document.GetText(fileHeader.Length, this.textEditor.Document.TextLength - fileHeader.Length - fileFooter.Length);
			
			Assert.AreEqual(expectedOutput, insertedText);
			Assert.AreEqual(fileHeader.Length + expectedOffset, textEditor.Caret.Offset);
		}
		public CodeSnippetCompletionWindow(ITextEditor editor, ICompletionItemList list)
			: base(editor, editor.GetService(typeof(TextArea)) as TextArea, list)
		{
			this.snippetInput = new TextBox();
			
			DockPanel panel = new DockPanel() {
				Children = {
					snippetInput
				}
			};
			
			this.Content = panel;
			
			panel.Children.Add(CompletionList);
			
			snippetInput.SetValue(DockPanel.DockProperty, Dock.Top);
			
			this.Width = 150;
			this.Height = 200;
			
			this.Loaded += delegate { Keyboard.Focus(snippetInput); };
			this.snippetInput.PreviewKeyDown += new KeyEventHandler(CodeSnippetCompletionWindowPreviewKeyDown);
			this.snippetInput.TextChanged += new TextChangedEventHandler(CodeSnippetCompletionWindow_TextChanged);
		}
Example #30
0
		public ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
		{
			completionItemsDisplayed = data;
			showCompletionWindowMethodCalled = true;
			
			if (showCompletionWindowReturnsNull) {
				completionWindowDisplayed = null;
			} else {
				completionWindowDisplayed = new MockCompletionListWindow();
			}
			return completionWindowDisplayed;
		}
 public ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
 {
     throw new NotImplementedException();
 }
Example #32
0
 public virtual ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
 {
     return(null);
 }
 protected virtual ICompletionItemList FilterList(ICompletionItemList itemList)
 {
     return(itemList);
 }
Example #34
0
        protected void TestTextInsert(string fileHeader, string fileFooter, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset)
        {
            textEditor.Document.Text = fileHeader + fileFooter;
            textEditor.Caret.Offset  = fileHeader.Length;

            CompletionContext context = new CompletionContext()
            {
                Editor         = this.textEditor,
                CompletionChar = completionChar,
                StartOffset    = textEditor.Caret.Offset,
                EndOffset      = textEditor.Caret.Offset
            };

            list.Complete(context, item);

            if (!context.CompletionCharHandled && context.CompletionChar != '\n')
            {
                this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + "");
            }

            string insertedText = this.textEditor.Document.GetText(fileHeader.Length, this.textEditor.Document.TextLength - fileHeader.Length - fileFooter.Length);

            Assert.AreEqual(expectedOutput, insertedText);
            Assert.AreEqual(fileHeader.Length + expectedOffset, textEditor.Caret.Offset);
        }
 public override ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
 {
     this.lastCompletionItemList = data;
     return(null);
 }
		public virtual ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
		{
			return null;
		}
Example #37
0
		public override ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
		{
			this.lastCompletionItemList = data;
			return null;
		}
        static ICompletionItemList AddTemplateCompletionItems(ITextEditor editor, ICompletionItemList list, char ch)
        {
            if(list == null) return null;

            if(ch == 'c' || ch == 'C'){
                var res = new DefaultCompletionItemList();
                res.Items.AddRange(list.Items);
                res.Items.Add(new CurveTemplateCompletionItem(editor));
                return res;
            }

            return null;
        }
Example #39
0
		public ICompletionListWindow ShowCompletionWindow(ICompletionItemList data)
		{
			throw new NotImplementedException();
		}