diff --git a/extensions/git/package.json b/extensions/git/package.json index 874588dd9aa..88553d91126 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -629,6 +629,7 @@ "command": "git.publish", "title": "%command.publish%", "category": "Git", + "icon": "$(cloud-upload)", "enablement": "!operationInProgress" }, { @@ -1887,14 +1888,24 @@ { "command": "git.pushRef", "group": "navigation", - "when": "scmProvider == git" + "when": "scmProvider == git && scmHistoryItemGroupHasUpstream" + }, + { + "command": "git.publish", + "group": "navigation", + "when": "scmProvider == git && !scmHistoryItemGroupHasUpstream" } ], "scm/outgoingChanges/context": [ { "command": "git.pushRef", "group": "1_modification@1", - "when": "scmProvider == git" + "when": "scmProvider == git && scmHistoryItemGroupHasUpstream" + }, + { + "command": "git.publish", + "group": "1_modification@1", + "when": "scmProvider == git && !scmHistoryItemGroupHasUpstream" } ], "scm/outgoingChanges/allChanges/context": [ diff --git a/src/vs/workbench/contrib/scm/browser/menus.ts b/src/vs/workbench/contrib/scm/browser/menus.ts index f79b6050a70..39ee31783bd 100644 --- a/src/vs/workbench/contrib/scm/browser/menus.ts +++ b/src/vs/workbench/contrib/scm/browser/menus.ts @@ -14,7 +14,7 @@ import { IMenu, IMenuService, MenuId, MenuRegistry } from 'vs/platform/actions/c import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; -import { ISCMHistoryProviderMenus, SCMHistoryItemTreeElement } from 'vs/workbench/contrib/scm/common/history'; +import { ISCMHistoryProviderMenus, SCMHistoryItemGroupTreeElement, SCMHistoryItemTreeElement } from 'vs/workbench/contrib/scm/common/history'; import { ISCMMenus, ISCMProvider, ISCMRepository, ISCMRepositoryMenus, ISCMResource, ISCMResourceGroup, ISCMService } from 'vs/workbench/contrib/scm/common/scm'; function actionEquals(a: IAction, b: IAction): boolean { @@ -258,38 +258,26 @@ export class SCMHistoryProviderMenus implements ISCMHistoryProviderMenus, IDispo private readonly historyItemMenus = new Map(); private readonly disposables = new DisposableStore(); - private _incomingHistoryItemGroupMenu: IMenu; - get incomingHistoryItemGroupMenu(): IMenu { return this._incomingHistoryItemGroupMenu; } - - private _incomingHistoryItemGroupContextMenu: IMenu; - get incomingHistoryItemGroupContextMenu(): IMenu { return this._incomingHistoryItemGroupContextMenu; } - - private _outgoingHistoryItemGroupMenu: IMenu; - get outgoingHistoryItemGroupMenu(): IMenu { return this._outgoingHistoryItemGroupMenu; } - - private _outgoingHistoryItemGroupContextMenu: IMenu; - get outgoingHistoryItemGroupContextMenu(): IMenu { return this._outgoingHistoryItemGroupContextMenu; } - constructor( @IContextKeyService private readonly contextKeyService: IContextKeyService, - @IMenuService private readonly menuService: IMenuService) { - this._incomingHistoryItemGroupMenu = this.menuService.createMenu(MenuId.SCMIncomingChanges, this.contextKeyService); - this.disposables.add(this._incomingHistoryItemGroupMenu); - - this._incomingHistoryItemGroupContextMenu = this.menuService.createMenu(MenuId.SCMIncomingChangesContext, this.contextKeyService); - this.disposables.add(this._incomingHistoryItemGroupContextMenu); - - this._outgoingHistoryItemGroupMenu = this.menuService.createMenu(MenuId.SCMOutgoingChanges, this.contextKeyService); - this.disposables.add(this._outgoingHistoryItemGroupMenu); - - this._outgoingHistoryItemGroupContextMenu = this.menuService.createMenu(MenuId.SCMOutgoingChangesContext, this.contextKeyService); - this.disposables.add(this._outgoingHistoryItemGroupContextMenu); - } + @IMenuService private readonly menuService: IMenuService) { } getHistoryItemMenu(historyItem: SCMHistoryItemTreeElement): IMenu { return this.getOrCreateHistoryItemMenu(historyItem); } + getHistoryItemGroupMenu(historyItemGroup: SCMHistoryItemGroupTreeElement): IMenu { + return historyItemGroup.direction === 'incoming' ? + this.menuService.createMenu(MenuId.SCMIncomingChanges, this.contextKeyService) : + this.getOutgoingHistoryItemGroupMenu(MenuId.SCMOutgoingChanges, historyItemGroup); + } + + getHistoryItemGroupContextMenu(historyItemGroup: SCMHistoryItemGroupTreeElement): IMenu { + return historyItemGroup.direction === 'incoming' ? + this.menuService.createMenu(MenuId.SCMIncomingChangesContext, this.contextKeyService) : + this.getOutgoingHistoryItemGroupMenu(MenuId.SCMOutgoingChangesContext, historyItemGroup); + } + private getOrCreateHistoryItemMenu(historyItem: SCMHistoryItemTreeElement): IMenu { let result = this.historyItemMenus.get(historyItem); @@ -316,6 +304,14 @@ export class SCMHistoryProviderMenus implements ISCMHistoryProviderMenus, IDispo return result; } + private getOutgoingHistoryItemGroupMenu(menuId: MenuId, historyItemGroup: SCMHistoryItemGroupTreeElement): IMenu { + const contextKeyService = this.contextKeyService.createOverlay([ + ['scmHistoryItemGroupHasUpstream', !!historyItemGroup.repository.provider.historyProvider?.currentHistoryItemGroup?.base], + ]); + + return this.menuService.createMenu(menuId, contextKeyService); + } + dispose(): void { this.disposables.dispose(); } diff --git a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts index e64b8ce1809..57f3428b3dc 100644 --- a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts @@ -831,11 +831,11 @@ class HistoryItemGroupRenderer implements ICompressibleTreeRenderer { - templateData.toolBar.setActions(primary, secondary, [menuId]); + templateData.toolBar.setActions(primary, secondary, [resetMenuId]); })); templateData.toolBar.context = historyItemGroup; @@ -3037,9 +3037,7 @@ export class SCMViewPane extends ViewPane { } } else if (isSCMHistoryItemGroupTreeElement(element)) { const menus = this.scmViewService.menus.getRepositoryMenus(element.repository.provider); - const menu = element.direction === 'incoming' ? - menus.historyProviderMenu?.incomingHistoryItemGroupContextMenu : - menus.historyProviderMenu?.outgoingHistoryItemGroupContextMenu; + const menu = menus.historyProviderMenu?.getHistoryItemGroupContextMenu(element); if (menu) { actionRunner = new HistoryItemGroupActionRunner(); diff --git a/src/vs/workbench/contrib/scm/common/history.ts b/src/vs/workbench/contrib/scm/common/history.ts index ff86e3693fc..70ab5a8f8bb 100644 --- a/src/vs/workbench/contrib/scm/common/history.ts +++ b/src/vs/workbench/contrib/scm/common/history.ts @@ -10,10 +10,8 @@ import { IMenu } from 'vs/platform/actions/common/actions'; import { ISCMRepository } from 'vs/workbench/contrib/scm/common/scm'; export interface ISCMHistoryProviderMenus { - readonly incomingHistoryItemGroupMenu: IMenu; - readonly incomingHistoryItemGroupContextMenu: IMenu; - readonly outgoingHistoryItemGroupMenu: IMenu; - readonly outgoingHistoryItemGroupContextMenu: IMenu; + getHistoryItemGroupMenu(historyItemGroup: SCMHistoryItemGroupTreeElement): IMenu; + getHistoryItemGroupContextMenu(historyItemGroup: SCMHistoryItemGroupTreeElement): IMenu; getHistoryItemMenu(historyItem: SCMHistoryItemTreeElement): IMenu; }