Automatic Code Completion for arbitrary programming language
If there is no SyntaxParser for your language, you can consider implementing automatic code completion using NeedCodeCompletion event:
private void edit_NeedCodeCompletion(object sender, Alternet.Syntax.CodeCompletionArgs e)
{
if ((e.CompletionType == CodeCompletionType.ListMembers) ||
(e.CompletionType == CodeCompletionType.CompleteWord) ||
((e.CompletionType == CodeCompletionType.None) && (e.KeyChar == '.')))
{
// Look at Manual Code Completion, list members section
...
e.Interval = (e.CompletionType != CodeCompletionType.None)
? 0 : 500;
}
if(e.CompletionType == CodeCompletionType.ParameterInfo ||
e. CompletionType == CodeCompletionType.None &&
e.KeyChar == '(')
{
// Look at Manual Code Completion, parameter info section
...
e.Interval = (e.CompletionType != CodeCompletionType.None)
? 0 : 500;
}
}
Depending on the kind of language you are working with, and whether you are using some complete library to work with that language or doing everything yourself, the actual information on symbols will be retrieved in different ways:
if you are using some third-party library, look for something that resembles the name "Symbolic Information API" or like in the manual for that library;
if you are developing your own language or at least your own engine for some existing language, you probably already know what exactly to do to acquire the information necessary for code completion to work;
If you are working with the .NET family of languages, CLR Reflection API should be of use for this purpose. The sample program supplied with the package provides a good starting point for working with it.
Manual Code Completion
If you use Code Editor with a parser that does not fully support automatic code completion, you can still provide some guidance to the users as they type by implementing some of the code completion logic manually.
Global Settings
If the application contains more than one instance of the editor, it is often desired to share their UI settings and provide the user with a centralized facility to manage them. Code Editor is shipped with Customize quick start project that demonstrates how this can be accomplished.
It includes the SyntaxSettings class which is a holder for the following set of settings:
The font used to display the text in the editor
Syntax highlighting styles (i.e., foreground and background colors, font style)
Whether the following features are enabled or not:
Show margin
Show gutter
URL highlighting
Outlining
Word wrapping
Use of spaces instead of tabs for indents
The width of the gutter area
The position of the margin
Tab-stop positions
Navigation options
Selection options
Outline options
Scrollbar options
Color Themes
To the GlobalSettings class, its instance must be created, i.e.:
private SyntaxSettings GlobalSettings;
...
GlobalSettings = new SyntaxSettings();
The settings can be retrieved from some particular SyntaxEdit controls as follows:
GlobalSettings.LoadFromEdit(edit);
And then assigned to some other editor like this:
GlobalSettings.ApplyToEdit(edit);
Settings can be stored in the file:
GlobalSettings.SaveFile("GlobalSettings.xml");
And later on, loaded from that file:
GlobalSettings.LoadFile("GlobalSettings.xml");
As the file's name suggests, settings are stored in XML format. Note that in the real application, you would check for the existence of that file, and also, this file should probably be located somewhere down the user's Application Data folder.
To make handling the global settings even easier, the Customize demo project includes an example settings dialog.
All you need to do to use it is to declare and construct its instance:
using Alternet.Editor.Dialogs;
using Alternet.Editor.Wpf.Dialogs; // for WPF edition
...
private DlgSyntaxSettings Options;
...
Options = new DlgSyntaxSettings();
And later on, when the user requests the editor settings dialog, perform something similar to the following:
Options.SyntaxSettings.Assign(GlobalSettings);
if(Options.ShowDialog() == DialogResult.OK)
{
GlobalSettings.Assign(Options.SyntaxSettings);
// for each syntaxEdit or TextEditor used in the application
GlobalSettings.ApplyToEdit(edit);
}
Localization of dialogs
All string constants used in dialogs are localized to a few foreign languages. CodeEditor supports dialog localization to German, French, Spanish, Russian, and Ukrainian languages. The following code demonstrates how to switch to the German language:
Using Alternet.Common;
...
CultureInfo oldcInfo = Thread.CurrentThread.CurrentUICulture;
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
try
{
StringConsts.Localize();
}
finally
{
Thread.CurrentThread.CurrentUICulture = oldcInfo;
}