Browse Source

Adds Graph toggle commands

main
Eric Amodio 1 year ago
parent
commit
03319dd695
4 changed files with 62 additions and 6 deletions
  1. +20
    -0
      package.json
  2. +11
    -3
      src/constants.ts
  3. +18
    -1
      src/plus/webviews/graph/registration.ts
  4. +13
    -2
      src/webviews/webviewController.ts

+ 20
- 0
package.json View File

@ -4601,6 +4601,18 @@
"icon": "$(gitlens-graph)"
},
{
"command": "gitlens.toggleGraph",
"title": "Toggle Commit Graph",
"category": "GitLens+",
"icon": "$(gitlens-graph)"
},
{
"command": "gitlens.toggleMaximizedGraph",
"title": "Toggle Maximized Commit Graph",
"category": "GitLens+",
"icon": "$(gitlens-graph)"
},
{
"command": "gitlens.showHomeView",
"title": "Show Home View",
"category": "GitLens"
@ -7737,6 +7749,14 @@
"when": "gitlens:enabled && config.gitlens.graph.layout == panel"
},
{
"command": "gitlens.toggleGraph",
"when": "gitlens:enabled && config.gitlens.graph.layout == panel"
},
{
"command": "gitlens.toggleMaximizedGraph",
"when": "gitlens:enabled && config.gitlens.graph.layout == panel"
},
{
"command": "gitlens.showHomeView",
"when": "gitlens:enabled"
},

+ 11
- 3
src/constants.ts View File

