参见:Fbt2008的大作 SharpDevelop源码分析笔记(一)
源文档 <http://www.cnblogs.com/fbt2008/archive/2005/08/02/205785.aspx?Pending=true>
在Fbt2008的大作中描述了SharpDevelop其Runtime的启动过程,我把其中GUI启动补充一下。
其中写到如下系统代码启动片断
系统代码:
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代码如下
{
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有多个等等。