Skip to content

Commit

Permalink
quickly open another namespace in server explorer, solve #9
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed May 13, 2019
1 parent a15e939 commit e0ea327
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down Expand Up @@ -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);
}
});
}
Expand Down
40 changes: 26 additions & 14 deletions explorer/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeBase> {
onDidChange?: vscode.Event<vscode.Uri>;
private _onDidChangeTreeData: vscode.EventEmitter<NodeBase> = new vscode.EventEmitter<NodeBase>();
readonly onDidChangeTreeData: vscode.Event<NodeBase> = 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<any> {
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 {
Expand Down Expand Up @@ -53,10 +65,10 @@ export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<Nod
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData);
rootNodes.push(node);

if (this.showSystem || this._showSystem4Workspace[workspaceFolder.name]) {
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, true);
this._showExtra4Workspace.forEach(ns => {
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, ns);
rootNodes.push(node);
}
})
}
});
return rootNodes;
Expand Down
22 changes: 11 additions & 11 deletions explorer/models/workspaceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeBase>,
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
};
}
Expand All @@ -51,7 +51,7 @@ export class WorkspaceNode extends NodeBase {

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

Expand Down
18 changes: 4 additions & 14 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
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);
Expand Down
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e0ea327

Please sign in to comment.