Skip to content

Commit 03d6a0e

Browse files
committed
Closes #710, #711 - Prompts on disabled views
1 parent 809160b commit 03d6a0e

File tree

9 files changed

+38
-10
lines changed

9 files changed

+38
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- 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)
12+
913
### Removed
1014

1115
- 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)

src/commands/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export enum Commands {
107107
}
108108

109109
interface CommandConstructor {
110-
new (): any;
110+
new (): Command;
111111
}
112112

113113
const registrableCommands: CommandConstructor[] = [];

src/container.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ export class Container {
226226

227227
private static _repositoriesView: RepositoriesView | undefined;
228228
static get repositoriesView(): RepositoriesView {
229-
return this._repositoriesView!;
229+
if (this._repositoriesView === undefined) {
230+
this._context.subscriptions.push((this._repositoriesView = new RepositoriesView()));
231+
}
232+
233+
return this._repositoriesView;
230234
}
231235

232236
private static _searchView: SearchView | undefined;

src/views/compareView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ViewBase } from './viewBase';
1515

1616
export class CompareView extends ViewBase<CompareNode> {
1717
constructor() {
18-
super('gitlens.views.compare');
18+
super('gitlens.views.compare', 'Compare');
1919

2020
setCommandContext(CommandContext.ViewsCompareKeepResults, this.keepResults);
2121
}

src/views/fileHistoryView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ViewBase } from './viewBase';
99

1010
export class FileHistoryView extends ViewBase<FileHistoryTrackerNode> {
1111
constructor() {
12-
super('gitlens.views.fileHistory');
12+
super('gitlens.views.fileHistory', 'File History');
1313
}
1414

1515
getRoot() {

src/views/lineHistoryView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ViewBase } from './viewBase';
88

99
export class LineHistoryView extends ViewBase<LineHistoryTrackerNode> {
1010
constructor() {
11-
super('gitlens.views.lineHistory');
11+
super('gitlens.views.lineHistory', 'Line History');
1212
}
1313

1414
getRoot() {

src/views/repositoriesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ViewBase } from './viewBase';
88

99
export class RepositoriesView extends ViewBase<RepositoriesNode> {
1010
constructor() {
11-
super('gitlens.views.repositories');
11+
super('gitlens.views.repositories', 'Repositories');
1212
}
1313

1414
private _onDidChangeAutoRefresh = new EventEmitter<void>();

src/views/searchView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface SearchQueryResult {
1515

1616
export class SearchView extends ViewBase<SearchNode> {
1717
constructor() {
18-
super('gitlens.views.search');
18+
super('gitlens.views.search', 'Search Commits');
1919

2020
setCommandContext(CommandContext.ViewsSearchKeepResults, this.keepResults);
2121
}

src/views/viewBase.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import {
33
commands,
44
ConfigurationChangeEvent,
5+
ConfigurationTarget,
56
Disposable,
67
Event,
78
EventEmitter,
9+
MessageItem,
810
TreeDataProvider,
911
TreeItem,
1012
TreeItemCollapsibleState,
@@ -16,7 +18,7 @@ import {
1618
import { configuration } from '../configuration';
1719
import { Container } from '../container';
1820
import { Logger } from '../logger';
19-
import { debug, Functions, log } from '../system';
21+
import { debug, Functions, log, Strings } from '../system';
2022
import { CompareView } from './compareView';
2123
import { FileHistoryView } from './fileHistoryView';
2224
import { LineHistoryView } from './lineHistoryView';
@@ -53,7 +55,7 @@ export abstract class ViewBase<TRoot extends ViewNode<View>> implements TreeData
5355
protected _root: TRoot | undefined;
5456
protected _tree: TreeView<ViewNode> | undefined;
5557

56-
constructor(public readonly id: string) {
58+
constructor(public readonly id: string, public readonly name: string) {
5759
this.registerCommands();
5860

5961
Container.context.subscriptions.push(configuration.onDidChange(this.onConfigurationChanged, this));
@@ -194,12 +196,30 @@ export abstract class ViewBase<TRoot extends ViewNode<View>> implements TreeData
194196

195197
@log()
196198
async show() {
199+
const location = this.location;
200+
197201
try {
198-
const location = this.location;
199202
return await commands.executeCommand(`${this.id}${location ? `:${location}` : ''}.focus`);
200203
}
201204
catch (ex) {
202205
Logger.error(ex);
206+
207+
const setting = `${Strings.splitSingle(this.id, '.')[1]}.enabled`;
208+
if (!configuration.get(setting)) {
209+
const actions: MessageItem[] = [{ title: 'Enable' }, { title: 'Cancel', isCloseAffordance: true }];
210+
211+
const result = await window.showErrorMessage(
212+
`Unable to show the ${this.name} view since it's currently disabled. Would you like to enable it?`,
213+
...actions
214+
);
215+
216+
if (result === actions[0]) {
217+
await configuration.update(setting, true, ConfigurationTarget.Global);
218+
219+
return commands.executeCommand(`${this.id}${location ? `:${location}` : ''}.focus`);
220+
}
221+
}
222+
203223
return undefined;
204224
}
205225
}

0 commit comments

Comments
 (0)