Skip to content

Commit e0ea327

Browse files
committed
quickly open another namespace in server explorer, solve #9
1 parent a15e939 commit e0ea327

File tree

6 files changed

+65
-42
lines changed

6 files changed

+65
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Class Suggestion in ##class, Extends, As, CompileAfter, DependsOn, PropertyClass
88
- \$SYSTEM suggestion by Classes from %SYSTEM
99
- Import and compile folder or file by context menu in File explorer
10+
- Server Explorer, now possible to open any other namespace
1011

1112
## [0.7.10]
1213

api/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class AtelierAPI {
1919
return workspaceState.get(currentWorkspaceFolder() + ':apiVersion', DEFAULT_API_VERSION);
2020
}
2121

22-
constructor() {
23-
this.setConnection(currentWorkspaceFolder());
22+
constructor(workspaceFolderName?: string) {
23+
this.setConnection(workspaceFolderName || currentWorkspaceFolder());
2424
const { name, host, port } = this._config;
2525
this._cache = new Cache(extensionContext, `API:${name}:${host}:${port}`);
2626
}
@@ -166,7 +166,7 @@ export class AtelierAPI {
166166
return this.request(0, 'GET').then(info => {
167167
if (info && info.result && info.result.content && info.result.content.api > 0) {
168168
let apiVersion = info.result.content.api;
169-
return workspaceState.update(currentWorkspaceFolder() + ':apiVersion', apiVersion);
169+
return workspaceState.update(currentWorkspaceFolder() + ':apiVersion', apiVersion).then(() => info);
170170
}
171171
});
172172
}

explorer/explorer.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,40 @@ import { NodeBase } from './models/nodeBase';
33

44
import { config } from '../extension';
55
import { WorkspaceNode } from './models/workspaceNode';
6+
import { AtelierAPI } from '../api';
67

78
export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<NodeBase> {
89
onDidChange?: vscode.Event<vscode.Uri>;
910
private _onDidChangeTreeData: vscode.EventEmitter<NodeBase> = new vscode.EventEmitter<NodeBase>();
1011
readonly onDidChangeTreeData: vscode.Event<NodeBase> = this._onDidChangeTreeData.event;
11-
private _showSystem = false;
12-
private _showSystem4Workspace: boolean[] = [];
12+
private _showExtra4Workspace: string[] = [];
1313

14-
constructor() {}
14+
constructor() { }
1515

16-
get showSystem(): boolean {
17-
return this._showSystem;
16+
async selectNamespace(workspaceFolder: string): Promise<any> {
17+
let api = new AtelierAPI(workspaceFolder);
18+
return api
19+
.serverInfo()
20+
.then(data => data.result.content.namespaces)
21+
.then(data => data.filter(ns => ns !== api.ns && !this._showExtra4Workspace.includes(ns)))
22+
.then(data => data.map(ns => ({ label: ns })))
23+
.then(vscode.window.showQuickPick)
24+
.then(ns => this.showExtra4Workspace(workspaceFolder, ns.label));
1825
}
1926

20-
set showSystem(value) {
21-
this._showSystem = value;
22-
this._onDidChangeTreeData.fire(null);
27+
showExtra4Workspace(workspaceFolder: string, ns: string) {
28+
if (!this._showExtra4Workspace.includes(ns)) {
29+
this._showExtra4Workspace.push(ns);
30+
this._onDidChangeTreeData.fire(null);
31+
}
2332
}
2433

25-
showSystem4Workspace(workspaceFolder: string, value: boolean) {
26-
this._showSystem4Workspace[workspaceFolder] = value;
27-
this._onDidChangeTreeData.fire(null);
34+
closeExtra4Workspace(workspaceFolder: string, ns: string) {
35+
let pos = this._showExtra4Workspace.indexOf(ns);
36+
if (pos >= 0) {
37+
this._showExtra4Workspace.splice(pos, 1)
38+
this._onDidChangeTreeData.fire(null);
39+
}
2840
}
2941

3042
refresh(): void {
@@ -53,10 +65,10 @@ export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<Nod
5365
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData);
5466
rootNodes.push(node);
5567

56-
if (this.showSystem || this._showSystem4Workspace[workspaceFolder.name]) {
57-
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, true);
68+
this._showExtra4Workspace.forEach(ns => {
69+
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, ns);
5870
rootNodes.push(node);
59-
}
71+
})
6072
}
6173
});
6274
return rootNodes;

explorer/models/workspaceNode.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ import { config } from '../../extension';
77

