Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 393986

Summary: need a way to create file from a plugin
Product: [ECD] Orion Reporter: Rafael Chaves <eclipse>
Component: ClientAssignee: Project Inbox <orion.client-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: davidleonigit-eclipse, mamacdon
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Rafael Chaves CLA 2012-11-09 10:16:15 EST
From this newsgroup post: http://www.eclipse.org/forums/index.php/t/424805/

I would like my plugin to contribute a navigator command that will add a file to the selected directory. Is that currently possible (from a plugin)?

Concrete case: in Cloudfier, a project has a related database. I want to allow the user to capture the current database's state as a JSON file in their project directory. My workaround for now requires the user to create an empty file, open it in the text editor, and trigger a editor command that will insert the database contents into the text editor buffer, which the user can then save.

The orion.navigate.content service feels a bit like what I need:

http://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_navigator#orion.navigate.content

However, it is meant to "create new top level folders with autogenerated content" (like the "Clone git Repository" and "SFTP Import" commands), and all I want is to create a new file (on the selected directory), and need a way of streaming the contents of the file so Orion can actually create the file (or a handle to the flie client API).
Comment 1 Susan McCourt CLA 2012-11-09 11:18:39 EST
I wonder if you could take advantage of "import from URL" somehow as a workaround, or maybe as an actual solution.  

Instead of taking the user to the editor, you could take them to the navigator at the right location with import from URL prefilled in with the location for the file.  I think the effort on our side would be to expose a URL binding for that command.  So you could do something like:

https://orion.eclipse.org/navigate/table.html#/file/I/org.eclipse.orion.client/?depth=1,importURL=http://myFile/is/here.txt

Similar to what works today...
https://orion.eclipse.org/navigate/table.html#/file/I/org.eclipse.orion.client/?depth=1,newFolder=foo

The user would have to hit enter to confirm the import.

Do you think that would be enough?
Comment 2 Rafael Chaves CLA 2012-11-09 12:33:18 EST
Susan, for the single file case, that would probably be sufficient.

For multiple files, either support for importing ZIP files or a multi-part response entity would work.
Comment 3 Rafael Chaves CLA 2012-11-09 12:34:54 EST
(assuming you could import in the current directory, not only as a top level directory).
Comment 4 David Leoni CLA 2012-12-17 05:51:31 EST
I wrote a plugin for compiling Javascript es6 files and I had a similar problem.

 The plugin offers a command to save current .es6 to a compiled file with .js extension. I discovered it is actually possible to save files in Orion 1.0 provided the user clones the plugin repo and then installs the plugin from address 


SERVER_ADDRESS/file/USERNAME/CLONED_REPO_NAME/somePlugin.html

For more details you can see the plugin install instructions 
https://github.com/DavidLeoni/galactic-harmony

and the file backend.js for reading/saving to the server: 

https://github.com/DavidLeoni/galactic-harmony/blob/1.0/main/plugins/galactic-harmony/backend.js
Comment 5 Rafael Chaves CLA 2013-11-05 10:28:31 EST
David, is there some mechanism in the server that automatically tells the UI to show the new added file, or does the user need to refresh the page to actually see it?
Comment 6 John Arthorne CLA 2015-05-05 16:18:55 EDT
Closing as part of a mass clean up of inactive bugs. Please reopen if this problem still occurs or is relevant to you. For more details see:


https://dev.eclipse.org/mhonarc/lists/orion-dev/msg03444.html