private void GitPluginUISetupCommandBar() { // Try to delete the commandbar if it exists from a previous execution, // because the /resetaddin command-line switch of VS 2005 (or higher) add-in // projects only resets commands and buttons, not commandbars _gitPlugin.DeleteGitExtCommandBar(); try { CommandBar commandBar = _gitPlugin.AddGitExtCommandBar(MsoBarPosition.msoBarTop); _gitPlugin.AddToolbarCommandWithText(commandBar, "Commit", "Commit", "Commit changes", 7, 1); _gitPlugin.AddToolbarCommand(commandBar, "Browse", "Browse", "Browse repository", 12, 2); _gitPlugin.AddToolbarCommand(commandBar, "Pull", "Pull", "Pull changes from remote repository", 9, 3); _gitPlugin.AddToolbarCommand(commandBar, "Push", "Push", "Push changes to remote repository", 8, 4); _gitPlugin.AddToolbarCommand(commandBar, "Stash", "Stash", "Stash changes", 3, 5); _gitPlugin.AddToolbarCommand(commandBar, "Settings", "Settings", "Settings", 2, 6); } catch (Exception ex) { _gitPlugin.OutputPane.OutputString("Error creating toolbar: " + ex); } }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. /// Receives notification that the Add-in is being loaded. /// </summary> /// <param name="application">The application.</param> /// <param name="connectMode">The connect mode.</param> /// <param name="addInInst">The add in inst.</param> /// <param name="custom">The custom.</param> /// <seealso class="IDTExtensibility2"/> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { if (_gitPlugin != null) { return; } try { var cultureInfo = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = cultureInfo; _applicationObject = (DTE2)application; _gitPlugin = new Plugin((DTE2)application, (AddIn)addInInst, "GitExtensions", "GitPlugin.Connect"); _gitPlugin.OutputPane.OutputString("Git Extensions plugin connected" + Environment.NewLine); //GitPlugin.DeleteCommandBar("GitExtensions"); try { _gitPlugin.RegisterCommand("GitExtensionsFileHistory", new ToolbarCommand <FileHistory>()); _gitPlugin.RegisterCommand("GitExtensionsCommit", new ToolbarCommand <Commit>()); _gitPlugin.RegisterCommand("GitExtensionsBrowse", new ToolbarCommand <Browse>()); _gitPlugin.RegisterCommand("GitExtensionsClone", new ToolbarCommand <Clone>()); _gitPlugin.RegisterCommand("GitExtensionsCreateBranch", new ToolbarCommand <CreateBranch>()); _gitPlugin.RegisterCommand("GitExtensionsSwitchBranch", new ToolbarCommand <SwitchBranch>()); _gitPlugin.RegisterCommand("GitExtensionsDiff", new ToolbarCommand <ViewDiff>()); _gitPlugin.RegisterCommand("GitExtensionsInitRepository", new ToolbarCommand <Init>()); _gitPlugin.RegisterCommand("GitExtensionsFormatPatch", new ToolbarCommand <FormatPatch>()); _gitPlugin.RegisterCommand("GitExtensionsPull", new ToolbarCommand <Pull>()); _gitPlugin.RegisterCommand("GitExtensionsPush", new ToolbarCommand <Push>()); _gitPlugin.RegisterCommand("GitExtensionsRebase", new ToolbarCommand <Rebase>()); _gitPlugin.RegisterCommand("GitExtensionsRevert", new ToolbarCommand <Revert>()); _gitPlugin.RegisterCommand("GitExtensionsMerge", new ToolbarCommand <Merge>()); _gitPlugin.RegisterCommand("GitExtensionsCherryPick", new ToolbarCommand <Cherry>()); _gitPlugin.RegisterCommand("GitExtensionsStash", new ToolbarCommand <Stash>()); _gitPlugin.RegisterCommand("GitExtensionsSettings", new ToolbarCommand <Settings>()); _gitPlugin.RegisterCommand("GitExtensionsSolveMergeConflicts", new ToolbarCommand <SolveMergeConflicts>()); _gitPlugin.RegisterCommand("GitExtensionsApplyPatch", new ToolbarCommand <ApplyPatch>()); _gitPlugin.RegisterCommand("GitExtensionsAbout", new ToolbarCommand <About>()); _gitPlugin.RegisterCommand("GitExtensionsBash", new ToolbarCommand <Bash>()); _gitPlugin.RegisterCommand("GitExtensionsGitIgnore", new ToolbarCommand <GitIgnore>()); _gitPlugin.RegisterCommand("GitExtensionsRemotes", new ToolbarCommand <Remotes>()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //Place the command on the tools menu. //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: var menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"]; CommandBarControl toolsControl; CommandBarPopup toolsPopup = null; try { toolsControl = menuBarCommandBar.Controls["Git"]; } catch { toolsControl = null; } try { if (toolsControl == null) { toolsControl = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 4, false); toolsControl.Caption = "Git"; } toolsPopup = (CommandBarPopup)toolsControl; toolsPopup.Caption = "Git"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); if (toolsControl == null) { toolsControl = menuBarCommandBar.Controls[GetToolsMenuName()]; toolsPopup = (CommandBarPopup)toolsControl; } } try { // add the toolbar and menu commands var commandBar = _gitPlugin.AddCommandBar("GitExtensions", MsoBarPosition.msoBarTop); _gitPlugin.AddToolbarCommandWithText( commandBar, "GitExtensionsCommit", "Commit", "Commit changes", 7, 1); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsBrowse", "Browse", "Browse repository", 12, 2); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsPull", "Pull", "Pull changes from remote repository", 9, 3); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsPush", "Push", "Push changes to remote repository", 8, 4); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsStash", "Stash", "Stash changes", 3, 5); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsSettings", "Settings", "Settings", 2, 6); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } try { var n = 1; _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsApplyPatch", "Apply patch", "Apply patch", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsBrowse", "Browse", "Browse repository", 12, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsSwitchBranch", "Checkout branch", "Switch to branch", 10, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsCherryPick", "Cherry pick", "Cherry pick commit", 11, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsCommit", "Commit", "Commit changes", 7, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsCreateBranch", "Create branch", "Create new branch", 10, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsClone", "Clone repository", "Clone existing Git", 14, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsGitIgnore", "Edit .gitignore", "Edit .gitignore file", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsFormatPatch", "Format patch", "Format patch", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsBash", "Git bash", "Start git bash", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsInitRepository", "Initialize new repository", "Initialize new Git repository", 13, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsRemotes", "Manage remotes", "Manage remote repositories", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsMerge", "Merge", "merge", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsPull", "Pull", "Pull changes from remote repository", 9, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsPush", "Push", "Push changes to remote repository", 8, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsRebase", "Rebase", "Rebase", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsStash", "Stash", "Stash changes", 3, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsSettings", "Settings", "Settings", 2, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsSolveMergeConflicts", "Solve mergeconflicts", "Solve mergeconflicts", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsDiff", "View changes", "View commit change history", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsAbout", "About Git Extensions", "About Git Extensions", 0, n++); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } AddContextMenuItemsToContextMenu("XML Editor"); AddContextMenuItemsToContextMenu("Web Item"); AddContextMenuItemsToContextMenu("Item"); AddContextMenuItemsToContextMenu("Easy MDI Document Window"); AddContextMenuItemsToContextMenu("Code Window"); AddContextMenuItemsToContextMenu("Script Context"); AddContextMenuItemsToContextMenu("ASPX Context"); /* * Uncomment the code block below to help find the name of commandbars in * visual studio. All commandbars (and context menu's) will get a new entry * with the name of that commandbar. * foreach (var commandBar in ((CommandBars)_applicationObject.CommandBars)) * { * try * { * var name = Guid.NewGuid().ToString("N"); * _gitPlugin.RegisterCommand(name, new ToolbarCommand<Remotes>()); * _gitPlugin.AddMenuCommand(((CommandBar)commandBar).Name, name, ((CommandBar)commandBar).Name, ((CommandBar)commandBar).Name, 6, 4); * } * catch * { * } * * _gitPlugin.OutputPane.OutputString(((CommandBar)commandBar).Name + Environment.NewLine); * } */ } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void GitPluginUISetup() { if (_gitPlugin == null) { return; } try { #if DEBUG this._gitPlugin.OutputPane.OutputString("Git Extensions plugin connected" + Environment.NewLine); #endif this.RegiserGitPluginCommand(); //Place the command on the tools menu. //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: var menuBarCommandBar = _gitPlugin.GetMenuBar(); CommandBarControl toolsControl; CommandBarPopup toolsPopup = null; try { toolsControl = menuBarCommandBar.Controls["Git"]; } catch { toolsControl = null; } try { if (toolsControl == null) { toolsControl = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 4, false); toolsControl.Caption = "&Git"; } toolsPopup = (CommandBarPopup)toolsControl; toolsPopup.Caption = "&Git"; } catch (Exception ex) { try { _gitPlugin.OutputPane.OutputString( "Error creating git menu (trying to add commands to tools menu): " + ex); if (toolsControl == null) { toolsControl = menuBarCommandBar.Controls[this.GetToolsMenuName()]; toolsPopup = (CommandBarPopup)toolsControl; } } catch (Exception ex2) { _gitPlugin.OutputPane.OutputString("Error menu: " + ex2); } } try { // add the toolbar and menu commands var commandBar = _gitPlugin.AddGitCommandBar(MsoBarPosition.msoBarTop); _gitPlugin.AddToolbarCommandWithText( commandBar, "GitExtensionsCommit", "Commit", "Commit changes", 7, 1); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsBrowse", "Browse", "Browse repository", 12, 2); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsPull", "Pull", "Pull changes from remote repository", 9, 3); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsPush", "Push", "Push changes to remote repository", 8, 4); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsStash", "Stash", "Stash changes", 3, 5); _gitPlugin.AddToolbarCommand(commandBar, "GitExtensionsSettings", "Settings", "Settings", 2, 6); } catch (Exception ex) { _gitPlugin.OutputPane.OutputString("Error creating toolbar: " + ex); } try { var n = 1; _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsApplyPatch", "&Apply patch", "Apply patch", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsBrowse", "&Browse", "Browse repository", 12, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsSwitchBranch", "Chec&kout branch", "Switch to branch", 10, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsCherryPick", "Cherry &pick", "Cherry pick commit", 11, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsCommit", "&Commit", "Commit changes", 7, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsCreateBranch", "Create bra&nch", "Create new branch", 10, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsClone", "Clone &repository", "Clone existing Git", 14, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsGitIgnore", "Edit &.gitignore", "Edit .gitignore file", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsFormatPatch", "&Format patch", "Format patch", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsBash", "&Git bash", "Start git bash", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsInitRepository", "Initialize new repositor&y", "Initialize new Git repository", 13, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsRemotes", "Manage rem&otes", "Manage remote repositories", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsMerge", "&Merge", "merge", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsPull", "P&ull", "Pull changes from remote repository", 9, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsPush", "Pu&sh", "Push changes to remote repository", 8, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsRebase", "R&ebase", "Rebase", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsSearchFile", "Search fi&le", "Search a file in the repository", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsSettings", "Se&ttings", "Settings", 2, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsSolveMergeConflicts", "Sol&ve mergeconflicts", "Solve mergeconflicts", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsStash", "Stas&h", "Stash changes", 3, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsDiff", "V&iew changes", "View commit change history", 0, n++); _gitPlugin.AddPopupCommand(toolsPopup, "GitExtensionsAbout", "About Git E&xtensions", "About Git Extensions", 0, n++); } catch (Exception ex) { _gitPlugin.OutputPane.OutputString("Error creating contextmenu: " + ex); } AddContextMenuItemsToContextMenu("Web Item"); AddContextMenuItemsToContextMenu("Item"); AddContextMenuItemsToContextMenu("Easy MDI Document Window"); AddContextMenuItemsToContextMenu("Code Window"); AddContextMenuItemsToContextMenu("Script Context"); AddContextMenuItemsToContextMenu("ASPX Context"); /* * Uncomment the code block below to help find the name of commandbars in * visual studio. All commandbars (and context menu's) will get a new entry * with the name of that commandbar. * foreach (var commandBar in _gitPlugin.CommandBars) * { * _gitPlugin.OutputPane.OutputString(((CommandBar)commandBar).Name + Environment.NewLine); * }*/ } catch (Exception ex) { this._gitPlugin.OutputPane.OutputString("Error loading plugin: " + ex); } }