Skip to content

Commit 5b1de2f

Browse files
committed
Reload list of authorities upon configuration change; remember selected register type
1 parent ec62f01 commit 5b1de2f

4 files changed

Lines changed: 46 additions & 15 deletions

File tree

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# TEI Publisher Extension for Visual Studio Code
22

3-
A package to help editors work on TEI files.
3+
An extension to help editors work on TEI files.
44

55
## Features
66

77
* Preview the currently edited TEI document by sending it to a TEI Publisher instance where it will be transformed to HTML via an existing ODD
8-
* Look up an entity in a register database
8+
* Look up an entity in one of the configured authority databases and replace the current selection with a TEI tag corresponding to the entity type
9+
910
### Preview
1011

1112
Get an HTML preview of the TEI file currently opened in the editor. The content is sent to a TEI Publisher endpoint and transformed to HTML via an ODD with processing instructions. The extension queries the server for a list of available ODDs and lets you choose one.
@@ -46,10 +47,13 @@ The _teipublisher.endpoint_ configuration property defines the HTTP or HTTPS URL
4647

4748
The extension supports various authorities to query for entities (plugin name in parentheses):
4849

49-
1. Karl Barth-Gesamtausgabe, Basel (kbga)
50-
2. Metagrid (metagrid)
51-
3. Google Places (google)
52-
4. GND (gnd)
50+
51+
Authority | Plugin name | Supported register types | Notes
52+
---------|----------|---------|------------
53+
Karl Barth-Gesamtausgabe, Basel | kbga | places, actors, terms |
54+
GND | gnd | places, actors, organisations, terms |
55+
Google Places | google | places | Requires an access token
56+
Metagrid (metagrid) | metagrid | actors |
5357

5458
You can define a different connector for each entity type. The configuration is a JSON snippet like below:
5559

@@ -74,6 +78,12 @@ You can define a different connector for each entity type. The configuration is
7478
]
7579
```
7680

81+
The `name` property defines the name of the register to search in. It should correspond to one of the supported register types for each authority given in the table above.
82+
83+
The `label` property provides the text to be shown to the user in the dropdown.
84+
85+
`plugin` should correspond to one of the available plugin names given in the table above.
86+
7787
## Recommended Extensions
7888

7989
For proper XML editing support, we recommend installing some of the following extensions:

media/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ class View {
99
this.lookup();
1010
});
1111

12+
const register = document.getElementById('api-list');
13+
register.addEventListener('change', (ev) => {
14+
this.vscode.postMessage({
15+
command: 'register',
16+
register: register.value
17+
});
18+
});
19+
1220
// Handle messages sent from the extension to the webview
1321
window.addEventListener('message', event => {
1422
const message = event.data; // The json data that the extension sent

src/extension.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function activate(context: vscode.ExtensionContext) {
1414
if (editor && !editor.selection.isEmpty) {
1515
provider.show();
1616
const selected = editor.document.getText(editor.selection);
17-
provider.query(selected, '', editor);
17+
provider.query(selected, null, editor);
1818
}
1919
})
2020
);
@@ -23,16 +23,20 @@ export function activate(context: vscode.ExtensionContext) {
2323
vscode.commands.registerCommand('teipublisher.preview', preview)
2424
);
2525

26-
vscode.workspace.onDidChangeConfiguration(() => configure(provider));
26+
vscode.workspace.onDidChangeConfiguration((ev) => {
27+
if (ev.affectsConfiguration('teipublisher')) {
28+
configure(provider, ev);
29+
}
30+
});
2731
configure(provider);
2832
}
2933

30-
function configure(provider: RegistryPanel) {
34+
function configure(provider: RegistryPanel, ev?: vscode.ConfigurationChangeEvent) {
3135
const endpoint:string|undefined = vscode.workspace.getConfiguration('teipublisher').get('endpoint');
3236
if (endpoint) {
3337
apiEndpoint = endpoint;
3438
}
35-
provider.configure();
39+
provider.configure(ev);
3640
}
3741

3842
// this method is called when your extension is deactivated

src/panel.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class RegistryPanel implements vscode.WebviewViewProvider {
1414
public static readonly viewType = 'teipublisher.entityView';
1515

1616
private _registry:Map<string, Registry> = new Map();
17-
17+
private _currentRegister:string = '';
1818
private _view?: vscode.WebviewView;
1919
private _currentEditor: vscode.TextEditor | undefined = undefined;
2020

@@ -31,6 +31,9 @@ export class RegistryPanel implements vscode.WebviewViewProvider {
3131
webviewView.webview.onDidReceiveMessage(
3232
message => {
3333
switch (message.command) {
34+
case 'register':
35+
this._currentRegister = message.register;
36+
break;
3437
case 'replace':
3538
if (this._currentEditor) {
3639
const editor = this._currentEditor;
@@ -40,7 +43,7 @@ export class RegistryPanel implements vscode.WebviewViewProvider {
4043
editor.insertSnippet(new vscode.SnippetString(snippet));
4144
}
4245
}
43-
return;
46+
break;
4447
case 'query':
4548
this.query(message.query, message.register);
4649
break;
@@ -53,7 +56,7 @@ export class RegistryPanel implements vscode.WebviewViewProvider {
5356
}
5457

5558

56-
public configure() {
59+
public configure(ev?: vscode.ConfigurationChangeEvent) {
5760
const configs:any[] | undefined = vscode.workspace.getConfiguration('teipublisher').get('apiList');
5861
if (!configs) {
5962
return;
@@ -77,16 +80,22 @@ export class RegistryPanel implements vscode.WebviewViewProvider {
7780
}
7881
this._registry.set(config.name, registry);
7982
});
83+
if (ev && this._view) {
84+
this._view.webview.html = this._getHtmlForWebview(this._view.webview);
85+
}
8086
}
8187

8288
public show() {
8389
this._view?.show(true);
8490
}
8591

86-
public async query(text: string, register: string, editor?:vscode.TextEditor) {
92+
public async query(text: string, register: string|null, editor?:vscode.TextEditor) {
8793
if (editor) {
8894
this._currentEditor = editor;
8995
}
96+
if (!register) {
97+
register = this._currentRegister;
98+
}
9099
vscode.window.withProgress({
91100
location: vscode.ProgressLocation.Notification,
92101
title: `Querying authorities for ${text}`,
@@ -146,7 +155,7 @@ export class RegistryPanel implements vscode.WebviewViewProvider {
146155
<body>
147156
<div class="toolbar">
148157
<select id="api-list">
149-
<option value=''>Alle</option>
158+
<option value=''>All</option>
150159
${ this._getApiOptions() }
151160
</select>
152161
<input id="query" class="input" type="text" placeholder="Suchtext">

0 commit comments

Comments
 (0)