From a13fdcbf500ec40e6262750415a8f8c8a4ca53da Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Thu, 28 Sep 2017 11:09:30 +0200 Subject: [PATCH] Repository.close fixes #35041 --- extensions/git/package.json | 12 +++++ extensions/git/src/commands.ts | 5 ++ extensions/git/src/model.ts | 10 ++++ src/vs/platform/actions/common/actions.ts | 47 +++++++++---------- .../electron-browser/menusExtensionPoint.ts | 6 +++ .../parts/scm/electron-browser/scmViewlet.ts | 38 +++++++++++++-- 6 files changed, 90 insertions(+), 28 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index a207c29d6a5..d4b341b4451 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -36,6 +36,11 @@ "dark": "resources/icons/dark/git.svg" } }, + { + "command": "git.close", + "title": "%command.close%", + "category": "Git" + }, { "command": "git.refresh", "title": "%command.refresh%", @@ -565,6 +570,13 @@ "when": "config.git.enabled && scmProvider == git" } ], + "scm/sourceControl": [ + { + "command": "git.close", + "group": "navigation", + "when": "config.git.enabled && scmProvider == git" + } + ], "scm/resourceGroup/context": [ { "command": "git.stageAll", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index e729856df73..5ca21612e77 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -358,6 +358,11 @@ export class CommandCenter { await this.model.tryOpenRepository(path); } + @command('git.close', { repository: true }) + async close(repository: Repository): Promise { + this.model.close(repository); + } + @command('git.openFile') async openFile(arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise { const preserveFocus = arg instanceof Resource; diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 68f8876beea..93a809a20fe 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -230,6 +230,16 @@ export class Model { this._onDidOpenRepository.fire(repository); } + close(repository: Repository): void { + const openRepository = this.getOpenRepository(repository); + + if (!openRepository) { + return; + } + + openRepository.dispose(); + } + async pickRepository(): Promise { if (this.openRepositories.length === 0) { throw new Error(localize('no repositories', "There are no available repositories")); diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 13cc878e1be..0b5586ace11 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -37,31 +37,28 @@ export interface IMenuItem { export class MenuId { - static readonly EditorTitle = new MenuId('1'); - static readonly EditorTitleContext = new MenuId('2'); - static readonly EditorContext = new MenuId('3'); - static readonly ExplorerContext = new MenuId('4'); - static readonly ProblemsPanelContext = new MenuId('5'); - static readonly DebugVariablesContext = new MenuId('6'); - static readonly DebugWatchContext = new MenuId('7'); - static readonly DebugCallStackContext = new MenuId('8'); - static readonly DebugBreakpointsContext = new MenuId('9'); - static readonly DebugConsoleContext = new MenuId('10'); - static readonly SCMTitle = new MenuId('11'); - static readonly SCMResourceGroupContext = new MenuId('12'); - static readonly SCMResourceContext = new MenuId('13'); - static readonly CommandPalette = new MenuId('14'); - static readonly ViewTitle = new MenuId('15'); - static readonly ViewItemContext = new MenuId('16'); - static readonly TouchBarContext = new MenuId('17'); - - constructor(private _id: string) { - - } - - get id(): string { - return this._id; - } + private static ID = 1; + + static readonly EditorTitle = new MenuId(); + static readonly EditorTitleContext = new MenuId(); + static readonly EditorContext = new MenuId(); + static readonly ExplorerContext = new MenuId(); + static readonly ProblemsPanelContext = new MenuId(); + static readonly DebugVariablesContext = new MenuId(); + static readonly DebugWatchContext = new MenuId(); + static readonly DebugCallStackContext = new MenuId(); + static readonly DebugBreakpointsContext = new MenuId(); + static readonly DebugConsoleContext = new MenuId(); + static readonly SCMTitle = new MenuId(); + static readonly SCMSourceControl = new MenuId(); + static readonly SCMResourceGroupContext = new MenuId(); + static readonly SCMResourceContext = new MenuId(); + static readonly CommandPalette = new MenuId(); + static readonly ViewTitle = new MenuId(); + static readonly ViewItemContext = new MenuId(); + static readonly TouchBarContext = new MenuId(); + + readonly id: string = String(MenuId.ID++); } export interface IMenuActionOptions { diff --git a/src/vs/platform/actions/electron-browser/menusExtensionPoint.ts b/src/vs/platform/actions/electron-browser/menusExtensionPoint.ts index bcb7b74b5fa..184962e9227 100644 --- a/src/vs/platform/actions/electron-browser/menusExtensionPoint.ts +++ b/src/vs/platform/actions/electron-browser/menusExtensionPoint.ts @@ -37,6 +37,7 @@ namespace schema { case 'editor/title/context': return MenuId.EditorTitleContext; case 'debug/callstack/context': return MenuId.DebugCallStackContext; case 'scm/title': return MenuId.SCMTitle; + case 'scm/sourceControl': return MenuId.SCMSourceControl; case 'scm/resourceGroup/context': return MenuId.SCMResourceGroupContext; case 'scm/resourceState/context': return MenuId.SCMResourceContext; case 'view/title': return MenuId.ViewTitle; @@ -140,6 +141,11 @@ namespace schema { type: 'array', items: menuItem }, + 'scm/sourceControl': { + description: localize('menus.scmSourceControl', "The Source Control menu"), + type: 'array', + items: menuItem + }, 'scm/resourceGroup/context': { description: localize('menus.resourceGroupContext', "The Source Control resource group context menu"), type: 'array', diff --git a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts index fac423da9e3..501bdf5d32e 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts @@ -32,9 +32,9 @@ import { ICommandService } from 'vs/platform/commands/common/commands'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IMessageService } from 'vs/platform/message/common/message'; import { IListService } from 'vs/platform/list/browser/listService'; -import { MenuItemAction } from 'vs/platform/actions/common/actions'; +import { MenuItemAction, IMenuService, MenuId } from 'vs/platform/actions/common/actions'; import { IAction, Action, IActionItem, ActionRunner } from 'vs/base/common/actions'; -import { MenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem'; +import { MenuItemActionItem, fillInActions } from 'vs/platform/actions/browser/menuItemActionItem'; import { SCMMenus } from './scmMenus'; import { ActionBar, IActionItemProvider, Separator, ActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { IThemeService, LIGHT } from 'vs/platform/theme/common/themeService'; @@ -219,7 +219,9 @@ class MainPanel extends ViewletPanel { @IContextMenuService protected contextMenuService: IContextMenuService, @ISCMService protected scmService: ISCMService, @IInstantiationService private instantiationService: IInstantiationService, - @IThemeService private themeService: IThemeService + @IThemeService private themeService: IThemeService, + @IContextKeyService private contextKeyService: IContextKeyService, + @IMenuService private menuService: IMenuService ) { super(localize('scm providers', "Source Control Providers"), {}, keybindingService, contextMenuService); this.updateBodySize(); @@ -265,6 +267,8 @@ class MainPanel extends ViewletPanel { this.disposables.push(this.list); this.disposables.push(attachListStyler(this.list, this.themeService)); this.list.onSelectionChange(this.onListSelectionChange, this, this.disposables); + this.list.onContextMenu(this.onListContextMenu, this, this.disposables); + this.viewModel.onDidSplice(({ index, deleteCount, elements }) => this.splice(index, deleteCount, elements), null, this.disposables); this.splice(0, 0, this.viewModel.repositories); } @@ -286,6 +290,34 @@ class MainPanel extends ViewletPanel { } } + private onListContextMenu(e: IListContextMenuEvent): void { + const repository = e.element; + + const contextKeyService = this.contextKeyService.createScoped(); + const scmProviderKey = contextKeyService.createKey('scmProvider', void 0); + scmProviderKey.set(repository.provider.contextValue); + + const menu = this.menuService.createMenu(MenuId.SCMSourceControl, contextKeyService); + const primary: IAction[] = []; + const secondary: IAction[] = []; + const result = { primary, secondary }; + + fillInActions(menu, { shouldForwardArgs: true }, result, g => g === 'inline'); + + menu.dispose(); + contextKeyService.dispose(); + + if (secondary.length === 0) { + return; + } + + this.contextMenuService.showContextMenu({ + getAnchor: () => e.anchor, + getActions: () => TPromise.as(secondary), + getActionsContext: () => repository.provider + }); + } + private onListSelectionChange(e: IListEvent): void { // select one repository if the selected one is gone if (e.elements.length === 0 && this.list.length > 0) { -- GitLab