/// <summary> Create a menu and its submenus and manage their actions</summary> /// <param name="parentControls">Control where the menu must be inserted</param> /// <param name="contextualMenu">Menu to insert</param> private void CreateMenus(CommandBarControls parentControls, IContextualMenu contextualMenu) { if (contextualMenu != null && contextualMenu.Items != null) { foreach (IContextualPart part in contextualMenu.Items) { if (part is IContextualMenu) { IContextualMenu contextualSubMenu = part as IContextualMenu; CommandBarPopup subMenu = (CommandBarPopup)parentControls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true); subMenu.Caption = contextualSubMenu.Caption; subMenu.BeginGroup = contextualSubMenu.BeginGroup; CreateMenus(subMenu.Controls, contextualSubMenu); } else { ContextualMenuItem contextualMenuItem = part as ContextualMenuItem; if (contextualMenuItem != null) { MsoControlType menuItem = MsoControlType.msoControlButton; CommandBarButton commandBarButton = (CommandBarButton)parentControls.Add(menuItem, Type.Missing, Type.Missing, Type.Missing, true); commandBarButton.Style = MsoButtonStyle.msoButtonIconAndCaption; commandBarButton.Caption = contextualMenuItem.Caption; commandBarButton.BeginGroup = contextualMenuItem.BeginGroup; if (contextualMenuItem.FaceId != 0) { commandBarButton.FaceId = contextualMenuItem.FaceId; } commandBarButton.Click += (CommandBarButton ctrl, ref bool cancel1) => { try { if (contextualMenuItem.Action != null) { contextualMenuItem.Action(); } } catch (Exception ex) { string methodName = contextualMenuItem.MethodInfo == null ? string.Empty : contextualMenuItem.MethodInfo.Name; throw new EtkException($"Contextual menu: '{methodName}' invocation failed: {ex.Message}."); } }; } } } } }
public void Initialize(CommandBarControls menuControls) { var menu = menuControls.Add(MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; menu.Caption = "Te&st"; _windowsTestExplorerButton = AddButton(menu, "&Test Explorer", false, new CommandBarButtonClickEvent(OnTestExplorerButtonClick), Resources.TestManager_8590_32); _runAllTestsButton = AddButton(menu, "&Run All Tests", true, new CommandBarButtonClickEvent(OnRunAllTestsButtonClick), Resources.AllLoadedTests_8644_24); }
public void Initialize(CommandBarControls menuControls) { _codeInspectionsButton = menuControls.Add(MsoControlType.msoControlButton, Temporary: true) as CommandBarButton; Debug.Assert(_codeInspectionsButton != null); _codeInspectionsButton.Caption = "Code &Inspections"; _codeInspectionsButton.Click += OnCodeInspectionsButtonClick; }
private CommandBarPopup addSubMenu(CommandBarControls popup, string name) { CommandBarControl ctrl = popup.Add( MsoControlType.msoControlPopup, Type.Missing, Type.Missing); ctrl.Caption = name; return((CommandBarPopup)ctrl); }
private CommandBarControl addItem(CommandBarControls popup, string name) { CommandBarControl ctrl = popup.Add( MsoControlType.msoControlButton, Type.Missing, Type.Missing); ctrl.Caption = name; return(ctrl); }
public void Initialize(CommandBarControls menuControls) { var menu = menuControls.Add(Type: MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; menu.Caption = "&Refactor"; _extractMethodButton = AddButton(menu, "Extract &Method", false, OnExtractMethodButtonClick, Resources.ExtractMethod_6786_32); _renameButton = AddButton(menu, "&Rename", false, OnRenameButtonClick); InitializeRefactorContextMenu(); }
public void Initialize(CommandBarControls menuControls) { var menu = menuControls.Add(Type: MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; menu.Caption = "&Refactor"; _parseModuleButton = AddMenuButton(menu); _parseModuleButton.Caption = "&Parse module"; _parseModuleButton.FaceId = 3039; _parseModuleButton.Click += OnParseModuleButtonClick; }
public void Initialize(CommandBarControls menuControls) { _codeExplorerButton = menuControls.Add(MsoControlType.msoControlButton, Temporary: true) as CommandBarButton; Debug.Assert(_codeExplorerButton != null); _codeExplorerButton.Caption = "&Code Explorer"; _codeExplorerButton.BeginGroup = true; _codeExplorerButton.FaceId = 3039; _codeExplorerButton.Click += OnCodeExplorerButtonClick; }
private void AddRightClickMenu() { // 添加右键按钮 CommandBarControls controls = textCommandBar.Controls; CommandBarButton addBtn = (CommandBarButton)controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); addBtn.BeginGroup = true; addBtn.Tag = "BookMarkAddin"; addBtn.Caption = "Add Bookmark"; addBtn.Enabled = true; addBtn.Click += new Office._CommandBarButtonEvents_ClickEventHandler(RightClickMenuHandler); }
CommandBarControl AddButton( CommandBarControls Controls, XTPControlType ControlType, int Id, string Caption, bool BeginGroup, string DescriptionText, XTPButtonStyle ButtonStyle, string Category ) { CommandBarControl Control = Controls.Add( ControlType, Id, Caption, -1, false ); Control.BeginGroup = BeginGroup; Control.DescriptionText = DescriptionText; Control.Category = Category; if ( Control is CommandBarButton ) { ( (CommandBarButton)Control ).Style = ButtonStyle; } return Control; }
public void Initialize(CommandBarControls menuControls) { _todoItemsButton = menuControls.Add(MsoControlType.msoControlButton, Temporary: true) as CommandBarButton; Debug.Assert(_todoItemsButton != null); _todoItemsButton.Caption = "&ToDo Items"; const int clipboardWithCheck = 837; _todoItemsButton.FaceId = clipboardWithCheck; _todoItemsButton.Click += OnShowTaskListButtonClick; }
public void Initialize(CommandBarControls menuControls) { _menuControls = menuControls; _menu = menuControls.Add(MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; _menu.Caption = RubberduckUI.RubberduckMenu_UnitTests; _windowsTestExplorerButton = AddButton(_menu, RubberduckUI.TestMenu_TextExplorer, false, OnTestExplorerButtonClick); SetButtonImage(_windowsTestExplorerButton, Resources.TestManager_8590_32, Resources.TestManager_8590_32_Mask); _runAllTestsButton = AddButton(_menu, RubberduckUI.TestMenu_RunAllTests, true, OnRunAllTestsButtonClick); SetButtonImage(_runAllTestsButton, Resources.AllLoadedTests_8644_24, Resources.AllLoadedTests_8644_24_Mask); }
public void Initialize(CommandBarControls menuControls) { _menuControls = menuControls; _menu = menuControls.Add(MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; _menu.Caption = RubberduckUI.RubberduckMenu_UnitTests; _windowsTestExplorerButton = AddButton(_menu, RubberduckUI.TestMenu_TextExplorer, false, OnTestExplorerButtonClick); SetButtonImage(_windowsTestExplorerButton, Resources.TestManager_8590_32, Resources.TestManager_8590_32_Mask); _runAllTestsButton = AddButton(_menu, RubberduckUI.TestMenu_RunAllTests, true, OnRunAllTestsButtonClick); SetButtonImage(_runAllTestsButton, Resources.AllLoadedTests_8644_24, Resources.AllLoadedTests_8644_24_Mask); }
CommandBarControl AddButton(CommandBarControls Controls, XTPControlType ControlType, int Id, string Caption, bool BeginGroup, string DescriptionText, XTPButtonStyle ButtonStyle, string Category) { CommandBarControl Control = Controls.Add(ControlType, Id, Caption, -1, false); Control.BeginGroup = BeginGroup; Control.DescriptionText = DescriptionText; Control.Category = Category; if (Control is CommandBarButton) { ((CommandBarButton)Control).Style = ButtonStyle; } return(Control); }
public void Initialize(CommandBarControls menuControls) { var menu = menuControls.Add(MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; Debug.Assert(menu != null); menu.Caption = "Te&st"; _windowsTestExplorerButton = AddMenuButton(menu, "&Test Explorer", Resources.TestManager_8590_32); _windowsTestExplorerButton.Click += OnTestExplorerButtonClick; _runAllTestsButton = AddMenuButton(menu, "&Run All Tests", Resources.AllLoadedTests_8644_24); _runAllTestsButton.BeginGroup = true; _runAllTestsButton.Click += OnRunAllTestsButtonClick; }
// Méthode jouée si contextmenu affiché sur une entrée private void addEntrytoContextMenu(CommandBar menu, Outlook.Selection Selection) { if (Selection.Count == 1 && Selection[1] is Outlook.MailItem) { CommandBarControls controls = menu.Controls; this.addActionButton = (CommandBarButton)controls.Add(MsoControlType.msoControlButton, 1, "", 1, true); this.addActionButton.FaceId = 341; this.addActionButton.Style = MsoButtonStyle.msoButtonIconAndCaption; this.addActionButton.Caption = "TaskLeader: ajouter à une action"; this.addActionButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(getSelectedItem); this.addActionButton.Visible = true; Marshal.FinalReleaseComObject(controls); } }
public void Initialize(CommandBarControls menuControls) { _menu = menuControls.Add(MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; _menu.Caption = RubberduckUI.RubberduckMenu_Refactor; _extractMethodButton = AddButton(_menu, RubberduckUI.RefactorMenu_ExtractMethod, false, OnExtractMethodButtonClick); SetButtonImage(_extractMethodButton, Resources.ExtractMethod_6786_32, Resources.ExtractMethod_6786_32_Mask); _renameButton = AddButton(_menu, RubberduckUI.RefactorMenu_Rename, false, OnRenameButtonClick); _reorderParametersButton = AddButton(_menu, RubberduckUI.RefactorMenu_ReorderParameters, false, OnReorderParametersButtonClick, Resources.ReorderParameters_6780_32); SetButtonImage(_reorderParametersButton, Resources.ReorderParameters_6780_32, Resources.ReorderParameters_6780_32_Mask); _removeParametersButton = AddButton(_menu, RubberduckUI.RefactorMenu_RemoveParameter, false, OnRemoveParameterButtonClick); SetButtonImage(_removeParametersButton, Resources.RemoveParameters_6781_32, Resources.RemoveParameters_6781_32_Mask); InitializeRefactorContextMenu(); }
public void Initialize(CommandBarControls menuControls) { _menu = menuControls.Add(MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; _menu.Caption = RubberduckUI.RubberduckMenu_Refactor; _extractMethodButton = AddButton(_menu, RubberduckUI.RefactorMenu_ExtractMethod, false, OnExtractMethodButtonClick); SetButtonImage(_extractMethodButton, Resources.ExtractMethod_6786_32, Resources.ExtractMethod_6786_32_Mask); _renameButton = AddButton(_menu, RubberduckUI.RefactorMenu_Rename, false, OnRenameButtonClick); _reorderParametersButton = AddButton(_menu, RubberduckUI.RefactorMenu_ReorderParameters, false, OnReorderParametersButtonClick, Resources.ReorderParameters_6780_32); SetButtonImage(_reorderParametersButton, Resources.ReorderParameters_6780_32, Resources.ReorderParameters_6780_32_Mask); _removeParametersButton = AddButton(_menu, RubberduckUI.RefactorMenu_RemoveParameter, false, OnRemoveParameterButtonClick); SetButtonImage(_removeParametersButton, Resources.RemoveParameters_6781_32, Resources.RemoveParameters_6781_32_Mask); InitializeRefactorContextMenu(); }
public static void addContectMenu(string menuType) { CommandBars bars = ExcelApp.Application.CommandBars; CommandBar bar = bars[menuType]; if (bar != null) { CommandBarControls controls = bar.Controls; dynamic rootControl = controls.Add(Type: MsoControlType.msoControlPopup, Before: 1, Temporary: true); rootControl.Caption = getRootMenuName(menuType); rootControl.BeginGroup = true; rootControl.Tag = getRootMenuName(menuType); button = rootControl.Controls.Add(Type: MsoControlType.msoControlButton) as CommandBarButton; button.Caption = "Refresh"; button.Tag = "Refresh"; button.OnAction = "OnButtonClick"; //button.Click += Button_Click; } }
/// <summary> /// Applies this menu to the given CommandBarControls. /// </summary> /// <param name="window">The window holding the controls.</param> /// <param name="controls">The control set to apply to.</param> protected void Apply(OfficeWindow window, CommandBarControls controls) { IList toadd = new ArrayList(this.controls); foreach (CommandBarControl control in controls) { if (control.Tag.StartsWith("UIManager_")) { string thetag = control.Tag.Substring(0, control.Tag.IndexOf("#")); ToolbarControl tcontrol = (ToolbarControl)controlMap[thetag]; if (tcontrol != null) { tcontrol.Apply(window, control); OfficeUIManager.RegisterCommandBarControl(control, window, tcontrol); toadd.Remove(tcontrol); } } } foreach (ToolbarControl tcontrol in toadd) { object newpos = System.Reflection.Missing.Value; if (tcontrol.Before != null) { int pos = 0; foreach (CommandBarControl findcontrol in controls) { pos++; if (findcontrol.Caption == tcontrol.Before) { newpos = pos; } } } CommandBarControl control = controls.Add(tcontrol.Type, 1, System.Reflection.Missing.Value, newpos, true); control.Tag = tcontrol.InternalTag + "#" + NEXT_TAG; control.OnAction = "!<" + OfficeUIManager.AddinProgID + ">"; NEXT_TAG++; tcontrol.Apply(window, control); OfficeUIManager.RegisterCommandBarControl(control, window, tcontrol); } }