public void AddMenuOption(IWindowPlugin plugin, string mainMenuText, string subMenuText) { ToolStripMenuItem item = null; foreach (ToolStripMenuItem menuItem in _menuStrip.Items) { // Dubious hack for & in title. Better way to find item? if (menuItem.Text.Trim('&') == mainMenuText) { item = menuItem; break; } } if (item == null) { item = new ToolStripMenuItem(mainMenuText); _menuStrip.Items.Insert(_menuStrip.Items.Count - 2, item); } ToolStripItem[] subitems = item.DropDownItems.Find(subMenuText, false); ToolStripItem subitem = null; if (subitems.Length == 0) { subitem = new ToolStripMenuItem(subMenuText); //subitem.Tag = new MenuInfo(plugin, null); subitem.Tag = new MenuInfo(plugin, _windowManager.ProjectBrowser.RootItem); subitem.Click += plugin_MenuClick; item.DropDownItems.Insert(item.DropDownItems.Count, subitem); _pluginIndex.Add(plugin.GetID(), subitem); } else { _windowManager.Logger.LogStr("Failed to add menu item:" + mainMenuText + "|" + subMenuText); } }
internal void AddContextMenuOption(IWindowPlugin plugin, List <Type> types, string text) { // Each plugin may deal with multiple types. foreach (Type t in types) { List <ToolStripMenuItem> list; if (_contextOptions.ContainsKey(t)) { list = _contextOptions[t]; } else { list = new List <ToolStripMenuItem>(); _contextOptions.Add(t, list); } ToolStripMenuItem mi = new ToolStripMenuItem(); mi.Text = text; mi.Click += plugin_MenuClick; // Hang onto the plugin for menu events. mi.Tag = new MenuInfo(plugin, null); list.Add(mi); string id = plugin.GetID(); _contextTypeIndex.Add(id + "_" + t.FullName, mi); } }
internal void UpdateMenuOption(IWindowPlugin plugin) { string id = plugin.GetID(); if (!_pluginIndex.ContainsKey(id)) { _windowManager.Logger.LogStr("Failed to update menu item"); return; } _pluginIndex[id].Tag = new MenuInfo(plugin, null); }
internal void UpdateWindow(IWindowPlugin plugin) { string id = plugin.GetID(); if (!_windows.ContainsKey(id)) { _logView.LogStr("ERROR : UpdatePlugin failed to find plugin : " + id); return; } _windows[id] = (DockContent)plugin; }
private void LoadWindowPlugin(string filename, Type t) { try { IWindowPlugin plugin = (IWindowPlugin)Activator.CreateInstance(t); plugin.SetServiceProvider(_windowManager); string id = plugin.GetID(); // Ignore classes with blank ID, for example a base class. if (!string.IsNullOrEmpty(id)) { _windowPlugins.Add(id, plugin); _windowManager.AddPlugin(id, plugin as DockContent, true); // If kind is MainWindow, then we have a main menu option, otherwise // the project browser will build a context sensitive right click menu. // Whatever, the menu option for the plugin will hold the reference to // that plugin, and duplicates should not matter. if (plugin.GetKind() == WindowPluginKind.MainWindow) { _windowManager.MenuManager.AddMenuOption( plugin, "Window", plugin.GetID()); } else { _windowManager.MenuManager.AddContextMenuOption( plugin, plugin.GetHandledTypes(), plugin.GetID()); } _windowManager.Logger.LogStr(string.Format( "Loaded UI Plugin '{0}'", t.Name)); } } catch (Exception exc) { if (_windowManager.Logger.LogCatchAll(exc, string.Format( "Unexpected error in plugin '{0}'", t.ToString()))) { throw; } } }
private void SetItemRefreshInternal(DockContent window, BaseItem item) { try { IActiveItemViewer viewer = window as IActiveItemViewer; IWindowPlugin plugin = window as IWindowPlugin; viewer.SetRefresh(item); } catch (Exception exc) { if (_logView.LogCatchAll(exc, "Unexpected plugin error")) { throw; } } }
internal void UpdateContextMenuOption(IWindowPlugin plugin) { string id = plugin.GetID(); List <Type> types = plugin.GetHandledTypes(); foreach (Type type in types) { if (_contextTypeIndex.ContainsKey(id + "_" + type.FullName)) { _contextTypeIndex[id + "_" + type.FullName].Tag = new MenuInfo(plugin, null); } else { _windowManager.Logger.LogStr("Browser failed to update menu item"); } } }
private void SetItemInternal(DockContent window, BaseItem item) { try { IActiveItemViewer viewer = window as IActiveItemViewer; IWindowPlugin plugin = window as IWindowPlugin; // Always set a main window plugin, but only set others if they've changed. if (plugin.GetKind() == WindowPluginKind.MainWindow || viewer.GetActiveItem() != item) { viewer.SetActiveItem(item); } } catch (Exception exc) { if (_logView.LogCatchAll(exc, "Unexpected plugin error")) { throw; } } }
internal void UpdatePluginItem(IWindowPlugin plugin, BaseItem item) { CachedSet(plugin as DockContent, item, false); }
public MenuInfo(IWindowPlugin plugin, BaseItem item) { Plugin = plugin; Item = item; }
internal void UpdateContextMenuOption(IWindowPlugin plugin) { string id = plugin.GetID(); List<Type> types = plugin.GetHandledTypes(); foreach (Type type in types) { if (_contextTypeIndex.ContainsKey(id + "_" + type.FullName)) { _contextTypeIndex[id + "_" + type.FullName].Tag = new MenuInfo(plugin, null); } else { _windowManager.Logger.LogStr("Browser failed to update menu item"); } } }
internal void AddContextMenuOption(IWindowPlugin plugin, List<Type> types, string text) { // Each plugin may deal with multiple types. foreach (Type t in types) { List<ToolStripMenuItem> list; if (_contextOptions.ContainsKey(t)) { list = _contextOptions[t]; } else { list = new List<ToolStripMenuItem>(); _contextOptions.Add(t, list); } ToolStripMenuItem mi = new ToolStripMenuItem(); mi.Text = text; mi.Click += plugin_MenuClick; // Hang onto the plugin for menu events. mi.Tag = new MenuInfo(plugin, null); list.Add(mi); string id = plugin.GetID(); _contextTypeIndex.Add(id + "_" + t.FullName, mi); } }