diff --git a/CHANGELOG.md b/CHANGELOG.md index 27d7039..b83b8fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] +### Added + +- Adds a prompt to enable the view to the _Show \* View_ commands when the specified view is disabled — closes [#710](https://github.com/eamodio/vscode-gitlens/issues/710) & [#711](https://github.com/eamodio/vscode-gitlens/issues/711) + ### Removed - Removes `-m` flag from `git log` when following renames (using `--follow`), because it ends up returning all merge commits (regardless if the file in question was changed or not) diff --git a/src/commands/common.ts b/src/commands/common.ts index 13ebbe0..b31bbd5 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -107,7 +107,7 @@ export enum Commands { } interface CommandConstructor { - new (): any; + new (): Command; } const registrableCommands: CommandConstructor[] = []; diff --git a/src/container.ts b/src/container.ts index 9c32608..2f87572 100644 --- a/src/container.ts +++ b/src/container.ts @@ -226,7 +226,11 @@ export class Container { private static _repositoriesView: RepositoriesView | undefined; static get repositoriesView(): RepositoriesView { - return this._repositoriesView!; + if (this._repositoriesView === undefined) { + this._context.subscriptions.push((this._repositoriesView = new RepositoriesView())); + } + + return this._repositoriesView; } private static _searchView: SearchView | undefined; diff --git a/src/views/compareView.ts b/src/views/compareView.ts index dbbe02c..36753e8 100644 --- a/src/views/compareView.ts +++ b/src/views/compareView.ts @@ -15,7 +15,7 @@ import { ViewBase } from './viewBase'; export class CompareView extends ViewBase { constructor() { - super('gitlens.views.compare'); + super('gitlens.views.compare', 'Compare'); setCommandContext(CommandContext.ViewsCompareKeepResults, this.keepResults); } diff --git a/src/views/fileHistoryView.ts b/src/views/fileHistoryView.ts index 04226c6..743468f 100644 --- a/src/views/fileHistoryView.ts +++ b/src/views/fileHistoryView.ts @@ -9,7 +9,7 @@ import { ViewBase } from './viewBase'; export class FileHistoryView extends ViewBase { constructor() { - super('gitlens.views.fileHistory'); + super('gitlens.views.fileHistory', 'File History'); } getRoot() { diff --git a/src/views/lineHistoryView.ts b/src/views/lineHistoryView.ts index 765700f..4a7aa3b 100644 --- a/src/views/lineHistoryView.ts +++ b/src/views/lineHistoryView.ts @@ -8,7 +8,7 @@ import { ViewBase } from './viewBase'; export class LineHistoryView extends ViewBase { constructor() { - super('gitlens.views.lineHistory'); + super('gitlens.views.lineHistory', 'Line History'); } getRoot() { diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index 65db0c5..b71591d 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -8,7 +8,7 @@ import { ViewBase } from './viewBase'; export class RepositoriesView extends ViewBase { constructor() { - super('gitlens.views.repositories'); + super('gitlens.views.repositories', 'Repositories'); } private _onDidChangeAutoRefresh = new EventEmitter(); diff --git a/src/views/searchView.ts b/src/views/searchView.ts index 8e70c52..e8b9c6b 100644 --- a/src/views/searchView.ts +++ b/src/views/searchView.ts @@ -15,7 +15,7 @@ interface SearchQueryResult { export class SearchView extends ViewBase { constructor() { - super('gitlens.views.search'); + super('gitlens.views.search', 'Search Commits'); setCommandContext(CommandContext.ViewsSearchKeepResults, this.keepResults); } diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index f112c1d..da5d6ad 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -2,9 +2,11 @@ import { commands, ConfigurationChangeEvent, + ConfigurationTarget, Disposable, Event, EventEmitter, + MessageItem, TreeDataProvider, TreeItem, TreeItemCollapsibleState, @@ -16,7 +18,7 @@ import { import { configuration } from '../configuration'; import { Container } from '../container'; import { Logger } from '../logger'; -import { debug, Functions, log } from '../system'; +import { debug, Functions, log, Strings } from '../system'; import { CompareView } from './compareView'; import { FileHistoryView } from './fileHistoryView'; import { LineHistoryView } from './lineHistoryView'; @@ -53,7 +55,7 @@ export abstract class ViewBase> implements TreeData protected _root: TRoot | undefined; protected _tree: TreeView | undefined; - constructor(public readonly id: string) { + constructor(public readonly id: string, public readonly name: string) { this.registerCommands(); Container.context.subscriptions.push(configuration.onDidChange(this.onConfigurationChanged, this)); @@ -194,12 +196,30 @@ export abstract class ViewBase> implements TreeData @log() async show() { + const location = this.location; + try { - const location = this.location; return await commands.executeCommand(`${this.id}${location ? `:${location}` : ''}.focus`); } catch (ex) { Logger.error(ex); + + const setting = `${Strings.splitSingle(this.id, '.')[1]}.enabled`; + if (!configuration.get(setting)) { + const actions: MessageItem[] = [{ title: 'Enable' }, { title: 'Cancel', isCloseAffordance: true }]; + + const result = await window.showErrorMessage( + `Unable to show the ${this.name} view since it's currently disabled. Would you like to enable it?`, + ...actions + ); + + if (result === actions[0]) { + await configuration.update(setting, true, ConfigurationTarget.Global); + + return commands.executeCommand(`${this.id}${location ? `:${location}` : ''}.focus`); + } + } + return undefined; } }