private void RegisterBlockInMenu(IApplicationBlock block) { ToolStripMenuItem blockHeader = new ToolStripMenuItem( block.Name ); // register each menu in block foreach (IMenu menu in block.Menus) { if (menu.ShowInMenuStrip) { ToolStripMenuItem menuHeader = new ToolStripMenuItem(menu.Text); menuHeader.Tag = menu; foreach (IMenuItem item in menu.Items) { ILinkMenuItem linkItem = item as ILinkMenuItem; if (linkItem.ShowOnExplorerBar) { ToolStripMenuItem newItem = new ToolStripMenuItem( linkItem.Text, linkItem.Image16x16, ToolStripItemActivate ); int index = menuHeader.DropDownItems.Add(newItem); menuHeader.DropDownItems[index].Tag = item; ToolStripBindings.Add( newItem, item ); } } blockHeader.DropDownItems.Add(menuHeader); } } // insert the block menu before the help menu InsertMenuItemBeforeHelpMenu(blockHeader); }
private void RebuildToolBar() { ToolStrip.SuspendLayout(); ToolStrip.Items.Clear(); #region Add standard buttons #endregion #region Add screen list buttons foreach (IApplicationBlock block in Plugins) { if (block.ShowInToolStrip) { if (ToolStrip.Items.Count > 0) { ToolStrip.Items.Add(new ToolStripSeparator()); } foreach (IMenu menu in block.Menus) { foreach (IMenuItem item in menu.Items) { if (item is ILinkMenuItem) { ILinkMenuItem linkItem = item as ILinkMenuItem; if (linkItem.ShowOnToolStrip) { ToolStripButton button = new ToolStripButton( string.Empty, item.Image16x16 != null ? item.Image16x16 : Sphere10.Framework.Windows.Forms.Properties.Resources.DefaultToolStripImage, ToolStripItemActivate ); button.ToolTipText = linkItem.Text; ToolStrip.Items.Add(button); ToolStripBindings.Add( button, item ); } } } } } } #endregion #region Add active screen buttons if (ActiveScreen != null) { if (ActiveScreen.ToolBar != null) { if (ToolStrip.Items.Count > 0) { ToolStrip.Items.Add(new ToolStripSeparator()); } int buttonCount = ActiveScreen.ToolBar.Items.Count; ActiveViewButtons.Clear(); for (int i = 0; i < buttonCount; i++) { ActiveViewButtons.Add( ActiveScreen.ToolBar.Items[i] ); } if (ActiveScreen.ToolBar.Tag == null) { foreach (Control ctrl in ActiveScreen.Controls) { ctrl.Location = new Point( ctrl.Location.X, ctrl.Location.Y - ActiveScreen.ToolBar.Height ); } ActiveScreen.ToolBar.Visible = false; ActiveScreen.ToolBar.Tag = "Removed"; } ToolStrip.Items.AddRange(ActiveViewButtons.ToArray()); } } #endregion #region Add help buttons ToolStrip.Items.Add(new ToolStripSeparator()); ToolStripItem contextHelpButton = ToolStrip.Items.Add( string.Empty, Sphere10.Framework.Windows.Forms.Properties.Resources.Help_16x16x32, ContextHelp_Click ); contextHelpButton.ToolTipText = "Get help for currently opened screen"; #endregion ToolStrip.ResumeLayout(); }