develop merge
[jalview.git] / src / jalview / gui / Desktop.java
index 27f60ea..8e863c1 100644 (file)
@@ -383,7 +383,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       @Override
       public void mousePressed(MouseEvent evt)
       {
-        if (SwingUtilities.isRightMouseButton(evt))
+        if (evt.isPopupTrigger())
         {
           showPasteMenu(evt.getX(), evt.getY());
         }
@@ -2507,9 +2507,21 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
               new Class[] { String.class, Object.class });
       java.lang.reflect.Method run = gcClass.getMethod("run");
-      Object gc = gccons.newInstance();
-      setvar.invoke(gc, new Object[] { "Jalview", this });
-      run.invoke(gc);
+      groovyConsole = gccons.newInstance();
+      setvar.invoke(groovyConsole, new Object[] { "Jalview", this });
+      run.invoke(groovyConsole);
+      /*
+       * and rebuild alignframe menus to enable 'Run Groovy'
+       */
+
+      AlignFrame[] alignFrames = getAlignFrames();
+      if (alignFrames != null)
+      {
+        for (AlignFrame af : alignFrames)
+        {
+          af.setGroovyEnabled(true);
+        }
+      }
     } catch (Exception ex)
     {
       jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
@@ -2917,6 +2929,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements
    */
   private java.util.concurrent.Semaphore block = new Semaphore(0);
 
+  /*
+   * groovy.ui.Console object - if Groovy jars are present and the 
+   * user has activated the Groovy console. Use via reflection to
+   * avoid compile-time dependency on Groovy libraries.
+   */
+  private static Object groovyConsole;
+
   /**
    * add another dialog thread to the queue
    * 
@@ -3145,4 +3164,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     Desktop.currentAlignFrame = currentAlignFrame;
   }
 
+  public static Object getGroovyConsole()
+  {
+    return groovyConsole;
+  }
+
 }