Typewriter.NET是一个简单易用的文本编辑器,它遵循几个核心原则,使得用户可以快速上手并提高工作效率。以下是Typewriter.NET的一些主要特点:
要构建并运行Typewriter.NET,请按照以下步骤操作:
这个快捷键会运行配置文件中的命令:
<item name="f5Command" value="!c:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe /verbosity:m /p:Configuration=Release /target:tw"/>
以下行允许自动补全:
<item name="omnisharpSln" value="."/>
要在Typewriter.NET中创建自定义命令,需要修改Commander.cs
文件。以下是添加命令的示例:
public void Init(MainForm mainForm, Settings settings, TempSettings tempSettings)
{
this.mainForm = mainForm;
this.settings = settings;
this.tempSettings = tempSettings;
history = tempSettings.CommandHistory;
commands.Add(
new Command(
"help",
"",
"open/close tab with help text",
DoHelp));
...
commands.Add(
new Command(
"replb",
"[{…}]command",
"open REPL bottom",
DoReplBottom));
}
探索命令枚举,该枚举在每个光标处输入数字:
commands.Add(
new Command(
"enum",
"[n0] [step] [count]",
"...",
DoEnum));
commands.Add(
new Command(
"enum0",
"[n0] [step] [count]",
"...",
DoEnum0));
commands.Add(
new Command(
"enumr",
"[n0] [step] [count]",
"...",
DoEnumr));
...
private void DoEnum(string text)
{
ProcessEnum(text, EnumGenerator.Mode.Number);
}
private void DoEnum0(string text)
{
ProcessEnum(text, EnumGenerator.Mode.ZeroBeforeNumber);
}
private void DoEnumr(string text)
{
ProcessEnum(text, EnumGenerator.Mode.Roman);
}
private void ProcessEnum(string text, EnumGenerator.Mode mode)
{
...
EnumGenerator generator = new EnumGenerator(text, lastBuffer.Controller.SelectionsCount, mode);
...
lastBuffer.Controller.InsertTexts(generator.texts.ToArray());
}
可以在MainForm.cs
中添加常见的菜单项。以下是添加菜单项的示例:
private void BuildMenu()
{
keyMap = new KeyMap();
doNothingKeyMap = new KeyMap();
doNothingKeyMap.AddItem(
new KeyItem(Keys.Escape, null, KeyAction.Nothing));
doNothingKeyMap.AddItem(
new KeyItem(Keys.Escape | Keys.Shift, null, KeyAction.Nothing));
doNothingKeyMap.AddItem(
new KeyItem(Keys.Control | Keys.J, null, KeyAction.Nothing));
doNothingKeyMap.AddItem(
new KeyItem(Keys.Control | Keys.K, null, KeyAction.Nothing));
keyMap.AddItem(
new KeyItem(Keys.Control | Keys.N, null,
new KeyAction(
"&File\\New", DoNew, null, false)));
keyMap.AddItem(
new KeyItem(Keys.Control | Keys.O, null,
new KeyAction(
"&File\\Open", DoOpen, null, false)));
keyMap.AddItem(
new KeyItem(Keys.None, null,
new KeyAction(
"&File\\-",
null,
null,
false)));
...
keyMap.AddItem(
new KeyItem(Keys.None, null,
new KeyAction(
"&?\\Kate syntax highlighting help…",
DoOpenSyntaxHelp,
null,
false)));
}
...
private bool DoOpenSyntaxHelp(Controller controller)
{
OpenDocument(Path.Combine(AppPath.StartupDir, "syntax/syntax.html"));
return true;
}
真正的命令结果会阻止其他具有相同快捷键的操作的快捷反应。
例如,创建一个简单的自动补全命令:
commands.Add(
new Command(
"simple-autocomplete",
"",
"simple autocomplete",
DoSimpleAutocomplete));
...
public void DoSimpleAutocomplete(string text)
{
Buffer lastBuffer = mainForm.LastBuffer;
if (lastBuffer == null)
{
mainForm.Dialogs.ShowInfo("Error", "No buffer");
return;
}
Selection selection = lastBuffer.Controller.LastSelection;
Place place = lastBuffer.Controller.Lines.PlaceOf(selection.anchor);
string word = lastBuffer.Controller.GetLeftWord(place);
List variants = new List();
for (int i = 1; i <= 3; i++)
{
Variant variant = new Variant();
variant.CompletionText = "simple_" + i;
variant.DisplayText = "simple_" + i;
variants.Add(variant);
}
if (mainForm.LastFrame.AsFrame != null)
mainForm.LastFrame.AsFrame.ShowAutocomplete(variants, word);
}
<item name="ctrlSpaceCommand:*.txt" value="simple-autocomplete"/>