Browse Source

Adds settings scoping

main
Eric Amodio 7 years ago
parent
commit
9dd554ba8c
5 changed files with 152 additions and 69 deletions
  1. +38
    -10
      src/pageProvider.ts
  2. +19
    -0
      src/ui/scss/main.scss
  3. +51
    -45
      src/ui/settings/index.html
  4. +42
    -12
      src/ui/shared/app-base.ts
  5. +2
    -2
      src/ui/welcome/index.html

+ 38
- 10
src/pageProvider.ts View File

@ -1,5 +1,5 @@
'use strict';
import { commands, ConfigurationTarget, Disposable, Event, EventEmitter, TextDocumentContentProvider, Uri, ViewColumn, workspace } from 'vscode';
import { commands, ConfigurationTarget, Disposable, Event, EventEmitter, TextDocument, TextDocumentContentProvider, Uri, ViewColumn, workspace } from 'vscode';
import { Container } from './container';
import { configuration } from './configuration';
import { Logger } from './logger';
@ -15,11 +15,13 @@ export class PageProvider extends Disposable implements TextDocumentContentProvi
}
private readonly _disposable: Disposable;
private _scope: Map<string, 'user' | 'workspace'> = new Map();
constructor() {
super(() => this.dispose());
this._disposable = Disposable.from(
workspace.onDidCloseTextDocument(this.onTextDocumentClosed, this),
workspace.registerTextDocumentContentProvider(settingsUri.scheme, this),
commands.registerCommand('gitlens.showSettingsPage', this.showSettings, this),
commands.registerCommand('gitlens.showWelcomePage', this.showWelcome, this),
@ -31,33 +33,59 @@ export class PageProvider extends Disposable implements TextDocumentContentProvi
this._disposable.dispose();
}
private onTextDocumentClosed(e: TextDocument) {
this._scope.delete(e.uri.toString());
}
async provideTextDocumentContent(uri: Uri): Promise<string> {
const doc = await workspace.openTextDocument(Uri.file(Container.context.asAbsolutePath(`${uri.path}.html`)));
let text = doc.getText().replace(/{{root}}/g, Uri.file(Container.context.asAbsolutePath('.')).toString());
if (text.includes('\'{{config}}\'')) {
text = text.replace(/'{{config}}'/g, JSON.stringify(Container.config));
if (text.includes('\'{{data}}\'')) {
text = text.replace(/'{{data}}'/g, JSON.stringify({
config: Container.config,
scope: this.getScope(uri),
scopes: this.getAvailableScopes(),
uri: uri.toString()
}));
}
return text;
}
refresh(uri?: Uri) {
private getAvailableScopes(): ['user' | 'workspace', string][] {
const scopes: ['user' | 'workspace', string][] = [['user', 'User Settings']];
if (workspace.workspaceFolders !== undefined && workspace.workspaceFolders.length) {
scopes.push(['workspace', 'Workspace Settings']);
}
return scopes;
}
private getScope(uri: Uri): 'user' | 'workspace' {
return this._scope.get(uri.toString()) || 'user';
}
refresh(uri ?: Uri) {
Logger.log('PageProvider.refresh');
this._onDidChange.fire(uri || settingsUri);
}
async save(changes: { [key: string]: any }) {
Logger.log(`PageProvider.save: changes=${JSON.stringify(changes)}`);
async save(options: { changes: { [key: string]: any }, scope: 'user' | 'workspace', uri: string }) {
Logger.log(`PageProvider.save: options=${JSON.stringify(options)}`);
this._scope.set(options.uri, options.scope);
const target = options.scope === 'workspace'
? ConfigurationTarget.Workspace
: ConfigurationTarget.Global;
for (const key in changes) {
for (const key in options.changes) {
const inspect = await configuration.inspect(key)!;
if (inspect.defaultValue === changes[key]) {
await configuration.update(key, undefined, ConfigurationTarget.Global);
if (inspect.defaultValue === options.changes[key]) {
await configuration.update(key, undefined, target);
}
else {
await configuration.update(key, changes[key], ConfigurationTarget.Global);
await configuration.update(key, options.changes[key], target);
}
}
}

+ 19
- 0
src/ui/scss/main.scss View File

@ -72,6 +72,8 @@ header {
}
input, select, button {
font-family: var(--font-family);
font-size: inherit;
margin: 0;
}
@ -401,6 +403,7 @@ ul {
.page-header {
margin: 1em 0 2em 0;
position: relative;
}
.page-header__title {
@ -583,6 +586,22 @@ ul {
margin-left: 7em;
}
.settings-scope {
margin: 1.6em 185px 0 0;
position: absolute;
right: 0;
top: -2px;
white-space: nowrap;
select, option {
background-color: var(--background-color) !important;
}
@media all and (max-width: 860px) {
margin-right: -9px;
}
}
.sidebar-group {
margin-top: 1em;
}

+ 51
- 45
src/ui/settings/index.html View File

@ -33,6 +33,12 @@
<p class="page-header__subtitle">For advanced customizations refer to the <a title="See the GitLens settings docs" href="https://github.com/eamodio/vscode-gitlens/tree/develop#gitlens-settings">GitLens settings docs</a> and edit your
<a class="command" title="Open User Settings" href="command:workbench.action.openGlobalSettings">User Settings</a>
</p>
<div class="settings-scope hidden">
<label for="scopes">Save to</label>
<select id="scopes" name="scope">
</select>
</div>
</div>
<div class="section-groups">
@ -49,13 +55,13 @@
<div class="section__settings">
<div class="settings-group">
<div class="settings-group__setting nowrap">
<input id="gitExplorer.enabled" name="gitExplorer.enabled" type="checkbox" />
<input class="setting" id="gitExplorer.enabled" name="gitExplorer.enabled" type="checkbox" />
<label for="gitExplorer.enabled">Show the GitLens explorer</label>
</div>
<div class="settings-group__setting ml-2" data-enablement="gitExplorer.enabled" disabled>
<label for="gitExplorer.view">When opened, show the</label>
<select id="gitExplorer.view" name="gitExplorer.view" disabled>
<select class="setting" id="gitExplorer.view" name="gitExplorer.view" disabled>
<option value="auto">last selected view</option>
<option value="repository">Repository view</option>
<option value="history">History view</option>
@ -64,7 +70,7 @@
<div class="settings-group__setting ml-2" data-enablement="gitExplorer.enabled" disabled>
<label for="gitExplorer.branches.layout">Layout branches</label>
<select id="gitExplorer.branches.layout" name="gitExplorer.branches.layout" disabled>
<select class="setting" id="gitExplorer.branches.layout" name="gitExplorer.branches.layout" disabled>
<option value="list">as a list</option>
<option value="tree">as a tree</option>
</select>
@ -72,7 +78,7 @@
<div class="settings-group__setting ml-2" data-enablement="gitExplorer.enabled" disabled>
<label for="gitExplorer.files.layout">Layout files</label>
<select id="gitExplorer.files.layout" name="gitExplorer.files.layout" disabled>
<select class="setting" id="gitExplorer.files.layout" name="gitExplorer.files.layout" disabled>
<option value="auto">automatically</option>
<option value="list">as a list</option>
<option value="tree">as a tree</option>
@ -81,18 +87,18 @@
<p class="setting__hint hidden" data-visibility="gitExplorer.files.layout =auto">Chooses the best layout based on the number of files at each nesting level</p>
<div class="settings-group__setting nowrap ml-2" data-enablement="gitExplorer.enabled" disabled>
<input id="gitExplorer.files.compact" name="gitExplorer.files.compact" type="checkbox" disabled />
<input class="setting" id="gitExplorer.files.compact" name="gitExplorer.files.compact" type="checkbox" disabled />
<label for="gitExplorer.files.compact">Use compact layout</label>
</div>
<p class="setting__hint setting__hint--indent-1">Compacts (flattens) unnecessary nesting when using a tree layouts</p>
<div class="settings-group__setting nowrap ml-2" data-enablement="gitExplorer.enabled" disabled>
<input id="gitExplorer.avatars" name="explorers.avatars" type="checkbox" disabled />
<input class="setting" id="gitExplorer.avatars" name="explorers.avatars" type="checkbox" disabled />
<label for="gitExplorer.avatars">Use author avatars icons</label>
</div>
<div class="settings-group__setting nowrap ml-2" data-enablement="gitExplorer.enabled" disabled>
<input id="gitExplorer.autoRefresh" name="gitExplorer.autoRefresh" type="checkbox" disabled />
<input class="setting" id="gitExplorer.autoRefresh" name="gitExplorer.autoRefresh" type="checkbox" disabled />
<label for="gitExplorer.autoRefresh">Automatically refreshes when the file system or any repository changes</label>
</div>
</div>
@ -125,7 +131,7 @@
<div class="settings-group">
<div class="settings-group__setting">
<label for="resultsExplorer.files.layout">Layout files</label>
<select id="resultsExplorer.files.layout" name="resultsExplorer.files.layout">
<select class="setting" id="resultsExplorer.files.layout" name="resultsExplorer.files.layout">
<option value="auto">automatically</option>
<option value="list">as a list</option>
<option value="tree">as a tree</option>
@ -133,13 +139,13 @@
</div>
<div class="settings-group__setting nowrap">
<input id="resultsExplorer.files.compact" name="resultsExplorer.files.compact" type="checkbox" />
<input class="setting" id="resultsExplorer.files.compact" name="resultsExplorer.files.compact" type="checkbox" />
<label for="resultsExplorer.files.compact">Use compact layout</label>
</div>
<p class="setting__hint setting__hint">Compacts (flattens) unnecessary nesting when using a tree layouts</p>
<div class="settings-group__setting nowrap">
<input id="resultsExplorer.avatars" name="explorers.avatars" type="checkbox" />
<input class="setting" id="resultsExplorer.avatars" name="explorers.avatars" type="checkbox" />
<label for="resultsExplorer.avatars">Use author avatars icons</label>
</div>
</div>
@ -169,18 +175,18 @@
<div class="section__settings">
<div class="settings-group">
<div class="settings-group__setting nowrap">
<input id="codeLens.enabled" name="codeLens.enabled" type="checkbox" />
<input class="setting" id="codeLens.enabled" name="codeLens.enabled" type="checkbox" />
<label for="codeLens.enabled">Show the authorship code lenses</label>
</div>
<div class="settings-group__setting nowrap ml-2" data-enablement="codeLens.enabled" disabled>
<input id="codeLens.recentChange.enabled" name="codeLens.recentChange.enabled" type="checkbox" disabled />
<input class="setting" id="codeLens.recentChange.enabled" name="codeLens.recentChange.enabled" type="checkbox" disabled />
<label for="codeLens.recentChange.enabled">Add the author and date of the most recent change for the file or code block</label>
</div>
<div class="settings-group__setting ml-4" data-enablement="codeLens.enabled &amp; codeLens.recentChange.enabled"
disabled>
<label for="codeLens.recentChange.command">When clicked</label>
<select id="codeLens.recentChange.command" name="codeLens.recentChange.command" disabled>
<select class="setting" id="codeLens.recentChange.command" name="codeLens.recentChange.command" disabled>
<option value="gitlens.toggleFileBlame">toggles the file blame annotations</option>
<option value="gitlens.diffWithPrevious">compares the commit with the previous</option>
<option value="gitlens.showQuickCommitDetails">shows details of the commit</option>
@ -191,13 +197,13 @@
</div>
<div class="settings-group__setting nowrap ml-2" data-enablement="codeLens.enabled" disabled>
<input id="codeLens.authors.enabled" name="codeLens.authors.enabled" type="checkbox" disabled />
<input class="setting" id="codeLens.authors.enabled" name="codeLens.authors.enabled" type="checkbox" disabled />
<label for="codeLens.authors.enabled">Add the number of authors and the most prominent author of the file or code block</label>
</div>
<div class="settings-group__setting ml-4" data-enablement="codeLens.enabled &amp; codeLens.authors.enabled"
disabled>
<label for="codeLens.authors.command">When clicked</label>
<select id="codeLens.authors.command" name="codeLens.authors.command" disabled>
<select class="setting" id="codeLens.authors.command" name="codeLens.authors.command" disabled>
<option value="gitlens.toggleFileBlame">toggles the file blame annotations</option>
<option value="gitlens.diffWithPrevious">compares the commit with the previous</option>
<option value="gitlens.showQuickCommitDetails">shows details of the commit</option>
@ -211,15 +217,15 @@
<label class="non-interactive">Add code lens to the following scopes</label>
</div>
<div class="settings-group__setting nowrap ml-4" data-enablement="codeLens.enabled" disabled>
<input id="codeLens.scopes" name="codeLens.scopes" type="checkbox" value="document" data-type="array" disabled />
<input class="setting" id="codeLens.scopes" name="codeLens.scopes" type="checkbox" value="document" data-type="array" disabled />
<label for="codeLens.scopes">File scope &mdash; added at the top of the file</label>
</div>
<div class="settings-group__setting nowrap ml-4" data-enablement="codeLens.enabled" disabled>
<input id="codeLens.scopes-1" name="codeLens.scopes" type="checkbox" value="containers" data-type="array" disabled />
<input class="setting" id="codeLens.scopes-1" name="codeLens.scopes" type="checkbox" value="containers" data-type="array" disabled />
<label for="codeLens.scopes-1">Containers scope &mdash; added at the start of modules, classes, interfaces, etc</label>
</div>
<div class="settings-group__setting nowrap ml-4" data-enablement="codeLens.enabled" disabled>
<input id="codeLens.scopes-2" name="codeLens.scopes" type="checkbox" value="blocks" data-type="array" disabled />
<input class="setting" id="codeLens.scopes-2" name="codeLens.scopes" type="checkbox" value="blocks" data-type="array" disabled />
<label for="codeLens.scopes-2">Block scope &mdash; added at the start of functions, methods, etc</label>
</div>
</div>
@ -260,7 +266,7 @@
<div class="section__settings">
<div class="settings-group">
<div class="settings-group__setting nowrap">
<input id="currentLine.enabled" name="currentLine.enabled" type="checkbox" data-add-settings-off="hovers.currentLine.over=line"
<input class="setting" id="currentLine.enabled" name="currentLine.enabled" type="checkbox" data-add-settings-off="hovers.currentLine.over=line"
/>
<label for="currentLine.enabled">Show a blame annotation at the end of the current line</label>
</div>
@ -293,44 +299,44 @@
<div class="section__settings">
<div class="settings-group">
<div class="settings-group__setting nowrap">
<input id="blame.heatmap.enabled" name="blame.heatmap.enabled" type="checkbox" />
<input class="setting" id="blame.heatmap.enabled" name="blame.heatmap.enabled" type="checkbox" />
<label for="blame.heatmap.enabled">Add a heatmap (age) indicator</label>
</div>
<p class="setting__hint">Quickly tell the age of a line &mdash; indicator ranges from bright yellow (newer) to dark brown (older)</p>
<div class="settings-group__setting ml-2" data-enablement="blame.heatmap.enabled" disabled>
<label for="blame.heatmap.location">Position the heatmap on the</label>
<select id="blame.heatmap.location" name="blame.heatmap.location" disabled>
<select class="setting" id="blame.heatmap.location" name="blame.heatmap.location" disabled>
<option value="left">left</option>
<option value="right">right</option>
</select>
</div>
<div class="settings-group__setting nowrap">
<input id="blame.avatars" name="blame.avatars" type="checkbox" />
<input class="setting" id="blame.avatars" name="blame.avatars" type="checkbox" />
<label for="blame.avatars">Add author avatars in the gutter</label>
</div>
<div class="settings-group__setting nowrap">
<input id="blame.highlight.enabled" name="blame.highlight.enabled" type="checkbox" />
<input class="setting" id="blame.highlight.enabled" name="blame.highlight.enabled" type="checkbox" />
<label for="blame.highlight.enabled">Highlight other lines changed with the current line</label>
</div>
<div class="settings-group__setting nowrap ml-2" data-enablement="blame.highlight.enabled" disabled>
<input id="blame.highlight.locations" name="blame.highlight.locations" type="checkbox" value="gutter" data-type="array" disabled />
<input class="setting" id="blame.highlight.locations" name="blame.highlight.locations" type="checkbox" value="gutter" data-type="array" disabled />
<label for="blame.highlight.locations">Add gutter highlight</label>
</div>
<div class="settings-group__setting nowrap ml-2" data-enablement="blame.highlight.enabled" disabled>
<input id="blame.highlight.locations-1" name="blame.highlight.locations" type="checkbox" value="line" data-type="array" disabled />
<input class="setting" id="blame.highlight.locations-1" name="blame.highlight.locations" type="checkbox" value="line" data-type="array" disabled />
<label for="blame.highlight.locations-1">Add line highlight</label>
</div>
<div class="settings-group__setting nowrap ml-2" data-enablement="blame.highlight.enabled" disabled>
<input id="blame.highlight.locations-2" name="blame.highlight.locations" type="checkbox" value="overviewRuler" data-type="array" disabled />
<input class="setting" id="blame.highlight.locations-2" name="blame.highlight.locations" type="checkbox" value="overviewRuler" data-type="array" disabled />
<label for="blame.highlight.locations-2">Add scroll bar highlight</label>
</div>
<div class="settings-group__setting nowrap">
<input id="blame.compact" name="blame.compact" type="checkbox" />
<input class="setting" id="blame.compact" name="blame.compact" type="checkbox" />
<label for="blame.compact">Use compact view</label>
</div>
<p class="setting__hint">Compacts (deduplicates) matching adjacent blame annotations</p>
@ -369,26 +375,26 @@
<div class="settings-group">
<div class="settings-group__setting">
<div class="settings-group__setting nowrap">
<input id="hovers.enabled" name="hovers.enabled" type="checkbox" />
<input class="setting" id="hovers.enabled" name="hovers.enabled" type="checkbox" />
<label for="hovers.enabled">Show blame hovers</label>
</div>
</div>
<div class="settings-group__setting">
<div class="settings-group__setting nowrap ml-2 hidden" data-visibility="currentLine.enabled" data-enablement="hovers.enabled"
disabled>
<input id="hovers.currentLine.enabled" name="hovers.currentLine.enabled" type="checkbox" disabled />
<input class="setting" id="hovers.currentLine.enabled" name="hovers.currentLine.enabled" type="checkbox" disabled />
<label for="hovers.currentLine.enabled">Show hovers for the current line</label>
</div>
<div class="settings-group__setting nowrap ml-2 hidden" data-visibility="currentLine.enabled =false"
data-enablement="hovers.enabled" disabled>
<input id="hovers.currentLine.enabled-1" name="hovers.currentLine.enabled" type="checkbox" data-add-settings-on="hovers.currentLine.over=line" disabled
<input class="setting" id="hovers.currentLine.enabled-1" name="hovers.currentLine.enabled" type="checkbox" data-add-settings-on="hovers.currentLine.over=line" disabled
/>
<label for="hovers.currentLine.enabled-1">Show hovers for the current line</label>
</div>
<div class="settings-group__setting ml-4 hidden" data-visibility="currentLine.enabled" data-enablement="hovers.enabled &amp; hovers.currentLine.enabled"
disabled>
<label for="hovers.currentLine.over">Shown when over the</label>
<select id="hovers.currentLine.over" name="hovers.currentLine.over" disabled>
<select class="setting" id="hovers.currentLine.over" name="hovers.currentLine.over" disabled>
<option value="annotation">annotation only</option>
<option value="line">line &amp; annotation</option>
</select>
@ -396,12 +402,12 @@
<div class="settings-group__setting nowrap ml-4" data-enablement="hovers.enabled &amp; hovers.currentLine.enabled"
disabled>
<input id="hovers.currentLine.details" name="hovers.currentLine.details" type="checkbox" disabled />
<input class="setting" id="hovers.currentLine.details" name="hovers.currentLine.details" type="checkbox" disabled />
<label for="hovers.currentLine.details">Add blame details</label>
</div>
<div class="settings-group__setting nowrap ml-4" data-enablement="hovers.enabled &amp; hovers.currentLine.enabled"
disabled>
<input id="hovers.currentLine.changes" name="hovers.currentLine.changes" type="checkbox" disabled />
<input class="setting" id="hovers.currentLine.changes" name="hovers.currentLine.changes" type="checkbox" disabled />
<label for="hovers.currentLine.changes">Add changes (diff)</label>
</div>
</div>
@ -425,12 +431,12 @@
<div class="settings-group">
<div class="settings-group__setting">
<div class="settings-group__setting nowrap ml-2" data-enablement="hovers.enabled" disabled>
<input id="hovers.annotations.enabled" name="hovers.annotations.enabled" type="checkbox" disabled />
<input class="setting" id="hovers.annotations.enabled" name="hovers.annotations.enabled" type="checkbox" disabled />
<label for="hovers.annotations.enabled">Show hovers while annotating</label>
</div>
<div class="settings-group__setting nowrap ml-4" data-enablement="hovers.enabled &amp; hovers.annotations.enabled" disabled>
<label for="hovers.annotations.over">Shown when over the</label>
<select id="hovers.annotations.over" name="hovers.annotations.over" disabled>
<select class="setting" id="hovers.annotations.over" name="hovers.annotations.over" disabled>
<option value="annotation">annotation only</option>
<option value="line">line &amp; annotation</option>
</select>
@ -438,12 +444,12 @@
<div class="settings-group__setting nowrap ml-4" data-enablement="hovers.enabled &amp; hovers.annotations.enabled"
disabled>
<input id="hovers.annotations.details" name="hovers.annotations.details" type="checkbox" disabled />
<input class="setting" id="hovers.annotations.details" name="hovers.annotations.details" type="checkbox" disabled />
<label for="hovers.annotations.details">Add blame details</label>
</div>
<div class="settings-group__setting nowrap ml-4" data-enablement="hovers.enabled &amp; hovers.annotations.enabled"
disabled>
<input id="hovers.annotations.changes" name="hovers.annotations.changes" type="checkbox" disabled />
<input class="setting" id="hovers.annotations.changes" name="hovers.annotations.changes" type="checkbox" disabled />
<label for="hovers.annotations.changes">Add changes (diff)</label>
</div>
</div>
@ -471,15 +477,15 @@
<div class="section__settings">
<div class="settings-group">
<div class="settings-group__setting nowrap">
<input id="recentChanges.highlight.locations" name="recentChanges.highlight.locations" type="checkbox" value="gutter" data-type="array" />
<input class="setting" id="recentChanges.highlight.locations" name="recentChanges.highlight.locations" type="checkbox" value="gutter" data-type="array" />
<label for="recentChanges.highlight.locations">Add gutter highlight</label>
</div>
<div class="settings-group__setting nowrap">
<input id="recentChanges.highlight.locations-1" name="recentChanges.highlight.locations" type="checkbox" value="line" data-type="array" />
<input class="setting" id="recentChanges.highlight.locations-1" name="recentChanges.highlight.locations" type="checkbox" value="line" data-type="array" />
<label for="recentChanges.highlight.locations-1">Add line highlight</label>
</div>
<div class="settings-group__setting nowrap">
<input id="recentChanges.highlight.locations-2" name="recentChanges.highlight.locations" type="checkbox" value="overviewRuler" data-type="array" />
<input class="setting" id="recentChanges.highlight.locations-2" name="recentChanges.highlight.locations" type="checkbox" value="overviewRuler" data-type="array" />
<label for="recentChanges.highlight.locations-2">Add scroll bar highlight</label>
</div>
</div>
@ -512,19 +518,19 @@
<div class="section__settings">
<div class="settings-group">
<div class="settings-group__setting nowrap">
<input id="statusBar.enabled" name="statusBar.enabled" type="checkbox" />
<input class="setting" id="statusBar.enabled" name="statusBar.enabled" type="checkbox" />
<label for="statusBar.enabled">Show a Git blame annotation for the current line in the status bar</label>
</div>
<div class="settings-group__setting ml-2" data-enablement="statusBar.enabled" disabled>
<label for="statusBar.alignment">Position the annotation on the</label>
<select id="statusBar.alignment" name="statusBar.alignment" disabled>
<select class="setting" id="statusBar.alignment" name="statusBar.alignment" disabled>
<option value="left">left</option>
<option value="right">right</option>
</select>
</div>
<div class="settings-group__setting ml-2" data-enablement="statusBar.enabled" disabled>
<label for="statusBar.command">When clicked</label>
<select id="statusBar.command" name="statusBar.command" disabled>
<select class="setting" id="statusBar.command" name="statusBar.command" disabled>
<option value="gitlens.toggleFileBlame">toggles the file blame annotations</option>
<option value="gitlens.diffWithPrevious">compares the line revision with the previous</option>
<option value="gitlens.diffWithWorking">compares the line revision with the working file</option>
@ -564,7 +570,7 @@
<div class="section__settings">
<div class="settings-group">
<label for="keymap">Use</label>
<select id="keymap" name="keymap">
<select class="setting" id="keymap" name="keymap">
<option value="standard">the default set of</option>
<option value="chorded">a chorded set of</option>
<option value="none">a custom set of</option>
@ -655,7 +661,7 @@
<a id="commandRelay" style="display: none"></a>
<script type="text/javascript">
window.gitlens = { config: '{{config}}' };
window.gitlens = '{{data}}';
</script>
</body>

+ 42
- 12
src/ui/shared/app-base.ts View File

@ -3,18 +3,36 @@ import { DOM } from './../shared/dom';
import { initializeColorPalette } from '../shared/colors';
import { IConfig } from './../config';
const config: IConfig = (window as any).gitlens.config;
const gitlens: { config: IConfig, scope: 'user' | 'workspace', scopes: ['user' | 'workspace', string][], uri: string } = (window as any).gitlens;
export abstract class App {
private readonly _commandRelay: HTMLAnchorElement;
private readonly _changes: { [key: string]: any } = Object.create(null);
private readonly _scopes: HTMLSelectElement | null = null;
constructor(private _appName: string) {
this.log(`${this._appName}.ctor`);
this._commandRelay = DOM.getElementById<HTMLAnchorElement>('commandRelay');
// Add scopes if available
const scopes = DOM.getElementById<HTMLSelectElement>('scopes');
if (scopes && gitlens.scopes.length > 1) {
for (const [scope, text] of gitlens.scopes) {
const option = document.createElement('option');
option.value = scope;
option.innerHTML = text;
if (gitlens.scope === scope) {
option.selected = true;
}
scopes.appendChild(option);
}
scopes.parentElement!.classList.remove('hidden');
this._scopes = scopes;
}
initializeColorPalette();
this.initialize();
this.bind();
@ -23,32 +41,32 @@ export abstract class App {
protected initialize() {
this.log(`${this._appName}.initializeState`);
for (const el of document.querySelectorAll<HTMLInputElement>('input[type="checkbox"]')) {
for (const el of document.querySelectorAll<HTMLInputElement>('input[type="checkbox"].setting')) {
const checked = el.dataset.type === 'array'
? (getSettingValue<string[]>(el.name) || []).includes(el.value)
: getSettingValue<boolean>(el.name) || false;
el.checked = checked;
}
for (const el of document.querySelectorAll<HTMLSelectElement>('select')) {
for (const el of document.querySelectorAll<HTMLSelectElement>('select.setting')) {
const value = getSettingValue<string>(el.name);
const input = el.querySelector<HTMLOptionElement>(`option[value='${value}']`);
if (input != null) {
input.selected = true;
const option = el.querySelector<HTMLOptionElement>(`option[value='${value}']`);
if (option != null) {
option.selected = true;
}
}
const state = flatten(config);
const state = flatten(gitlens.config);
this.setVisibility(state);
this.setEnablement(state);
}
protected bind() {
const onInputChecked = this.onInputChecked.bind(this);
DOM.listenAll('input[type="checkbox"],input[type="radio"]', 'change', function(this: HTMLInputElement) { onInputChecked(this); });
DOM.listenAll('input[type="checkbox"].setting', 'change', function(this: HTMLInputElement) { onInputChecked(this); });
const onInputSelected = this.onInputSelected.bind(this);
DOM.listenAll('select', 'change', function(this: HTMLInputElement) { onInputSelected(this); });
DOM.listenAll('select.setting', 'change', function(this: HTMLInputElement) { onInputSelected(this); });
}
protected log(message: string) {
@ -89,6 +107,8 @@ export abstract class App {
}
private onInputSelected(element: HTMLSelectElement) {
if (element === this._scopes) return;
const value = element.options[element.selectedIndex].value;
this.log(`${this._appName}.onInputSelected: name=${element.name}, value=${value}`);
@ -99,8 +119,12 @@ export abstract class App {
}
private applyChanges() {
const args = JSON.stringify(this._changes);
this.log(`${this._appName}.applyChanges: changes=${args}`);
const args = JSON.stringify({
changes: this._changes,
scope: this.getScope(),
uri: gitlens.uri
});
this.log(`${this._appName}.applyChanges: args=${args}`);
const command = 'command:gitlens.saveSettings?' + encodeURI(args);
setTimeout(() => this.executeCommand(command), 0);
@ -115,6 +139,12 @@ export abstract class App {
this._commandRelay.click();
}
private getScope(): 'user' | 'workspace' {
return this._scopes != null
? this._scopes.options[this._scopes.selectedIndex].value as 'user' | 'workspace'
: 'user';
}
private setAdditionalSettings(expression: string | undefined) {
if (!expression) return;
@ -200,7 +230,7 @@ function get(o: { [key: string ]: any}, path: string): T | undefined {
}
function getSettingValue<T>(path: string): T | undefined {
return get<T>(config, path);
return get<T>(gitlens.config, path);
}
function parseAdditionalSettingsExpression(expression: string): [string, string | boolean][] {

+ 2
- 2
src/ui/welcome/index.html View File

@ -45,7 +45,7 @@
</p>
<div class="settings-group__setting nowrap ml-1">
<input id="showWhatsNewAfterUpgrades" name="showWhatsNewAfterUpgrades" type="checkbox" />
<input class="setting" id="showWhatsNewAfterUpgrades" name="showWhatsNewAfterUpgrades" type="checkbox" />
<label for="showWhatsNewAfterUpgrades">Show What's New after upgrading to new feature releases</label>
</div>
</section>
@ -199,7 +199,7 @@
</div>
<a id="commandRelay" style="display: none"></a>
<script type="text/javascript">
window.gitlens = { config: '{{config}}' };
window.gitlens = '{{data}}';
</script>
</body>

Loading…
Cancel
Save