diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 5d3c0d7ef47..bc244991a5b 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -5,7 +5,7 @@ 'use strict'; -import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceGroup, SourceControlResourceState, TextDocumentShowOptions, ViewColumn } from 'vscode'; +import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControl, SourceControlResourceGroup, SourceControlResourceState, TextDocumentShowOptions, ViewColumn } from 'vscode'; import { Ref, RefType, Git, GitErrorCodes, Branch } from './git'; import { Repository, Resource, Status, CommitOptions, ResourceGroupType } from './repository'; import { Model } from './model'; @@ -145,8 +145,22 @@ export class CommandCenter { }); } - @command('git.refresh', { repository: true }) - async refresh(repository: Repository): Promise { + @command('git.refresh') + async refresh(sourceControl?: SourceControl): Promise { + let repository: Repository | undefined = undefined; + + if (sourceControl) { + repository = this.model.getRepositoryFromSourceControl(sourceControl); + } + + if (!repository) { + repository = await this.model.pickRepository(); + } + + if (!repository) { + return; + } + await repository.status(); } diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 6e3a92df692..af41e5f8a6c 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -5,7 +5,7 @@ 'use strict'; -import { Uri, window, QuickPickItem, Disposable, SourceControlResourceGroup } from 'vscode'; +import { Uri, window, QuickPickItem, Disposable, SourceControl, SourceControlResourceGroup } from 'vscode'; import { Repository, State } from './repository'; import { memoize } from './decorators'; import { toDisposable, filterEvent, once } from './util'; @@ -60,7 +60,17 @@ export class Model { return pick && pick.repository; } - getRepositoryFromResourceGroup(resourceGroup?: SourceControlResourceGroup): Repository | undefined { + getRepositoryFromSourceControl(sourceControl: SourceControl): Repository | undefined { + for (let [, repository] of this.repositories) { + if (sourceControl === repository.sourceControl) { + return repository; + } + } + + return undefined; + } + + getRepositoryFromResourceGroup(resourceGroup: SourceControlResourceGroup): Repository | undefined { for (let [, repository] of this.repositories) { if (resourceGroup === repository.mergeGroup || resourceGroup === repository.indexGroup || resourceGroup === repository.workingTreeGroup) { return repository; diff --git a/src/vs/workbench/api/electron-browser/mainThreadSCM.ts b/src/vs/workbench/api/electron-browser/mainThreadSCM.ts index fb8d1f155a5..9144743dea9 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadSCM.ts @@ -199,6 +199,13 @@ class MainThreadSCMProvider implements ISCMProvider { return this.proxy.$provideOriginalResource(this.handle, uri); } + toJSON(): any { + return { + $mid: 5, + handle: this.handle + }; + } + dispose(): void { } diff --git a/src/vs/workbench/api/node/extHostSCM.ts b/src/vs/workbench/api/node/extHostSCM.ts index 126466f2f14..8dd6656aa91 100644 --- a/src/vs/workbench/api/node/extHostSCM.ts +++ b/src/vs/workbench/api/node/extHostSCM.ts @@ -307,6 +307,14 @@ export class ExtHostSCM { } return sourceControl.getResourceGroup(arg.groupHandle); + } else if (arg && arg.$mid === 5) { + const sourceControl = this._sourceControls.get(arg.handle); + + if (!sourceControl) { + return arg; + } + + return sourceControl; } return arg; diff --git a/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts b/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts index 84015f00e6f..3e1850b0dc8 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts @@ -46,7 +46,8 @@ export class SCMMenus implements IDisposable { private updateTitleActions(): void { this.titleActions = []; this.titleSecondaryActions = []; - fillInActions(this.titleMenu, null, { primary: this.titleActions, secondary: this.titleSecondaryActions }); + // TODO@joao: second arg used to be null + fillInActions(this.titleMenu, { shouldForwardArgs: true }, { primary: this.titleActions, secondary: this.titleSecondaryActions }); this._onDidChangeTitle.fire(); } diff --git a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts index 51ea8641cb4..650a3ea3308 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmViewlet.ts @@ -253,6 +253,7 @@ class SourceControlView extends CollapsibleView { @IContextMenuService protected contextMenuService: IContextMenuService, @IListService protected listService: IListService, @ICommandService protected commandService: ICommandService, + @IMessageService protected messageService: IMessageService, @IWorkbenchEditorService protected editorService: IWorkbenchEditorService, @IEditorGroupService protected editorGroupService: IEditorGroupService, @IInstantiationService protected instantiationService: IInstantiationService @@ -318,6 +319,18 @@ class SourceControlView extends CollapsibleView { return this.menus.getTitleSecondaryActions(); } + getActionItem(action: IAction): IActionItem { + if (!(action instanceof MenuItemAction)) { + return undefined; + } + + return new SCMMenuItemActionItem(action, this.keybindingService, this.messageService); + } + + getActionsContext(): any { + return this.provider; + } + private updateList(): void { const elements = this.provider.resources .reduce<(ISCMResourceGroup | ISCMResource)[]>((r, g) => [...r, g, ...g.resources.sort(resourceSorter)], []); diff --git a/src/vs/workbench/parts/views/browser/views.ts b/src/vs/workbench/parts/views/browser/views.ts index 09471ced8de..fcedaed1c83 100644 --- a/src/vs/workbench/parts/views/browser/views.ts +++ b/src/vs/workbench/parts/views/browser/views.ts @@ -72,6 +72,8 @@ export interface IView extends IBaseView, IThemable { getActionItem(action: IAction): IActionItem; + getActionsContext(): any; + showHeader(): boolean; hideHeader(): boolean; @@ -171,6 +173,7 @@ export abstract class CollapsibleView extends AbstractCollapsibleView implements protected updateActions(): void { this.toolBar.setActions(prepareActions(this.getActions()), prepareActions(this.getSecondaryActions()))(); + this.toolBar.context = this.getActionsContext(); } protected renderViewTree(container: HTMLElement): HTMLElement { @@ -228,6 +231,10 @@ export abstract class CollapsibleView extends AbstractCollapsibleView implements return null; } + public getActionsContext(): any { + return undefined; + } + public shutdown(): void { // Subclass to implement }