示例#1
0
        private void CreateUIToolBars(Dictionary <string, NBGIS.PluginEngine.IToolBarDef> Toolbars)
        {
            foreach (KeyValuePair <string, NBGIS.PluginEngine.IToolBarDef> toolbar in Toolbars)
            {
                NBGIS.PluginEngine.IToolBarDef nbToolbar = toolbar.Value;

                Janus.Windows.UI.CommandBars.UICommandBar uiToolbar = new Janus.Windows.UI.CommandBars.UICommandBar();

                uiToolbar.CommandManager = this.uiCommandManager;

                uiToolbar.CommandsStyle = Janus.Windows.UI.CommandBars.CommandStyle.TextImage;

                uiToolbar.Name = nbToolbar.Name;
                uiToolbar.Text = nbToolbar.Caption;
                //Tag=nbToolbar?
                uiToolbar.Tag     = nbToolbar;
                uiToolbar.Key     = nbToolbar.ToString();
                uiToolbar.Visible = nbToolbar.IsVisible;

                //将Command和Tool插入到Toolbar中
                NBGIS.PluginEngine.IItemDef itemDef = new NBGIS.PluginEngine.ItemDef();
                for (int i = 0; i < nbToolbar.ItemCount; i++)
                {
                    nbToolbar.GetItemInfo(i, itemDef);
                    Janus.Windows.UI.CommandBars.UICommand uiCmd = null;

                    //如果一个ICommand对象由于某些原因并没有正确产生,
                    //而在Toolbar或Menu中又存在它的名称
                    //获取该ICommand对象就会出现异常
                    try
                    {
                        //uiCmd = this.uiCommandManager.Commands[itemDef.ID];
                        uiCmd = this.uiCommandManager.Commands[i];
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(itemDef.ID + " Plugin" + " didn't load.\n" + " Message: " + ex.Message);
                    }
                    if (uiCmd != null)
                    {
                        if (itemDef.Group)
                        {
                            uiToolbar.Commands.AddSeparator();
                        }
                        uiToolbar.Commands.Add(uiCmd);
                    }
                }
            }
        }
