It took me about 30 minutes to figure this out. I just discovered the whole "Scripts" part of Aptana today. It was kind of complicated, so I'll just describe what I actually had to do here:
1. If you don't have a project, create one.
2. If you don't have a "scripts" folder in your project, create one (I put mine in the root directory of my project. No clue if it will work from anywhere else).
3. Create a new file inside your scripts folder with a .js extension (I named mine "upload_current_file_on_save.js", not sure if it will work with any other name).
4. Place this code inside the file:
- Code: Select all
/*
* Menu: gMan > Upload On Save
* Kudos: Ingo Muschenetz
* License: EPL 1.0
* Listener: commandService().addExecutionListener(this);
* DOM: http://localhost/com.aptana.ide.syncing
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/
// Add * Listener: commandService().addExecutionListener(this); to the top of this file to enable it
/**
* Returns a reference to the workspace command service
*/
function commandService()
{
var commandServiceClass = Packages.org.eclipse.ui.commands.ICommandService;
// same as doing ICommandService.class
var commandService = Packages.org.eclipse.ui.PlatformUI.getWorkbench().getAdapter(commandServiceClass);
return commandService;
}
/**
* Called before any/every command is executed, so we must filter on command ID
*/
function preExecute(commandId, event) {}
/* Add in all methods required by the interface, even if they are unused */
function postExecuteSuccess(commandId, returnValue)
{
// if we see a save command
if (commandId == "org.eclipse.ui.file.save")
{
sync.uploadCurrentEditor();
/* Replace above line if you'd like to limit it to just certain projects
var fileName = editors.activeEditor.uri;
if(fileName.match(/projectName/ig))
{
sync.uploadCurrentEditor();
}
*/
}
}
function notHandled(commandId, exception) {}
function postExecuteFailure(commandId, exception) {}
5. Save the file.
A few notes on what needed changed in this file from the sample:
1. Added this line of code to the comment block at the top:
- Code: Select all
* Listener: commandService().addExecutionListener(this);
I know there is a comment in this file that tells you to "add this to the top of this file", but since I'm new to the whole scripts thing I didn't get that when it said "top of the file" it meant "the middle of the comment block at the top of this file". I thought I was literally supposed to make that line the very first line in the file... Which didn't work at all...
2. Changed the "menu" line to:
- Code: Select all
* Menu: gMan > Upload On Save
from:
- Code: Select all
* Menu: Synchronize > Upload Current File On Save Enabled
For some reason it didn't work until I changed this line. Since my project is code named "gMan" (It's a user management system, you'll make the connection...) I just named the menu item "gMan" after my project. Then the command is to upload on save, so that's what I named it. As soon as I made this change is when the whole thing started working. Could be coincidence, or could be that you have to do this for the script to work (rename the menu command something other than what the sample is named).
3. In case you haven't figured it out, you run the script by going to the "Scripts" menu in the toolbar at the top of Apatan (and selecting the script, whatever you named it in the previous step).
Hope this helps someone...