Skip to content

Commit

Permalink
SCM - refactor incoming/outgoing settings (#198368)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Nov 15, 2023
1 parent 9a207df commit 11a6cf4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
41 changes: 22 additions & 19 deletions src/vs/workbench/contrib/scm/browser/scm.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,29 +298,32 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
markdownDescription: localize('showActionButton', "Controls whether an action button can be shown in the Source Control view."),
default: true
},
'scm.showIncomingChanges': {
type: 'string',
enum: ['always', 'never', 'auto'],
enumDescriptions: [
localize('scm.showIncomingChanges.always', "Always show incoming changes in the Source Control view."),
localize('scm.showIncomingChanges.never', "Never show incoming changes in the Source Control view."),
localize('scm.showIncomingChanges.auto', "Only show incoming changes in the Source Control view when any exist."),
],
description: localize('scm.showIncomingChanges', "Controls whether incoming changes are shown in the Source Control view."),
default: 'never'
},
'scm.showOutgoingChanges': {
type: 'string',
enum: ['always', 'never', 'auto'],
enumDescriptions: [
localize('scm.showOutgoingChanges.always', "Always show outgoing changes in the Source Control view."),
localize('scm.showOutgoingChanges.never', "Never show outgoing changes in the Source Control view."),
localize('scm.showOutgoingChanges.auto', "Only show outgoing changes in the Source Control view when any exist."),
],
description: localize('scm.showOutgoingChanges', "Controls whether outgoing changes are shown in the Source Control view."),
default: 'never'
},
'scm.experimental.showSyncView': {
type: 'boolean',
description: localize('showSyncView', "Controls whether the Source Control Sync view is shown."),
default: false
},
'scm.experimental.showSyncInformation': {
type: 'object',
description: localize('showSyncInformation', "Controls whether incoming/outgoing changes are shown in the Source Control view."),
additionalProperties: false,
properties: {
'incoming': {
type: 'boolean',
description: localize('showSyncInformationIncoming', "Show incoming changes in the Source Control view."),
},
'outgoing': {
type: 'boolean',
description: localize('showSyncInformationOutgoing', "Show outgoing changes in the Source Control view."),
},
},
default: {
'incoming': false,
'outgoing': false
}
}
}
});
Expand Down
35 changes: 24 additions & 11 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ type TreeElement =
IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement> |
SCMViewSeparatorElement;

type ShowChangesSetting = 'always' | 'never' | 'auto';