示例#2
0
        private void CreateUIMenus(Dictionary <string, NBGIS.PluginEngine.IMenuDef> Menus)
        {
            foreach (KeyValuePair <string, NBGIS.PluginEngine.IMenuDef> menu in Menus)
            {
                NBGIS.PluginEngine.IMenuDef nbMenu = menu.Value;

                Janus.Windows.UI.CommandBars.UICommand uiMenu = new Janus.Windows.UI.CommandBars.UICommand();


                this.uiMainMenu.Commands.Add(uiMenu);

                uiMenu.Text    = nbMenu.Caption;
                uiMenu.Name    = nbMenu.Name;
                uiMenu.Tag     = nbMenu;
                uiMenu.Key     = nbMenu.ToString();
                uiMenu.Visible = nbMenu.IsVisible;

                //将Command和Tool插入到menu中
                //遍历每一个菜单item
                NBGIS.PluginEngine.IItemDef itemDef = new NBGIS.PluginEngine.ItemDef();
                for (int i = 0; i < nbMenu.ItemCount; i++)
                {
                    //寻找该菜单对象的信息,如该菜单上所有的Item数量,是否为Group
                    nbMenu.GetItemInfo(i, itemDef);
                    Janus.Windows.UI.CommandBars.UICommand uiCmd = null;
                    try
                    {
                        uiCmd = this.uiCommandManager.Commands[i];
                    }
                    catch (Exception ex)
                    {}
                    //如果该uiCommand存在,则添加
                    if (uiCmd != null)
                    {
                        //暂时不考虑Subtype的情况
                        if (itemDef.Group)
                        {
                            uiMenu.Commands.AddSeparator();
                        }
                        uiMenu.Commands.Add(uiCmd);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// 创建UI层的菜单栏
        /// </summary>
        /// <param name="Menus"></param>
        private void CreateMenus(Dictionary <string, NBGIS.PluginEngine.IMenuDef> Menus)
        {
            //遍历Menu集合中的元素
            foreach (KeyValuePair <string, NBGIS.PluginEngine.IMenuDef> menu in Menus)
            {
                NBGIS.PluginEngine.IMenuDef nbMenu = menu.Value;
                //新建菜单对象
                ToolStripMenuItem UIMenu = new ToolStripMenuItem();
                //设置菜单属性
                UIMenu.Text           = nbMenu.Caption;
                UIMenu.Tag            = nbMenu;
                UIMenu.AccessibleName = nbMenu.ToString();
                //将Menu添加MainMenu的Commands中
                MainMenu.Items.Add(UIMenu);
                //将Command和Tool插入到menu中
                //遍历每一个菜单item
                NBGIS.PluginEngine.ItemDef itemDef = new NBGIS.PluginEngine.ItemDef();
                for (int i = 0; i < nbMenu.ItemCount; i++)
                {
                    //寻找该菜单对象的信息,如该菜单上的Item数量,是否为Group
                    nbMenu.GetItemInfo(i, itemDef);

                    NBGIS.PluginEngine.ITool nbtool = m_DicPlugins[itemDef.ID] as NBGIS.PluginEngine.ITool;
                    if (nbtool != null)
                    {
                        //产生一个ITool对象
                        ToolStripMenuItem UITool = new ToolStripMenuItem();
                        //根据ITool的信息设置UITool的属性
                        UITool.ToolTipText    = nbtool.Tooltip;
                        UITool.Text           = nbtool.Caption;
                        UITool.Image          = nbtool.Bitmap;
                        UITool.AccessibleName = nbtool.ToString();
                        //UITool.Key = nbtool.ToString();
                        UITool.Enabled = nbtool.Enabled;
                        UITool.Checked = nbtool.Checked;
                        //产生UICommand是调用OnCreate方法,将主框架对象传递给插件对象
                        nbtool.OnCreate(this._App);
                        //使用委托机制处理Command的事件
                        //所有的UICommand对象Click事件均使用this.UITool_Click方法处理
                        UITool.Click += new EventHandler(UITool_Click);
                        //将生成的UICommand添加到CommandManager中
                        if (itemDef.Group)
                        {
                            UIMenu.DropDownItems.Add(new ToolStripSeparator());
                        }
                        UIMenu.DropDownItems.Add(UITool);
                    }
                    NBGIS.PluginEngine.ICommand nbcmd = m_DicPlugins[itemDef.ID] as NBGIS.PluginEngine.ICommand;
                    if (nbcmd != null)
                    {
                        //产生一个UICommand对象
                        ToolStripMenuItem UICommand = new ToolStripMenuItem();
                        //根据ICommand的信息设置UICommand的属性
                        UICommand.ToolTipText    = nbcmd.Tooltip;
                        UICommand.Text           = nbcmd.Caption;
                        UICommand.Image          = nbcmd.Bitmap;
                        UICommand.AccessibleName = nbcmd.ToString();
                        UICommand.Enabled        = nbcmd.Enabled;
                        //UICommand的Checked与command的属性一致
                        UICommand.Checked = nbcmd.Checked;
                        //产生UICommand是调用OnCreate方法,将主框架对象传递给插件对象
                        nbcmd.OnCreate(this._App);
                        //使用委托机制处理Command的事件
                        //所有的UICommand对象Click事件均使用this.Command_Click方法处理
                        UICommand.Click += new EventHandler(UICommand_Click);
                        //将生成的UICommand添加到CommandManager中
                        //如果分组,则在该UI对象前加上一个分隔符
                        if (itemDef.Group)
                        {
                            UIMenu.DropDownItems.Add(new ToolStripSeparator());
                        }
                        UIMenu.DropDownItems.Add(UICommand);
                    }
                }
            }
        }