Skip to content

Commit 9dd554b

Browse files
committed
Adds settings scoping
1 parent 3a6a00a commit 9dd554b

File tree

5 files changed

+152
-69
lines changed

5 files changed

+152
-69
lines changed

src/pageProvider.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { commands, ConfigurationTarget, Disposable, Event, EventEmitter, TextDocumentContentProvider, Uri, ViewColumn, workspace } from 'vscode';
2+
import { commands, ConfigurationTarget, Disposable, Event, EventEmitter, TextDocument, TextDocumentContentProvider, Uri, ViewColumn, workspace } from 'vscode';
33
import { Container } from './container';
44
import { configuration } from './configuration';
55
import { Logger } from './logger';
@@ -15,11 +15,13 @@ export class PageProvider extends Disposable implements TextDocumentContentProvi
1515
}
1616

1717
private readonly _disposable: Disposable;
18+
private _scope: Map<string, 'user' | 'workspace'> = new Map();
1819

1920
constructor() {
2021
super(() => this.dispose());
2122

2223
this._disposable = Disposable.from(
24+
workspace.onDidCloseTextDocument(this.onTextDocumentClosed, this),
2325
workspace.registerTextDocumentContentProvider(settingsUri.scheme, this),
2426
commands.registerCommand('gitlens.showSettingsPage', this.showSettings, this),
2527
commands.registerCommand('gitlens.showWelcomePage', this.showWelcome, this),
@@ -31,33 +33,59 @@ export class PageProvider extends Disposable implements TextDocumentContentProvi
3133
this._disposable.dispose();
3234
}
3335

36+
private onTextDocumentClosed(e: TextDocument) {
37+
this._scope.delete(e.uri.toString());
38+
}
39+
3440
async provideTextDocumentContent(uri: Uri): Promise<string> {
3541
const doc = await workspace.openTextDocument(Uri.file(Container.context.asAbsolutePath(`${uri.path}.html`)));
3642

3743
let text = doc.getText().replace(/{{root}}/g, Uri.file(Container.context.asAbsolutePath('.')).toString());
38-
if (text.includes('\'{{config}}\'')) {
39-
text = text.replace(/'{{config}}'/g, JSON.stringify(Container.config));
44+
if (text.includes('\'{{data}}\'')) {
45+
text = text.replace(/'{{data}}'/g, JSON.stringify({
46+
config: Container.config,
47+
scope: this.getScope(uri),
48+
scopes: this.getAvailableScopes(),
49+
uri: uri.toString()
50+
}));
4051
}
4152

4253
return text;
4354
}
4455

45-
refresh(uri?: Uri) {
56+
private getAvailableScopes(): ['user' | 'workspace', string][] {
57+
const scopes: ['user' | 'workspace', string][] = [['user', 'User Settings']];
58+
if (workspace.workspaceFolders !== undefined && workspace.workspaceFolders.length) {
59+
scopes.push(['workspace', 'Workspace Settings']);
60+
}
61+
return scopes;
62+
}
63+
64+
private getScope(uri: Uri): 'user' | 'workspace' {
65+
return this._scope.get(uri.toString()) || 'user';
66+
}
67+
68+
refresh(uri ?: Uri) {
4669
Logger.log('PageProvider.refresh');
4770

4871
this._onDidChange.fire(uri || settingsUri);
4972
}
5073

51-
async save(changes: { [key: string]: any }) {
52-
Logger.log(`PageProvider.save: changes=${JSON.stringify(changes)}`);
74+
async save(options: { changes: { [key: string]: any }, scope: 'user' | 'workspace', uri: string }) {
75+
Logger.log(`PageProvider.save: options=${JSON.stringify(options)}`);
76+
77+
this._scope.set(options.uri, options.scope);
78+
const target = options.scope === 'workspace'
79+
? ConfigurationTarget.Workspace
80+
: ConfigurationTarget.Global;
5381

54-
for (const key in changes) {
82+
for (const key in options.changes) {
5583
const inspect = await configuration.inspect(key)!;
56-
if (inspect.defaultValue === changes[key]) {
57-
await configuration.update(key, undefined, ConfigurationTarget.Global);
84+
if (inspect.defaultValue === options.changes[key]) {
85+
await configuration.update(key, undefined, target);
5886
}
5987
else {
60-
await configuration.update(key, changes[key], ConfigurationTarget.Global);
88+
await configuration.update(key, options.changes[key], target);
6189
}
6290
}
6391
}

src/ui/scss/main.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ header {
7272
}
7373

7474
input, select, button {
75+
font-family: var(--font-family);
76+
font-size: inherit;
7577
margin: 0;
7678
}
7779

@@ -401,6 +403,7 @@ ul {
401403

402404
.page-header {
403405
margin: 1em 0 2em 0;
406+
position: relative;
404407
}
405408

406409
.page-header__title {
@@ -583,6 +586,22 @@ ul {
583586
margin-left: 7em;
584587
}
585588

589+
.settings-scope {
590+
margin: 1.6em 185px 0 0;
591+
position: absolute;
592+
right: 0;
593+
top: -2px;
594+
white-space: nowrap;
595+
596+
select, option {
597+
background-color: var(--background-color) !important;
598+
}
599+
600+
@media all and (max-width: 860px) {
601+
margin-right: -9px;
602+
}
603+
}
604+
586605
.sidebar-group {
587606
margin-top: 1em;
588607
}

0 commit comments

Comments
 (0)