public static void DelOpenFloderForVS() { CommandBars cmdBars = (CommandBars)(Common.chDTE.DTE.CommandBars); if (menuItemPI != null) { menuItemPI.Delete(null); } if (menuItem != null) { menuItem.Delete(null); } if (menuItemCTH != null) { menuItemCTH.Delete(null); } if (menuItemCTH_C != null) { menuItemCTH_C.Delete(null); } if (menuItemCopyPath != null) { menuItemCopyPath.Delete(null); } if (menuItem != null) { menuItem.Delete(null); } //if (menuItemCTH != null) //{ // menuItemCTH.Delete(null); //} }
public void DeleteOldGitExtMainMenuBar() { try { CommandBarControl control = GetMenuBar() .Controls.Cast <CommandBarControl>() .FirstOrDefault(c => c.Caption == OldGitMainMenuName); if (control != null) { control.Delete(false); } control = GetMenuBar() .Controls.Cast <CommandBarControl>() .FirstOrDefault(c => c.Caption == OldGitExtMainMenuName); if (control != null) { control.Delete(false); } CommandBar cb = CommandBars.Cast <CommandBar>() .FirstOrDefault(c => c.Name == OldGitMainMenuName); if (cb != null && !cb.BuiltIn) { cb.Delete(); } } catch (Exception) { } }
/// <summary> /// 清除指定名称的项(删除可能VS崩溃没执行删除而残余的菜单) /// </summary> /// <param name="bar"></param> /// <param name="name"></param> private void ClearControl(Microsoft.VisualStudio.CommandBars.CommandBar bar, string name) { int trac = 0; CommandBarControl ctr = null; while (true) { trac++; if (trac >= 100) { return; } try { ctr = bar.Controls[name] as CommandBarControl; } catch { } if (ctr == null) { return; } ctr.Delete(Type.Missing); ctr = null; } }
/// <summary> /// 从菜单或工具条中删除指定的命令 /// </summary> /// <param name="CmdName"></param> /// <param name="SubItemName"></param> /// <param name="Name"></param> /// <param name="Caption"></param> /// <returns></returns> /// <remarks></remarks> public static Exception DeleteCommand(string CmdName, string SubItemName, string Name, string Caption) { //CmdName 工具条名称, SubItemName 工具条子项目名称,Name 要添加的项目名称, //Caption 要添加的项目标题.此方法内用于删除该按钮/项 Exception e = null; Commands2 Cmds = (Commands2)chDTE.Commands; CommandBars CmdBars = (CommandBars)chDTE.CommandBars; CommandBar mnuBarCmdBar = CmdBars[CmdName]; //菜单 CommandBarControl CmdCtrl = mnuBarCmdBar.Controls[SubItemName]; CommandBarPopup CmdPopup = (CommandBarPopup)CmdCtrl; try { Cmds.Item("KeelKit.Commands." + Name, 0).Delete(); } catch (Exception ex) { e = ex; } try { CommandBarControl chCmdConfig = CmdPopup.Controls[Caption]; chCmdConfig.Delete(null); } catch (Exception ex) { e = ex; } return(e); }
private void onDisconnect() { if (m_socket != null) { m_socket.release(); m_socket = null; } if (m_toolBarObj != null) { m_applicationObject.Commands.RemoveCommandBar(m_toolBarObj); m_toolBarObj = null; } int nCommand = m_commandList.Length; for (int ithCmd = 0; ithCmd < nCommand; ++ithCmd) { CommandObj cmdObj = m_commandList[ithCmd]; if (cmdObj.command != null) { //m_commandList[ithCmd].command.Bindings = ""; m_commandList[ithCmd].command.Delete(); m_commandList[ithCmd].command = null; } } if (m_menuBarObj != null) { m_menuBarObj.Delete(); m_menuBarObj = null; } }
/* * OnDisconnection */ /// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary> /// <param term="disconnectMode">Describes how the Add-in is being unloaded.</param> /// <param term="custom">Array of parameters that are host application specific.</param> /// <seealso class="IDTExtensibility2" /> public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { if (_taskListUI != null && !_taskListUI.IsDisposed) { _taskListUI.Dispose(); } if (_solution != null) { _solution.BeforeClosing -= _Solution_BeforeClosing; _solution.Opened -= _Solution_Opened; } if (_taskListMenuItem != null) { try { _taskListMenuItem.Delete(Type.Missing); } catch (Exception e) { Trace.WriteLineIf( _ErrorEnabled, "Error occured while deleting menu item: " + e.Message ); } } }
/// <summary> /// Removes VCB toolbar and menu from Visual Studio. /// </summary> /// <param name="dte"> /// <c>DTE</c> object (VS environment) to remove from. /// </param> private static void DeleteBars(DTE dte) { try { CommandBar toolbar = ((CommandBars)dte.CommandBars)[Constants.CommandBarName]; if (toolbar != null) { dte.Commands.RemoveCommandBar(toolbar); } } catch { } // remove menu main entry try { for (int i = ((CommandBars)dte.CommandBars).ActiveMenuBar.Controls.Count; i > 0; i--) { CommandBarControl cbc = (CommandBarControl)((CommandBars)dte.CommandBars).ActiveMenuBar.Controls[i].Control; if (cbc.Caption == Constants.MenuName) { cbc.Delete(false); break; } } } catch { } }
} // RemoveCommand /// <summary> /// Remove a Control from a CommnandBar /// </summary> /// <param name="applicationObject">The host application.</param> /// <param name="commandBarName"></param> /// <param name="controlName"></param> public static void RemoveCommandControl(DTE2 applicationObject, string commandBarName, string controlName) { // Remove the controls from the CommandBars try { CommandBars cmdBars = (CommandBars)(applicationObject.CommandBars); CommandBar bar = cmdBars[commandBarName]; CommandBarControl ctrl = null; for (int n = 1; n <= bar.Controls.Count; n++) { string cap = bar.Controls[n].Caption; if (bar.Controls[n].Caption == controlName) { ctrl = bar.Controls[n]; } } // for // CommandBarControl ctrl = bar.Controls[controlName]; if (ctrl != null) { ctrl.Delete(false); } } catch (Exception ex) { Debug.WriteLine(ex.Message, "ChirpyPopupAddIn.RemoveCommandControl"); } // try } // RemoveCommandControl
public void RemoveCreatedControls() { for (int n = createdControls.Count - 1; n >= 0; n--) { CommandBarControl control = createdControls[n]; control.Delete(true); } createdControls.Clear(); }
private void RemoveRightClickMenu() { // 这里我写了一个循环,目标是清理所有由我创建的右键按钮,尤其是由于Addin Crash时所遗留的按钮 CommandBarControl control = textCommandBar.FindControl(MsoControlType.msoControlButton, missing, "BookMarkAddin", true, true); while (control != null) { control.Delete(true); control = textCommandBar.FindControl(MsoControlType.msoControlButton, missing, "BookMarkAddin", true, true); } }
public void DeleteGitExtMainMenuBar() { try { CommandBarControl control = GetMenuBar().Controls.Cast <CommandBarControl>() .FirstOrDefault(c => c.Caption == GitMainMenuName); control?.Delete(false); } catch (Exception) { } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or /// resetting unmanaged resources. /// </summary> /// <param name="disposing"> /// true to release both managed and unmanaged resources; false to release only /// unmanaged resources. /// </param> protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { if (_commandBaseCommandBarControl != null) { _commandBaseCommandBarControl.Delete(); _commandBaseCommandBarControl = null; } } } _isDisposed = true; }
/// <summary> /// Destroys the user interface. /// </summary> public void DestroyUserInterface() { if (controlCodeMenuDisassembleCommand == null) { return; } try { controlCodeMenuDisassembleCommand.Delete(); } catch { // The application is shutting down, don't interfere with the user. } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or /// resetting unmanaged resources. /// </summary> /// <param name="disposing"> /// true to release both managed and unmanaged resources; false to release only /// unmanaged resources. /// </param> protected virtual void Dispose(bool disposing) { logger.Trace("Entered CommandBase::Dispose."); if (!_isDisposed) { if (disposing) { if (_commandBaseCommandBarControl != null) { _commandBaseCommandBarControl.Delete(); _commandBaseCommandBarControl = null; } } } _isDisposed = true; }
/// <summary> /// Removes all occurrences of menus for specified command named. /// </summary> private static void RemoveMenuItem(CommandBar commandBar, string commandMenuName) { if (commandBar != null) { while (true) { try { CommandBarControl ctl = commandBar.Controls[commandMenuName]; ctl.Delete(false); } catch (ArgumentException) { break; } } } }
/// <summary>实现 IDTExtensibility2 接口的 OnDisconnection 方法。接收正在卸载外接程序的通知。</summary> /// <param name="disconnectMode">描述外接程序的卸载方式。</param> /// <param name="custom">特定于宿主应用程序的参数数组。</param> /// <seealso class='IDTExtensibility2' /> public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { try { switch (disconnectMode) { case ext_DisconnectMode.ext_dm_HostShutdown: case ext_DisconnectMode.ext_dm_UserClosed: if (BuildMenu != null) { BuildMenu.Delete(true); } break; } } catch (Exception ex) { Logger.WriteExceptionLog("Disconnection error:" + ex.Message + Environment.NewLine + ex.StackTrace); } }
private static void deleteContextMenu(string menuType) { CommandBars bars = ExcelApp.Application.CommandBars; CommandBar bar = bars[menuType]; if (bar != null) { CommandBarControls controls = bar.Controls; try { CommandBarControl control = controls[getRootMenuName(menuType)]; if (control != null) { control.Delete(); } } catch { } } }
public void UnregisterUI() { _uiControl.Delete(); _uiControl = null; }
/// <summary>Registers refactoring actions with Visual Studio</summary> private void SetupRefactorActions() { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)applicationObject.Commands; Command refactorCommand = null; IList <CommandBar> targets = new List <CommandBar>(); try { try { CommandBar menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"]; targets.Add(((CommandBarPopup)menuBarCommandBar.Controls[FindLocalizedMenuName("Refactor")]).CommandBar); } catch { } try { targets.Add(((CommandBars)applicationObject.CommandBars)["Refactor"]); } catch { } try { targets.Add(((CommandBars)applicationObject.CommandBars)["XAML Editor"]); } catch { } try { targets.Add(((CommandBars)applicationObject.CommandBars)["ASPX Context"]); } catch { } try { targets.Add(((CommandBars)applicationObject.CommandBars)["ASPX Code Context"]); } catch { } try { targets.Add(((CommandBars)applicationObject.CommandBars)["ASPX VB Code Context"]); } catch { } try { targets.Add(((CommandBars)applicationObject.CommandBars)["HTML Context"]); } catch { } foreach (var target in targets) { while (true) { try { CommandBarControl ctl = (CommandBarControl)(target.Controls[Strings.RefactorCommandText]); ctl.Delete(false); } catch (ArgumentException) { break; } } } // Create refactor command if necessary try { refactorCommand = commands.AddNamedCommand2(addInInstance, Strings.RefactorCommandName, Strings.RefactorCommandText, Strings.RefactorCommandToolTip, true, 69, ref contextGUIDS, (int)(vsCommandStatus.vsCommandStatusEnabled | vsCommandStatus.vsCommandStatusSupported), (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton); if (!String.IsNullOrEmpty(Strings.RefactorCommandHotkey)) { refactorCommand.Bindings = new object[] { Strings.RefactorCommandHotkey }; } } catch (ArgumentException) { refactorCommand = commands.Item(addInInstance.ProgID + "." + Strings.RefactorCommandName, -1); } foreach (var target in targets) { refactorCommand.AddControl(target, target.Controls.Count + 1); } } catch (Exception e) { System.Diagnostics.Trace.TraceError(e.ToString()); throw; } }
public void RemoveItem(IContext context, string path, bool recurse) { _control.Delete(false); }