Quantcast
Channel: Web Services » eclipse
Viewing all articles
Browse latest Browse all 2

Aptana Outline Auto-Expansion Monkeyed!

$
0
0

You may have seen my last post Monkeying with my outline! where I apparently managed to get Aptana automatically expanding my outline whenever I viewed a new file in the editor. Well… it didn’t quite go to plan. Long story short, the script only executed properly when it was loaded after editing in the script editor, not when Aptana loaded up at the start. Details here in the Aptana scripting forum. I was rescued by Kevin Lindsey. Above and beyond the run of the mill support, he even emailed me to let me know he’d snuck the fix into 1.2. It’s working brilliantly! So now here’s my code with the updated bits from Kevin, I’ve commented out all the println’s cause I like a clean console.

/*
 *
 * Menu: EHU > HandlerService (Auto expand outline)
 * Kudos: Ingo Muschenetz & Kevin Lindsey & Steve Daniels
 * License: EPL 1.0
 * Listener: getPartService().addPartListener(this);
 * DOM: http://localhost/com.aptana.ide.scripting
 * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
 *
 *
*/
 
function getPartService()
{
    var workbench = Packages.org.eclipse.ui.PlatformUI.getWorkbench();
    var result = null;
 
    if (workbench)
    {
        var window = null;
 
        runOnUIThread(function() {
            window = workbench.getActiveWorkbenchWindow();
 
            if (window != null)
            {
                result = window.getPartService();
                //out.println("result set to " + result);
            }
            else
            {
                //out.println("window is not defined");
            }
        });
    }
    else
    {
        //out.println("workbench is not defined");
    }
 
    //out.println("getPartService() is returning " + result);
 
    return result;
}
 
function partBroughtToTop(part)
{
  //out.println("part*()\n");
}  
 
function partClosed(part)
{
  //out.println("part*()\n");
}
 
function partDeactivated(part)
{
  //out.println("part*()\n");
}  
 
function partOpened(part)
{
  //out.println("part*()\n");
}
 
function partActivated(part)
{
  if (part.getEditorInput)
  {
    expandOutline();
  }
}
 
function partVisible(part)
{
  //out.println("part*()\n");
}
 
function partHidden(part)
{
  //out.println("part*()\n");
}
 
function expandOutline()
{
  //out.println("expandOutline()\n");
  try
  {
    //out.println("try\n");
    var editor = editors.activeEditor.textEditor;
 
    editor.getOutlinePage().getTreeViewer().expandAll();
  }
  catch (e)
  {
    //out.println("catch\n");
  }
}

Enjoy :-)

Steve Daniels


Viewing all articles
Browse latest Browse all 2

Trending Articles