使用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 ...
随机推荐
- 【LeetCode】2. 两数相加
题目 给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表 ...
- linux安装IB驱动方法
一.准备 1.Linux操作系统7.6(根据实际情况变更,此处用redhat7.6系统举例) 2.驱动:MLNX_OFED_LINUX-4.6-1.0.1.1-rhel7.6-x86_64.tgz(根 ...
- Windows下 gcc/g++的安装与配置
引言 我们知道开发最好用Mac/Linux,效率很高,但是对于很多还是Windows用户的我们来说,编写代码再到linux上运行也是很常有的事情,但对于我们写一些小demo使用上面的流程难免有点兴师动 ...
- 一个匹配字字符串是aabbcc或者其他模式的运用
<!--一个匹配字字符串是aabbcc或aaaabccc或者其他模式的运用--> function isPattern(str, pattern) { let str_a = str.sp ...
- NumPy实现数组的拼接和分裂
一.数组的拼接 import numpy as np x=np.array([,,]) x2=np.array([,,])np.concatenate([x,x2]) 输出:array([1, 2, ...
- CodeWarrior IDE烧写介绍
点击Flash烧写 选择芯片系列 下面将以PPC8548 NOR Flash烧写为例 默认配置文件目录:C:\Program Files (x86)\Freescale\CodeWarrior PA ...
- c语言的全排列
在c语言中实现全排列,对于刚接触c语言,还没学习算法的人来说,比较困难了吧.估计大佬也不会看这种基础的东西,全排列实现的办法很多,在c++中有一个专门的函数可以使用,但是在c中实现就有点困难了.如果你 ...
- [20190930]oracle raw类型转化number脚本.txt
[20190930]oracle raw类型转化number脚本.txt --//写一个简单oracle raw转化number脚本,简单说明:--//输入必须是c1,02 或者 c102,不支持c1 ...
- BayaiM__ oracle函数_01
BayaiM__ oracle函数_01 Oracle函数--------------------------------------------------------------------- ...
- MIPI CSI2学习(一):说一说MIPI CSI2
1. MIPI CSI2简介 MIPI联盟是一个开放的会员制组织.2003年7月,由美国德州仪器(TI).意法半导体(ST).英国ARM和芬兰诺基亚(Nokia)4家公司共同成立.MIPI联盟旨在推进 ...