使用AvalonEdit实现WPF的Lua编辑器

您所在的位置:网站首页 wpf代码编辑器 使用AvalonEdit实现WPF的Lua编辑器

使用AvalonEdit实现WPF的Lua编辑器

2024-01-01 18:18| 来源: 网络整理| 查看: 265

原文发布于:https://www.chenxublog.com/2019/07/14/use-avalonedit-make-wpf-lua-editor.html

由于LLCOM里面内置了Lua代码的编辑器,所以我就使用了AvalonEdit这个轮子,不过一开始的Lua语言支持让我一顿好找

不过好在找到了网上的资料,我就把整个实现过程贴在下面

准备

先去nuget安装一下AvalonEdit,以备后面使用:

接着把下面的文件内容,保存为Lua.xshd文件名的文件:

TODO FIXME HACK UNDONE --- --\[[=]*\[ \][=]*] -- " " ' ' \[[=]*\[ \][=]*] true false and break do else elseif end false for function if in local not or repeat return then true until while using continue break return local nil \b [\d\w_]+ # an identifier (?=\s*\() # followed by ( \b [\d\w_]+ # an identifier (?=\s*\") # followed by " \b [\d\w_]+ # an identifier (?=\s*\') # followed by ' \b [\d\w_]+ # an identifier (?=\s*\{) # followed by { \b [\d\w_]+ # an identifier (?=\s*\[) # followed by [ \b0[xX][0-9a-fA-F]+ # hex number | ( \b\d+(\.[0-9]+)? #number with optional floating point | \.[0-9]+ #or just starting with floating point ) ([eE][+-]?[0-9]+)? # optional exponent [?,.;()\[\]{}+\-/%*;;^+~!|;]+

把Lua.xshd放到解决方案资源管理器中,生成操作改为嵌入的资源:

使用

xaml里的代码如下:

然后在窗体的loaded事件中运行下面的代码即可:

//快速搜索功能 SearchPanel.Install(textEditor.TextArea); //设置语法规则 string name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".Lua.xshd"; System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); using (System.IO.Stream s = assembly.GetManifestResourceStream(name)) { using (XmlTextReader reader = new XmlTextReader(s)) { var xshd = HighlightingLoader.LoadXshd(reader); textEditor.SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance); } } 效果

效果什么的。。。自己去下载一个LLCOM看看就知道了嘛:



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3