From e0ea327ccae915149a3a93b0e9100b8b5737d205 Mon Sep 17 00:00:00 2001 From: Dmitry Maslennikov Date: Mon, 13 May 2019 16:02:44 +0300 Subject: [PATCH] quickly open another namespace in server explorer, solve #9 --- CHANGELOG.md | 1 + api/index.ts | 6 ++--- explorer/explorer.ts | 40 +++++++++++++++++++++----------- explorer/models/workspaceNode.ts | 22 +++++++++--------- extension.ts | 18 ++++---------- package.json | 20 ++++++++++++++++ 6 files changed, 65 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad875145..1c208398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Class Suggestion in ##class, Extends, As, CompileAfter, DependsOn, PropertyClass - \$SYSTEM suggestion by Classes from %SYSTEM - Import and compile folder or file by context menu in File explorer +- Server Explorer, now possible to open any other namespace ## [0.7.10] diff --git a/api/index.ts b/api/index.ts index afe31c88..3b823d5a 100644 --- a/api/index.ts +++ b/api/index.ts @@ -19,8 +19,8 @@ export class AtelierAPI { return workspaceState.get(currentWorkspaceFolder() + ':apiVersion', DEFAULT_API_VERSION); } - constructor() { - this.setConnection(currentWorkspaceFolder()); + constructor(workspaceFolderName?: string) { + this.setConnection(workspaceFolderName || currentWorkspaceFolder()); const { name, host, port } = this._config; this._cache = new Cache(extensionContext, `API:${name}:${host}:${port}`); } @@ -166,7 +166,7 @@ export class AtelierAPI { return this.request(0, 'GET').then(info => { if (info && info.result && info.result.content && info.result.content.api > 0) { let apiVersion = info.result.content.api; - return workspaceState.update(currentWorkspaceFolder() + ':apiVersion', apiVersion); + return workspaceState.update(currentWorkspaceFolder() + ':apiVersion', apiVersion).then(() => info); } }); } diff --git a/explorer/explorer.ts b/explorer/explorer.ts index ea1d17ba..af263efb 100644 --- a/explorer/explorer.ts +++ b/explorer/explorer.ts @@ -3,28 +3,40 @@ import { NodeBase } from './models/nodeBase'; import { config } from '../extension'; import { WorkspaceNode } from './models/workspaceNode'; +import { AtelierAPI } from '../api'; export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider { onDidChange?: vscode.Event; private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; - private _showSystem = false; - private _showSystem4Workspace: boolean[] = []; + private _showExtra4Workspace: string[] = []; - constructor() {} + constructor() { } - get showSystem(): boolean { - return this._showSystem; + async selectNamespace(workspaceFolder: string): Promise { + let api = new AtelierAPI(workspaceFolder); + return api + .serverInfo() + .then(data => data.result.content.namespaces) + .then(data => data.filter(ns => ns !== api.ns && !this._showExtra4Workspace.includes(ns))) + .then(data => data.map(ns => ({ label: ns }))) + .then(vscode.window.showQuickPick) + .then(ns => this.showExtra4Workspace(workspaceFolder, ns.label)); } - set showSystem(value) { - this._showSystem = value; - this._onDidChangeTreeData.fire(null); + showExtra4Workspace(workspaceFolder: string, ns: string) { + if (!this._showExtra4Workspace.includes(ns)) { + this._showExtra4Workspace.push(ns); + this._onDidChangeTreeData.fire(null); + } } - showSystem4Workspace(workspaceFolder: string, value: boolean) { - this._showSystem4Workspace[workspaceFolder] = value; - this._onDidChangeTreeData.fire(null); + closeExtra4Workspace(workspaceFolder: string, ns: string) { + let pos = this._showExtra4Workspace.indexOf(ns); + if (pos >= 0) { + this._showExtra4Workspace.splice(pos, 1) + this._onDidChangeTreeData.fire(null); + } } refresh(): void { @@ -53,10 +65,10 @@ export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider { + node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, ns); rootNodes.push(node); - } + }) } }); return rootNodes; diff --git a/explorer/models/workspaceNode.ts b/explorer/models/workspaceNode.ts index 2bb020ea..8f0805df 100644 --- a/explorer/models/workspaceNode.ts +++ b/explorer/models/workspaceNode.ts @@ -7,27 +7,27 @@ import { config } from '../../extension'; export class WorkspaceNode extends NodeBase { private _conn: any; - private _namespace: string; - showSystem: boolean; + private _extraNode: boolean; constructor( public readonly label: string, public eventEmitter: vscode.EventEmitter, - private _showSystem: boolean = false + private _namespace?: string ) { super(label); this._conn = config('conn', this.label); - this._namespace = this._conn.ns; - if (this._showSystem) { - this._namespace = '%SYS'; - } - this._showSystem = this._showSystem || this._namespace === '%SYS'; + this._namespace = _namespace || this._conn.ns; + this._extraNode = (this._conn.ns !== this._namespace); + } + + get ns(): string { + return this._namespace; } getTreeItem(): vscode.TreeItem { return { - label: `${this.label}${this._showSystem ? ' - System' : ''}`, - contextValue: `serverNode${this._showSystem ? 'System' : ''}`, + label: `${this.label}${this._extraNode ? `[${this._namespace}]` : ''}`, + contextValue: `serverNode${this._extraNode ? 'Extra:' + this._namespace : ''}`, collapsibleState: vscode.TreeItemCollapsibleState.Expanded }; } @@ -51,7 +51,7 @@ export class WorkspaceNode extends NodeBase { getDocNames(category: string): Promise { const excludeSystem = - this._showSystem || this._namespace === '%SYS' + this._namespace === '%SYS' ? () => true : ({ db }) => !['IRISLIB', 'IRISSYS', 'CACHELIB', 'CACHESYS'].includes(db); diff --git a/extension.ts b/extension.ts index f5696709..447fffc8 100644 --- a/extension.ts +++ b/extension.ts @@ -153,21 +153,11 @@ export async function activate(context: vscode.ExtensionContext): Promise vscode.commands.registerCommand('vscode-objectscript.explorer.openRoutine', vscode.window.showTextDocument), vscode.commands.registerCommand('vscode-objectscript.explorer.export', exportExplorerItem), vscode.commands.registerCommand('vscode-objectscript.explorer.delete', deleteItem), - vscode.commands.registerCommand('vscode-objectscript.explorer.showSystem', (workspaceNode?: WorkspaceNode) => { - if (workspaceNode) { - explorerProvider.showSystem4Workspace(workspaceNode.label, true); - } else { - vscode.commands.executeCommand('setContext', 'vscode-objectscript.explorer.showSystem', true); - explorerProvider.showSystem = true; - } + vscode.commands.registerCommand('vscode-objectscript.explorer.otherNamespace', (workspaceNode: WorkspaceNode) => { + return explorerProvider.selectNamespace(workspaceNode.label); }), - vscode.commands.registerCommand('vscode-objectscript.explorer.hideSystem', (workspaceNode?) => { - if (workspaceNode) { - explorerProvider.showSystem4Workspace(workspaceNode.label, false); - } else { - vscode.commands.executeCommand('setContext', 'vscode-objectscript.explorer.showSystem', false); - explorerProvider.showSystem = false; - } + vscode.commands.registerCommand('vscode-objectscript.explorer.otherNamespaceClose', (workspaceNode: WorkspaceNode) => { + return explorerProvider.closeExtra4Workspace(workspaceNode.label, workspaceNode.ns); }), vscode.commands.registerCommand('vscode-objectscript.previewXml', (...args) => { xml2doc(context, window.activeTextEditor); diff --git a/package.json b/package.json index 2f6c0bf4..0627b77a 100644 --- a/package.json +++ b/package.json @@ -147,6 +147,16 @@ { "command": "vscode-objectscript.explorer.hideSystem", "when": "view == ObjectScriptExplorer && viewItem == serverNodeSystem" + }, + { + "command": "vscode-objectscript.explorer.otherNamespace", + "when": "view == ObjectScriptExplorer && viewItem == serverNode", + "group": "inline" + }, + { + "command": "vscode-objectscript.explorer.otherNamespaceClose", + "when": "view == ObjectScriptExplorer && viewItem =~ /^serverNodeExtra:/", + "group": "inline" } ], "editor/context": [ @@ -313,6 +323,16 @@ "title": "Export", "category": "ObjecScript" }, + { + "command": "vscode-objectscript.explorer.otherNamespace", + "title": "View another namespace", + "category": "ObjecScript" + }, + { + "command": "vscode-objectscript.explorer.otherNamespaceClose", + "title": "Close namespace", + "category": "ObjecScript" + }, { "command": "vscode-objectscript.explorer.delete", "title": "Delete",