
Below is the code from my two objects. You don't have an HTML editor in your samples and the C# editors works quite a bit differently.
For our HTML editor we're just using the basic editor with the example HTML xml langauge with a few key bindings and commands added.
namespace KaliEditorControl {
public partial class KaliEditor : UserControl {
static KaliEditor() {
// Start the parser service (only call this once at the start of your application)
SemanticParserService.Start();
}
public KaliEditor() {
InitializeComponent();
// Show line numbers
syntaxEditor.LineNumberMarginVisible = true;
//
// Bind search/replace dialog to CTRL-F
//
syntaxEditor.CommandLinks.Add(new CommandLink(new SearchReplaceCommand(),
new KeyBinding(ActiproSoftware.WinUICore.Input.ModifierKeys.Control, Keys.F)));
//
// Bind toggle line numbers to CTRL-SHIFT-3
//
syntaxEditor.CommandLinks.Add(new CommandLink(new ToggleLineNumberCommand(),
new KeyBinding(ActiproSoftware.WinUICore.Input.ModifierKeys.ControlShift, Keys.D3)));
//
// Bind find next to CTRL-N and F3
//
syntaxEditor.CommandLinks.Add(new CommandLink(new IncrementalSearchCommand(),
new KeyBinding(ActiproSoftware.WinUICore.Input.ModifierKeys.Control, Keys.N)));
syntaxEditor.CommandLinks.Add(new CommandLink(new IncrementalSearchCommand(),
new KeyBinding(ActiproSoftware.WinUICore.Input.ModifierKeys.None, Keys.F3)));
//
// Bind reverse find next to CTRL-SHIFT-N and CTRL-SHIFT-I
//
syntaxEditor.CommandLinks.Add(new CommandLink(new ReverseIncrementalSearchCommand(),
new KeyBinding(ActiproSoftware.WinUICore.Input.ModifierKeys.ControlShift, Keys.N)));
//
// Unbind those commands that are buggy and/or dangerous to users.
//
UnbindCommands();
}
public virtual void InitEditor(string langFilePath) {
//
// Add the langauge to the editor.
//
syntaxEditor.Document.LoadLanguageFromXml(langFilePath, 0);
//
// This is very important to call, when using inheritance the designer will add this call
// automatically, when wrapped you must call it yourself of the syntax editor will not function
// correctly.
//
syntaxEditor.InitializeLifetimeService();
}
public void SetScript(string script) {
syntaxEditor.Document.Text = script;
}
public string GetScript() {
return syntaxEditor.Document.Text;
}
private void UnbindCommands() {
for (int index = syntaxEditor.CommandLinks.Count - 1; index >= 0; index--) {
//
// Unbind the Insert hot key since it deletes selected text when clicked.
//
if (HotKeysMatch(syntaxEditor.CommandLinks[index],
ActiproSoftware.WinUICore.Input.ModifierKeys.None, Keys.Insert))
{
syntaxEditor.CommandLinks.RemoveAt(index);
}
//
// Ubind transpose lines as it is buggy
//
if (HotKeysMatch(syntaxEditor.CommandLinks[index],
ActiproSoftware.WinUICore.Input.ModifierKeys.ControlShiftAlt, Keys.T))
{
syntaxEditor.CommandLinks.RemoveAt(index);
}
//
// Ubind transpose words as it is buggy
//
if (HotKeysMatch(syntaxEditor.CommandLinks[index],
ActiproSoftware.WinUICore.Input.ModifierKeys.ControlShift, Keys.T))
{
syntaxEditor.CommandLinks.RemoveAt(index);
}
}
syntaxEditor.Focus();
}
private bool HotKeysMatch(CommandLink commandLink, ActiproSoftware.WinUICore.Input.ModifierKeys modiferKey, Keys key) {
if (commandLink.KeyBinding.Modifiers != modiferKey || (commandLink.KeyBinding.Key != key)) {
return false;
}
return true;
}
}
}
namespace KaliHtmlEditor {
public partial class TestEditorForm : Form {
private string script;
public TestEditorForm() {
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// Couple of different test patterns.
//
kaliEditor.InitEditor("../../ActiproSoftware.HTML.xml");
script = LoadScript();
}
//
// Hard coded for testing purposes only.
//
private string LoadScript() {
FileStream file = new FileStream("../../TestJsp.htm", FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(file);
string script = reader.ReadToEnd();
reader.Close();
file.Close();
return script;
}
private void buttonLoad_Click(object sender, EventArgs e) {
kaliEditor.SetScript(script);
}
private void buttonOk_Click(object sender, EventArgs e) {
script = kaliEditor.GetScript();
kaliEditor.SetScript(null);
}
}
}