registerColor('scm.historyItemAdditionsForeground', {
dark: 'gitDecoration.addedResourceForeground',
light: 'gitDecoration.addedResourceForeground',
Expand Down Expand Up @@ -1023,8 +1025,6 @@ class SCMTreeFilter implements ITreeFilter<TreeElement> {
return true;
} else if (isSCMResourceGroup(element)) {
return element.resources.length > 0 || !element.hideWhenEmpty;
} else if (isSCMHistoryItemGroupTreeElement(element)) {
return (element.count ?? 0) > 0;
} else if (isSCMViewSeparator(element)) {
return element.repository.provider.groups.some(g => g.resources.length > 0);
} else {
Expand Down Expand Up @@ -2351,8 +2351,11 @@ export class SCMViewPane extends ViewPane {
private _alwaysShowRepositories = false;
get alwaysShowRepositories(): boolean { return this._alwaysShowRepositories; }

private _showSyncInformation: { incoming: boolean; outgoing: boolean } = { incoming: false, outgoing: false };
get showSyncInformation(): { incoming: boolean; outgoing: boolean } { return this._showSyncInformation; }
private _showIncomingChanges: ShowChangesSetting | undefined;
get showIncomingChanges(): ShowChangesSetting { return this._showIncomingChanges ?? 'never'; }

private _showOutgoingChanges: ShowChangesSetting | undefined;
get showOutgoingChanges(): ShowChangesSetting { return this._showOutgoingChanges ?? 'never'; }

private readonly items = new DisposableMap<ISCMRepository, IDisposable>();
private readonly visibilityDisposables = new DisposableStore();
Expand Down Expand Up @@ -2468,10 +2471,15 @@ export class SCMViewPane extends ViewPane {
await this.tree.setInput(this.scmViewService, viewState);

const onDidChangeConfiguration = (e?: IConfigurationChangeEvent) => {
if (!e || e.affectsConfiguration('scm.showActionButton') || e.affectsConfiguration('scm.alwaysShowRepositories') || e.affectsConfiguration('scm.experimental.showSyncInformation')) {
if (!e ||
e.affectsConfiguration('scm.showActionButton') ||
e.affectsConfiguration('scm.alwaysShowRepositories') ||
e.affectsConfiguration('scm.showIncomingChanges') ||
e.affectsConfiguration('scm.showOutgoingChanges')) {
this._showActionButton = this.configurationService.getValue<boolean>('scm.showActionButton');
this._alwaysShowRepositories = this.configurationService.getValue<boolean>('scm.alwaysShowRepositories');
this._showSyncInformation = this.configurationService.getValue<{ incoming: boolean; outgoing: boolean }>('scm.experimental.showSyncInformation');
this._showIncomingChanges = this.configurationService.getValue<ShowChangesSetting>('scm.showIncomingChanges');
this._showOutgoingChanges = this.configurationService.getValue<ShowChangesSetting>('scm.showOutgoingChanges');

if (e?.affectsConfiguration('scm.alwaysShowRepositories')) {
this.updateActions();
Expand Down Expand Up @@ -2521,7 +2529,7 @@ export class SCMViewPane extends ViewPane {
actionRunner.onWillRun(() => this.tree.domFocus(), this, this.disposables);
this.disposables.add(actionRunner);

this.treeDataSource = this.instantiationService.createInstance(SCMTreeDataSource, () => this.viewMode, () => this.alwaysShowRepositories, () => this.showActionButton, () => this.showSyncInformation);
this.treeDataSource = this.instantiationService.createInstance(SCMTreeDataSource, () => this.viewMode, () => this.alwaysShowRepositories, () => this.showActionButton, () => this.showIncomingChanges, () => this.showOutgoingChanges);

this.tree = this.instantiationService.createInstance(
WorkbenchCompressibleAsyncDataTree,
Expand Down Expand Up @@ -2970,7 +2978,8 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
private readonly viewMode: () => ViewMode,
private readonly alwaysShowRepositories: () => boolean,
private readonly showActionButton: () => boolean,
private readonly showSyncInformation: () => { incoming: boolean; outgoing: boolean },
private readonly showIncomingChanges: () => ShowChangesSetting,
private readonly showOutgoingChanges: () => ShowChangesSetting,
@ISCMViewService private readonly scmViewService: ISCMViewService,
@IUriIdentityService private uriIdentityService: IUriIdentityService,
) { }
Expand Down Expand Up @@ -3088,7 +3097,7 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
const historyProvider = scmProvider.historyProvider;
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;

if (!historyProvider || !currentHistoryItemGroup || (this.showSyncInformation().incoming === false && this.showSyncInformation().outgoing === false)) {
if (!historyProvider || !currentHistoryItemGroup || (this.showIncomingChanges() === 'never' && this.showOutgoingChanges() === 'never')) {
return [];
}

Expand All @@ -3105,7 +3114,9 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
}

// Incoming
if (this.showSyncInformation().incoming && historyItemGroupDetails?.incoming) {
if (historyItemGroupDetails?.incoming &&
(this.showIncomingChanges() === 'always' ||
(this.showIncomingChanges() === 'auto' && (historyItemGroupDetails.incoming.count ?? 0) > 0))) {
children.push({
...historyItemGroupDetails.incoming,
repository: element,
Expand All @@ -3114,7 +3125,9 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
}

// Outgoing
if (this.showSyncInformation().outgoing && historyItemGroupDetails?.outgoing) {
if (historyItemGroupDetails?.outgoing &&
(this.showOutgoingChanges() === 'always' ||
(this.showOutgoingChanges() === 'auto' && (historyItemGroupDetails.outgoing.count ?? 0) > 0))) {
children.push({
...historyItemGroupDetails.outgoing,
repository: element,
Expand Down

0 comments on commit 11a6cf4

Please sign in to comment.