示例#1
0
        public void AddPlugin(IPluginView pluginView)
        {
            TabPage tabPage = new TabPage(pluginView.DisplayName);
            ToolTip toolTip = new ToolTip();

            this.pluginViewTabPage.Add(pluginView, tabPage);
            this.pluginViewToolTip.Add(pluginView, toolTip);

            // Attach a new ToolTip because there's no way to detach a global (form) ToolTip
            // when closing the plugin
            toolTip.SetToolTip(tabPage, pluginView.DisplayName);

            Control pluginViewControl = pluginView as Control;

            tabPage.Controls.Add(pluginViewControl);

            Size tabPageSize = this.pluginsTabControl.DisplayRectangle.Size;

            tabPageSize.Height -= this.pluginsTabControl.ItemSize.Height;

            tabPage.Size = tabPageSize;

            this.UpdatePluginTabPageProperties(pluginView);

            this.pluginsTabControl.Controls.Add(tabPage);

            this.pluginManagerController.AddPlugin();

            this.pluginsTabControl.SelectedIndex = this.pluginManagerController.ActivePluginIndex;
        }
示例#2
0
 public void ClosePlugin(IPluginView pluginView)
 {
     if (pluginView != null)
     {
         this.applicationLogic.RemovePlugin(pluginView);
     }
 }
示例#3
0
        private void UpdatePluginTabPageProperties(IPluginView pluginView)
        {
            TabPage tabPage           = this.pluginViewTabPage[pluginView];
            Size    size              = tabPage.ClientSize;
            Control pluginViewControl = pluginView as Control;

            pluginViewControl.Size = size;
        }
示例#4
0
        /// <summary>
        /// 从插件方案中,查找与指定Ribbon控件关联的插件容器
        /// </summary>
        /// <param name="pluginView"></param>
        /// <param name="name"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static IPluginContainer QueryContainer(this IPluginView pluginView, string name, string text)
        {
            var container = pluginView.Containers.FirstOrDefault(v => v.Name == name && v.Text == text);

            if (container == null)
            {
                throw new Exception($"在插件视图“{pluginView.Name}”中找不到容器控件“{text}”({name})的对应的插件配置!");
            }
            return(container);
        }
示例#5
0
        /// <summary>
        /// 调用相应类型的插件
        /// </summary>
        /// <param name="view"></param>
        /// <param name="invokeType"></param>
        public static void InvokePlugins(this IPluginView view, IPluginPlan pluginPlan, EPluginInvokeType invokeType)
        {
            if (pluginPlan == null)
            {
                return;
            }
            var pluginView = pluginPlan.Views.First(v => v.Name == view.Name && v.Text == view.Text);
            var plugins    = pluginView.QueryPlugins(invokeType).ToList();

            plugins.ForEach(p => p.Command.Invoke(view));
        }
        public void ManageNewPlugin(string pluginName)
        {
            this.ValidatePluginManagerView();

            IPluginView pluginView = this.pluginViewFactory.CreateNew(pluginName);

            if (pluginView != null)
            {
                this.pluginManagerView.AddPlugin(pluginView);
            }
        }
示例#7
0
        /// <summary>
        /// 从插件方案中,查找与指定<see cref="MenuStrip"/>关联的插件容器
        /// </summary>
        /// <param name="pluginView"></param>
        /// <param name="menuStrip"></param>
        /// <returns></returns>
        private static IPluginContainer QueryContainer(this IPluginView pluginView, MenuStrip menuStrip)
        {
            var name      = menuStrip.Name;
            var text      = menuStrip.Text;
            var container = pluginView.Containers.FirstOrDefault(v => v.Name == name && v.Text == text);

            if (container == null)
            {
                throw new Exception($"在插件视图“{pluginView.Name}”中找不到容器控件“{text}”({name})的对应的插件配置!");
            }
            return(container);
        }
示例#8
0
        /// <summary>
        /// 从插件方案中,查找与指定Ribbon控件关联的插件容器
        /// </summary>
        /// <param name="pluginView"></param>
        /// <param name="ribbonCtrl"></param>
        /// <returns></returns>
        private static IPluginContainer QueryContainer(this IPluginView pluginView, RibbonControl ribbonCtrl)
        {
            var name      = ribbonCtrl.DefaultPageCategory.Name;
            var text      = ribbonCtrl.DefaultPageCategory.Text;
            var container = pluginView.Containers.FirstOrDefault(v => v.Name == name && v.Text == text);

            if (container == null)
            {
                throw new Exception($"在插件视图“{pluginView.Name}”中找不到容器控件“{text}”({name})的对应的插件配置!");
            }
            return(container);
        }
示例#9
0
        public void RemovePlugin(IPluginView rawPluginView)
        {
            TabPage tabPage = this.pluginViewTabPage[rawPluginView];
            ToolTip toolTip = this.pluginViewToolTip[rawPluginView];

            this.pluginsTabControl.Controls.Remove(tabPage);
            this.pluginViewTabPage.Remove(rawPluginView);
            this.pluginViewToolTip.Remove(rawPluginView);

            tabPage.Dispose();
            toolTip.Dispose();

            this.pluginManagerController.RemoveActivePlugin();
        }
示例#10
0
        private void PluginClick(object sender, EventArgs e)
        {
            ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;

            if (toolStripMenuItem.Name == MainWindow.closePluginName)
            {
                IPluginView pluginView = this.pluginManagerView.GetActivePlugin();

                this.pluginOperationController.ClosePlugin(pluginView);
            }
            else
            {
                this.pluginOperationController.CreatePlugin(toolStripMenuItem.Name);
            }
        }
