mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-19 23:07:09 -05:00
@@ -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",
|
||||
|
||||
@@ -358,6 +358,11 @@ export class CommandCenter {
|
||||
await this.model.tryOpenRepository(path);
|
||||
}
|
||||
|
||||
@command('git.close', { repository: true })
|
||||
async close(repository: Repository): Promise<void> {
|
||||
this.model.close(repository);
|
||||
}
|
||||
|
||||
@command('git.openFile')
|
||||
async openFile(arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> {
|
||||
const preserveFocus = arg instanceof Resource;
|
||||
|
||||
@@ -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<Repository | undefined> {
|
||||
if (this.openRepositories.length === 0) {
|
||||
throw new Error(localize('no repositories', "There are no available repositories"));
|
||||
|
||||
@@ -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');
|
||||
private static ID = 1;
|
||||
|
||||
constructor(private _id: string) {
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
readonly id: string = String(MenuId.ID++);
|
||||
}
|
||||
|
||||
export interface IMenuActionOptions {
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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<ISCMRepository>): void {
|
||||
const repository = e.element;
|
||||
|
||||
const contextKeyService = this.contextKeyService.createScoped();
|
||||
const scmProviderKey = contextKeyService.createKey<string | undefined>('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<ISCMRepository>): void {
|
||||
// select one repository if the selected one is gone
|
||||
if (e.elements.length === 0 && this.list.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user