Full sample with INtelliprompt for SyntaxEditor

1 Answer 77 Views
SyntaxEditor
Richard
Top achievements
Rank 1
Richard asked on 27 Jul 2021, 07:38 AM

Hi,

 

I'm developing an application that will support scripting in it, so SyntaxEditor seems to be the perfect control to allow users to write there own script. But...

I tried to populate intelliprompts using this article (WPF SyntaxEditor | IntelliPrompts | Telerik UI for WPF) but with no success.

Do you have a full example not only an extract? In which event I populate the overlad list?

 

Thank's for any help.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 30 Jul 2021, 07:40 AM

Hello Richard,

The IntelliPrompts feature of RadSyntaxEditor provides a UI for intellisense-based functionality. The feature basically gives you a couple of popups (prompts) from which you can select a pre-defined word which will be included in the document. Those popups can be opened using the CompleteCode() and the IntelliPrompts.OverloadListWindow.Show() methods or the Ctrl+Space key combination. However, there is no automatic mechanism that opens the intelliprompts (like in Visual Studio for example). In case you want to achieve this, you will need to manually implement it by opening the prompts using one of the aforementioned methods. One way to do this is to use the DocumentContentChanged event of RadSyntaxEditor, where you can get information about the new state of the document, and based on it decide if prompt should be opened.

About the moment when the intelliprompts should be populated with items, it depends on your exact requirements. The example in the documentation implies that the collections are populated on initialization of the application, the view or the editor. In other words, all intellisense information is added beforehand. For example:

public MainWindow()
{
	InitializeComponent();

	var completionListItems = new CompletionInfoCollection()
	{
		new CompletionInfo("Collapsed", new BitmapImage(new Uri("../../Entity-Enum.png", UriKind.RelativeOrAbsolute))),
		new CompletionInfo("Hidden", new BitmapImage(new Uri("../../Entity-Enum.png", UriKind.RelativeOrAbsolute))),
		new CompletionInfo("Visible", new BitmapImage(new Uri("../../Entity-Enum.png", UriKind.RelativeOrAbsolute))),
	};

	this.syntaxEditor.IntelliPrompts.CompletionListWindow.Presenter.CompletionListItems = completionListItems;           
	this.syntaxEditor.Document = new Telerik.Windows.SyntaxEditor.Core.Text.TextDocument();
	this.syntaxEditor.TaggersRegistry.RegisterTagger(new CSharpTagger(this.syntaxEditor));
}

If you want to populate the intelliprompts dynamically while the user is typing, you can use the DocumentContentChanged  event.

private void syntaxEditor_DocumentContentChanged(object sender, Telerik.Windows.SyntaxEditor.Core.Text.TextContentChangedEventArgs e)
{
	if(the completion list prompt should be shown)
	{
		this.syntaxEditor.IntelliPrompts.CompletionListWindow.Presenter.CompletionListItems.Add(myNewItem);
		this.syntaxEditor.IntelliPrompts.CompletionListWindow.Show();
	}
}

I hope this information helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Richard
Top achievements
Rank 1
commented on 09 Aug 2021, 06:03 AM

So the difficulty is to know what is the change. For example, imagine I wrote:

MyLabel = "MyDb";

Then, I move the cursor just after MyLabel and write . So, I the user do Ctrl + Space, in the intellisense, I want to know that the "context" is "MyLabel." so I will add in completionListItems "Text" to allow him to write:

MyLabel.Text = "MyDb";

It's not easy with argument of DocumentContentChanged

Martin Ivanov
Telerik team
commented on 11 Aug 2021, 11:33 AM

Indeed, in this situation the DocumentContentChanged event won't be executed (unless you enter any text) which means that it won't be suitable for the case. For this case, you can use the PreviewSyntaxEditorKeyDown. Here is one way to do so:

private void syntaxEditor_PreviewSyntaxEditorKeyDown(object sender, Telerik.Windows.Controls.SyntaxEditor.UI.PreviewSyntaxEditorKeyEventArgs e)
{
	if (KeyboardModifiers.IsControlDown && e.Key == System.Windows.Input.Key.Space)
	{
		var doc = this.syntaxEditor.Document.CurrentSnapshot;
		CaretPosition caretPosition = this.syntaxEditor.CaretPosition;
		TextSnapshotLine currentLine = doc.Lines.ElementAt(caretPosition.LineNumber);
		string lineText = currentLine.GetText();
		char currentCharacter = lineText[caretPosition.ColumnNumber - 1];
		if (currentCharacter.Equals('.'))
		{
			// update the completion list
		}
	}
}

Tags
SyntaxEditor
Asked by
Richard
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or