|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import { ExtensionContext, TreeDataProvider, EventEmitter, TreeItem, Event, window, TreeItemCollapsibleState, Uri, commands, workspace, TextDocumentContentProvider, CancellationToken, ProviderResult } from 'vscode';
|
|
|
|
|
import * as os from 'os';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
|
|
interface IEntry {
|
|
|
|
@ -6,66 +7,91 @@ interface IEntry {
|
|
|
|
|
type: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ConnectionNode {
|
|
|
|
|
type TreeNode = ConnectionNode | FolderNode
|
|
|
|
|
|
|
|
|
|
constructor(private _name:string, private _uri:string) {
|
|
|
|
|
export class FolderNode {
|
|
|
|
|
constructor(public name:string, public children : TreeNode[]) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get name(): string {
|
|
|
|
|
return this._name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get uri(): string {
|
|
|
|
|
return this._name;
|
|
|
|
|
export class ConnectionNode {
|
|
|
|
|
|
|
|
|
|
constructor(public name:string, public host:string, public port:Number, public schema:String, public username:String, public password:String) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ConnectionModel {
|
|
|
|
|
|
|
|
|
|
public get roots(): Thenable<ConnectionNode[]> {
|
|
|
|
|
let list : ConnectionNode[] = [
|
|
|
|
|
new ConnectionNode("swdev", "foobar"),
|
|
|
|
|
new ConnectionNode("swint", "foobar")
|
|
|
|
|
];
|
|
|
|
|
constructor(public data:any) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private traverse(data) : TreeNode[] {
|
|
|
|
|
return data['items'].map( (x) => {
|
|
|
|
|
if (x['type'] == 'connection') {
|
|
|
|
|
return new ConnectionNode(x['name'], x['host'], x['port'], x['sid'], x['username'], x['password'])
|
|
|
|
|
} else {
|
|
|
|
|
return new FolderNode(x['name'], this.traverse(x))
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get roots(): Thenable<TreeNode[]> {
|
|
|
|
|
let list : TreeNode[] = this.traverse(this.data);
|
|
|
|
|
return new Promise((c, e) => c(list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getChildren(node: ConnectionNode): Thenable<ConnectionNode[]> {
|
|
|
|
|
return new Promise((c, e) => []);
|
|
|
|
|
public getChildren(node: TreeNode): Thenable<TreeNode[]> {
|
|
|
|
|
if (node instanceof FolderNode) {
|
|
|
|
|
return new Promise((c, e) => c(node.children));
|
|
|
|
|
} else {
|
|
|
|
|
return new Promise((c, e) => c([]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ConnectionProvider implements TreeDataProvider<ConnectionNode>, TextDocumentContentProvider {
|
|
|
|
|
export class ConnectionProvider implements TreeDataProvider<TreeNode>, TextDocumentContentProvider {
|
|
|
|
|
|
|
|
|
|
private _onDidChangeTreeData: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
readonly onDidChangeTreeData: Event<any> = this._onDidChangeTreeData.event;
|
|
|
|
|
|
|
|
|
|
private model: ConnectionModel;
|
|
|
|
|
|
|
|
|
|
public getTreeItem(element: ConnectionNode): TreeItem {
|
|
|
|
|
public getTreeItem(element: TreeNode): TreeItem {
|
|
|
|
|
if (element instanceof FolderNode) {
|
|
|
|
|
return {
|
|
|
|
|
label: element.name,
|
|
|
|
|
collapsibleState: TreeItemCollapsibleState.Collapsed,
|
|
|
|
|
command: void 0
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
label: element.name,
|
|
|
|
|
collapsibleState: void 0,
|
|
|
|
|
command: {
|
|
|
|
|
command: 'openConnection',
|
|
|
|
|
arguments: [element.uri],
|
|
|
|
|
command: 'selectConnection',
|
|
|
|
|
arguments: [element],
|
|
|
|
|
title: 'Open Connection'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getChildren(element?: ConnectionNode): ConnectionNode[] | Thenable<ConnectionNode[]> {
|
|
|
|
|
public getChildren(element?: TreeNode): TreeNode[] | Thenable<TreeNode[]> {
|
|
|
|
|
if (!element) {
|
|
|
|
|
if (!this.model) {
|
|
|
|
|
this.model = new ConnectionModel();
|
|
|
|
|
let data = require(os.homedir() + '/.frog.json');
|
|
|
|
|
this.model = new ConnectionModel(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.model.roots;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (element instanceof FolderNode) {
|
|
|
|
|
return element.children;
|
|
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public provideTextDocumentContent(uri: Uri, token: CancellationToken): ProviderResult<string> {
|
|
|
|
|
return "nix";
|
|
|
|
|