示例#11
0
        /// <summary>
        /// 以菜单形式加载插件
        /// <para>将<see cref="IPluginView"/>中的插件以<see cref="MenuStrip"/>的菜单形式来加载, 在点击菜单、窗口加载、窗口关闭时调用相应插件</para>
        /// </summary>
        /// <param name="menuStrip"></param>
        /// <param name="view"></param>
        /// <param name="form"></param>
        /// <param name="cmdData">插件命令的传入参数</param>
        /// <param name="bingdingPluginCommandEvents">插件命令事件处理方法</param>
        public static void LoadPluginView <TCmdData>(this MenuStrip menuStrip,
                                                     Form form, IPluginView view, TCmdData cmdData, Action <IPluginView> bingdingPluginCommandEvents)
        {
            try
            {
                var container = view.QueryContainer(menuStrip);
                menuStrip.LoadPluginContainer(container);
                container.LoadPluginCommands(cmdData);
                bingdingPluginCommandEvents(view);//绑定插件命令事件处理

                //在窗口加载时、窗口关闭时触发相应插件
                view.InvokePlugins(EPluginInvokeType.OnViewLoad, form);
                form.FormClosing += (sender, e) => view.InvokePlugins(EPluginInvokeType.OnViewClose, form);
            }
            catch (Exception ex) { MessageBoxEx.ShowError(ex); }
        }
示例#12
0
        /// <summary>
        /// 向插件窗口的RibbonControl控件加载插件
        /// </summary>
        /// <param name="ribbonCtrl">加载插件的RibbonControl控件</param>
        /// <param name="caller">调用插件的控件,一般是窗体、菜单栏、RibbonControl、XtraTabControl、DcokControl、各类容器控件等</param>
        /// <param name="view">加载的插件视图</param>
        /// <param name="cmdData">命令输入参数</param>
        /// <param name="imageDir"></param>
        /// <param name="bindingEvent"></param>
        public static void LoadPlugins <TCmdData>(this RibbonControl ribbonCtrl, IPluginView view, object caller, TCmdData cmdData, string imageDir, Action <ICommand> bindingEvent)
        {
            var container = view.QueryContainer(ribbonCtrl.DefaultPageCategory.Name, ribbonCtrl.DefaultPageCategory.Text);

            var sbErrorCmds     = new StringBuilder();
            var imageCollection = ribbonCtrl.LargeImages == null ? new ImageCollection() : (ImageCollection)ribbonCtrl.LargeImages;

            ribbonCtrl.LargeImages = imageCollection;
            foreach (var pageContainer in container.SubContainers)//菜单页
            {
                var page = new RibbonPage {
                    Text = pageContainer.Text, Name = pageContainer.Name, Visible = pageContainer.Visible, Tag = pageContainer
                };
                ribbonCtrl.DefaultPageCategory.Pages.Add(page);
                foreach (var groupContainer in pageContainer.SubContainers)//菜单组
                {
                    var group = new RibbonPageGroup {
                        Text = groupContainer.Text, Name = groupContainer.Name, Visible = groupContainer.Visible, Tag = groupContainer
                    };
                    page.Groups.Add(group);
                    var plugins = groupContainer.Plugins.OrderBy(v => v.Index);
                    foreach (var plugin in plugins)//菜单项(插件项)
                    {
                        try
                        {
                            var item = PluginToButtonItem(plugin, imageCollection, caller, imageDir, cmdData);
                            bindingEvent(plugin.Command);
                            group.ItemLinks.Add(item);
                        }
                        catch (Exception ex) { sbErrorCmds.AppendLine($"程序集:{ plugin.AssemblyPath}\r\n命令:{plugin.TypeName}"); }
                        Application.DoEvents();
                    }
                }
            }
            if (sbErrorCmds.Length > 0)
            {
                sbErrorCmds.Insert(0, "以下插件命令创建失败(找不到程序集或命令,或加载过程出错,请注意程序集路径、名称、后缀(dll、exe)、类名是否正确):");
                throw new Exception(sbErrorCmds.ToString());
            }
        }
        public void RemovePlugin(IPluginView pluginView)
        {
            this.ValidatePluginManagerView();

            this.RemovePluginViewFromCurrentPluginManagerView(pluginView);
        }
        private void RemovePluginViewFromCurrentPluginManagerView(IPluginView pluginView)
        {
            this.pluginManagerView.RemovePlugin(pluginView);

            pluginView.Close();
        }
示例#15
0
 /// <summary>
 /// 获取插件视图中的全部插件
 /// </summary>
 /// <param name="view">插件视图</param>
 /// <param name="invokeType">插件调用类型</param>
 /// <returns></returns>
 public static IEnumerable<IPluginItem> QueryPlugins(this IPluginView view)
 {
     return view.Containers.SelectMany(container => QueryPlugins(container));
 }
示例#16
0
 /// <summary>
 /// 从插件视图中筛选指定的调用类型的插件
 /// </summary>
 /// <param name="view">插件视图</param>
 /// <param name="invokeType">插件调用类型</param>
 /// <returns></returns>
 public static IEnumerable<IPluginItem> QueryPlugins(this IPluginView view, EPluginInvokeType invokeType)
 {
     return view.Containers.SelectMany(container => QueryPlugins(container, invokeType));
 }
示例#17
0
 /// <summary>
 /// 调用相应类型的插件
 /// </summary>
 /// <param name="view"></param>
 /// <param name="invokeType"></param>
 public static void InvokePlugins(this IPluginView view, EPluginInvokeType invokeType, object caller = null)
 {
     var plugins = view.QueryPlugins(invokeType).ToList();
     plugins.ForEach(p => p.Command?.Invoke(caller));
 }
 public void RemovePlugin(IPluginView pluginView)
 {
 }