SharpDevelop源码分析笔记(一)
?
參見:Fbt2008的大作? SharpDevelop源碼分析筆記(一)???
?
源文檔 <http://www.cnblogs.com/fbt2008/archive/2005/08/02/205785.aspx?Pending=true>
?
在Fbt2008的大作中描述了SharpDevelop其Runtime的啟動過程,我把其中GUI啟動補充一下。
?
其中寫到如下系統代碼啟動片斷
?
系統代碼:
?
//這段代碼就是程序啟動時加載前臺插件了,/Workspace/Autostart是系統自動運行命令的擴展點路徑,定義在這個路徑下的插件會在系統啟動的時候自動運行。在這里,通過插件樹初始化建立處于這個路徑下的Command(命令),并逐一執行。BuildChildItems方法的功能是建立這個擴展點下的Command列表commands?=?AddInTreeSingleton.AddInTree.GetTreeNode("/Workspace/Autostart").BuildChildItems(null);
for?(int?i?=?0;?i?<?commands.Count?-?1;?++i)?
{
????((ICommand)commands[i]).Run();
????}
}?
?
這段代碼會載入如下清單文件,并根據此清單文件中的ClassId載入運行
插件清單之一(SharpDevelopCore.addin文件)
?
片斷
<Extension path = "/Workspace/Autostart">
<Class id = "InitializeWorkbenchCommand"
class = "ICSharpCode.SharpDevelop.Commands.InitializeWorkbenchCommand"/>
<Class id = "StartCodeCompletionWizard"
class = "ICSharpCode.SharpDevelop.Commands.StartCodeCompletionWizard"/>
<Class id = "StartParserServiceThread"
class = "ICSharpCode.SharpDevelop.Commands.StartParserServiceThread"/>
<!-- #assembly preload -->
<Class id = "StartSharpAssemblyPreloadThread"
class = "ICSharpCode.SharpDevelop.Commands.StartSharpAssemblyPreloadThread"/>
<Class id = "StartWorkbenchCommand"
class = "ICSharpCode.SharpDevelop.Commands.StartWorkbenchCommand"/>
</Extension>
?
大家注意了:"/Workspace/Autostart" 就是上面代碼根據此描述將這一段的描述中的Class的實例載入,然后執行他們的方法(這些Class都繼承了Icommand)
?
這些類都在文件AutostartCommands.cs中
?
而GUI的主要啟動過程就在InitializeWorkbenchCommand類上,如下:
?
{
????const?string?workbenchMemento?=?"SharpDevelop.Workbench.WorkbenchMemento";
????
????public?override?void?Run()
????{
????????//產生一個默認的Workbench
????????DefaultWorkbench?w?=?new?DefaultWorkbench();
????????WorkbenchSingleton.Workbench?=?w;
????????//啟動Workbench
????????w.InitializeWorkspace();
????????PropertyService?propertyService?=?(PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
????????//將上一次使用的Workbench布局等信息重新載入
????????w.SetMemento((IXmlConvertable)propertyService.GetProperty(workbenchMemento,?new?WorkbenchMemento()));
????????//刷新Workbench,根據布局信息,打開啟動時需要展現的Pad和Editor
????????w.UpdatePadContents(null,?null);
????????WorkbenchSingleton.CreateWorkspace();
????????
????}
}
?
DefaultWorkbench 的 InitializeWorkspace代碼如下
?
public?void?InitializeWorkspace(){
????Menu?=?null;
????//狀態條
????statusBarManager.Control.Dock?=?DockStyle.Bottom;
????
????ActiveWorkbenchWindowChanged?+=?new?EventHandler(UpdateMenu);
????
????MenuComplete?+=?new?EventHandler(SetStandardStatusBar);
????SetStandardStatusBar(null,?null);
????
????IProjectService?projectService?=?(IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
????IFileService?fileService?=?(IFileService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IFileService));
????
????projectService.CurrentProjectChanged?+=?new?ProjectEventHandler(SetProjectTitle);
????projectService.CombineOpened
????????
????????????+=?new?CombineEventHandler(CombineOpened);
????fileService.FileRemoved?+=?new?FileEventHandler(CheckRemovedFile);
????fileService.FileRenamed?+=?new?FileEventHandler(CheckRenamedFile);
????fileService.FileRemoved?+=?new?FileEventHandler(fileService.RecentOpen.FileRemoved);
????fileService.FileRenamed?+=?new?FileEventHandler(fileService.RecentOpen.FileRenamed);
????//
????
????TopMenu.Selected???+=?new?CommandHandler(OnTopMenuSelected);
????//
????
????TopMenu.Deselected?+=?new?CommandHandler(OnTopMenuDeselected);
????//創建菜單
????CreateMainMenu();
????//創建工具條
????CreateToolBars();
}
???w.SetMemento(...);
??? w.UpdatePadContents(null, null);
??? 這兩句稍稍復雜些,在這里就不分析了。
?
注意:有關Workbench,pad和Editor等概念基本可以參照Eclipse文檔。有一些細小差別,例如Pad在Eclipse中叫View,Workench在SharpDevelop僅存在一個WorkbenchWindow.而在SharpDevelop有多個等等。
?
關注 - 0
粉絲 - 0
關注博主 0 0 (請您對文章做出評價) ? 上一篇:強烈推薦兩本經典OO書籍以及對用例編寫的啟發
總結
以上是生活随笔為你收集整理的SharpDevelop源码分析笔记(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .Net遍历窗口
- 下一篇: (MSDN)VB.NET的强大和C#语言