ScintillaNET的应用
出于工作需要,需要制作一个嵌入在桌面应用中的C语言编辑器,经过一系列调研,目前ScintillaNET应该是最合适的了,开源、轻便、功能丰富,但是踩得坑也很多,接下面一一说道。
目前ScintillaNET托管在https://github.com/jacobslusser/ScintillaNET,拉下来重新编译。由于需要移植到.NET 2.0的平台上,需要修改源码中的对Linq的依赖,这里不多说,把目标框架改为.NET 2.0,编译,哪里报错改哪里。
1. 编辑器风格
参考:https://github.com/robinrodricks/ScintillaNET.Demo

2. 括号的匹配和高亮
为了方便多处调用该控件,继承Scintilla类,实现“自定义”控件,以下均以这种做法来实现功能。
重写OnUpdateUI事件,在UpdateUI中实现括号匹配功能。
private int m_lastCaretPos =;
protected override void OnUpdateUI(UpdateUIEventArgs e)
{
base.OnUpdateUI(e);
MatchAndLightBracket();
}
private void MatchAndLightBracket()
{
// Has the caret changed position?
int caretPos = this.CurrentPosition;
if (m_lastCaretPos != caretPos)
{
m_lastCaretPos = caretPos;
int bracePos1 = -;
int bracePos2 = -; // Is there a brace to the left or right?
if (caretPos > && IsBrace(this.GetCharAt(caretPos - )))
bracePos1 = (caretPos - );
else if (IsBrace(this.GetCharAt(caretPos)))
bracePos1 = caretPos; if (bracePos1 >= )
{
// Find the matching brace
bracePos2 = this.BraceMatch(bracePos1);
if (bracePos2 == CodeEditor.InvalidPosition)
{
ReleaseHighlightB();
}
else
{
ReleaseHighlightB();
HighlightBracket(bracePos1);
HighlightBracket(bracePos2);
}
}
else
{
ReleaseHighlightB();
}
}
}
private void HighlightBracket(int pos)
{
if (pos < )
return;
this.IndicatorFillRange(pos, );
}
private void ReleaseHighlightB()
{
this.IndicatorClearRange(, this.TextLength);
}
private static bool IsBrace(int c)
{
switch (c)
{
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
case '<':
case '>':
return true;
} return false;
}
3. Ctrl+Z会一次性清空所有的修改
protected override void OnBeforeInsert(BeforeModificationEventArgs e)
{
base.OnBeforeInsert(e);
Count = this.Text.Length;
this.BeginUndoAction();
}
protected override void OnInsert(ModificationEventArgs e)
{
base.OnInsert(e);
if (Count < this.Text.Length)
this.EndUndoAction();
}
4.缩进调整
protected override void OnCharAdded(CharAddedEventArgs e)
{
base.OnCharAdded(e);
AutoIndicator();
}
private void AutoIndicator()
{
int pos = this.CurrentPosition;
if (pos > && this.GetCharAt(pos - ) == '\n' && this.GetCharAt(pos - ) == '\r')
{
if (this.GetCharAt(pos - ) == '{')
{
string[] Text = GetStringList();
string line = Text[this.CurrentLine - ];
int start = line.IndexOf(line.TrimStart());
string ss = line.Substring(, start);
string str = new string(' ',);
this.InsertText(pos, ss+str);
this.SelectionStart = this.SelectionEnd = pos + ss.Length + ;
}
else
{
string[] Text = GetStringList();
string line = Text[this.CurrentLine - ];
int start = line.IndexOf(line.TrimStart());
string ss = line.Substring(, start);
this.InsertText(pos, ss);
this.SelectionStart = this.SelectionEnd = pos + ss.Length;
} }
}
private string[] GetStringList()
{
string[] s = new string[] { "\n" };
return this.Text.Split(s, StringSplitOptions.None);
}
目前整理了这么多,有机会再继续深入理解和应用ScintillaNET。
ScintillaNET的应用的更多相关文章
- WinForm搭载ScintillaNET时文本由于发生偏移被隐藏解决方案
项目用ScintillaNet搭载到WinForm以满足文本编辑的需求,在用FindReplace.Scintilla.Text=“显示内容”输出文本内容的时候会碰到文本被WinForm边框隐藏的情况 ...
- DotNet 资源大全中文版(Awesome最新版)
Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...
- C#开源
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C# 开源项目一
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C#开源大全--汇总(转)
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C#开源大全--汇总
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C#源码大汇总
C#高仿QQ2013可在广域网部署聊天系统GG叽叽 动态显示硬盘分区容量饼图 自定义ProgressBar控件高仿Win8进度条 多皮肤精美在线QQ悬浮客服插件 jQuery仿天猫首页多格焦点图片轮播 ...
- C#开源汇总
原文:C#开源汇总 商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Pho ...
- C# 网上收集的一些所谓的开源项目
C#开源 商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7- ...
随机推荐
- android 使用webview 加载网页
1. <WebView android:id="@+id/webView" android:layout_width="fill_parent" andr ...
- STL基础3:map
#include <iostream> #include <map> #include <string> using namespace std; #define ...
- ContextMune上下文菜单中,二级菜单获取及状态设置
ContextMune上下文菜单中,二级菜单获取及状态设置 在使用ContextMune上下文菜单中,能够通过二级菜单来获取及状态设置 //二级菜单获取和状态设置((ToolStripDropDown ...
- 【轻松前端之旅】<!DOCTYPE>标签
前端学习,先学习HTML,CSS,Javascript HTML - HyperText Markup Language HTML-超文本标记语言,提供了一种标记网页内容的方法. 浏览器怎么知道如何显 ...
- 2018.11.09 bzoj1706: relays 奶牛接力跑(倍增+floyd)
传送门 倍增+floyd板子题. 先列出状态fi,j,kf_{i,j,k}fi,j,k表示经过iii条边从jjj到kkk的最短路. 然后发现可以用fi−1,j,kf_{i-1,j,k}fi−1,j, ...
- ASP项目部署IIS7.5中遇到的问题
我们大家都熟悉了tomcat服务器的部署,如果是一个ASP项目如何部署呢.这也是我在客户现场遇到的问题.ASP项目一般是用的系统组件IIS来部署项目.下面我讲一下自己在部署过程中遇到的问题. 如果在网 ...
- poj-3067(树状数组)
题目链接:传送门 题意:日本有东城m个城市,西城m个城市,东城与西城相互连线架桥,判断这些桥相交的次数. 思路:两个直线相交就是(x1-x2)*(y1-y2)<0,所以,对x,y进行排序,按照x ...
- 关于上级机构的冲突性测试bug修复
描述: 1.上级机构可以为空. 2.机构添加时,选择了上级机构,在未提交前,另一用户将该机构删除,然后前一用户再提交表单,提示会保存成功,本操作应该保存失败. 思路:在上级机构不为空时,保存前进行查询 ...
- openstack的Host Aggregates和Availability Zones
1.关系 Availability Zones 通常是对 computes 节点上的资源在小的区域内进行逻辑上的分组和隔离.例如在同一个数据中心,我们可以将 Availability Zones 规划 ...
- idea中Eclipse Code Formatter插件设置和使用,以及注释模板的修改
在settings里面找到plugins这个选项,搜索Eclipse Code Formatter,点击安装,重启idea即可进行配置: 首先,先安装Eclipse Code Formatter插件: ...