88
export class WorkspaceNode extends NodeBase {
99
private _conn: any;
10-
private _namespace: string;
11-
showSystem: boolean;
10+
private _extraNode: boolean;
1211

1312
constructor(
1413
public readonly label: string,
1514
public eventEmitter: vscode.EventEmitter<NodeBase>,
16-
private _showSystem: boolean = false
15+
private _namespace?: string
1716
) {
1817
super(label);
1918
this._conn = config('conn', this.label);
20-
this._namespace = this._conn.ns;
21-
if (this._showSystem) {
22-
this._namespace = '%SYS';
23-
}
24-
this._showSystem = this._showSystem || this._namespace === '%SYS';
19+
this._namespace = _namespace || this._conn.ns;
20+
this._extraNode = (this._conn.ns !== this._namespace);
21+
}
22+
23+
get ns(): string {
24+
return this._namespace;
2525
}
2626

2727
getTreeItem(): vscode.TreeItem {
2828
return {
29-
label: `${this.label}${this._showSystem ? ' - System' : ''}`,
30-
contextValue: `serverNode${this._showSystem ? 'System' : ''}`,
29+
label: `${this.label}${this._extraNode ? `[${this._namespace}]` : ''}`,
30+
contextValue: `serverNode${this._extraNode ? 'Extra:' + this._namespace : ''}`,
3131
collapsibleState: vscode.TreeItemCollapsibleState.Expanded
3232
};
3333
}
@@ -51,7 +51,7 @@ export class WorkspaceNode extends NodeBase {
5151

5252
getDocNames(category: string): Promise<any> {
5353
const excludeSystem =
54-
this._showSystem || this._namespace === '%SYS'
54+
this._namespace === '%SYS'
5555
? () => true
5656
: ({ db }) => !['IRISLIB', 'IRISSYS', 'CACHELIB', 'CACHESYS'].includes(db);
5757

extension.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
153153
vscode.commands.registerCommand('vscode-objectscript.explorer.openRoutine', vscode.window.showTextDocument),
154154
vscode.commands.registerCommand('vscode-objectscript.explorer.export', exportExplorerItem),
155155
vscode.commands.registerCommand('vscode-objectscript.explorer.delete', deleteItem),
156-
vscode.commands.registerCommand('vscode-objectscript.explorer.showSystem', (workspaceNode?: WorkspaceNode) => {
157-
if (workspaceNode) {
158-
explorerProvider.showSystem4Workspace(workspaceNode.label, true);
159-
} else {
160-
vscode.commands.executeCommand('setContext', 'vscode-objectscript.explorer.showSystem', true);
161-
explorerProvider.showSystem = true;
162-
}
156+
vscode.commands.registerCommand('vscode-objectscript.explorer.otherNamespace', (workspaceNode: WorkspaceNode) => {
157+
return explorerProvider.selectNamespace(workspaceNode.label);
163158
}),
164-
vscode.commands.registerCommand('vscode-objectscript.explorer.hideSystem', (workspaceNode?) => {
165-
if (workspaceNode) {
166-
explorerProvider.showSystem4Workspace(workspaceNode.label, false);
167-
} else {
168-
vscode.commands.executeCommand('setContext', 'vscode-objectscript.explorer.showSystem', false);
169-
explorerProvider.showSystem = false;
170-
}
159+
vscode.commands.registerCommand('vscode-objectscript.explorer.otherNamespaceClose', (workspaceNode: WorkspaceNode) => {
160+
return explorerProvider.closeExtra4Workspace(workspaceNode.label, workspaceNode.ns);
171161
}),
172162
vscode.commands.registerCommand('vscode-objectscript.previewXml', (...args) => {
173163
xml2doc(context, window.activeTextEditor);

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@
147147
{
148148
"command": "vscode-objectscript.explorer.hideSystem",
149149
"when": "view == ObjectScriptExplorer && viewItem == serverNodeSystem"
150+
},
151+
{
152+
"command": "vscode-objectscript.explorer.otherNamespace",
153+
"when": "view == ObjectScriptExplorer && viewItem == serverNode",
154+
"group": "inline"
155+
},
156+
{
157+
"command": "vscode-objectscript.explorer.otherNamespaceClose",
158+
"when": "view == ObjectScriptExplorer && viewItem =~ /^serverNodeExtra:/",
159+
"group": "inline"
150160
}
151161
],
152162
"editor/context": [
@@ -313,6 +323,16 @@
313323
"title": "Export",
314324
"category": "ObjecScript"
315325
},
326+
{
327+
"command": "vscode-objectscript.explorer.otherNamespace",
328+
"title": "View another namespace",
329+
"category": "ObjecScript"
330+
},
331+
{
332+
"command": "vscode-objectscript.explorer.otherNamespaceClose",
333+
"title": "Close namespace",
334+
"category": "ObjecScript"
335+
},
316336
{
317337
"command": "vscode-objectscript.explorer.delete",
318338
"title": "Delete",

0 commit comments

Comments
 (0)