工作台
工作台的加载,布局,管理
命令模式:以Command
作为对象的事件,实际上不过是统一(RUN)
接口的事件而已,
new SdMenuCommand()
o = AddIn.CreateObject(Class);// class = "ISpiderMan.PoManage.RunPoManage"
IMenuCommand menuCommand = (IMenuCommand)o;
SdMenuCommand.menuCommand = menuCommand;
//=============================================================================================
CreateMainMenu();
=================================
把主菜单显示在CommandBar上面==================================
CreateToolBars();
TopMenu.Items.AddRange(items);
this.commandBar.AddItem(item);
this.UpdateItems();
this.AddItems();
for (int i = 0; i < items.Count; i++)
{
NativeMethods.TBBUTTON button = new NativeMethods.TBBUTTON();
button.idCommand = i;
NativeMethods.SendMessage(this.Handle, NativeMethods.TB_INSERTBUTTON, i, ref button);
画button
}
==============================================================================================
DefaultWorkbench
: Form, IWorkbench
1,
从
AddInTree
中取得信息
"/SharpDevelop/Workbench/MainMenu"
生成
MainMenu
存入到容器中
TopMenu
èCommandBar
CommandBar {
CommandBarItemCollection{ ArrayList{ CommandBarItem []}}}
CommandBarItem[]
中存放Menu实体(new SdMenuCommand()),
è
祥见:MenuItemCodon
2,
从AddInTree中取得信息"/SharpDevelop/Workbench/ToolBar"生成ToolBar存入到容器中
ToolBars
è
CommandBar[]
CommandBar {
CommandBarItemCollection{ ArrayList{ new SdMenuCommand()}
CommandBarItem[]
中存放Menu实体(new SdMenuCommand())
3
,
把
TopMenu, ToolBars
中CommandBar存入CommandBarManager的CommandBarCollection中
CommandBarManager{CommandBarCollection{ArrayList{CommandBar}}}
4,
从AddInTree中取得信息"/SharpDevelop/Workbench/Views"生成可隐藏的视图存入到容器中
PadContentCollection
viewContentCollection = new PadContentCollection();
PadContentCollection.Add(content);
public
class PadCodon : ClassCodon
return AddIn.CreateObject(Class);
//Clase = "ISpiderMan.SharpDevelop.Services.DefaultProjectService"
Infragistics.Win.UltraWinListBar.UltraListBar ulbRentals = new UltraListBar();
显示控件
CommandBarItem[] items = (CommandBarItem[])(AddInTreeSingleton.AddInTree.GetTreeNode(mainMenuPath).BuildChildItems(this)).ToArray(typeof(CommandBarItem));
BuildChildItems(this)
返回的是ArrayList,中装的是CommandBarItem封装的SdMenuCommand
public
class ModuleBrowser : AbstractPadContent
{
RedrawContent()//
处理显示控件
InitializeRentalsListBar();
public
override Control Control
{ get { return ulbRentals; } }
}
SdiWorkbenchLayout
: IWorkbenchLayout
布局管理器
workbench.WorkbenchLayout = new SdiWorkbenchLayout();
DefaultWorkbench.layout
//
将上一次使用的Workbench布局等信息重新载入,
//return new WorkbenchMemento(element);
w.SetMemento((IXmlConvertable)propertyService.GetProperty(workbenchMemento, new WorkbenchMemento()));
//
刷新Workbench,根据插件树信息,打开启动时需要展现的Pad和Editor
w.UpdatePadContents(null, null);
//
WorkbenchSingleton.CreateWorkspace();//UI
布局创建默认工作台
public
static void CreateWorkspace()
{
SetWbLayout();//UI
布局
OnWorkbenchCreated();
workbench.RedrawAllComponents();//
更新标题
}
workbench.WorkbenchLayout = new SdiWorkbenchLayout();//
通过属性初始化布局
public void Attach(IWorkbench workbench)
{ dockPanel = new WeifenLuo.WinFormsUI.DockPanel();}//
关键控件,可以隐藏,附着的Panel
一级菜单和工具条先加入到DefaultWorkbench的CommandBarManage中(相当与ToolBar)
((DefaultWorkbench)workbench).commandBarManager.CommandBars.Add(((DefaultWorkbench)workbench).TopMenu);
//
主菜单
((DefaultWorkbench)workbench).commandBarManager.CommandBars.Add(toolBar);//CommandBarManage
统一管理主菜单,工具条****SDMenuCommand怎么转换到CommandBarItem,一定要转吗?
DockContent newContent = CreateContent(content);//
包装
newContent.Show(dockPanel);//
挂到Panel控件
不管是菜单还是工具条单击都是先触发CommandBar
//========================================================================================
public
class CommandBar : Control, IDisposable
{
protected override void WndProc(ref Message message) //Windows
编程消息机制
{ this.PerformClick(this.items[index]);//
工具条响应事件,有效
base.WndProc(ref message);
}
public
abstract class CommandBarControl : CommandBarItem{
private
bool PerformClick(CommandBarItem item)
{control.PerformClick(EventArgs.Empty);//
工具条响应事件}}
CommandBar
{
protected
override void OnMouseDown(MouseEventArgs e)//
菜单的响应事件,Control本身的Event封装
{
if
((e.Button == MouseButtons.Left) && (e.Clicks == 1))
{int index = this.HitTest(point);//
从单击相素点判断单击菜单项
this
.TrackDropDown(index);//
生成下拉菜单,index为单击菜单项在CommandBar上的位置
}}
private void TrackDropDown(int index)
{this.contextMenu.Items.AddRange(menu.Items); // = menu.Items;
生成下拉菜单}
}
//Menu
菜单响应事件
PerformClick(EventArgs e)
//===================================================================
private
class MenuBarItem : MenuItem
{
this.item = item;//item
为SdMenuCommand?
protected
override void OnClick(EventArgs e)
{
base.OnClick(e);
CommandBarControl control = this.item as CommandBarControl; //
实际上item为SdMenuCommand实际上item为SdMenuCommand封装
if (control != null)
{ control.PerformClick(EventArgs.Empty); //
菜单单击响应事件,已确定
}
}
//
单击CommandBar重画MenuCommandBar
//=========================================================================================
class
CommandBarControl : CommandBarItem{
internal
void PerformClick(EventArgs e)
{ MessageBox.Show("
工具条,菜单单击响应事件"
);
this.OnClick(e);//this
其实是SdMenuCommand,怎样触发Command.Run()
}}
public
class SdMenuCommand : CommandBarButton, IStatusUpdate
{
protected
override void OnClick(System.EventArgs e)
{
base.OnClick(e);
if (menuCommand != null) {
//menuCommand.Run();//
调用菜单的Run() Command模式的伟大
}
}
}
点击菜单CommandBar生成下拉菜单
private
CommandBarItemCollection items = new CommandBarItemCollection();
CommandBarMenu menu = CommandBar.items[index] as CommandBarMenu;
public CommandBarItem this[int index]
{
get { return (CommandBarItem)items[index]; }
}
private
CommandBarContextMenu contextMenu = new CommandBarContextMenu();
this
.contextMenu.Items.AddRange(menu.Items); // = menu.Items;
生成下拉菜单,加入到
CommandBarContextMenu
protected override void OnPopup(EventArgs e)// CommandBarContextMenu
响应事件
{
base.OnPopup(e);
this.UpdateItems();//
转换为可单击的菜单
}
//
生成下拉菜单
this.MenuItems.Add(new MenuBarItem(item, imageSize, this.font, this.mnemonics));
// MenuItems
为系统Menu提供菜单集合, new MenuBarItem提供单击响应事件,触发CommandBar.Run()
this
.commandBar.AddItem(item);
this
.UpdateItems();//
private
void UpdateItems()
{
if (this.IsHandleCreated)//
成立
{
this.BeginUpdate();
this.RemoveItems();
this.AddItems();//
this.EndUpdate();
}
}
this
.contextMenu.Show(this, position);//
在CommandBar上显示CommandBarContextMenu
//==========================================================================================
菜单响应事件==》以PO采购为例
CommandBarButtonBase
: CommandBarControl
注册的基类
1
Public
abstract
class CommandBarControl
: CommandBarItem
internal
void PerformClick(EventArgs e)
{
MessageBox.Show("
菜单,工具条单击响应事件"
);
this.OnClick(e);
//
工具条单击响应事件
}
protected
virtual void OnClick(EventArgs e)
{
if (this.Click != null)
{
this.Click(this, e);
}
}
2
public
class RunPoManage : AbstractMenuCommand
{
public override void Run()//
命令入口
{
//004
代表采购管理
ModuleCommand.DispMenu(null,typeof(int),"004",true,null);
}
public
class ModuleCommand
{
//004
代表采购管理
//ModuleCommand.DispMenu(null,typeof(int),"004",true,null);
public static void DispMenu(object menu,Type menutype,string Title,bool isMenu,IList Actions)
{
menu = isMenu ? new MenuControl(Title) : menu;//
è
@A.1
WorkbenchSingleton.Workbench.ShowView(new UnitView(menu,Title,isMenu,Actions));
//
è
@B.
1
statusBarService.ProgressMonitor.Done();
}}
è
@A.1
//
从数据库中取得
Module(
“
004
”
)
下的子菜单,返回MenuEntity实体集合
InitTitle();
MenuList = configmenu.GetMenuByModule(Module);
//==============================================================================================
è
public
class Menu : MarshalByRefObject,IConfig
myList = MenuMapper.GetMenuByModule(Module);//"004"
采购
è
public
class MenuMapper
{
public
static IList GetMenuByModule(string Module)
{
string
sqlCommand = "Select * " +
"From Menu where MenuCode like '"+Module+"%' order by MenuCode,MenuOrder" ;
tmpMenuEntity = new MenuEntity()//
返回MenuEntity实体集合,包括Action序列
}
new MenuControl("004"),"004",true,null
private
void MenuControl_Load(object sender, System.EventArgs e)
{ GetMenu(this.Module);/
建立所有的菜单按钮,及响应事件
DrawWorkFlow();
}
================================================================================================
menubutton.Click += new MyMenuHandler(ins_menu).EventHandler;
public
MyMenuHandler(MenuEntity Target)
{
this.target = Target;
}
public EventHandler EventHandler
{
get
{
return new EventHandler(PopupMenuHandler);
}
}
void PopupMenuHandler(object sender, EventArgs e)
{
if(target.ObjectCode != "")
ExecutePage(target.ObjectCode,target.MenuName,target.Actions);//
进入编辑界面
else
MessageBox.Show("ObjectCode
为空,页面没有完成"
);
}
private void ExecutePage(string AsmStr, string Title, IList Actions)//AsmStr
是关键字段ObjectCode
{
statusBarService.ProgressMonitor.BeginTaskAuto("
开启"
+stringParserService.Parse(BaseBusinessView.FormatRes(AsmStr)),100,80);
IDictionaryEnumerator myEnumerator = AddInTreeSingleton.RegisteredAssemblies.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
bool find = false;
Assembly assembly = (Assembly)myEnumerator.Value;
foreach(Type type in assembly.GetTypes())
{
if (type.ToString().EndsWith(AsmStr))//AsmStr
是关键字段ObjectCode,也是编辑界面的域名+类名
{
ModuleCommand.DispMenu(Activator.CreateInstance(type),type,Title,false,Actions);
find = true;
break;
}
}
if(find)
{
break;
}
}
statusBarService.ProgressMonitor.Done();
}
====================================================================================================
è
@B.1
1@
public
class UnitView : AbstractViewContent
{
//new MenuControl("004"),"004",true,null
public UnitView(object menu,string Title,bool isMenu,IList Actions)
}
2@
public
class DefaultWorkbench : Form, IWorkbench{
public
virtual void ShowView(IViewContent content)
{ ViewContentCollection.Add(content);
layout.ShowView(content);
content.WorkbenchWindow.SelectWindow();//SdiWorkspaceWindow,Show()
OnViewOpened(new ViewContentEventArgs(content));}
}
public class SdiWorkbenchLayout : IWorkbenchLayout
{
public IWorkbenchWindow ShowView(IViewContent content)
{ SdiWorkspaceWindow sdiWorkspaceWindow = new SdiWorkspaceWindow(content);
sdiWorkspaceWindow.Show(dockPanel);
//
把
sdiWorkspaceWindow
封装的对象显示在dockPanel上
}}
public class DockContent : Form
{
Show(DockPanel);
public void Show(DockPanel dockPanel)
Activate();
Pane.Activate();//
最终显示
}