SharpDevelop框架中的四棵树

框架中的四棵树
1、   addin 文件本身的树结构
2、   addin 文件形成的 addinTree 树
3、   addin 文件中 Extension(Conditions/Codons) 形成的逻辑关系树(真正有意义逻辑的关系)
4、   根据逻辑关系形成的框架结构(工作台)
============================================================================================
<Extension path = "/SharpDevelop/Workbench/SharpDevelopSideBar/SideTab/ContextMenu">
         <MenuItem id = "RenameTabItem"
                   label = "${res:SideBarComponent.ContextMenu.RenameTabItem}"
                   class = "ISpiderMan.SharpDevelop.Commands.SideBarRenameTabItem" />
         <MenuItem id = "DeleteTabItem"
                   label = "${res:SideBarComponent.ContextMenu.DeleteTabItem}"
                   class = "ISpiderMan.SharpDevelop.Commands.SideBarDeleteTabItem"/>
         <Conditional ownerstate="TabCanBeDeleted">
              <MenuItem id = "Separator1" label = "-" />
              <Conditional ownerstate="CanMoveItemUp" action="Disable">
                   <MenuItem id = "MoveItemUp"
                             label = "${res:SideBarComponent.ContextMenu.MoveTabItemUp}"
                             class = "ISpiderMan.SharpDevelop.Commands.SideBarMoveActiveItemUp"/>
              </Conditional>
                                        
              <Conditional ownerstate="CanMoveItemDown" action="Disable">
                   <MenuItem id = "MoveItemDown"
                             label = "${res:SideBarComponent.ContextMenu.MoveTabItemDown}"
                             class = "ISpiderMan.SharpDevelop.Commands.SideBarMoveActiveItemDown"/>
              </Conditional>
         </Conditional>
     </Extension>
 
public class AddIn
{
string name        = null;
string author      = null;
string copyright   = null;
string url         = null;
string description = null;
string version     = null;
string fileName    = null;      
Hashtable         runtimeLibraries       = new Hashtable();      
ArrayList         extensions = new ArrayList();
public class Extension
{
         string    path;
         ArrayList codonCollection = new ArrayList();
         Hashtable conditions       = new Hashtable();
}
}
1 、1个Extension Path= ”…… .. 一个ConditionCollection
2 、1个Extension 下的所有代码子对应同一个ConditionCollection
==================================================================================================
子对象的 建立事件,对象实例化如菜单
/// <summary>
         /// Creates an item with the specified sub items. And the current
         /// Condition status for this item.
         ///</summary>
         public override object BuildItem(object owner, ArrayList subItems, ConditionCollection conditions)
         {//newItem = curNode.Codon.BuildItem(caller, subItems, curNode.ConditionCollection);sumItem 为owner的子节点集合
              CommandBarItem newItem = null;
              if (Label == "-") {
                   newItem = new SdMenuSeparator(conditions, owner);
              } else if (Link != null) {
                   newItem = new SdMenuCommand(conditions, null, Label, Link.StartsWith("http") ? (IMenuCommand)new GotoWebSite(Link) : (IMenuCommand)new GotoLink(Link));
              } else {
                   object o = null;
                   if (Class != null) {
                    o = AddIn.CreateObject(Class);// 创建对象IMenuCommand的子类
                   }
                   if (o != null) {
                       if (o is IMenuCommand) {
                            IMenuCommand menuCommand = (IMenuCommand)o;
                            menuCommand.Owner = owner;
                            if (o is ICheckableMenuCommand) {
                                 newItem = new SdMenuCheckBox(conditions, owner, Label, (ICheckableMenuCommand)menuCommand);
                            } else {
                                 newItem = new SdMenuCommand(conditions, owner, Label, menuCommand);
                            }
                       } else if (o is ISubmenuBuilder) {
                            return o;//((ISubmenuBuilder)o).BuildSubmenu(owner);
                       }
                   }
              }
              if (newItem == null) {
                   SdMenu newMenu = new SdMenu(conditions, owner, Label);
                   if (subItems != null && subItems.Count > 0) {
                       foreach (object item in subItems) {
                            if (item != null) {
                                 newMenu.SubItems.Add(item);// 包含子菜单
                            }
                       }
                   }
                   newItem = newMenu;
              }
              System.Diagnostics.Debug.Assert(newItem != null);
             
              if (Icon != null) {
                   ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
                   newItem.Image = resourceService.GetBitmap(Icon);
              }
             
              if (newItem is SdMenuCommand) {
                   ((SdMenuCommand)newItem).Description = description;
              }
             
              if (Shortcut != null && newItem is SdMenuCommand) {
                   try {
                       foreach (string key in this.shortcut) {
                            ((SdMenuCommand)newItem).Shortcut |= (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), key);
                       }
                   } catch (Exception) {
                       ((SdMenuCommand)newItem).Shortcut = System.Windows.Forms.Keys.None;
                   }
              }
              newItem.IsEnabled = true; //action != ConditionFailedAction.Disable;
              return newItem;
      }
 
public object CreateObject(string className)// 此代码不够好实例化对象补充代码,如ToolBars
         {
              object newInstance;
              foreach (DictionaryEntry library in runtimeLibraries) {// 字典键/值对-->1
                   newInstance = ((Assembly)library.Value).CreateInstance(className);//ClaseCodon
                   if (newInstance != null) {
                       return newInstance;
                   }
              }
              newInstance = Assembly.GetExecutingAssembly().CreateInstance(className);
             
              if (newInstance == null) {
                   foreach (Assembly assembly in runtimeLibraries.Values) {//-->3 和是否一样?
                       newInstance = assembly.CreateInstance(className);
                       if (newInstance != null) {
                            break;
                       }
                   }
                  
                   if (newInstance == null) {
                       newInstance = Assembly.GetCallingAssembly().CreateInstance(className);
                   }
              }
             
              if (newInstance == null) {
                   MessageBox.Show("Type not found: " + className + ". Please check : " + fileName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
              }
             
              return newInstance;
      }
====================================================================================================
public class DefaultAddInTreeNode : IAddInTreeNode
     {
         Hashtable childNodes = new Hashtable();
         ICodon    codon      = null;// 一个 DefaultAddInTreeNode 一个 ICodon
         ConditionCollection conditionCollection = null;
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值