From 680e23ccad4acf64aaf84a49214fda9ee8504d66 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 25 Aug 2022 02:24:52 -0400 Subject: [PATCH] Adds refresh command for the Graph --- package.json | 15 +++++++++++++++ src/constants.ts | 4 +++- src/plus/webviews/graph/graphWebview.ts | 17 +++++++++++++++-- src/plus/webviews/timeline/timelineWebview.ts | 2 +- src/webviews/webviewBase.ts | 16 ++++++++-------- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 6e6b93e..d7295b7 100644 --- a/package.json +++ b/package.json @@ -3966,6 +3966,12 @@ "icon": "$(gitlens-graph)" }, { + "command": "gitlens.refreshGraphPage", + "title": "Refresh", + "category": "GitLens", + "icon": "$(refresh)" + }, + { "command": "gitlens.showSettingsPage", "title": "Open Settings", "category": "GitLens", @@ -6425,6 +6431,10 @@ "when": "gitlens:enabled" }, { + "command": "gitlens.refreshGraphPage", + "when": "false" + }, + { "command": "gitlens.showSettingsPage#views", "when": "false" }, @@ -8159,6 +8169,11 @@ "command": "gitlens.refreshTimelinePage", "when": "gitlens:timelinePage:focused", "group": "navigation@-99" + }, + { + "command": "gitlens.refreshGraphPage", + "when": "gitlens:graphPage:focused", + "group": "navigation@-99" } ], "editor/title/context": [ diff --git a/src/constants.ts b/src/constants.ts index 3df5665..aeab79d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -152,7 +152,9 @@ export const enum Commands { PlusStartPreviewTrial = 'gitlens.plus.startPreviewTrial', PlusValidate = 'gitlens.plus.validate', QuickOpenFileHistory = 'gitlens.quickOpenFileHistory', + RefreshGraphPage = 'gitlens.refreshGraphPage', RefreshHover = 'gitlens.refreshHover', + RefreshTimelinePage = 'gitlens.refreshTimelinePage', ResetAvatarCache = 'gitlens.resetAvatarCache', ResetSuppressedWarnings = 'gitlens.resetSuppressedWarnings', ResetTrackedUsage = 'gitlens.resetTrackedUsage', @@ -199,7 +201,6 @@ export const enum Commands { ShowStashesView = 'gitlens.showStashesView', ShowTagsView = 'gitlens.showTagsView', ShowWorktreesView = 'gitlens.showWorktreesView', - RefreshTimelinePage = 'gitlens.refreshTimelinePage', ShowCommitDetailsView = 'gitlens.showCommitDetailsView', ShowTimelinePage = 'gitlens.showTimelinePage', ShowTimelineView = 'gitlens.showTimelineView', @@ -246,6 +247,7 @@ export const enum ContextKeys { DisabledToggleCodeLens = 'gitlens:disabledToggleCodeLens', Disabled = 'gitlens:disabled', Enabled = 'gitlens:enabled', + GraphPageFocused = 'gitlens:graphPage:focused', HasConnectedRemotes = 'gitlens:hasConnectedRemotes', HasRemotes = 'gitlens:hasRemotes', HasRichRemotes = 'gitlens:hasRichRemotes', diff --git a/src/plus/webviews/graph/graphWebview.ts b/src/plus/webviews/graph/graphWebview.ts index a2b91eb..3c69c22 100644 --- a/src/plus/webviews/graph/graphWebview.ts +++ b/src/plus/webviews/graph/graphWebview.ts @@ -132,6 +132,10 @@ export class GraphWebview extends WebviewBase { return this.getState(); } + protected override registerCommands(): Disposable[] { + return [registerCommand(Commands.RefreshGraphPage, () => this.refresh(true))]; + } + protected override onInitializing(): Disposable[] | undefined { this._theme = window.activeColorTheme; return [window.onDidChangeActiveColorTheme(this.onThemeChanged, this)]; @@ -158,9 +162,18 @@ export class GraphWebview extends WebviewBase { } protected override onFocusChanged(focused: boolean): void { - if (focused && this.selection != null) { - void GitActions.Commit.showDetailsView(this.selection[0], { pin: true, preserveFocus: true }); + if (focused) { + // If we are becoming focused, delay it a bit to give the UI time to update + setTimeout(() => void setContext(ContextKeys.GraphPageFocused, focused), 0); + + if (this.selection != null) { + void GitActions.Commit.showDetailsView(this.selection[0], { pin: true, preserveFocus: true }); + } + + return; } + + void setContext(ContextKeys.GraphPageFocused, focused); } protected override onVisibilityChanged(visible: boolean): void { diff --git a/src/plus/webviews/timeline/timelineWebview.ts b/src/plus/webviews/timeline/timelineWebview.ts index c0eb08f..12849c7 100644 --- a/src/plus/webviews/timeline/timelineWebview.ts +++ b/src/plus/webviews/timeline/timelineWebview.ts @@ -106,7 +106,7 @@ export class TimelineWebview extends WebviewBase { } protected override registerCommands(): Disposable[] { - return [registerCommand(Commands.RefreshTimelinePage, () => this.refresh())]; + return [registerCommand(Commands.RefreshTimelinePage, () => this.refresh(true))]; } protected override onFocusChanged(focused: boolean): void { diff --git a/src/webviews/webviewBase.ts b/src/webviews/webviewBase.ts index 1eba674..8e23780 100644 --- a/src/webviews/webviewBase.ts +++ b/src/webviews/webviewBase.ts @@ -103,12 +103,7 @@ export abstract class WebviewBase implements Disposable { this._panel.webview.html = await this.getHtml(this._panel.webview); } else { - const html = await this.getHtml(this._panel.webview); - - // Reset the html to get the webview to reload - this._panel.webview.html = ''; - this._panel.webview.html = html; - + await this.refresh(true); this._panel.reveal(this._panel.viewColumn ?? ViewColumn.Active, false); } } @@ -131,10 +126,15 @@ export abstract class WebviewBase implements Disposable { protected includeBody?(): string | Promise; protected includeEndOfBody?(): string | Promise; - protected async refresh(): Promise { + protected async refresh(force?: boolean): Promise { if (this._panel == null) return; - this._panel.webview.html = await this.getHtml(this._panel.webview); + const html = await this.getHtml(this._panel.webview); + if (force) { + // Reset the html to get the webview to reload + this._panel.webview.html = ''; + } + this._panel.webview.html = html; } private onPanelDisposed() {