diff --git a/extensions/git/package.json b/extensions/git/package.json index 53aa0fad747e3..4556255d3dac0 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -163,14 +163,14 @@ "title": "%command.stageAll%", "category": "Git", "icon": "$(add)", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmResourceGroupResourceCount > 0" }, { "command": "git.stageAllTracked", "title": "%command.stageAllTracked%", "category": "Git", "icon": "$(add)", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmResourceGroupResourceCount > 0" }, { "command": "git.stageAllUntracked", @@ -243,7 +243,7 @@ "title": "%command.unstageAll%", "category": "Git", "icon": "$(remove)", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmResourceGroupResourceCount > 0" }, { "command": "git.unstageSelectedRanges", @@ -270,14 +270,14 @@ "title": "%command.cleanAll%", "category": "Git", "icon": "$(discard)", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmResourceGroupResourceCount > 0" }, { "command": "git.cleanAllTracked", "title": "%command.cleanAllTracked%", "category": "Git", "icon": "$(discard)", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmResourceGroupResourceCount > 0" }, { "command": "git.cleanAllUntracked", @@ -889,14 +889,14 @@ "title": "%command.viewChanges%", "icon": "$(diff-multiple)", "category": "Git", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmResourceGroupResourceCount > 0" }, { "command": "git.viewStagedChanges", "title": "%command.viewStagedChanges%", "icon": "$(diff-multiple)", "category": "Git", - "enablement": "!operationInProgress" + "enablement": "!operationInProgress && scmResourceGroupResourceCount > 0" }, { "command": "git.viewUntrackedChanges", diff --git a/src/vs/workbench/contrib/scm/browser/menus.ts b/src/vs/workbench/contrib/scm/browser/menus.ts index f14d8ea79f67c..352f63b6f3ec9 100644 --- a/src/vs/workbench/contrib/scm/browser/menus.ts +++ b/src/vs/workbench/contrib/scm/browser/menus.ts @@ -6,7 +6,7 @@ import { IAction } from '../../../../base/common/actions.js'; import { equals } from '../../../../base/common/arrays.js'; import { Emitter } from '../../../../base/common/event.js'; -import { DisposableStore, IDisposable, dispose } from '../../../../base/common/lifecycle.js'; +import { DisposableStore, IDisposable, MutableDisposable, dispose } from '../../../../base/common/lifecycle.js'; import './media/scm.css'; import { localize } from '../../../../nls.js'; import { getActionBarActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js'; @@ -70,13 +70,14 @@ interface IContextualResourceMenuItem { class SCMMenusItem implements IDisposable { - private _resourceGroupMenu: IMenu | undefined; + private readonly _resourceGroupMenu = new MutableDisposable(); get resourceGroupMenu(): IMenu { - if (!this._resourceGroupMenu) { - this._resourceGroupMenu = this.menuService.createMenu(MenuId.SCMResourceGroupContext, this.contextKeyService); - } + const contextKeyService = this.contextKeyService.createOverlay([ + ['scmResourceGroupResourceCount', this.group.resources.length], + ]); - return this._resourceGroupMenu; + this._resourceGroupMenu.value = this.menuService.createMenu(MenuId.SCMResourceGroupContext, contextKeyService); + return this._resourceGroupMenu.value; } private _resourceFolderMenu: IMenu | undefined; @@ -92,8 +93,9 @@ class SCMMenusItem implements IDisposable { private contextualResourceMenus: Map | undefined; constructor( - private contextKeyService: IContextKeyService, - private menuService: IMenuService + private readonly group: ISCMResourceGroup, + private readonly contextKeyService: IContextKeyService, + private readonly menuService: IMenuService ) { } getResourceMenu(resource: ISCMResource): IMenu { @@ -206,7 +208,7 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable { ['multiDiffEditorEnableViewChanges', group.multiDiffEditorEnableViewChanges], ]); - result = new SCMMenusItem(contextKeyService, this.menuService); + result = new SCMMenusItem(group, contextKeyService, this.menuService); this.resourceGroupMenusItems.set(group, result); }