Skip to content

Commit

Permalink
Cleans up "welcome" views
Browse files Browse the repository at this point in the history
Makes them conditional on state
  • Loading branch information
eamodio committed Oct 22, 2020
1 parent 3fecdf1 commit 81d5137
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 138 deletions.
40 changes: 12 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2120,18 +2120,6 @@
"markdownDescription": "Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _Tags_ view. Only applies when `#gitlens.views.tags.files.layout#` is set to `auto`",
"scope": "window"
},
"gitlens.views.updates.enabled": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to show the _Updates_ view",
"scope": "window"
},
"gitlens.views.welcome.enabled": {
"type": "boolean",
"default": true,
"markdownDescription": "Specifies whether to show the _Welcome_ view",
"scope": "window"
},
"gitlens.advanced.abbreviatedShaLength": {
"type": "number",
"default": "7",
Expand Down Expand Up @@ -7714,58 +7702,54 @@
"viewsWelcome": [
{
"view": "gitlens.views.welcome",
"contents": "GitLens 11 is powerful, feature rich, and highly customizable to meet your needs. You can use the GitLens Welcome experience to get setup quickly.\n\n[Welcome (Quick Setup)](command:gitlens.showWelcomePage \"Opens the GitLens Welcome (Quick Setup)\")\n\nFor more options, use the [GitLens: Open Settings](command:gitlens.showSettingsPage \"Opens the GitLens Interactive Settings\") command from the Command Palette, to open the interactive GitLens settings editor."
"contents": "GitLens 11 is powerful, feature rich, and highly customizable to meet your needs. You can use the GitLens Welcome experience to get setup quickly.\n\n[Welcome (Quick Setup)](command:gitlens.showWelcomePage \"Opens the GitLens Welcome (Quick Setup)\")\n\nFor more options, run [GitLens: Open Settings](command:gitlens.showSettingsPage \"Opens the GitLens Interactive Settings\") from the Command Palette to open the interactive GitLens settings editor."
},
{
"view": "gitlens.views.welcome",
"contents": "You can also quickly switch between different side bar layouts for GitLens views to best match your workflow, via the [GitLens: Set Views Layout](command:gitlens.setViewsLayout \"Changes the GitLens Views Layout\") command from the Command Palette."
"contents": "[GitLens views](command:gitlens.showSettingsPage%23views) are shown on the Source Control side bar, by default. Run [GitLens: Set Views Layout](command:gitlens.setViewsLayout \"Changes the GitLens Views Layout\") from the Command Palette to switch to an alternate side bar layout, or drag & drop them."
},
{
"view": "gitlens.views.welcome",
"contents": "And if you find GitLens useful, please consider sponsoring it.\n\n[Sponsor GitLens ❤](command:gitlens.supportGitLens)"
"contents": "[Sponsor GitLens ❤](command:gitlens.supportGitLens)\n\nIf you find GitLens useful, please consider sponsoring it."
},
{
"view": "gitlens.views.welcome",
"contents": "Once you are satisfied, feel free to [close this view](command:gitlens.closeWelcomeView \"Closes the Welcome view\")."
},
{
"view": "gitlens.views.updates",
"contents": "[What's New in GitLens 11](https://gitlens.amod.io/#whats-new \"Opens the What's New page on the GitLens website\")\n\n[Sponsor GitLens ❤](command:gitlens.supportGitLens)\n\nSee the [release notes](https://github.com/eamodio/vscode-gitlens/blob/master/CHANGELOG.md \"Opens the Release Notes\") for the full set of changes."
"contents": "[Close](command:gitlens.closeWelcomeView \"Closes the Welcome view\")"
},
{
"view": "gitlens.views.updates",
"contents": "VIEW CHANGES (🧀 has been moved)"
"contents": "[GitLens views](command:gitlens.showSettingsPage%23views) have moved to the Source Control side bar.\nRun [GitLens: Set Views Layout](command:gitlens.setViewsLayout \"Changes the GitLens Views Layout\") from the Command Palette to switch to an alternate side bar layout, or drag & drop them."
},
{
"view": "gitlens.views.updates",
"contents": "All [GitLens views](command:gitlens.showSettingsPage%23views) have been moved to the Source Control side bar, by default. You can easily switch between different side bar layouts for GitLens views to best match your workflow, via the [GitLens: Set Views Layout](command:gitlens.setViewsLayout \"Changes the GitLens Views Layout\") command from the Command Palette."
"contents": "★ [Repositories](command:gitlens.showSettingsPage%23repositories-view) — replaced by [Commits](command:gitlens.showSettingsPage%23commits-view), [Branches](command:gitlens.showSettingsPage%23branches-view), [Remotes](command:gitlens.showSettingsPage%23remotes-view), [Stashes](command:gitlens.showSettingsPage%23stashes-view), [Tags](command:gitlens.showSettingsPage%23tags-view), and [Contributors](command:gitlens.showSettingsPage%23contributors-view) views. If you want it back, [click here](command:gitlens.showRepositoriesView)."
},
{
"view": "gitlens.views.updates",
"contents": "The [Repositories](command:gitlens.showSettingsPage%23repositories-view) view has been superseded by many new views: [Commits](command:gitlens.showSettingsPage%23commits-view), [Branches](command:gitlens.showSettingsPage%23branches-view), [Remotes](command:gitlens.showSettingsPage%23remotes-view), [Stashes](command:gitlens.showSettingsPage%23stashes-view), [Tags](command:gitlens.showSettingsPage%23tags-view), and [Contributors](command:gitlens.showSettingsPage%23contributors-view). Although, if you want to continue using the Repositories view, you can [click here](command:gitlens.showRepositoriesView) to re-enable it."
"contents": "★ [File History](command:gitlens.showSettingsPage%23file-history-view) — combines file and line history into a single view"
},
{
"view": "gitlens.views.updates",
"contents": "The Line History view has been integrated directly into the [File History](command:gitlens.showSettingsPage%23file-history-view) view."
"contents": "★ [Search & Compare](command:gitlens.showSettingsPage%23search-compare-view) — combines Search Commits and Compare Commits into a single view"
},
{
"view": "gitlens.views.updates",
"contents": "The Search Commits and Compare Commits views have been combined into a more powerful and user-friendly [Search & Compare](command:gitlens.showSettingsPage%23search-compare-view) view."
"contents": "[Close](command:gitlens.closeUpdatesView)"
}
],
"views": {
"gitlens": [
{
"id": "gitlens.views.updates",
"name": "What's New in GitLens 11",
"when": "config.gitlens.views.updates.enabled",
"name": "Where did my views go?",
"when": "gitlens:views:updates:visible != false",
"contextualTitle": "GitLens",
"icon": "images/gitlens-activitybar.svg"
},
{
"id": "gitlens.views.welcome",
"name": "Welcome",
"when": "config.gitlens.views.welcome.enabled",
"when": "gitlens:views:welcome:visible != false",
"contextualTitle": "GitLens",
"icon": "images/gitlens-activitybar.svg"
}
Expand Down
6 changes: 3 additions & 3 deletions src/annotations/annotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
window,
} from 'vscode';
import { FileAnnotationType } from '../configuration';
import { CommandContext, setCommandContext } from '../constants';
import { ContextKeys, setContext } from '../constants';
import { Logger } from '../logger';
import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker';

Expand Down Expand Up @@ -90,7 +90,7 @@ export abstract class AnnotationProviderBase implements Disposable {

this.status = AnnotationStatus.Computing;
if (editor === window.activeTextEditor) {
await setCommandContext(CommandContext.AnnotationStatus, this.status);
await setContext(ContextKeys.AnnotationStatus, this.status);
}

this.editor = editor;
Expand All @@ -105,7 +105,7 @@ export abstract class AnnotationProviderBase implements Disposable {

this.status = AnnotationStatus.Computed;
if (editor === window.activeTextEditor) {
await setCommandContext(CommandContext.AnnotationStatus, this.status);
await setContext(ContextKeys.AnnotationStatus, this.status);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/annotations/fileAnnotationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
configuration,
FileAnnotationType,
} from '../configuration';
import { CommandContext, isTextEditor, setCommandContext } from '../constants';
import { ContextKeys, isTextEditor, setContext } from '../constants';
import { Container } from '../container';
import { GutterBlameAnnotationProvider } from './gutterBlameAnnotationProvider';
import { GutterChangesAnnotationProvider } from './gutterChangesAnnotationProvider';
Expand Down Expand Up @@ -238,10 +238,10 @@ export class FileAnnotationController implements Disposable {

const provider = this.getProvider(editor);
if (provider == null) {
void setCommandContext(CommandContext.AnnotationStatus, undefined);
void setContext(ContextKeys.AnnotationStatus, undefined);
void this.detachKeyboardHook();
} else {
void setCommandContext(CommandContext.AnnotationStatus, provider.status);
void setContext(ContextKeys.AnnotationStatus, provider.status);
void this.attachKeyboardHook();
}
}
Expand Down Expand Up @@ -385,7 +385,7 @@ export class FileAnnotationController implements Disposable {
const provider = await window.withProgress(
{ location: ProgressLocation.Window },
async (progress: Progress<{ message: string }>) => {
await setCommandContext(CommandContext.AnnotationStatus, AnnotationStatus.Computing);
await setContext(ContextKeys.AnnotationStatus, AnnotationStatus.Computing);

const computingAnnotations = this.showAnnotationsCore(
currentProvider,
Expand All @@ -397,7 +397,7 @@ export class FileAnnotationController implements Disposable {
const provider = await computingAnnotations;

if (editor === this._editor) {
await setCommandContext(CommandContext.AnnotationStatus, provider?.status);
await setContext(ContextKeys.AnnotationStatus, provider?.status);
}

return computingAnnotations;
Expand Down Expand Up @@ -465,7 +465,7 @@ export class FileAnnotationController implements Disposable {
provider.dispose();

if (this._annotationProviders.size === 0 || key === AnnotationProviderBase.getCorrelationKey(this._editor)) {
await setCommandContext(CommandContext.AnnotationStatus, undefined);
await setContext(ContextKeys.AnnotationStatus, undefined);
await this.detachKeyboardHook();
}

Expand Down
4 changes: 2 additions & 2 deletions src/codelens/codeLensController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
import { ConfigurationChangeEvent, Disposable, languages } from 'vscode';
import { configuration } from '../configuration';
import { CommandContext, setCommandContext } from '../constants';
import { ContextKeys, setContext } from '../constants';
import { Container } from '../container';
import { Logger } from '../logger';
import {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class GitCodeLensController implements Disposable {
}

this._canToggle = cfg.recentChange.enabled || cfg.authors.enabled;
void setCommandContext(CommandContext.CanToggleCodeLens, this._canToggle);
void setContext(ContextKeys.CanToggleCodeLens, this._canToggle);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/commands/closeView.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
import { configuration } from '../configuration';
import { command, Command, CommandContext, Commands } from './common';
import { ContextKeys, GlobalState, setContext } from '../constants';
import { Container } from '../container';

@command()
export class CloseViewCommand extends Command {
Expand All @@ -15,10 +16,12 @@ export class CloseViewCommand extends Command {
async execute(command: Commands) {
switch (command) {
case Commands.CloseWelcomeView:
void (await configuration.updateEffective('views', 'welcome', 'enabled', false));
await Container.context.globalState.update(GlobalState.WelcomeViewVisible, false);
await setContext(ContextKeys.ViewsWelcomeVisible, false);
break;
case Commands.CloseUpdatesView:
void (await configuration.updateEffective('views', 'updates', 'enabled', false));
await Container.context.globalState.update(GlobalState.UpdatesViewVisible, false);
await setContext(ContextKeys.ViewsUpdatesVisible, false);
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/commands/showView.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
import { commands } from 'vscode';
import { command, Command, CommandContext, Commands } from './common';
import { configuration } from '../configuration';
import { ContextKeys, GlobalState, setContext } from '../constants';
import { Container } from '../container';
import { command, Command, CommandContext, Commands } from './common';

@command()
export class ShowViewCommand extends Command {
Expand Down Expand Up @@ -55,9 +56,8 @@ export class ShowViewCommand extends Command {
case Commands.ShowTagsView:
return Container.tagsView.show();
case Commands.ShowWelcomeView:
if (!Container.config.views.welcome.enabled) {
await configuration.updateEffective('views', 'welcome', 'enabled', true);
}
await setContext(ContextKeys.ViewsWelcomeVisible, true);
void Container.context.globalState.update(GlobalState.WelcomeViewVisible, true);
void (await commands.executeCommand('gitlens.views.welcome.focus'));
}

Expand Down
10 changes: 0 additions & 10 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ interface ViewsConfigs {
searchAndCompare: SearchAndCompareViewConfig;
stashes: StashesViewConfig;
tags: TagsViewConfig;
updates: UpdatesViewConfig;
welcome: WelcomeViewConfig;
}

export type ViewsConfigKeys = keyof ViewsConfigs;
Expand Down Expand Up @@ -556,14 +554,6 @@ export interface TagsViewConfig {
files: ViewsFilesConfig;
}

export interface UpdatesViewConfig {
enabled: boolean;
}

export interface WelcomeViewConfig {
enabled: boolean;
}

export interface ViewsFilesConfig {
compact: boolean;
layout: ViewFilesLayout;
Expand Down
8 changes: 6 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export enum BuiltInCommands {
ShowReferences = 'editor.action.showReferences',
}

export enum CommandContext {
export enum ContextKeys {
ActiveFileStatus = 'gitlens:activeFileStatus',
AnnotationStatus = 'gitlens:annotationStatus',
CanToggleCodeLens = 'gitlens:canToggleCodeLens',
Expand All @@ -49,10 +49,12 @@ export enum CommandContext {
ViewsLineHistoryEditorFollowing = 'gitlens:views:lineHistory:editorFollowing',
ViewsRepositoriesAutoRefresh = 'gitlens:views:repositories:autoRefresh',
ViewsSearchAndCompareKeepResults = 'gitlens:views:searchAndCompare:keepResults',
ViewsUpdatesVisible = 'gitlens:views:updates:visible',
ViewsWelcomeVisible = 'gitlens:views:welcome:visible',
Vsls = 'gitlens:vsls',
}

export function setCommandContext(key: CommandContext | string, value: any) {
export function setContext(key: ContextKeys | string, value: any) {
return commands.executeCommand(BuiltInCommands.SetContext, key, value);
}

Expand Down Expand Up @@ -135,6 +137,8 @@ export enum GlobalState {
Avatars = 'gitlens:avatars',
DisallowConnectionPrefix = 'gitlens:disallow:connection:',
Version = 'gitlensVersion',
UpdatesViewVisible = 'gitlens:views:updates:visible',
WelcomeViewVisible = 'gitlens:views:welcome:visible',
}

export const ImageMimetypes: Record<string, string> = {
Expand Down
45 changes: 25 additions & 20 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { commands, ExtensionContext, extensions, window, workspace } from 'vscod
import { Commands, registerCommands } from './commands';
import { ViewShowBranchComparison } from './config';
import { configuration, Configuration } from './configuration';
import { CommandContext, extensionQualifiedId, GlobalState, GlyphChars, setCommandContext } from './constants';
import { ContextKeys, extensionQualifiedId, GlobalState, GlyphChars, setContext } from './constants';
import { Container } from './container';
import { Git, GitCommit } from './git/git';
import { GitService } from './git/gitService';
Expand All @@ -17,7 +17,24 @@ export async function activate(context: ExtensionContext) {
const start = process.hrtime();

// Pretend we are enabled (until we know otherwise) and set the view contexts to reduce flashing on load
void setCommandContext(CommandContext.Enabled, true);
void setContext(ContextKeys.Enabled, true);

const previousVersion = context.globalState.get<string>(GlobalState.Version);

if (previousVersion == null) {
void context.globalState.update(GlobalState.WelcomeViewVisible, true);
void setContext(ContextKeys.ViewsWelcomeVisible, true);
void setContext(ContextKeys.ViewsUpdatesVisible, false);
} else {
void setContext(
ContextKeys.ViewsWelcomeVisible,
context.globalState.get(GlobalState.WelcomeViewVisible) ?? false,
);
void setContext(
ContextKeys.ViewsUpdatesVisible,
context.globalState.get(GlobalState.UpdatesViewVisible) !== false,
);
}

Logger.configure(context, configuration.get('outputLevel'), o => {
if (GitUri.is(o)) {
Expand All @@ -43,8 +60,8 @@ export async function activate(context: ExtensionContext) {
const enabled = workspace.getConfiguration('git', null).get<boolean>('enabled', true);
if (!enabled) {
Logger.log(`GitLens (v${gitlensVersion}) was NOT activated -- "git.enabled": false`);
void setCommandContext(CommandContext.Enabled, false);
void setCommandContext(CommandContext.Disabled, true);
void setContext(ContextKeys.Enabled, false);
void setContext(ContextKeys.Disabled, true);

void Messages.showGitDisabledErrorMessage();

Expand All @@ -55,14 +72,13 @@ export async function activate(context: ExtensionContext) {

const cfg = configuration.get();

const previousVersion = context.globalState.get<string>(GlobalState.Version);
await migrateSettings(context, previousVersion);

try {
await GitService.initialize();
} catch (ex) {
Logger.error(ex, `GitLens (v${gitlensVersion}) activate`);
void setCommandContext(CommandContext.Enabled, false);
void setContext(ContextKeys.Enabled, false);

const msg: string = ex?.message ?? '';
if (msg.includes('Unable to find git')) {
Expand Down Expand Up @@ -155,7 +171,7 @@ function notifyOnUnsupportedGitVersion(version: string) {
}

async function showWelcomeOrWhatsNew(version: string, previousVersion: string | undefined) {
if (previousVersion === undefined) {
if (previousVersion == null) {
Logger.log('GitLens first-time install');
await commands.executeCommand(Commands.ShowWelcomePage);

Expand All @@ -177,18 +193,7 @@ async function showWelcomeOrWhatsNew(version: string, previousVersion: string |
return;
}

if (major !== prevMajor) {
if (Container.config.showWhatsNewAfterUpgrades && Container.config.views.welcome.enabled) {
await commands.executeCommand(Commands.ShowWelcomeView);
}

// if (Container.config.showWhatsNewAfterUpgrades) {
// await Messages.showWhatsNewMessage(version);
// }

// // Show a views upgrade notification
// if (major === 11) {
// await Messages.showViewsUpgradeMessage();
// }
if (major !== prevMajor && Container.config.showWhatsNewAfterUpgrades) {
await Messages.showWhatsNewMessage(version);
}
}

0 comments on commit 81d5137

Please sign in to comment.