@ -293,6 +293,8 @@ export const enum Commands {
ToggleFileHeatmap = 'gitlens.toggleFileHeatmap',
ToggleFileHeatmapInDiffLeft = 'gitlens.toggleFileHeatmapInDiffLeft',
ToggleFileHeatmapInDiffRight = 'gitlens.toggleFileHeatmapInDiffRight',
ToggleGraph = 'gitlens.toggleGraph',
ToggleMaximizedGraph = 'gitlens.toggleMaximizedGraph',
ToggleLineBlame = 'gitlens.toggleLineBlame',
ToggleReviewMode = 'gitlens.toggleReviewMode',
ToggleZenMode = 'gitlens.toggleZenMode',
@ -318,8 +320,12 @@ export type WebviewViewIds = 'commitDetails' | 'graph' | 'graphDetails' | 'home'
export type ContextKeys =
| `${typeof extensionPrefix}:action:${string}`
| `${typeof extensionPrefix}:key:${Keys}`
| `${typeof extensionPrefix}:webview:${WebviewIds | CustomEditorIds}:${'active' | 'focus' | 'inputFocus'}`
| `${typeof extensionPrefix}:webviewView:${WebviewViewIds}:${'active' | 'focus' | 'inputFocus'}`
| `${typeof extensionPrefix}:webview:${WebviewIds | CustomEditorIds}:${
| 'active'
| 'focus'
| 'inputFocus'
| 'visible'}`
| `${typeof extensionPrefix}:webviewView:${WebviewViewIds}:${'active' | 'focus' | 'inputFocus' | 'visible'}`
| `${typeof extensionPrefix}:activeFileStatus`
| `${typeof extensionPrefix}:annotationStatus`
| `${typeof extensionPrefix}:debugging`
@ -370,9 +376,11 @@ export type CoreCommands =
| 'vscode.moveViews'
| 'vscode.previewHtml'
| 'workbench.action.closeActiveEditor'
| 'workbench.action.openWalkthrough'
| 'workbench.action.closeAllEditors'
| 'workbench.action.closePanel'
| 'workbench.action.nextEditor'
| 'workbench.action.openWalkthrough'
| 'workbench.action.toggleMaximizedPanel'
| 'workbench.extensions.installExtension'
| 'workbench.extensions.uninstallExtension'
| 'workbench.files.action.focusFilesExplorer'

+ 18
- 1
src/plus/webviews/graph/registration.ts View File

@ -2,8 +2,9 @@ import { Disposable, ViewColumn } from 'vscode';
import { Commands } from '../../../constants';
import type { Container } from '../../../container';
import type { Repository } from '../../../git/models/repository';
import { executeCommand, registerCommand } from '../../../system/command';
import { executeCommand, executeCoreCommand, registerCommand } from '../../../system/command';
import { configuration } from '../../../system/configuration';
import { getContext } from '../../../system/context';
import type { BranchNode } from '../../../views/nodes/branchNode';
import type { CommitFileNode } from '../../../views/nodes/commitFileNode';
import type { CommitNode } from '../../../views/nodes/commitNode';
@ -77,6 +78,22 @@ export function registerGraphWebviewCommands(container: Container, webview: Webv
void executeCommand(Commands.ShowGraphView);
});
}),
registerCommand(Commands.ToggleGraph, (...args: any[]) => {
if (getContext('gitlens:webviewView:graph:visible')) {
void executeCoreCommand('workbench.action.closePanel');
} else {
void executeCommand(Commands.ShowGraphView, ...args);
}
}),
registerCommand(Commands.ToggleMaximizedGraph, (...args: any[]) => {
if (getContext('gitlens:webviewView:graph:visible')) {
void executeCoreCommand('workbench.action.toggleMaximizedPanel');
void executeCoreCommand('workbench.action.closePanel');
} else {
void executeCommand(Commands.ShowGraphView, ...args);
void executeCoreCommand('workbench.action.toggleMaximizedPanel');
}
}),
registerCommand(
Commands.ShowInCommitGraph,
(

+ 13
- 2
src/webviews/webviewController.ts View File

@ -156,7 +156,7 @@ export class WebviewController<
? parent.onDidChangeViewState(({ webviewPanel: { visible, active } }) =>
this.onParentVisibilityChanged(visible, active),
)
: parent.onDidChangeVisibility(() => this.onParentVisibilityChanged(this.visible)),
: parent.onDidChangeVisibility(() => this.onParentVisibilityChanged(this.visible, this.active)),
parent.onDidDispose(this.onParentDisposed, this),
...(this.provider.registerCommands?.() ?? []),
this.provider,
@ -194,6 +194,13 @@ export class WebviewController<
return !this._isEditor;
}
get active() {
if ('active' in this.parent) {
return this._disposed ? false : this.parent.active;
}
return this._disposed ? false : undefined;
}
get badge(): ViewBadge | undefined {
return 'badge' in this.parent ? this.parent.badge : undefined;
}
@ -267,6 +274,8 @@ export class WebviewController<
this.provider.onVisibilityChanged?.(true);
}
}
setContextKeys(this.descriptor.contextKeyPrefix, this.active);
}
private readonly _cspNonce = getNonce();
@ -373,8 +382,8 @@ export class WebviewController<
if (visible) {
void this.container.usage.track(`${this.descriptor.trackingFeature}:shown`);
setContextKeys(this.descriptor.contextKeyPrefix, active);
if (active != null) {
setContextKeys(this.descriptor.contextKeyPrefix, active);
this.provider.onActiveChanged?.(active);
if (!active) {
this.provider.onFocusChanged?.(false);
@ -578,6 +587,7 @@ export function replaceWebviewHtmlTokens(
export function resetContextKeys(
contextKeyPrefix: `gitlens:webview:${WebviewIds | CustomEditorIds}` | `gitlens:webviewView:${WebviewViewIds}`,
): void {
void setContext(`${contextKeyPrefix}:visible`, false);
void setContext(`${contextKeyPrefix}:inputFocus`, false);
void setContext(`${contextKeyPrefix}:focus`, false);
if (contextKeyPrefix.startsWith('gitlens:webview:')) {
@ -591,6 +601,7 @@ export function setContextKeys(
focus?: boolean,
inputFocus?: boolean,
): void {
void setContext(`${contextKeyPrefix}:visible`, true);
if (contextKeyPrefix.startsWith('gitlens:webview:')) {
if (active != null) {
void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewIds | CustomEditorIds}`}:active`, active);

Loading…
Cancel
Save