From aab8067cbf6e7cd5311c80900c535011eb380891 Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Fri, 2 Nov 2018 16:00:05 +0200 Subject: [PATCH 1/2] Add FTP TextDocumentContentProvider --- tree-view-sample-plugin/src/ftp-explorer.ts | 32 +++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tree-view-sample-plugin/src/ftp-explorer.ts b/tree-view-sample-plugin/src/ftp-explorer.ts index 207cc08..fce6fb0 100644 --- a/tree-view-sample-plugin/src/ftp-explorer.ts +++ b/tree-view-sample-plugin/src/ftp-explorer.ts @@ -49,7 +49,10 @@ export class FtpModel { client.end(); - return c(this.sort(list.map(entry => ({ resource: theia.Uri.parse(`ftp://${this.host}///${entry.name}`), isDirectory: entry.type === 'd' })))); + return c(this.sort(list.map(entry => ({ + resource: theia.Uri.parse(`ftp://${this.host}/${entry.name}`), + isDirectory: entry.type === 'd' + })))); }); }); }); @@ -65,7 +68,10 @@ export class FtpModel { client.end(); - return c(this.sort(list.map(entry => ({ resource: theia.Uri.parse(`${node.resource.fsPath}/${entry.name}`), isDirectory: entry.type === 'd' })))); + return c(this.sort(list.map(entry => ({ + resource: theia.Uri.parse(`ftp://${this.host}${node.resource.fsPath}/${entry.name}`), + isDirectory: entry.type === 'd' + })))); }); }); }); @@ -88,7 +94,7 @@ export class FtpModel { public getContent(resource: theia.Uri): Promise { return this.connect().then(client => { return new Promise((c, e) => { - client.get(resource.path.substr(2), (err, stream) => { + client.get(resource.path, (err, stream) => { if (err) { return e(err); } @@ -112,8 +118,7 @@ export class FtpModel { } -// Implement theia.TextDocumentContentProvider intreface and uncomment provideTextDocumentContent -export class FtpTreeDataProvider implements theia.TreeDataProvider { +export class FtpTreeDataProvider implements theia.TreeDataProvider, theia.TextDocumentContentProvider { private _onDidChangeTreeData: theia.EventEmitter = new theia.EventEmitter(); readonly onDidChangeTreeData: theia.Event = this._onDidChangeTreeData.event; @@ -151,9 +156,9 @@ export class FtpTreeDataProvider implements theia.TreeDataProvider { } - // public provideTextDocumentContent(uri: theia.Uri, token: theia.CancellationToken): theia.ProviderResult { - // return this.model.getContent(uri).then(content => content); - // } + public provideTextDocumentContent(uri: theia.Uri, token: theia.CancellationToken): theia.ProviderResult { + return this.model.getContent(uri).then(content => content); + } } const ftpExplorerRefresh: theia.Command = { @@ -180,20 +185,23 @@ export class FtpExplorer { constructor(context: theia.PluginContext) { this.ftpModel = new FtpModel('mirror.switch.ch', 'anonymous', 'anonymous@anonymous.de'); const treeDataProvider = new FtpTreeDataProvider(this.ftpModel); - // theia.workspace.registerTextDocumentContentProvider('ftp', treeDataProvider) + theia.workspace.registerTextDocumentContentProvider('ftp', treeDataProvider) this.ftpViewer = theia.window.createTreeView('ftpExplorer', { treeDataProvider }); context.subscriptions.push( theia.commands.registerCommand(ftpExplorerRefresh, () => treeDataProvider.refresh())); context.subscriptions.push( - theia.commands.registerCommand(ftpExplorerOpenFtpResource, resource => this.openResource(resource))); + theia.commands.registerCommand(ftpExplorerOpenFtpResource, args => this.openResource(args))); context.subscriptions.push( theia.commands.registerCommand(ftpExplorerRevealResource, () => this.reveal())); } - private openResource(resource: theia.Uri): void { - theia.workspace.openTextDocument(resource); + private openResource(args: any[]): void { + if (args && args.length > 0) { + const resource: theia.Uri = args[0] as theia.Uri; + theia.workspace.openTextDocument(resource); + } } private async reveal(): Promise { From 2dcedc39ad6af6de477bd6431aa48a3fe2e733ad Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Wed, 7 Nov 2018 23:59:11 +0200 Subject: [PATCH 2/2] Fix dependencies --- tree-view-sample-plugin/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree-view-sample-plugin/package.json b/tree-view-sample-plugin/package.json index 6d660eb..d8fa447 100644 --- a/tree-view-sample-plugin/package.json +++ b/tree-view-sample-plugin/package.json @@ -46,12 +46,12 @@ "devDependencies": { "@theia/plugin": "next", "@theia/plugin-packager": "latest", + "@types/ftp": "^0.3.10", "rimraf": "2.6.2", "typescript-formatter": "7.2.2", "typescript": "2.9.2" }, "dependencies": { - "@types/ftp": "^0.3.10", "ftp": "^0.3.10" }, "scripts": {