使用AvalonEdit实现WPF的Lua编辑器
原文发布于:https://www.chenxublog.com/2019/07/14/use-avalonedit-make-wpf-lua-editor.html
由于LLCOM里面内置了Lua代码的编辑器,所以我就使用了AvalonEdit
这个轮子,不过一开始的Lua语言支持让我一顿好找
不过好在找到了网上的资料,我就把整个实现过程贴在下面
准备
先去nuget安装一下AvalonEdit
,以备后面使用:
接着把下面的文件内容,保存为Lua.xshd
文件名的文件:
<?xml version="1.0"?>
<SyntaxDefinition name="SharpLua" extensions=".slua;.lua" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<!-- The named colors 'Comment' and 'String' are used in SharpDevelop to detect if a line is inside a multiline string/comment -->
<Color name="Comment" foreground="#ff999999" exampleText="-- comment" />
<Color name="String" foreground="#fff99157" />
<Color name="Punctuation" />
<Color name="MethodCall" foreground="#ffffcc66" fontWeight="bold"/>
<Color name="NumberLiteral" foreground="#ff99cc99"/>
<Color name="NilKeyword" fontWeight="bold"/>
<Color name="Keywords" fontWeight="bold" foreground="#ff6699cc" />
<Color name="GotoKeywords" foreground="#ffcc99cc" />
<Color name="Visibility" fontWeight="bold" foreground="#fff99157"/>
<Color name="TrueFalse" fontWeight="bold" foreground="#ff66cccc" />
<RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="#fff2777a">
<Word>TODO</Word>
<Word>FIXME</Word>
</Keywords>
<Keywords fontWeight="bold" foreground="#fff2777a">
<Word>HACK</Word>
<Word>UNDONE</Word>
</Keywords>
</RuleSet>
<!-- This is the main ruleset. -->
<RuleSet>
<Span color="Comment">
<Begin color="XmlDoc/DocComment">---</Begin>
<RuleSet>
<Import ruleSet="XmlDoc/DocCommentSet"/>
<Import ruleSet="CommentMarkerSet"/>
</RuleSet>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true">
<Begin>--\[[=]*\[</Begin>
<End>\][=]*]</End>
</Span>
<Span color="Comment" ruleSet="CommentMarkerSet">
<Begin>--</Begin>
</Span>
<Span color="String">
<Begin>"</Begin>
<End>"</End>
<RuleSet>
<!-- span for escape sequences -->
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Span color="String">
<Begin>'</Begin>
<End>'</End>
<RuleSet>
<!-- span for escape sequences -->
<Span begin="\\" end="."/>
</RuleSet>
</Span>
<Span color="String" multiline="true">
<Begin color="String">\[[=]*\[</Begin>
<End>\][=]*]</End>
</Span>
<Keywords color="TrueFalse">
<Word>true</Word>
<Word>false</Word>
</Keywords>
<Keywords color="Keywords">
<Word>and</Word>
<Word>break</Word>
<Word>do</Word>
<Word>else</Word>
<Word>elseif</Word>
<Word>end</Word>
<Word>false</Word>
<Word>for</Word>
<Word>function</Word>
<Word>if</Word>
<Word>in</Word>
<Word>local</Word>
<!--<Word>nil</Word>-->
<Word>not</Word>
<Word>or</Word>
<Word>repeat</Word>
<Word>return</Word>
<Word>then</Word>
<Word>true</Word>
<Word>until</Word>
<Word>while</Word>
<Word>using</Word>
<Word>continue</Word>
</Keywords>
<Keywords color="GotoKeywords">
<Word>break</Word>
<Word>return</Word>
</Keywords>
<Keywords color="Visibility">
<Word>local</Word>
</Keywords>
<Keywords color="NilKeyword">
<Word>nil</Word>
</Keywords>
<!-- Mark previous rule-->
<Rule color="MethodCall">
\b
[\d\w_]+ # an identifier
(?=\s*\() # followed by (
</Rule>
<Rule color="MethodCall">
\b
[\d\w_]+ # an identifier
(?=\s*\") # followed by "
</Rule>
<Rule color="MethodCall">
\b
[\d\w_]+ # an identifier
(?=\s*\') # followed by '
</Rule>
<Rule color="MethodCall">
\b
[\d\w_]+ # an identifier
(?=\s*\{) # followed by {
</Rule>
<Rule color="MethodCall">
\b
[\d\w_]+ # an identifier
(?=\s*\[) # followed by [
</Rule>
<!-- Digits -->
<Rule color="NumberLiteral">
\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
</Rule>
<Rule color="Punctuation">
[?,.;()\[\]{}+\-/%*<>^+~!|&]+
</Rule>
</RuleSet>
</SyntaxDefinition>
把Lua.xshd
放到解决方案资源管理器
中,生成操作
改为嵌入的资源
:
使用
xaml里的代码如下:
<avalonEdit:TextEditor
Grid.Row="2"
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
Name="textEditor"
FontFamily="Consolas"
FontSize="10pt"
ShowLineNumbers="True"
LostFocus="TextEditor_LostFocus"/>
然后在窗体的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看看就知道了嘛:
使用AvalonEdit实现WPF的Lua编辑器的更多相关文章
- 最好用的lua编辑器--------emmylua使用汇总
最好的lua编辑器Emmylua,欢迎打脸 官方文档 https://emmylua.github.io/zh_CN/ github https://github.com/EmmyLua ...
- 基于WPF&Prism&AvalonEdit的XAML轻量编辑器
1. 写在前面 一直从事WPF的相关开发工作,有时为了尝试或演示某些仅仅基于XAML的效果时,但又不想大动干戈打开VS去创建项目,所以一个轻便简单,集编辑与预览于一身的XAML编辑器就显得格外重要. ...
- Cocos2d-x游戏开发之lua编辑器 Sublime 搭建,集成cocos2dLuaApi和自有类
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/wisdom605768292/article/details/34085969 Sublime Te ...
- debian上安装lua编辑器
Debian服务器上安装lua 1)下载压缩包 wget http://www.lua.org/ftp/lua-5.1.4.tar.gz 2)解压文件 tar zxvf lua-5.1.4.tar. ...
- wpf 富文本编辑器richtextbox的简单用法
最近弄得一个小软件,需要用到富文本编辑器,richtextbox,一开始以为是和文本框一样的用法,但是实践起来碰壁之后才知道并不简单. richtextbox 类似于Word,是一个可编辑的控件.结构 ...
- WPF学习笔记(四):AvalonEdit 代码高亮编辑控件专题
AvalonEdit 是一个基于 WPF 的文本编辑器组件.它是由 Daniel Grunwald 为 SharpDevelop 编写的.从 5.0 版开始,AvalonEdit 根据MIT许可证发布 ...
- WPF开发时光之痕日记本(一)——富文本编辑器
本篇给大家推荐一个 WPF 版的富文本编辑器,SmithHtmlEditor,具体网址大家可以找一找,我在这个编辑器的基础上修改了界面,增加了一些功能,模仿了kindeditor 的界面,鉴于自己现在 ...
- Lua------------------改善Unity编辑器对Lua文件的支持
原创 2017年03月10日 18:44:22 标签: Unity / lua / 编辑器 952 当前版本的Unity(截至Unity5.5.x)中TextAsset类不支持后缀为lua的文件,将l ...
- .NET Core/.NET5/.NET6 开源项目汇总12:WPF组件库2
系列目录 [已更新最新开发文章,点击查看详细] WPF(Windows Presentation Foundation)是微软推出的基于Windows 的用户界面框架,属于.NET Frame ...
随机推荐
- Web前端基础(2):HTML(二)
1. body中的相关标签 1.1 标题标签:hn HTML提供<hn>系列标签,用于修饰标签,包含:<h1>.<h2>.<h3>.<h4> ...
- python中反转列表的三种方式
1.内建函数reversed() li =[1, 2, 3, 4, 5, 6] a = list(reversed(li)) print (a) 注意:reversed()函数返回的是一个迭代器,而不 ...
- The method newInstance() from the type Class is deprecated since version 9
newInstance()在 java9中已被弃用 JAVA9之前用法 Class.forName("类的全限定名").newInstance(); JAVA9之后用法 Class ...
- layui 集成第三方和自定义组件到模块规范
1.新建一个layui.extend.js文件,页面调用时这个文件放到layui.js后面. 2.基础的配置卸载config中,扩展的组件写入extend,组件的路径是相对于config下base的路 ...
- querySelectorAll和getElementsByClassName获取元素的区别
querySelectorAll()方法是HTML5新增的方法,通过传入一个css选择符,返回所有匹配的元素而不仅仅是一个元素.这个方法返回的是一个NodeList的实例.那么它和通过getEleme ...
- 被 GANs 虐千百遍后,我总结出来的 10 条训练经验
一年前,我决定开始探索生成式对抗网络(GANs).自从我对深度学习产生兴趣以来,我就一直对它们很着迷,主要是因为深度学习能做到很多不可置信的事情.当我想到人工智能的时候,GAN是我脑海中最先出现的一个 ...
- 转.HTML中img标签的src属性绝对路径问题解决办法,完全解决!
HTML中img标签的src属性绝对路径问题解决办法,完全解决 需求:有时候自己的项目img的src路径需要用到本地某文件夹下的图片,而不是直接使用项目根目录下的图片. 场景:eclipse,to ...
- 安卓开发笔记(三十四):Material Design框架实现优美的左侧侧滑栏
首先我们先上图: 下面是主页面的代码,activity_main.xml: <?xml version="1.0" encoding="utf-8"?& ...
- 有趣的bug——Java静态变量的循环依赖
背景 是的,标题没有错误,不是Spring Bean的循环依赖,而是静态变量之间的循环依赖. 近期的项目均是简单的Maven项目,通过K8S部署在阿里云上,其配置文件读取规则如下所示: (1) 优先读 ...
- MySQL 部署分布式架构 MyCAT (四)
分片(水平拆分) 2.取模分片(mod-long) cd /data/mycat/conf cp schema.xml schema.xml.rang-long vi schema.xml <? ...