Closes #150 - adds auto view to custom view

This commit is contained in:
Eric Amodio
2017-09-22 00:48:57 -04:00
parent 65736a6ce7
commit 0eb202b8ae
6 changed files with 49 additions and 24 deletions

View File

@@ -109,7 +109,12 @@ export const GlyphChars = {
ZeroWidthSpace: '\u200b' as GlyphChars
};
export type WorkspaceState = 'gitlensVersion';
export type GlobalState = 'gitlensVersion';
export const GlobalState = {
GitLensVersion: 'gitlensVersion' as GlobalState
};
export type WorkspaceState = 'gitlens:gitExplorer:view';
export const WorkspaceState = {
GitLensVersion: 'gitlensVersion' as WorkspaceState
GitExplorerView: 'gitlens:gitExplorer:view' as WorkspaceState
};

View File

@@ -16,7 +16,7 @@ import { ShowQuickRepoStatusCommand, ShowQuickStashListCommand } from './command
import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands';
import { ToggleCodeLensCommand } from './commands';
import { CodeLensLocations, IConfig, LineHighlightLocations } from './configuration';
import { ApplicationInsightsKey, CommandContext, ExtensionKey, QualifiedExtensionId, setCommandContext, WorkspaceState } from './constants';
import { ApplicationInsightsKey, CommandContext, ExtensionKey, GlobalState, QualifiedExtensionId, setCommandContext } from './constants';
import { CodeLensController } from './codeLensController';
import { CurrentLineController, LineAnnotationType } from './currentLineController';
import { RemoteProviderFactory } from './git/remotes/factory';
@@ -71,7 +71,7 @@ export async function activate(context: ExtensionContext) {
notifyOnUnsupportedGitVersion(context, gitVersion);
notifyOnNewGitLensVersion(context, gitlensVersion);
await context.globalState.update(WorkspaceState.GitLensVersion, gitlensVersion);
await context.globalState.update(GlobalState.GitLensVersion, gitlensVersion);
const git = new GitService(repoPath);
context.subscriptions.push(git);
@@ -148,7 +148,7 @@ export async function activate(context: ExtensionContext) {
export function deactivate() { }
async function migrateSettings(context: ExtensionContext) {
const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion);
const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
if (previousVersion === undefined) return;
const [major] = previousVersion.split('.');
@@ -274,7 +274,7 @@ async function migrateSettings(context: ExtensionContext) {
async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) {
if (context.globalState.get(SuppressedKeys.UpdateNotice, false)) return;
const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion);
const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
if (previousVersion === undefined) {
Logger.log(`GitLens first-time install`);

View File

@@ -4,16 +4,18 @@ import { commands, Event, EventEmitter, ExtensionContext, TextDocumentShowOption
import { Commands, DiffWithCommandArgs, DiffWithCommandArgsRevision, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
import { UriComparer } from '../comparers';
import { ExtensionKey, IConfig } from '../configuration';
import { CommandContext, setCommandContext } from '../constants';
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
import { GitService, GitUri, RepoChangedReasons } from '../gitService';
export * from './explorerNodes';
export type GitExplorerView =
'auto' |
'history' |
'repository';
export const GitExplorerView = {
Auto: 'auto' as GitExplorerView,
History: 'history' as GitExplorerView,
Repository: 'repository' as GitExplorerView
};
@@ -31,7 +33,7 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
private _config: IConfig;
private _root?: ExplorerNode;
private _view: GitExplorerView = GitExplorerView.Repository;
private _view: GitExplorerView | undefined;
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
public get onDidChangeTreeData(): Event<ExplorerNode> {
@@ -62,10 +64,6 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
context.subscriptions.push(workspace.onDidChangeConfiguration(this.onConfigurationChanged, this));
this.onConfigurationChanged();
this._view = this._config.gitExplorer.view;
setCommandContext(CommandContext.GitExplorerView, this._view);
this._root = this.getRootNode();
}
async getTreeItem(node: ExplorerNode): Promise<TreeItem> {
@@ -116,16 +114,25 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
private onConfigurationChanged() {
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
let changed = false;
if (!Objects.areEquivalent(cfg.gitExplorer, this._config && this._config.gitExplorer) ||
!Objects.areEquivalent(cfg.insiders, this._config && this._config.insiders)) {
setTimeout(() => {
this._root = this.getRootNode(window.activeTextEditor);
this.refresh();
}, 1);
changed = true;
}
this._config = cfg;
}
if (changed) {
let view = cfg.gitExplorer.view;
if (view === GitExplorerView.Auto) {
view = this.context.workspaceState.get<GitExplorerView>(WorkspaceState.GitExplorerView, GitExplorerView.Repository);
}
this.setView(view);
this._root = this.getRootNode(window.activeTextEditor);
this.refresh();
}
}
private onRepoChanged(reasons: RepoChangedReasons[]) {
if (this._view !== GitExplorerView.Repository) return;
@@ -149,11 +156,21 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
this.refresh(node);
}
switchTo(view: GitExplorerView) {
setView(view: GitExplorerView) {
if (this._view === view) return;
if (this._config.gitExplorer.view === GitExplorerView.Auto) {
this.context.workspaceState.update(WorkspaceState.GitExplorerView, view);
}
this._view = view;
setCommandContext(CommandContext.GitExplorerView, this._view);
}
switchTo(view: GitExplorerView) {
if (this._view === view) return;
this.setView(view);
this._root = this.getRootNode(window.activeTextEditor);
this.refresh();