Skip to content

Commit

Permalink
Adds graph.showDetailsView setting
Browse files Browse the repository at this point in the history
Controls how the Commit Details view is shown by the graph
Honors avatar setting in remote icons
  • Loading branch information
eamodio committed Oct 6, 2022
1 parent 79f932b commit fe0b6b0
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 11 deletions.
26 changes: 23 additions & 3 deletions package.json
Expand Up @@ -2097,7 +2097,7 @@
"gitlens.graph.avatars": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to show avatar images instead of author initials in the _Commit Graph_",
"markdownDescription": "Specifies whether to show avatar images instead of author initials and remote icons in the _Commit Graph_",
"scope": "window",
"order": 10
},
Expand All @@ -2108,12 +2108,32 @@
"scope": "window",
"order": 11
},
"gitlens.graph.showDetailsView": {
"type": [
"boolean",
"string"
],
"default": "selection",
"enum": [
false,
"open",
"selection"
],
"enumDescriptions": [
"Never shows the _Commit Details_ view automatically",
"Shows the _Commit Details_ view automatically when the _Commit Graph_ is first opened",
"Shows the _Commit Details_ view automatically when selection changes in the _Commit Graph_"
],
"markdownDescription": "Specifies when to show the _Commit Details_ view for the selected row in the _Commit Graph_",
"scope": "window",
"order": 12
},
"gitlens.graph.showGhostRefsOnRowHover": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to show a ghost ref of the hovered/selected row in the _Commit Graph_",
"markdownDescription": "Specifies whether to show a ghost ref for the hovered/selected row in the _Commit Graph_",
"scope": "window",
"order": 12
"order": 13
},
"gitlens.graph.defaultItemLimit": {
"type": "number",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gitCommands.actions.ts
Expand Up @@ -768,7 +768,7 @@ export namespace GitActions {

export function showDetailsView(
commit: GitRevisionReference | GitCommit,
options?: { pin?: boolean; preserveFocus?: boolean },
options?: { pin?: boolean; preserveFocus?: boolean; preserveVisibility?: boolean },
): Promise<void> {
return Container.instance.commitDetailsView.show({ ...options, commit: commit });
}
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Expand Up @@ -380,6 +380,7 @@ export interface GraphConfig {
dateStyle: DateStyle | null;
defaultItemLimit: number;
highlightRowsOnRefHover: boolean;
showDetailsView: 'open' | 'selection' | false;
showGhostRefsOnRowHover: boolean;
pageItemLimit: number;
searchItemLimit: number;
Expand Down
4 changes: 3 additions & 1 deletion src/env/node/git/localGitProvider.ts
Expand Up @@ -1664,6 +1664,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
);
}

const useAvatars = configuration.get('graph.avatars', undefined, true);

const avatars = new Map<string, string>();
const ids = new Set<string>();
const reachableFromHEAD = new Set<string>();
Expand Down Expand Up @@ -1829,7 +1831,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
owner: remote.name,
url: remote.url,
avatarUrl: (
remote.provider?.avatarUri ??
(useAvatars ? remote.provider?.avatarUri : undefined) ??
getRemoteIconUri(this.container, remote, asWebviewUri)
)?.toString(true),
context: serializeWebviewItemContext<GraphItemRefContext>({
Expand Down
7 changes: 5 additions & 2 deletions src/plus/github/githubGitProvider.ts
Expand Up @@ -1078,6 +1078,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
const defaultLimit = options?.limit ?? configuration.get('graph.defaultItemLimit') ?? 5000;
// const defaultPageLimit = configuration.get('graph.pageItemLimit') ?? 1000;
const ordering = configuration.get('graph.commitOrdering', undefined, 'date');
const useAvatars = configuration.get('graph.avatars', undefined, true);

const [logResult, branchResult, remotesResult, tagsResult, currentUserResult] = await Promise.allSettled([
this.getLog(repoPath, { all: true, ordering: ordering, limit: defaultLimit }),
Expand All @@ -1100,7 +1101,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
getSettledValue(currentUserResult),
avatars,
ids,
options,
{ ...options, useAvatars: useAvatars },
);
}

Expand All @@ -1119,6 +1120,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
limit?: number;
mode?: 'single' | 'local' | 'all';
ref?: string;
useAvatars?: boolean;
},
): Promise<GitGraph> {
if (log == null) {
Expand Down Expand Up @@ -1184,7 +1186,8 @@ export class GitHubGitProvider implements GitProvider, Disposable {
owner: remote.name,
url: remote.url,
avatarUrl: (
remote.provider?.avatarUri ?? getRemoteIconUri(this.container, remote, asWebviewUri)
(options?.useAvatars ? remote.provider?.avatarUri : undefined) ??
getRemoteIconUri(this.container, remote, asWebviewUri)
)?.toString(true),
context: serializeWebviewItemContext<GraphItemRefContext>({
webviewItem: 'gitlens:branch+remote',
Expand Down
29 changes: 25 additions & 4 deletions src/plus/webviews/graph/graphWebview.ts
Expand Up @@ -28,6 +28,7 @@ import type {
} from '../../../commands';
import { parseCommandContext } from '../../../commands/base';
import { GitActions } from '../../../commands/gitCommands.actions';
import type { Config } from '../../../configuration';
import { configuration } from '../../../configuration';
import { Commands, ContextKeys, CoreGitCommands } from '../../../constants';
import type { Container } from '../../../container';
Expand Down Expand Up @@ -185,17 +186,18 @@ export class GraphWebview extends WebviewBase<State> {

private _etagSubscription?: number;
private _etagRepository?: number;
private _firstSelection = true;
private _graph?: GitGraph;
private _pendingIpcNotifications = new Map<IpcNotificationType, IpcMessage | (() => Promise<boolean>)>();
private _refsMetadata: Map<string, GraphRefMetadata | null> | null | undefined;
private _search: GitSearch | undefined;
private _searchCancellation: CancellationTokenSource | undefined;
private _selectedId?: string;
private _selectedRows: GraphSelectedRows | undefined;
private _repositoryEventsDisposable: Disposable | undefined;

private _showDetailsView: Config['graph']['showDetailsView'];
private _statusBarItem: StatusBarItem | undefined;
private _theme: ColorTheme | undefined;
private _repositoryEventsDisposable: Disposable | undefined;

private previewBanner?: boolean;
private trialBanner?: boolean;
Expand All @@ -210,6 +212,9 @@ export class GraphWebview extends WebviewBase<State> {
'graphWebview',
Commands.ShowGraphPage,
);

this._showDetailsView = configuration.get('graph.showDetailsView');

this.disposables.push(
configuration.onDidChange(this.onConfigurationChanged, this),
once(container.onReady)(() => queueMicrotask(() => this.updateStatusBar())),
Expand Down Expand Up @@ -260,6 +265,7 @@ export class GraphWebview extends WebviewBase<State> {
}

override async show(options?: { column?: ViewColumn; preserveFocus?: boolean }, ...args: unknown[]): Promise<void> {
this._firstSelection = true;
if (!(await ensurePlusFeaturesEnabled())) return;

if (this.container.git.repositoryCount > 1) {
Expand Down Expand Up @@ -412,7 +418,11 @@ export class GraphWebview extends WebviewBase<State> {
setTimeout(() => void setContext(ContextKeys.GraphPageFocused, focused), 0);

if (this.selection != null) {
void GitActions.Commit.showDetailsView(this.selection[0], { pin: true, preserveFocus: true });
void GitActions.Commit.showDetailsView(this.selection[0], {
pin: true,
preserveFocus: true,
preserveVisibility: this._showDetailsView === false,
});
}

return;
Expand All @@ -433,6 +443,10 @@ export class GraphWebview extends WebviewBase<State> {
}

private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (configuration.changed(e, 'graph.showDetailsView')) {
this._showDetailsView = configuration.get('graph.showDetailsView');
}

if (configuration.changed(e, 'graph.statusBar.enabled') || configuration.changed(e, 'plusFeatures.enabled')) {
this.updateStatusBar();
}
Expand Down Expand Up @@ -812,7 +826,14 @@ export class GraphWebview extends WebviewBase<State> {

if (commits == null) return;

void GitActions.Commit.showDetailsView(commits[0], { pin: true, preserveFocus: true });
void GitActions.Commit.showDetailsView(commits[0], {
pin: true,
preserveFocus: true,
preserveVisibility: this._firstSelection
? this._showDetailsView === false
: this._showDetailsView !== 'selection',
});
this._firstSelection = false;
}

private _notifyDidChangeStateDebounced: Deferrable<GraphWebview['notifyDidChangeState']> | undefined = undefined;
Expand Down
24 changes: 24 additions & 0 deletions src/webviews/apps/settings/partials/commit-graph.html
Expand Up @@ -75,6 +75,30 @@ <h2>
</div>
</div>

<div class="setting">
<div class="setting__input setting__input--inner-select">
<input
id="graph.showDetailsView"
name="graph.showDetailsView"
type="checkbox"
value="selection"
data-setting
/>
<label for="graph.showDetailsView">Show the Commit Details view</label>
<div class="select-container">
<select
id="graph.showDetailsView"
name="graph.showDetailsView"
data-setting
data-enablement="graph.showDetailsView !false"
>
<option value="open">when first opened</option>
<option value="selection">when selection changes (default)</option>
</select>
</div>
</div>
</div>

<div class="setting">
<div class="setting__input">
<input
Expand Down
3 changes: 3 additions & 0 deletions src/webviews/commitDetails/commitDetailsWebviewView.ts
Expand Up @@ -113,6 +113,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
commit?: GitRevisionReference | GitCommit;
pin?: boolean;
preserveFocus?: boolean | undefined;
preserveVisibility?: boolean | undefined;
}): Promise<void> {
if (options != null) {
let commit;
Expand All @@ -134,6 +135,8 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
}
}

if (options?.preserveVisibility) return;

return super.show(options);
}

Expand Down

0 comments on commit fe0b6b0

Please sign in to comment.