Skip to content

Commit 0925521

Browse files
authored
SCM Graph - add actions back to the view title (microsoft#234091)
* Initial implementation * Adjust commands and context key computation
1 parent 32f6e84 commit 0925521

File tree

3 files changed

+58
-17
lines changed

3 files changed

+58
-17
lines changed

extensions/git/package.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@
567567
"title": "%command.pull%",
568568
"icon": "$(repo-pull)",
569569
"category": "Git",
570-
"enablement": "!operationInProgress"
570+
"enablement": "!operationInProgress && scmCurrentHistoryItemRefInFilter && scmCurrentHistoryItemRefHasRemote"
571571
},
572572
{
573573
"command": "git.push",
@@ -616,7 +616,7 @@
616616
"title": "%command.push%",
617617
"icon": "$(repo-push)",
618618
"category": "Git",
619-
"enablement": "!operationInProgress"
619+
"enablement": "!operationInProgress && scmCurrentHistoryItemRefInFilter && scmCurrentHistoryItemRefHasRemote"
620620
},
621621
{
622622
"command": "git.cherryPick",
@@ -1968,8 +1968,23 @@
19681968
"scm/history/title": [
19691969
{
19701970
"command": "git.fetchAll",
1971-
"group": "navigation@999",
1971+
"group": "navigation@900",
1972+
"when": "scmProvider == git"
1973+
},
1974+
{
1975+
"command": "git.pullRef",
1976+
"group": "navigation@901",
19721977
"when": "scmProvider == git"
1978+
},
1979+
{
1980+
"command": "git.pushRef",
1981+
"when": "scmProvider == git && scmCurrentHistoryItemRefHasRemote",
1982+
"group": "navigation@902"
1983+
},
1984+
{
1985+
"command": "git.publish",
1986+
"when": "scmProvider == git && !scmCurrentHistoryItemRefHasRemote",
1987+
"group": "navigation@903"
19731988
}
19741989
],
19751990
"scm/historyItem/context": [

src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import { compare } from '../../../../base/common/strings.js';
6161
import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js';
6262
import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js';
6363
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
64-
import { INotificationService } from '../../../../platform/notification/common/notification.js';
6564
import { IExtensionService } from '../../../services/extensions/common/extensions.js';
6665
import { groupBy as groupBy2 } from '../../../../base/common/collections.js';
6766

@@ -196,7 +195,9 @@ registerAction2(class extends ViewAction<SCMHistoryViewPane> {
196195
title: localize('goToCurrentHistoryItem', "Go to Current History Item"),
197196
icon: Codicon.target,
198197
viewId: HISTORY_VIEW_PANE_ID,
199-
precondition: ContextKeys.SCMHistoryItemCount.notEqualsTo(0),
198+
precondition: ContextKeyExpr.and(
199+
ContextKeys.SCMHistoryItemCount.notEqualsTo(0),
200+
ContextKeys.SCMCurrentHistoryItemRefInFilter.isEqualTo(true)),
200201
f1: false,
201202
menu: {
202203
id: MenuId.SCMHistoryTitle,
@@ -1205,12 +1206,13 @@ export class SCMHistoryViewPane extends ViewPane {
12051206
private readonly _updateChildrenThrottler = new Throttler();
12061207

12071208
private readonly _scmProviderCtx: IContextKey<string | undefined>;
1209+
private readonly _scmCurrentHistoryItemRefHasRemote: IContextKey<boolean>;
1210+
private readonly _scmCurrentHistoryItemRefInFilter: IContextKey<boolean>;
12081211

12091212
constructor(
12101213
options: IViewPaneOptions,
12111214
@ICommandService private readonly _commandService: ICommandService,
12121215
@IInstantiationService private readonly _instantiationService: IInstantiationService,
1213-
@INotificationService private readonly _notificationService: INotificationService,
12141216
@IProgressService private readonly _progressService: IProgressService,
12151217
@IConfigurationService configurationService: IConfigurationService,
12161218
@IContextMenuService contextMenuService: IContextMenuService,
@@ -1230,6 +1232,8 @@ export class SCMHistoryViewPane extends ViewPane {
12301232
}, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService);
12311233

12321234
this._scmProviderCtx = ContextKeys.SCMProvider.bindTo(this.scopedContextKeyService);
1235+
this._scmCurrentHistoryItemRefHasRemote = ContextKeys.SCMCurrentHistoryItemRefHasRemote.bindTo(this.scopedContextKeyService);
1236+
this._scmCurrentHistoryItemRefInFilter = ContextKeys.SCMCurrentHistoryItemRefInFilter.bindTo(this.scopedContextKeyService);
12331237

12341238
this._actionRunner = this.instantiationService.createInstance(SCMHistoryViewPaneActionRunner);
12351239
this._register(this._actionRunner);
@@ -1311,15 +1315,15 @@ export class SCMHistoryViewPane extends ViewPane {
13111315
return;
13121316
}
13131317

1314-
// Update context
1315-
this._scmProviderCtx.set(repository.provider.contextValue);
1316-
13171318
// HistoryItemId changed (checkout)
13181319
const historyItemRefId = derived(reader => {
13191320
return historyProvider.historyItemRef.read(reader)?.id;
13201321
});
1321-
store.add(runOnChange(historyItemRefId, () => {
1322+
store.add(runOnChange(historyItemRefId, historyItemRefIdValue => {
13221323
this.refresh();
1324+
1325+
// Update context key (needs to be done after the refresh call)
1326+
this._scmCurrentHistoryItemRefInFilter.set(this._isCurrentHistoryItemInFilter(historyItemRefIdValue));
13231327
}));
13241328

13251329
// HistoryItemRefs changed
@@ -1344,8 +1348,20 @@ export class SCMHistoryViewPane extends ViewPane {
13441348
// HistoryItemRefs filter changed
13451349
store.add(runOnChange(this._treeViewModel.onDidChangeHistoryItemsFilter, () => {
13461350
this.refresh();
1351+
1352+
// Update context key (needs to be done after the refresh call)
1353+
this._scmCurrentHistoryItemRefInFilter.set(this._isCurrentHistoryItemInFilter(historyItemRefId.get()));
13471354
}));
13481355

1356+
// HistoryItemRemoteRef changed
1357+
store.add(autorun(reader => {
1358+
this._scmCurrentHistoryItemRefHasRemote.set(!!historyProvider.historyItemRemoteRef.read(reader));
1359+
}));
1360+
1361+
// Update context
1362+
this._scmProviderCtx.set(repository.provider.contextValue);
1363+
this._scmCurrentHistoryItemRefInFilter.set(this._isCurrentHistoryItemInFilter(historyItemRefId.get()));
1364+
13491365
// We skip refreshing the graph on the first execution of the autorun
13501366
// since the graph for the first repository is rendered when the tree
13511367
// input is set.
@@ -1438,16 +1454,11 @@ export class SCMHistoryViewPane extends ViewPane {
14381454
const repository = this._treeViewModel.repository.get();
14391455
const historyProvider = repository?.provider.historyProvider.get();
14401456
const historyItemRef = historyProvider?.historyItemRef.get();
1441-
const historyItemFilter = this._treeViewModel.getHistoryItemsFilter();
1442-
1443-
if (!repository || !historyItemRef?.revision || !historyItemFilter) {
1457+
if (!repository || !historyItemRef?.id || !historyItemRef?.revision) {
14441458
return;
14451459
}
14461460

1447-
// Filter set to `all`, `auto` or it contains the current history item
1448-
if (Array.isArray(historyItemFilter) &&
1449-
!historyItemFilter.find(ref => ref.id === historyItemRef.id)) {
1450-
this._notificationService.info(localize('scmGraphViewRevealCurrentHistoryItem', "The current history item is not present in the source control graph. Please use the history item references picker to expand the set of history items in the graph."));
1461+
if (this._isCurrentHistoryItemInFilter(historyItemRef.id)) {
14511462
return;
14521463
}
14531464

@@ -1513,6 +1524,19 @@ export class SCMHistoryViewPane extends ViewPane {
15131524
this._tree.onContextMenu(this._onContextMenu, this, this._store);
15141525
}
15151526

1527+
private _isCurrentHistoryItemInFilter(historyItemRefId: string | undefined): boolean {
1528+
if (!historyItemRefId) {
1529+
return false;
1530+
}
1531+
1532+
const historyItemFilter = this._treeViewModel.getHistoryItemsFilter();
1533+
if (historyItemFilter === 'all' || historyItemFilter === 'auto') {
1534+
return true;
1535+
}
1536+
1537+
return Array.isArray(historyItemFilter) && !!historyItemFilter.find(ref => ref.id === historyItemRefId);
1538+
}
1539+
15161540
private async _onDidOpen(e: IOpenEvent<TreeElement | undefined>): Promise<void> {
15171541
if (!e.element) {
15181542
return;

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ export const ContextKeys = {
964964
SCMProviderRootUri: new RawContextKey<string | undefined>('scmProviderRootUri', undefined),
965965
SCMProviderHasRootUri: new RawContextKey<boolean>('scmProviderHasRootUri', undefined),
966966
SCMHistoryItemCount: new RawContextKey<number>('scmHistoryItemCount', 0),
967+
SCMCurrentHistoryItemRefHasRemote: new RawContextKey<boolean>('scmCurrentHistoryItemRefHasRemote', false),
968+
SCMCurrentHistoryItemRefInFilter: new RawContextKey<boolean>('scmCurrentHistoryItemRefInFilter', false),
967969
RepositoryCount: new RawContextKey<number>('scmRepositoryCount', 0),
968970
RepositoryVisibilityCount: new RawContextKey<number>('scmRepositoryVisibleCount', 0),
969971
RepositoryVisibility(repository: ISCMRepository) {

0 commit comments

Comments
 (0)