男人见女人最适合的微信头像换了个头像就说:怎么又换了头像,还显示你的nice的名字,是想给谁看吗?男人什么意思?

当前位置: →
→ SharpDevelop浅析3Internationalization&TextEditor国际化文档编辑器语法高亮显示
SharpDevelop浅析3Internationalization&TextEditor国际化文档编辑器语法高亮显示
& 作者及来源: lin-zhang - 博客园 &
&收藏到→_→:
摘要: SharpDevelop浅析_3_Internationalization & TextEditor
国际化、文档编辑器、语法高亮显示……
"SharpDevelop浅析3Internationalization&TextEditor国际化文档编辑器语法高亮显示"::
sharpdevelop浅析_3_internationalization & texteditor国际化、文档、语法高亮显示……1、demo界面及功能解释2、sharpdevelop的internationalization的使用3、sharpdevelop的internationalization的实现分析4、sharpdevelop的的基本概念5、sharpdevelop的syntaxhighlighting配置文件的定义6、sharpdevelop的texteditor控件的实现概述7、待分析的部分8、总结demo下载1、demo界面及功能解释启动后,打开文档(默认支持.cs, . , .java, .aspx等类型文件的语法高亮显示,详见icsharpcode.texteditor\resources\syntaxmodes.xml)、切换语言界面如下:
切换为中文语言环境后的界面如下:
功能说明:可以实时改变语言环境;提供对常用的编辑:支持语法高亮显示、括号匹配、设置书签;尚未提供查找/替换、代码折叠、代码提示/自动完成等功能。2、sharpdevelop的internationalization的使用多语言的实现就是在显示时根据键获取相应语言环境下的键值(dictionary&key,value&),因此在编写程序时应该引用键,而非直接书写要显示的字符。一般地,的显示包括菜单、状态栏、提示字符等,因此demo中的主菜单在配置文件(参见basic.addin)中使用label = "${res:menu.file.open}",退出的提示字符使用string s = stringparser.parse("${res:info.exit}");。icsharpcode.core.dll支持语言环境的实时修改(修改后语言设置不需重启),因此要在订阅语言环境改变的事件,相关代码如下:
语言环境的修改及事件响应&1//a,&设置语言&2//引自sharppad项目的dialogs\selectculturepanel.cs&3public&override&bool&receivedialogmessage(dialogmessage&message)&4{&5&&&&if&(message&==&dialogmessage.ok)&{&6&&&&&&&&if&(selectedculture&!=&null)&{&7&&&&&&&&&&&&propertyservice.set("coreproperties.uilanguage",&selectedculture);&8&&&&&&&&}&9&&&&}<span style="color: #&&&&return&true;<span style="color: #}<span style="color: #//返回当前窗体用户选择的语言设置(从显示国家国旗的listview控件)<span style="color: #string&selectedculture&{<span style="color: #&&&&get&{<span style="color: #&&&&&&&&if&(listview.selecteditems.count&&&<span style="color: #)&{<span style="color: #&&&&&&&&&&&&return&listview.selecteditems[<span style="color: #].subitems[<span style="color: #].<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&return&null;<span style="color: #&&&&}<span style="color: #}<span style="color: #//b,&刷新当前<span style="color: #//引自sharppad项目的sharppad.cs<span style="color: #void&inifrm()<span style="color: #{<span style="color: #&&&&//<span style="color: #&&&&_menustrip&=&new&menustrip();<span style="color: #&&&&menuservice.additemstomenu(_menustrip.items,&this,&"/michael/mymenus");<span style="color: #&&&&this.controls.add(_menustrip);<span style="color: #<span style="color: #&&&&propertyservice.propertychanged&+=&new&propertychangedeventhandler(propertyservice_propertychanged);<span style="color: #&&&&resourceservice.languagechanged&+=&delegate{<span style="color: #&&&&&&&&//更新菜单项的text显示<span style="color: #&&&&&&&&foreach&(toolstripitem&item&in&_menustrip.items)<span style="color: #&&&&&&&&{<span style="color: #&&&&&&&&&&&&if&(item&is&istatusupdate)<span style="color: #&&&&&&&&&&&&{<span style="color: #&&&&&&&&&&&&&&&&((istatusupdate)item).updatetext();<span style="color: #&&&&&&&&&&&&}<span style="color: #&&&&&&&&}<span style="color: #&&&&};<span style="color: #}<span style="color: #//引自icsharpcode.core的src\addintree\addin\defaultdoozers\menuitem\gui\istatusupdate.core<span style="color: #using&<span style="color: #namespace&icsharpcode.core<span style="color: #{<span style="color: #&&&&public&interface&istatusupdate<span style="color: #&&&&{<span style="color: #&&&&&&&&void&updatestatus();<span style="color: #&&&&&&&&void&updatetext();<span style="color: #&&&&}<span style="color: #}
另外,可以看到demo中的选项命令窗口也采用了插件模式来构造窗体(实现细节就不多谈了),容器窗体是treeviewoption,插件窗体如:selectculturepanel, selectstylepanel, demonothing,真是&#8220;扩展--无处不在&#8221;呀。sharpdevelop源码中的这些窗体的成员控件是通过.xfrm配置文件配置,窗体继承自xmlusercontrol来根据配置文件生成控件,有一定的灵活性。新的语言包资源文件放在\data\resources\目录下(如-gb.resources),注意默认语言选项以及在未找到相关语言资源时都是引用entry中的myres.resx资源文件;语言声明文件是\data\resources\languages\languagedefinition.xml,其格式如下:
languagedefinition.xml<span style="color: #&languages&<span style="color: #&&&&&languages&name="chinese&(gb)"&&&&&&&&&&&&&&&&&&code="cn-gb"&&&&page=""&&icon="chinalg.png"&/&<span style="color: #&&&&&languages&name="german"&&&&&&&&&&&&&&&&&&&&&&&&code="de"&&&&&&&page=""&&icon="germany.png"&/&<span style="color: #&&&&&languages&name="english"&&&&&&&&&&&&&&&&&code="en"&&&&&&&page=""&&icon="uk.png"&/&<span style="color: #&/languages&
sharppad中动态显示可选语言项的分析类是languageservice.cs和language.cs,此处就不多解释了。3、sharpdevelop的internationalization的实现分析sharpdevelop的的键值对是通过本地资源文件存储的,当demo中更改语言环境设置时,引发icsharpcode.core.dll中的事件及方法顺序如下:propertyservice类的属性更新引发propertychanged事件& -&& resourceservice响应接收到的事件并重新加载保存在内存中的资源键此文来自: 马开东博客
转载请注明出处 网址:
值对,然后引发languagechanged事件(由使用端接收并作相关处理,如demo中的sharppad.cs中的事件订阅/处理)属性更新的相关代码如下:
属性更改&1//propertyservice类实际是提供了对properties类的包装,因此直接看properties类中的代码:&2//引自icsharpcode.core\src\services\propertservice\properties.cs&3public&void&set&t&(string&property,&t&value)&4{&5&&&&t&oldvalue&=&default(t);&6&&&&if&(!properties.containskey(property))&{&7&&&&&&&&properties.add(property,&value);&8&&&&}&else&{&9&&&&&&&&oldvalue&=&get&t&(property,&value);<span style="color: #&&&&&&&&properties[property]&=&<span style="color: #&&&&}<span style="color: #&&&&onpropertychanged(new&propertychangedeventargs(this,&property,&oldvalue,&value));<span style="color: #}<span style="color: #protected&virtual&void&onpropertychanged(propertychangedeventargs&e)<span style="color: #{<span style="color: #&&&&if&(propertychanged&!=&null)&{<span style="color: #&&&&&&&&propertychanged(this,&e);<span style="color: #&&&&}<span style="color: #}<span style="color: #public&delegate&void&propertychangedeventhandler(object&sender,&propertychangedeventargs&e);<span style="color: #public&event&propertychangedeventhandler&
资源服务类的事件响应代码如下:
resourceservice类的事件响应&1//引自icsharpcode.core\src\services\resourceservice\resourceservice.cs&2//首先在类的初始化中订阅属性更改事件:&3propertyservice.propertychanged&+=&new&propertychangedeventhandler(onpropertychange);&4//类级别变量:&5static&hashtable&localstrings&=&null;&6static&hashtable&localicons&&&=&null;&7public&static&event&eventhandler&&8//事件响应:&9static&void&onpropertychange(object&sender,&propertychangedeventargs&e)<span style="color: #{<span style="color: #&&&&if&(e.key&==&uilanguageproperty&&&&e.newvalue&!=&e.oldvalue)&{<span style="color: #&&&&&&&&loadlanguageresources((string)e.newvalue);<span style="color: #&&&&&&&&if&(languagechanged&!=&null)<span style="color: #&&&&&&&&&&&&languagechanged(null,&e);<span style="color: #&&&&}<span style="color: #}<span style="color: #static&void&loadlanguageresources(string&language)<span style="color: #{<span style="color: #&&&&try<span style="color: #&&&&{<span style="color: #&&&&&&&&thread.currentthread.currentuiculture&=&new&system.globalization.cultureinfo(language);<span style="color: #&&&&}<span style="color: #&&&&catch&(exception)<span style="color: #&&&&{<span style="color: #&&&&&&&&try<span style="color: #&&&&&&&&{<span style="color: #&&&&&&&&&&&&thread.currentthread.currentuiculture&=&new&system.globalization.cultureinfo(language.split('-')[<span style="color: #]);<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&catch&(exception)&{&}<span style="color: #&&&&}<span style="color: #<span style="color: #&&&&localstrings&=&load(stringresources,&language);<span style="color: #&&&&if&(localstrings&==&null&&&&language.indexof('-')&&&<span style="color: #)<span style="color: #&&&&{<span style="color: #&&&&&&&&localstrings&=&load(stringresources,&language.split('-')[<span style="color: #]);<span style="color: #&&&&}<span style="color: #<span style="color: #&&&&localicons&=&load(imageresources,&language);<span style="color: #&&&&if&(localicons&==&null&&&&language.indexof('-')&&&<span style="color: #)<span style="color: #&&&&{<span style="color: #&&&&&&&&localicons&=&load(imageresources,&language.split('-')[<span style="color: #]);<span style="color: #&&&&}<span style="color: #<span style="color: #&&&&localstringsresmgrs.clear();<span style="color: #&&&&localiconsresmgrs.clear();<span style="color: #&&&&currentlanguage&=&<span style="color: #&&&&foreach&(resourceassembly&ra&in&resourceassemblies)<span style="color: #&&&&{<span style="color: #&&&&&&&&ra.load();<span style="color: #&&&&}<span style="color: #}<span style="color: #static&hashtable&load(string&name,&string&language)<span style="color: #{<span style="color: #&&&&return&load(resourcedirectory&+&path.directoryseparatorchar&+&name&+&"."&+&language&+&".resources");<span style="color: #}<span style="color: #static&hashtable&load(string&filename)<span style="color: #{<span style="color: #&&&&if&(file.exists(filename))&{<span style="color: #&&&&&&&&hashtable&resources&=&new&hashtable();<span style="color: #&&&&&&&&resourcereader&rr&=&new&resourcereader(filename);<span style="color: #&&&&&&&&foreach&(dictionaryentry&entry&in&rr)&{<span style="color: #&&&&&&&&&&&&resources.add(entry.key,&entry.value);<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&rr.close();<span style="color: #&&&&&&&&return&<span style="color: #&&&&}<span style="color: #&&&&return&null;<span style="color: #}
4、sharpdevelop的的基本概念代码编写工具的核心是代码编辑窗口(如打开一个.cs文件的窗口),如何在中存储该窗口内的字符内容?有些文件可能有上千行,统计下来可能有过万个字符,如果使用string对象存储字符内容,显然是不能满足性能要求,而且要实现语法高亮显示的话,还需要区分存储text 和相应颜色&#8230;&#8230;先看一下字符管理的基本要求:
itextbufferstrategy接口&1//引自icsharpcode.texteditor\src\document\textbufferstrategy\itextbufferstrategy.cs&2namespace&icsharpcode.texteditor.document&3{&4&&&&/**////&&summary&&5&&&&///&interface&to&describe&a&sequence&of&characters&that&can&be&edited.&&&&&&6&&&&///&&/summary&&7&&&&public&interface&itextbufferstrategy&8&&&&{&9&&&&&&&&/**////&&value&<span style="color: #&&&&&&&&///&the&current&length&of&the&sequence&of&characters&that&can&be&edited.<span style="color: #&&&&&&&&///&&/value&<span style="color: #&&&&&&&&int&length&{<span style="color: #&&&&&&&&&&&&get;<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&<span style="color: #&&&&&&&&/**////&&summary&<span style="color: #&&&&&&&&///&inserts&a&string&of&characters&into&the&sequence.<span style="color: #&&&&&&&&///&&/summary&<span style="color: #&&&&&&&&///&&param&name="offset"&<span style="color: #&&&&&&&&///&offset&where&to&insert&the&string.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&///&&param&name="text"&<span style="color: #&&&&&&&&///&text&to&be&inserted.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&void&insert(int&offset,&string&text);<span style="color: #&&&&&&&&<span style="color: #&&&&&&&&/**////&&summary&<span style="color: #&&&&&&&&///&removes&some&portion&of&the&sequence.<span style="color: #&&&&&&&&///&&/summary&<span style="color: #&&&&&&&&///&&param&name="offset"&<span style="color: #&&&&&&&&///&offset&of&the&remove.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&///&&param&name="length"&<span style="color: #&&&&&&&&///&number&of&characters&to&remove.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&void&remove(int&offset,&int&length);<span style="color: #&&&&&&&&<span style="color: #&&&&&&&&/**////&&summary&<span style="color: #&&&&&&&&///&replace&some&portion&of&the&sequence.<span style="color: #&&&&&&&&///&&/summary&<span style="color: #&&&&&&&&///&&param&name="offset"&<span style="color: #&&&&&&&&///&offset.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&///&&param&name="length"&<span style="color: #&&&&&&&&///&number&of&characters&to&replace.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&///&&param&name="text"&<span style="color: #&&&&&&&&///&text&to&be&replaced&with.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&void&replace(int&offset,&int&length,&string&text);<span style="color: #&&&&&&&&<span style="color: #&&&&&&&&/**////&&summary&<span style="color: #&&&&&&&&///&fetches&a&string&of&characters&contained&in&the&sequence.<span style="color: #&&&&&&&&///&&/summary&<span style="color: #&&&&&&&&///&&param&name="offset"&<span style="color: #&&&&&&&&///&offset&into&the&sequence&to&fetch<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&///&&param&name="length"&<span style="color: #&&&&&&&&///&number&of&characters&to&copy.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&string&gettext(int&offset,&int&length);<span style="color: #&&&&&&&&<span style="color: #&&&&&&&&/**////&&summary&<span style="color: #&&&&&&&&///&returns&a&specific&char&of&the&sequence.<span style="color: #&&&&&&&&///&&/summary&<span style="color: #&&&&&&&&///&&param&name="offset"&<span style="color: #&&&&&&&&///&offset&of&the&char&to&get.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&char&getcharat(int&offset);<span style="color: #&&&&&&&&<span style="color: #&&&&&&&&/**////&&summary&<span style="color: #&&&&&&&&///&this&method&sets&the&stored&content.<span style="color: #&&&&&&&&///&&/summary&<span style="color: #&&&&&&&&///&&param&name="text"&<span style="color: #&&&&&&&&///&the&string&that&represents&the&character&sequence.<span style="color: #&&&&&&&&///&&/param&<span style="color: #&&&&&&&&void&setcontent(string&text);<span style="color: #&&&&}<span style="color: #}
sharpdevelop采用的策略是使用带gap的字符,gap的长度小于预定规格时,按约定增加一定长度(有些类似于sqlserver的表空间管理?),插入/修改/删除字符时只是修改gap的长度和位置和移动部分字符,核心函数如下:
gaptextbufferstrategy类&1//引自icsharpcode.texteditor\src\document\textbufferstrategy\gaptextbufferstrategy.cs&2//类级别变量:&3char[]&buffer&=&new&char[<span style="color: #];&4int&gapbeginoffset&=&<span style="color: #;&5int&gapendoffset&&&=&<span style="color: #;&6/**////&&summary&&7///&小于此长度时增长buffer/gap&8///&&/summary&&9int&mingaplength&=&<span style="color: #;<span style="color: #/**////&&summary&<span style="color: #///&每次需要增长时,增长此长度的gap<span style="color: #///&&/summary&<span style="color: #int&maxgaplength&=&<span style="color: #6;<span style="color: #//重要函数:<span style="color: #public&void&setcontent(string&text)&<span style="color: #{<span style="color: #&&&&if&(text&==&null)&{<span style="color: #&&&&&&&&text&=&string.<span style="color: #&&&&}<span style="color: #&&&&buffer&=&text.tochararray();<span style="color: #&&&&gapbeginoffset&=&gapendoffset&=&<span style="color: #;<span style="color: #}<span style="color: #public&void&insert(int&offset,&string&text)<span style="color: #{<span style="color: #&&&&replace(offset,&<span style="color: #,&text);<span style="color: #}<span style="color: #public&void&remove(int&offset,&int&length)<span style="color: #{<span style="color: #&&&&replace(offset,&length,&string.empty);<span style="color: #}<span style="color: #public&void&replace(int&offset,&int&length,&string&text)&<span style="color: #{<span style="color: #&&&&if&(text&==&null)&{<span style="color: #&&&&&&&&text&=&string.<span style="color: #&&&&}<span style="color: #&&&&<span style="color: #&&&&//&math.max&is&used&so&that&if&we&need&to&resize&the&array<span style="color: #&&&&//&the&new&array&has&enough&space&for&all&old&chars<span style="color: #&&&&placegap(offset&+&length,&math.max(text.length&-&length,&<span style="color: #));<span style="color: #&&&&text.copyto(<span style="color: #,&buffer,&offset,&text.length);<span style="color: #&&&&gapbeginoffset&+=&text.length&-&<span style="color: #}<span style="color: #void&placegap(int&offset,&int&length)&<span style="color: #{<span style="color: #&&&&int&deltalength&=&gaplength&-&<span style="color: #&&&&//&如果gap的长度足够大,则只是作移动相关字符的处理<span style="color: #&&&&if&(mingaplength&&=&deltalength&&&&deltalength&&=&maxgaplength)&{<span style="color: #&&&&&&&&int&delta&=&gapbeginoffset&-&<span style="color: #&&&&&&&&//&check&if&the&gap&is&already&in&place<span style="color: #&&&&&&&&if&(offset&==&gapbeginoffset)&{<span style="color: #&&&&&&&&&&&&return;<span style="color: #&&&&&&&&}&else&if&(offset&&&gapbeginoffset)&{<span style="color: #&&&&&&&&&&&&int&gaplength&=&gapendoffset&-&<span style="color: #&&&&&&&&&&&&array.copy(buffer,&offset,&buffer,&offset&+&gaplength,&delta);<span style="color: #&&&&&&&&}&else&{&//offset&&&gapbeginoffset<span style="color: #&&&&&&&&&&&&array.copy(buffer,&gapendoffset,&buffer,&gapbeginoffset,&-delta);<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&gapbeginoffset&-=&<span style="color: #&&&&&&&&gapendoffset&&&-=&<span style="color: #&&&&&&&&return;<span style="color: #&&&&}<span style="color: #&&&&<span style="color: #&&&&//&否则,需要新分析buffer的大小,并修改offset等位置数值<span style="color: #&&&&int&oldlength&&&&&&&=&<span style="color: #&&&&int&newlength&&&&&&&=&maxgaplength&+&<span style="color: #&&&&int&newgapendoffset&=&offset&+&<span style="color: #&&&&char[]&newbuffer&&&&=&new&char[buffer.length&+&newlength&-&oldlength];&&&&//新分配后将有maxgaplength长度的gap<span style="color: #&&&&<span style="color: #&&&&if&(oldlength&==&<span style="color: #)&{<span style="color: #&&&&&&&&array.copy(buffer,&<span style="color: #,&newbuffer,&<span style="color: #,&offset);<span style="color: #&&&&&&&&array.copy(buffer,&offset,&newbuffer,&newgapendoffset,&newbuffer.length&-&newgapendoffset);<span style="color: #&&&&}&else&if&(offset&&&gapbeginoffset)&{<span style="color: #&&&&&&&&int&delta&=&gapbeginoffset&-&<span style="color: #&&&&&&&&array.copy(buffer,&<span style="color: #,&newbuffer,&<span style="color: #,&offset);<span style="color: #&&&&&&&&array.copy(buffer,&offset,&newbuffer,&newgapendoffset,&delta);<span style="color: #&&&&&&&&array.copy(buffer,&gapendoffset,&newbuffer,&newgapendoffset&+&delta,&buffer.length&-&gapendoffset);<span style="color: #&&&&}&else&{<span style="color: #&&&&&&&&int&delta&=&offset&-&<span style="color: #&&&&&&&&array.copy(buffer,&<span style="color: #,&newbuffer,&<span style="color: #,&gapbeginoffset);<span style="color: #&&&&&&&&array.copy(buffer,&gapendoffset,&newbuffer,&gapbeginoffset,&delta);<span style="color: #&&&&&&&&array.copy(buffer,&gapendoffset&+&delta,&newbuffer,&newgapendoffset,&newbuffer.length&-&newgapendoffset);<span style="color: #&&&&}<span style="color: #&&&&<span style="color: #&&&&buffer&&&&&&&&&=&<span style="color: #&&&&gapbeginoffset&=&<span style="color: #&&&&gapendoffset&&&=&<span style="color: #}
有了基本的数据容器,核心问题已经解决了,但是在绘制界面时直接使用上面的类,显然不够方便,于是就定义了linesegment和text 类来分别存储行、单词,注意这两个类存储的只是int类型的offset和length信息,而不存储字符或字符串对象。注意text 类中有个highlightcolor类型的变量用以存储语法高亮显示信息。有了上面的这些类,便可以组合起来补充些其它信息对此文来自: 马开东博客
转载请注明出处 网址:
外提供服务了,idocument接口存在的目的即在于此,它封装了itexteditorproperties(是否显示空格/tab/eol/hruler等)、undostack、itextbufferstrategy、ihighlightingstrategy、foldingmanager、bookmarkmanager等属性对象。
5、sharpdevelop的syntaxhighlighting配置文件的定义是时候对语法高亮显示作一些分析了,此处不详述其实现,而重点分析其配置定义,从中亦可以猜出部分实现。相关配置文件均保存在icsharpcode.texteditor项目\resource\目录下首先syntaxmode.xml文件中显示了已定义的及其声明文件位置,其解析类参见\src\document\highlightingstrategy\syntaxmodes\filesyntaxmodeprovider.cs
syntaxmode.xml&1&syntaxmodes&version="1.0"&&2&&&&&mode&file&&&&&&&=&"aspx.xshd"&3&&&&&&&&&&name&&&&&&&=&"asp/xhtml"&4&&&&&&&&&&extensions&=&"....asmx"/&&5&&&&&6&&&&&mode&file&&&&&&&=&"bat-mode.xshd"&7&&&&&&&&&&name&&&&&&&=&"bat"&8&&&&&&&&&&extensions&=&".bat"/&&9&&&&<span style="color: #&&&&&mode&file&&&&&&&=&"cpp-mode.xshd"<span style="color: #&&&&&&&&&&name&&&&&&&=&"c++.net"<span style="color: #&&&&&&&&&&extensions&=&".c;.h;..c;..hpp"/&<span style="color: #&&&&<span style="color: #&&&&&mode&file&&&&&&&=&"csharp-mode.xshd"<span style="color: #&&&&&&&&&&name&&&&&&&=&"c#"<span style="color: #&&&&&&&&&&extensions&=&".cs"/&<span style="color: #&&&&<span style="color: #&&&&&mode&file&&&&&&&=&"xml-mode.xshd"<span style="color: #&&&&&&&&&&name&&&&&&&=&"xml"<span style="color: #&&&&&&&&&&extensions&=&".......................disco"/&<span style="color: #&/syntaxmodes&
取csharp-mode.xshd(注:xshd是xml syntax highlighting definition的缩写)为例,查看其定义:
csharp-mode.xshd&1&?xml&version="1.0"?&&2&syntaxdefinition&name&=&"c#"&extensions&=&".cs"&&3&&&&&properties&&4&&&&&&&&&property&name="linecomment"&value="//"/&&5&&&&&/properties&&6&&&&&digits&name&=&"digits"&bold&=&"false"&italic&=&"false"&color&=&"darkblue"/&&7&&&&&rulesets&&8&&&&&&&&&ruleset&ignorecase="false"&&9&&&&&&&&&&&&&delimiters&&&&~!%^*()-+=|\#/{}[]:;"'&,&&&&.?&/delimiters&<span style="color: #&&&&&&&&&&&&&span&name&=&"preprocessordirectives"&rule&=&"preprocessorset"&bold="false"&italic="false"&color="green"&stopateol&=&"true"&<span style="color: #&&&&&&&&&&&&&&&&&begin&#&/begin&<span style="color: #&&&&&&&&&&&&&/span&<span style="color: #&&&&&&&&&&&&&span&name&=&"blockcomment"&rule&=&"commentmarkerset"&bold&=&"false"&italic&=&"false"&color&=&"green"&stopateol&=&"false"&<span style="color: #&&&&&&&&&&&&&&&&&begin&/*&/begin&<span style="color: #&&&&&&&&&&&&&&&&&end&*/&/end&<span style="color: #&&&&&&&&&&&&&/span&<span style="color: #&&&&&&&&&&&&&key s&name&=&"punctuation"&bold&=&"false"&italic&=&"false"&color&=&"darkgreen"&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"?"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&","&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"."&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&";"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"("&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&")"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"["&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"]"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"{"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"}"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"+"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"-"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"/"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"%"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"*"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"&"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"&"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"^"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"="&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"~"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"!"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"|"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"&"&/&<span style="color: #&&&&&&&&&&&&&&&/key s&<span style="color: #&&&&&&&&&&<span style="color: #&&&&&&&&&&&&&key s&name&=&"accesskey s"&bold="true"&italic="false"&color="black"&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"this"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"base"&/&<span style="color: #&&&&&&&&&&&&&/key s&<span style="color: #&&&&&&&&&&&&<span style="color: #&&&&&&&&&&&&&key s&name&=&"operatorkey s"&bold="true"&italic="false"&color="darkcyan"&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"as"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"is"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"new"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"sizeof"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"typeof"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"true"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"false"&/&<span style="color: #&&&&&&&&&&&&&&&&&key& &=&"stackalloc"&/&<span style="color: #&&&&&&&&&&&&&/key s&<span style="color: #&&&&&&&&&/ruleset&<span style="color: #&&&&&/rulesets&<span style="color: #&/syntaxdefinition&
上面的文件公摘选了部分标签,其中&property&标签定义了指定名称属性的指定值&digits&标签定义了数值的字体显示样式&delimiters&定义了分隔单词的字符&span&定义了包含在此指定begin/end中的字符的显示样式,注意没有&end&标签的一般设stopateol(stop at end-of-line)为true&key s&指定了其子集&key&声明的单词的显示样式
6、sharpdevelop的texteditor控件的实现概述接下来的任务是要显示和支持用户输入了,直接使用textbox或richtextbox好像都不太现实,效率上也必定有不少损失,于是sharpdevelop的方式是直接继承自control, panel, usercontrol 的方式来实现编辑控件(参见icsharpcode.texteditor项目\src\gui\...)。首先使用texteditorcontrolbase(继承自usercontrol)封装当前文件路径、encoding、idocument对象、itexteditorproperties对象、快捷键列表(dictionary&keys, ieditaction&类型)的变量,提供loadfile()、savefile()等重要方法。texteditorcontrol类继承自上面的类,并声明了panel、splitter、textareacontrol、printdocument控件,其中显示文件的核心控件是textareacontrol,该控件在此类中被声明了两个变量,默认只有一个primarytextarea显示,支持切分为两个窗口的显示,当有两个窗口时,splitter控件才有效;prindocument控件用以打印输出内容;该类的另一个重要功能是提供了undo()、redo()方法。textareacontrol(继承自panel)控件,封装了textarea、vscrollbar、hscrollbar控件,其中textarea负责文件数据显示,另外两个控件负责文件内容大于可见尺寸时的滚动条服务。textarea(继承自control)封装了textview, iconbarmargin, guttermargin, foldmargin, selectionmanager, caret 等控件或类对象,其中前四个控件均继承自abstractmargin,代表区域对象,各自负责字符区域(较大的文件内容绘制区)、图标区域(如bookmark图标所在列)、gutter区域(如行号)、折叠控制区域的绘制,selectionmanager用以控制选中项,caret用以控制光标位置调整和显示。下面是一些我在读代码的过程中有过的疑问及解答:a, 加载文件时发生了什么?答:加载文件时控件根据文件的后缀名选择了相应的高亮显示策略,然后读取文件的内容并生成相应的gaptextbufferstrategy, linesegment, text
等对象,并且对所有的text 对象的highlightcolor类型成员变量完成分析赋值(用以在paint函数中显示),相关代码如下:
loadfile()相关代码&1//取自texteditorcontrolbase.cs&2public&void&loadfile(string&filename,&bool&autoloadhighlighting,&bool&autodetectencoding)&3{&4&&&&beginupdate();&5&&&&document.textcontent&=&string.&6&&&&document.undostack.clearall();&7&&&&document.bookmarkmanager.clear();&8&&&&if&(autoloadhighlighting)&{&9&&&&&&&&&&&&&&&&//根据文件扩展名判断并赋值高亮显示的策略<span style="color: #&&&&&&&&document.highlightingstrategy&=&highlightingstrategyfactory.createhighlightingstrategyforfile(filename);<span style="color: #&&&&}<span style="color: #&&&&<span style="color: #&&&&if&(autodetectencoding)&{<span style="color: #&&&&&&&&encoding&encoding&=&this.<span style="color: #&&&&&&&&&&&&&&&&//赋值<span style="color: #&&&&&&&&document.textcontent&=&util.filereader.readfilecontent(filename,&ref&encoding,&this.texteditorproperties.encoding);<span style="color: #&&&&&&&&this.encoding&=&<span style="color: #&&&&}&else&{<span style="color: #&&&&&&&&using&(streamreader&reader&=&new&streamreader(filename,&this.encoding))&{<span style="color: #&&&&&&&&&&&&document.textcontent&=&reader.readtoend();<span style="color: #&&&&&&&&}<span style="color: #&&&&}<span style="color: #&&&&<span style="color: #&&&&this.filename&=&<span style="color: #&&&&optionschanged();<span style="color: #&&&&document.updatequeue.clear();<span style="color: #&&&&endupdate();<span style="color: #&&&&<span style="color: #&&&&refresh();<span style="color: #}<span style="color: #//引自defaultdocument.cs<span style="color: #itextbufferstrategy&&&textbufferstrategy&&&=&null;<span style="color: #ilinemanager&&&&&&&&&&linetrackingstrategy&=&null;<span style="color: #public&string&textcontent&{<span style="color: #&&&&get&{<span style="color: #&&&&&&&&return&gettext(<span style="color: #,&textbufferstrategy.length);<span style="color: #&&&&}<span style="color: #&&&&set&{<span style="color: #&&&&&&&&debug.assert(textbufferstrategy&!=&null);<span style="color: #&&&&&&&&debug.assert(linetrackingstrategy&!=&null);<span style="color: #&&&&&&&&ondocumentabouttobechanged(new&documenteventargs(this,&<span style="color: #,&<span style="color: #,&value));<span style="color: #&&&&&&&&&&&&&&&&//赋值<span style="color: #&&&&&&&&textbufferstrategy.setcontent(value);<span style="color: #&&&&&&&&&&&&&&&&//赋值&&&&分析并完成高亮分析的赋值<span style="color: #&&&&&&&&linetrackingstrategy.setcontent(value);<span style="color: #&&&&&&&&<span style="color: #&&&&&&&&ondocumentchanged(new&documenteventargs(this,&<span style="color: #,&<span style="color: #,&value));<span style="color: #&&&&&&&&ontextcontentchanged(eventargs.empty);<span style="color: #&&&&}<span style="color: #}<span style="color: #//引自defaultlinemanager.cs<span style="color: #public&void&setcontent(string&text)<span style="color: #{<span style="color: #&&&&linecollection.clear();<span style="color: #&&&&if&(text&!=&null)&{<span style="color: #&&&&&&&&textlength&=&text.<span style="color: #&&&&&&&&&&&&&&&&//&生成linesegment集合<span style="color: #&&&&&&&&createlines(text,&<span style="color: #,&<span style="color: #);<span style="color: #&&&&&&&&&&&&&&&&//&高亮分析<span style="color: #&&&&&&&&runhighlighter();<span style="color: #&&&&}<span style="color: #}
b, 控件如何响应键盘事件?答:对于方向键及快捷功能键通过预定义的实现ieditaction接口的类响应(执行功能,不影响字符内容);其它字母/数字键直接输入,同时执行更新folding, bookmark, higlighting等属性信息。相关代码:
键盘事件响应&&1//功能键的定义(引自texteditorcontrolbase.cs):&&2protected&dictionary&keys,&ieditaction&&editactions&=&new&dictionary&keys,&ieditaction&();&&3protected&texteditorcontrolbase()&&4{&&5&&&&generatedefaultactions();&&6&&&&highlightingmanager.manager.reloadsyntaxhighlighting&+=&new&eventhandler(reloadhighlighting);&&7}&&8void&generatedefaultactions()&&9{&10&&&&editactions[keys.left]&=&new&caretleft();&11&&&&editactions[keys.left&|&keys.shift]&=&new&shiftcaretleft();&12&&&&editactions[keys.left&|&keys.control]&=&new& left();&13&&&&editactions[keys.left&|&keys.control&|&keys.shift]&=&new&shift left();&14&&&&editactions[keys.right]&=&new&caretright();&15&&&&editactions[keys.right&|&keys.shift]&=&new&shiftcaretright();&16&&&&editactions[keys.right&|&keys.control]&=&new& right();&17&&&&editactions[keys.right&|&keys.control&|&keys.shift]&=&new&shift right();&18&&&&editactions[keys.up]&=&new&caretup();&19&&&&editactions[keys.up&|&keys.shift]&=&new&shiftcaretup();&20&&&&editactions[keys.up&|&keys.control]&=&new&scrolllineup();&21&&&&editactions[keys.down]&=&new&caretdown();&22&&&&editactions[keys.down&|&keys.shift]&=&new&shiftcaretdown();&23&&&&editactions[keys.down&|&keys.control]&=&new&scrolllinedown();&24&&&&&25&&&&editactions[keys.insert]&=&new&toggleeditmode();&26&&&&editactions[keys.insert&|&keys.control]&=&new&copy();&27&&&&editactions[keys.insert&|&keys.shift]&=&new&paste();&28&&&&editactions[keys.delete]&=&new&delete();&29&&&&editactions[keys.delete&|&keys.shift]&=&new&cut();&30&&&&editactions[keys.home]&=&new&home();&31&&&&editactions[keys.home&|&keys.shift]&=&new&shifthome();&32&&&&editactions[keys.home&|&keys.control]&=&new&movetostart();&33&&&&editactions[keys.home&|&keys.control&|&keys.shift]&=&new&shiftmovetostart();&34&&&&editactions[keys.end]&=&new&end();&35&&&&editactions[keys.end&|&keys.shift]&=&new&shiftend();&36&&&&editactions[keys.end&|&keys.control]&=&new&movetoend();&37&&&&editactions[keys.end&|&keys.control&|&keys.shift]&=&new&shiftmovetoend();&38&&&&editactions[keys.pageup]&=&new&movepageup();&39&&&&editactions[keys.pageup&|&keys.shift]&=&new&shiftmovepageup();&40&&&&editactions[keys.pagedown]&=&new&movepagedown();&41&&&&editactions[keys.pagedown&|&keys.shift]&=&new&shiftmovepagedown();&42&&&&&43&&&&editactions[keys.return]&=&new&return();&44&&&&editactions[keys.tab]&=&new&tab();&45&&&&editactions[keys.tab&|&keys.shift]&=&new&shifttab();&46&&&&editactions[keys.back]&=&new&backspace();&47&&&&editactions[keys.back&|&keys.shift]&=&new&backspace();&48&&&&&49&&&&editactions[keys.x&|&keys.control]&=&new&cut();&50&&&&editactions[keys.c&|&keys.control]&=&new&copy();&51&&&&editactions[keys.v&|&keys.control]&=&new&paste();&52&&&&&53&&&&editactions[keys.a&|&keys.control]&=&new&selectwholedocument();&54&&&&editactions[keys.escape]&=&new&clearallselections();&55&&&&&56&&&&editactions[keys.divide&|&keys.control]&=&new&togglecomment();&57&&&&editactions[keys.oemquestion&|&keys.control]&=&new&togglecomment();&58&&&&&59&&&&editactions[keys.back&|&keys.alt]&&=&new&actions.undo();&60&&&&editactions[keys.z&|&keys.control]&=&new&actions.undo();&61&&&&editactions[keys.y&|&keys.control]&=&new&redo();&62&&&&&63&&&&editactions[keys.delete&|&keys.control]&=&new&delete ();&64&&&&editactions[keys.back&|&keys.control]&&&=&new& backspace();&65&&&&editactions[keys.d&|&keys.control]&&&&&&=&new&deleteline();&66&&&&editactions[keys.d&|&keys.shift&|&keys.control]&&&&&&=&new&deletetolineend();&67&&&&&68&&&&editactions[keys.b&|&keys.control]&&&&&&=&new&gotomatchingbrace();&69}&70internal&ieditaction&geteditaction(keys&keydata)&71{&72&&&&if&(!editactions.containskey(keydata))&{&73&&&&&&&&return&null;&74&&&&}&75&&&&return&(ieditaction)editactions[keydata];&76}&77//功能键的响应(取自textarea.cs):&78protected&override&bool&processdialogkey(keys&keydata)&79{&80&&&&return&executedialogkey(keydata)&||&base.processdialogkey(keydata);&81}&82public&bool&executedialogkey(keys&keydata)&83{&84&&&&//&try,&if&a&dialog&key&processor&was&set&to&use&this&85&&&&if&(doprocessdialogkey&!=&null&&&&doprocessdialogkey(keydata))&{&86&&&&&&&&return&true;&87&&&&}&88&&&&&89&&&&if&(keydata&==&keys.back&||&keydata&==&keys.delete&||&keydata&==&keys.enter)&{&90&&&&&&&&if&(texteditorproperties.usecustomline&==&true)&{&91&&&&&&&&&&&&if&(selectionmanager.hassomethingselected)&{&92&&&&&&&&&&&&&&&&if&(document.customlinemanager.isreadonly(selectionmanager.selectioncollection[<span style="color: #],&false))&93&&&&&&&&&&&&&&&&&&&&return&true;&94&&&&&&&&&&&&}&else&{&95&&&&&&&&&&&&&&&&int&curlinenr&&&=&document.getlinenumberforoffset(caret.offset);&96&&&&&&&&&&&&&&&&if&(document.customlinemanager.isreadonly(curlinenr,&false)&==&true)&97&&&&&&&&&&&&&&&&&&&&return&true;&98&&&&&&&&&&&&&&&&if&((caret.column&==&<span style="color: #)&&&&(curlinenr&-&<span style="color: #&&=&<span style="color: #)&&&&keydata&==&keys.back&&&&99&&&&&&&&&&&&&&&&&&&&document.customlinemanager.isreadonly(curlinenr&-&<span style="color: #,&false)&==&true)<span style="color: #0&&&&&&&&&&&&&&&&&&&&return&true;<span style="color: #1&&&&&&&&&&&&&&&&if&(keydata&==&keys.delete)&{<span style="color: #2&&&&&&&&&&&&&&&&&&&&linesegment&curline&=&document.getlinesegment(curlinenr);<span style="color: #3&&&&&&&&&&&&&&&&&&&&if&(curline.offset&+&curline.length&==&caret.offset&&&<span style="color: #4&&&&&&&&&&&&&&&&&&&&&&&&document.customlinemanager.isreadonly(curlinenr&+&<span style="color: #,&false)&==&true)&{<span style="color: #5&&&&&&&&&&&&&&&&&&&&&&&&return&true;<span style="color: #6&&&&&&&&&&&&&&&&&&&&}<span style="color: #7&&&&&&&&&&&&&&&&}<span style="color: #8&&&&&&&&&&&&}<span style="color: #9&&&&&&&&}<span style="color: #0&&&&}<span style="color: #1&&&&<span style="color: #2&&&&//&if&not&(or&the&process&was&'silent',&use&the&standard&edit&actions<span style="color: #3&&&&ieditaction&action&=&&mothertexteditorcontrol.geteditaction(keydata);<span style="color: #4&&&&autoclearselection&=&true;<span style="color: #5&&&&if&(action&!=&null)&{<span style="color: #6&&&&&&&&mothertexteditorcontrol.beginupdate();<span style="color: #7&&&&&&&&try&{<span style="color: #8&&&&&&&&&&&&lock&(document)&{<span style="color: #9&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&执行相关的功能操作<span style="color: #0&&&&&&&&&&&&&&&&action.execute(this);<span style="color: #1&&&&&&&&&&&&&&&&if&(selectionmanager.hassomethingselected&&&&autoclearselection&/**//*&&&caretchanged*/)&{<span style="color: #2&&&&&&&&&&&&&&&&&&&&if&(document.texteditorproperties.documentselectionmode&==&documentselectionmode.normal)&{<span style="color: #3&&&&&&&&&&&&&&&&&&&&&&&&selectionmanager.clearselection();<span style="color: #4&&&&&&&&&&&&&&&&&&&&}<span style="color: #5&&&&&&&&&&&&&&&&}<span style="color: #6&&&&&&&&&&&&}<span style="color: #7&&&&&&&&}&finally&{<span style="color: #8&&&&&&&&&&&&mothertexteditorcontrol.endupdate();<span style="color: #9&&&&&&&&&&&&caret.updatecaretposition();<span style="color: #0&&&&&&&&}<span style="color: #1&&&&&&&&return&true;<span style="color: #2&&&&}<span style="color: #3&&&&return&false;<span style="color: #4}<span style="color: #5<span style="color: #6//输入键的响应(取自textarea.cs):<span style="color: #7protected&override&void&onkeypress(keypresseventargs&e)<span style="color: #8{<span style="color: #9&&&&base.onkeypress(e);<span style="color: #0&&&&simulatekeypress(e.keychar);<span style="color: #1&&&&e.handled&=&true;<span style="color: #2}<span style="color: #3public&void&simulatekeypress(char&ch)<span style="color: #4{<span style="color: #5&&&&if&(document.readonly)&{<span style="color: #6&&&&&&&&return;<span style="color: #7&&&&}<span style="color: #8&&&&<span style="color: #9&&&&if&(texteditorproperties.usecustomline&==&true)&{<span style="color: #0&&&&&&&&if&(selectionmanager.hassomethingselected)&{<span style="color: #1&&&&&&&&&&&&if&(document.customlinemanager.isreadonly(selectionmanager.selectioncollection[<span style="color: #],&false))<span style="color: #2&&&&&&&&&&&&&&&&return;<span style="color: #3&&&&&&&&}&else&if&(document.customlinemanager.isreadonly(caret.line,&false)&==&true)<span style="color: #4&&&&&&&&&&&&return;<span style="color: #5&&&&}<span style="color: #6&&&&<span style="color: #7&&&&if&(ch&&&'&')&{<span style="color: #8&&&&&&&&return;<span style="color: #9&&&&}<span style="color: #0&&&&<span style="color: #1&&&&if&(!hiddenmousecursor&&&&texteditorproperties.hidemousecursor)&{<span style="color: #2&&&&&&&&hiddenmousecursor&=&true;<span style="color: #3&&&&&&&&cursor.hide();<span style="color: #4&&&&}<span style="color: #5&&&&closetooltip();<span style="color: #6&&&&<span style="color: #7&&&&mothertexteditorcontrol.beginupdate();<span style="color: #8&&&&//&insert&char<span style="color: #9&&&&if&(!handlekeypress(ch))&{<span style="color: #0&&&&&&&&switch&(caret.caretmode)&{<span style="color: #1&&&&&&&&&&&&case&caretmode.insertmode:<span style="color: #2&&&&&&&&&&&&&&&&insertchar(ch);<span style="color: #3&&&&&&&&&&&&&&&&break;<span style="color: #4&&&&&&&&&&&&case&caretmode.overwritemode:<span style="color: #5&&&&&&&&&&&&&&&&replacechar(ch);<span style="color: #6&&&&&&&&&&&&&&&&break;<span style="color: #7&&&&&&&&&&&&default:<span style="color: #8&&&&&&&&&&&&&&&&debug.assert(false,&"unknown&caret&mode&"&+&caret.caretmode);<span style="color: #9&&&&&&&&&&&&&&&&break;<span style="color: #0&&&&&&&&}<span style="color: #1&&&&}<span style="color: #2&&&&<span style="color: #3&&&&int&currentlinenr&=&caret.<span style="color: #4&&&&int&delta&=&document.formattingstrategy.formatline(this,&currentlinenr,&document.positiontooffset(caret.position),&ch);<span style="color: #5&&&&<span style="color: #6&&&&mothertexteditorcontrol.endupdate();<span style="color: #7&&&&if&(delta&!=&<span style="color: #)&{<span style="color: #8//&&&&&&&&&&&&&&&&this.mothertexteditorcontrol.updatelines(currentlinenr,&currentlinenr);<span style="color: #9&&&&}<span style="color: #0}<span style="color: #1//输入键通过底层的方法输入字符和更改高亮显示,如下分析(以insert为例,取自defaultdocument.cs):<span style="color: #2public&void&insert(int&offset,&string&text)<span style="color: #3{<span style="color: #4&&&&if&(readonly)&{<span style="color: #5&&&&&&&&return;<span style="color: #6&&&&}<span style="color: #7&&&&ondocumentabouttobechanged(new&documenteventargs(this,&offset,&-<span style="color: #,&text));<span style="color: #8&&&&datetime&time&=&datetime.<span style="color: #9&&&&//增加字符<span style="color: #0&&&&textbufferstrategy.insert(offset,&text);<span style="color: #1&&&&<span style="color: #2&&&&time&=&datetime.<span style="color: #3&&&&//更新linesegment,&text 对象<span style="color: #4&&&&linetrackingstrategy.insert(offset,&text);<span style="color: #5&&&&<span style="color: #6&&&&time&=&datetime.<span style="color: #7&&&&<span style="color: #8&&&&undostack.push(new&undoableinsert(this,&offset,&text));<span style="color: #9&&&&<span style="color: #0&&&&time&=&datetime.<span style="color: #1&&&&ondocumentchanged(new&documenteventargs(this,&offset,&-<span style="color: #,&text));<span style="color: #2}<span style="color: #3//&追踪到defaultlinemanager.cs中insert()方法实际上调用到replace(offset,length,string.empty)方法:<span style="color: #4public&void&replace(int&offset,&int&length,&string&text)&<span style="color: #5{<span style="color: #6&&&&int&linenumber&=&getlinenumberforoffset(offset);&&&&&&&&&&&&<span style="color: #7&&&&int&insertlinenumber&=&<span style="color: #8&&&&if&(remove(linenumber,&offset,&length))&{<span style="color: #9&&&&&&&&--<span style="color: #0&&&&}<span style="color: #1&&&&<span style="color: #2&&&&linenumber&+=&insert(insertlinenumber,&offset,&text);<span style="color: #3&&&&<span style="color: #4&&&&int&delta&=&-<span style="color: #5&&&&if&(text&!=&null)&{<span style="color: #6&&&&&&&&delta&=&text.length&+&<span style="color: #7&&&&}<span style="color: #8&&&&<span style="color: #9&&&&if&(delta&!=&<span style="color: #)&{<span style="color: #0&&&&&&&&adaptlineoffsets(linenumber,&delta);&&&&&&&&<span style="color: #1&&&&}<span style="color: #2&&&&//启用高亮显示分析&-----&&&注:此时的&marklines&仅存储变化的相关行,而setcontent时存储的是所有行,因此只是按需分析<span style="color: #3&&&&runhighlighter();<span style="color: #4}
c, 文件字符的绘制究竟是在何处?答:在textview.cs中的public override void paint(graphics g, rectangle rect)函数中,重要函数:paintlinepart(),辅助绘制函数:drawdocument (), drawbrackethighlight(), drawspacemarker(), drawverticalruler() 等
d, 括号匹配在何处被定义和捕捉更新?答:textarea.cs中的list&brackethighlightingsheme& bracketshemes& = new list&brackethighlightingsheme&();变量存储在查找的匹配项,searchmatchingbracket()方法中搜索并更新匹配项的显示,相关代码如下:
括号匹配&1//引自textarea.cs&2list&brackethighlightingsheme&&bracketshemes&&=&new&list&brackethighlightingsheme&();&3caret&&&&&&&&&&&&&4public&textarea(texteditorcontrol&mothertexteditorcontrol,&textareacontrol&mothertextareacontrol)&5{&6&&&&//&省略无关代码&7&&&&bracketshemes.add(new&brackethighlightingsheme('{',&'}'));&8&&&&bracketshemes.add(new&brackethighlightingsheme('(',&')'));&9&&&&bracketshemes.add(new&brackethighlightingsheme('[',&']'));<span style="color: #&&&&<span style="color: #&&&&caret.positionchanged&+=&new&eventhandler(searchmatchingbracket);<span style="color: #&&&&//&省略无关代码<span style="color: #}<span style="color: #void&searchmatchingbracket(object&sender,&eventargs&e)<span style="color: #{<span style="color: #&&&&if&(!texteditorproperties.showmatchingbracket)&{<span style="color: #&&&&&&&&textview.highlight&=&null;<span style="color: #&&&&&&&&return;<span style="color: #&&&&}<span style="color: #&&&&bool&changed&=&false;<span style="color: #&&&&if&(caret.offset&==&<span style="color: #)&{<span style="color: #&&&&&&&&if&(textview.highlight&!=&null)&{<span style="color: #&&&&&&&&&&&&int&line&&=&textview.highlight.openbrace.y;<span style="color: #&&&&&&&&&&&&int&line2&=&textview.highlight.closebrace.y;<span style="color: #&&&&&&&&&&&&textview.highlight&=&null;<span style="color: #&&&&&&&&&&&&updateline(line);<span style="color: #&&&&&&&&&&&&updateline(line2);<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&return;<span style="color: #&&&&}<span style="color: #&&&&foreach&(brackethighlightingsheme&bracketsheme&in&bracketshemes)&{<span style="color: #//&&&&&&&&&&&&&&&&if&(bracketsheme.isinside(textareapainter.document,&textareapainter.document.caret.offset))&{<span style="color: #&&&&&&&&highlight&highlight&=&bracketsheme.gethighlight(document,&caret.offset&-&<span style="color: #);<span style="color: #&&&&&&&&if&(textview.highlight&!=&null&&&&textview.highlight.openbrace.y&&=<span style="color: #&&&&textview.highlight.openbrace.y&&&document.totalnumberoflines)&{<span style="color: #&&&&&&&&&&&&//取消旧匹配项的高亮显示<span style="color: #&&&&&&&&&&&&updateline(textview.highlight.openbrace.y);<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&if&(textview.highlight&!=&null&&&&textview.highlight.closebrace.y&&=<span style="color: #&&&&textview.highlight.closebrace.y&&&document.totalnumberoflines)&{<span style="color: #&&&&&&&&&&&&//取消旧匹配项的高亮显示<span style="color: #&&&&&&&&&&&&updateline(textview.highlight.closebrace.y);<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&textview.highlight&=&<span style="color: #&&&&&&&&if&(highlight&!=&null)&{<span style="color: #&&&&&&&&&&&&changed&=&true;<span style="color: #&&&&&&&&&&&&break;<span style="color: #&&&&&&&&}<span style="color: #//&&&&&&&&&&&&&&&&}<span style="color: #&&&&}<span style="color: #&&&&if&(changed&||&textview.highlight&!=&null)&{<span style="color: #&&&&&&&&int&line&=&textview.highlight.openbrace.y;<span style="color: #&&&&&&&&int&line2&=&textview.highlight.closebrace.y;<span style="color: #&&&&&&&&if&(!changed)&{<span style="color: #&&&&&&&&&&&&textview.highlight&=&null;<span style="color: #&&&&&&&&}<span style="color: #&&&&&&&&//更新显示新匹配项&openbrace<span style="color: #&&&&&&&&updateline(line);<span style="color: #&&&&&&&&//更新显示新匹配项&closebrace<span style="color: #&&&&&&&&updateline(line2);<span style="color: #&&&&}<span style="color: #}
7、待分析的部分本篇讨论暂未涉及如下(有价值?)内容的分析:syntaxhighlighting实现分析bookmarkmanager, foldingmanager, formattingmanager等paint()处理中坐标分析及转换
8、总结本篇分析对应的《dissecting a搜索此文相关文章:语法高亮显示此文来自: 马开东博客
网址: 站长QQ
SharpDevelop浅析3Internationalization&TextEditor国际化文档编辑器语法高亮显示_博客园相关文章
博客园_总排行榜
博客园_最新
博客园_月排行榜
博客园_周排行榜
博客园_日排行榜

我要回帖

更多关于 女人最适合的微信头像 的文章

 

随机推荐