From 042ee28c715485645cba3a928ca56cc4d7b0df1b Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 21 Feb 2022 16:40:21 -0500 Subject: [PATCH] Adds show visual file history command Adds show method to webview views --- package.json | 10 ++++++++++ src/commands/showView.ts | 10 ++++++---- src/constants.ts | 1 + src/container.ts | 20 ++++++++++---------- src/views/viewBase.ts | 4 +++- src/webviews/webviewBase.ts | 2 +- src/webviews/webviewViewBase.ts | 14 +++++++++++++- src/webviews/webviewWithConfigBase.ts | 2 +- 8 files changed, 45 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 5c0f175..c332fc6 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "onCommand:gitlens.showSearchAndCompareView", "onCommand:gitlens.showStashesView", "onCommand:gitlens.showTagsView", + "onCommand:gitlens.showTimelineView", "onCommand:gitlens.showWorktreesView", "onCommand:gitlens.compareWith", "onCommand:gitlens.compareHeadWith", @@ -3786,6 +3787,11 @@ "category": "GitLens" }, { + "command": "gitlens.showTimelineView", + "title": "Show Visual File History View", + "category": "GitLens" + }, + { "command": "gitlens.showWorktreesView", "title": "Show Worktrees View", "category": "GitLens" @@ -6023,6 +6029,10 @@ "when": "gitlens:enabled" }, { + "command": "gitlens.showTimelineView", + "when": "gitlens:enabled" + }, + { "command": "gitlens.showWorktreesView", "when": "gitlens:enabled && !gitlens:hasVirtualFolders" }, diff --git a/src/commands/showView.ts b/src/commands/showView.ts index c95c282..06ae257 100644 --- a/src/commands/showView.ts +++ b/src/commands/showView.ts @@ -1,6 +1,6 @@ import { Commands } from '../constants'; import type { Container } from '../container'; -import { command, executeCommand } from '../system/command'; +import { command } from '../system/command'; import { Command, CommandContext } from './base'; @command() @@ -17,6 +17,7 @@ export class ShowViewCommand extends Command { Commands.ShowSearchAndCompareView, Commands.ShowStashesView, Commands.ShowTagsView, + Commands.ShowTimelineView, Commands.ShowWorktreesView, Commands.ShowHomeView, ]); @@ -36,6 +37,8 @@ export class ShowViewCommand extends Command { return this.container.contributorsView.show(); case Commands.ShowFileHistoryView: return this.container.fileHistoryView.show(); + case Commands.ShowHomeView: + return this.container.homeView.show(); case Commands.ShowLineHistoryView: return this.container.lineHistoryView.show(); case Commands.ShowRemotesView: @@ -48,11 +51,10 @@ export class ShowViewCommand extends Command { return this.container.stashesView.show(); case Commands.ShowTagsView: return this.container.tagsView.show(); + case Commands.ShowTimelineView: + return this.container.timelineView.show(); case Commands.ShowWorktreesView: return this.container.worktreesView.show(); - case Commands.ShowHomeView: - void (await executeCommand('gitlens.views.home.focus')); - break; } return Promise.resolve(undefined); diff --git a/src/constants.ts b/src/constants.ts index 6a5fc7c..cbae421 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -194,6 +194,7 @@ export const enum Commands { ShowTagsView = 'gitlens.showTagsView', ShowWorktreesView = 'gitlens.showWorktreesView', ShowTimelinePage = 'gitlens.showTimelinePage', + ShowTimelineView = 'gitlens.showTimelineView', ShowWelcomePage = 'gitlens.showWelcomePage', StashApply = 'gitlens.stashApply', StashSave = 'gitlens.stashSave', diff --git a/src/container.ts b/src/container.ts index 5983b09..412f9a8 100644 --- a/src/container.ts +++ b/src/container.ts @@ -191,7 +191,7 @@ export class Container { context.subscriptions.push((this._contributorsView = new ContributorsView(this))); context.subscriptions.push((this._searchAndCompareView = new SearchAndCompareView(this))); - context.subscriptions.push((this._homeWebviewView = new HomeWebviewView(this))); + context.subscriptions.push((this._homeView = new HomeWebviewView(this))); context.subscriptions.push((this._timelineView = new TimelineWebviewView(this))); if (config.terminalLinks.enabled) { @@ -365,6 +365,15 @@ export class Container { } } + private _homeView: HomeWebviewView | undefined; + get homeView() { + if (this._homeView == null) { + this._context.subscriptions.push((this._homeView = new HomeWebviewView(this))); + } + + return this._homeView; + } + @memoize() get insiders() { return this._context.extension.id.endsWith('-insiders'); @@ -408,15 +417,6 @@ export class Container { return this._rebaseEditor; } - private _homeWebviewView: HomeWebviewView | undefined; - get homeWebviewView() { - if (this._homeWebviewView == null) { - this._context.subscriptions.push((this._homeWebviewView = new HomeWebviewView(this))); - } - - return this._homeWebviewView; - } - private _remotesView: RemotesView | undefined; get remotesView() { if (this._remotesView == null) { diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index cc1c2d8..578e41c 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -512,10 +512,12 @@ export abstract class ViewBase< @log() async show(options?: { preserveFocus?: boolean }) { + const cc = Logger.getCorrelationContext(); + try { void (await executeCommand(`${this.id}.focus`, options)); } catch (ex) { - Logger.error(ex); + Logger.error(ex, cc); } } diff --git a/src/webviews/webviewBase.ts b/src/webviews/webviewBase.ts index 73d0fed..f8b463c 100644 --- a/src/webviews/webviewBase.ts +++ b/src/webviews/webviewBase.ts @@ -50,7 +50,7 @@ export abstract class WebviewBase implements Disposable { constructor( protected readonly container: Container, - public readonly id: string, + public readonly id: `gitlens.${string}`, private readonly fileName: string, private readonly iconPath: string, title: string, diff --git a/src/webviews/webviewViewBase.ts b/src/webviews/webviewViewBase.ts index 477c05f..d07674c 100644 --- a/src/webviews/webviewViewBase.ts +++ b/src/webviews/webviewViewBase.ts @@ -15,6 +15,7 @@ import { Commands } from '../constants'; import type { Container } from '../container'; import { Logger } from '../logger'; import { executeCommand } from '../system/command'; +import { log } from '../system/decorators/log'; import { ExecuteCommandType, IpcMessage, @@ -51,7 +52,7 @@ export abstract class WebviewViewBase implements WebviewViewProvider, Dis constructor( protected readonly container: Container, - public readonly id: string, + public readonly id: `gitlens.views.${string}`, protected readonly fileName: string, title: string, ) { @@ -88,6 +89,17 @@ export abstract class WebviewViewBase implements WebviewViewProvider, Dis return this._view?.visible ?? false; } + @log() + async show(options?: { preserveFocus?: boolean }) { + const cc = Logger.getCorrelationContext(); + + try { + void (await executeCommand(`${this.id}.focus`, options)); + } catch (ex) { + Logger.error(ex, cc); + } + } + protected onReady?(): void; protected onMessageReceived?(e: IpcMessage): void; protected onVisibilityChanged?(visible: boolean): void; diff --git a/src/webviews/webviewWithConfigBase.ts b/src/webviews/webviewWithConfigBase.ts index 8ba6092..1cc9ff1 100644 --- a/src/webviews/webviewWithConfigBase.ts +++ b/src/webviews/webviewWithConfigBase.ts @@ -28,7 +28,7 @@ export abstract class WebviewWithConfigBase extends WebviewBase { constructor( container: Container, - id: string, + id: `gitlens.${string}`, fileName: string, iconPath: string, title: string,