JAL-629 Opening files in new windows. not working yet
authorBen Soares <b.soares@dundee.ac.uk>
Tue, 28 Mar 2023 10:17:23 +0000 (11:17 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Tue, 28 Mar 2023 10:17:23 +0000 (11:17 +0100)
src/jalview/bin/Commands.java
src/jalview/bin/Jalview.java
src/jalview/bin/argparser/Arg.java
src/jalview/bin/argparser/ArgParser.java
src/jalview/bin/argparser/ArgValue.java
src/jalview/bin/argparser/BootstrapArgs.java
src/jalview/bin/argparser/SubVals.java
src/jalview/gui/Desktop.java

index 67c0c64..43dc1fd 100644 (file)
@@ -2,6 +2,7 @@ package jalview.bin;
 
 import java.io.File;
 import java.io.IOException;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -10,6 +11,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import jalview.analysis.AlignmentUtils;
 import jalview.api.AlignmentViewPanel;
 
 import jalview.analysis.AlignmentUtils;
 import jalview.api.AlignmentViewPanel;
@@ -33,6 +35,7 @@ import jalview.gui.StructureChooser;
 import jalview.gui.StructureViewer;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.DataSourceType;
 import jalview.gui.StructureViewer;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
 import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
 import jalview.io.FileLoader;
 import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
 import jalview.io.FileLoader;
@@ -164,8 +167,19 @@ public class Commands
       boolean first = true;
       boolean progressBarSet = false;
       AlignFrame af;
       boolean first = true;
       boolean progressBarSet = false;
       AlignFrame af;
-      for (ArgValue av : avm.getArgValueList(Arg.OPEN))
+      List<Entry<Arg, ArgValue>> openAvList = new ArrayList<>();
+      avm.getArgValueList(Arg.OPEN).stream()
+              .forEachOrdered(av -> openAvList.add(
+                      new AbstractMap.SimpleEntry<Arg, ArgValue>(Arg.OPEN,
+                              av)));
+      avm.getArgValueList(Arg.OPENNEW).stream()
+              .forEachOrdered(av -> openAvList
+                      .add(new AbstractMap.SimpleEntry<Arg, ArgValue>(
+                              Arg.OPENNEW, av)));
+      for (Entry<Arg, ArgValue> aav : openAvList)
       {
       {
+        Arg a = aav.getKey();
+        ArgValue av = aav.getValue();
         String openFile = av.getValue();
         if (openFile == null)
           continue;
         String openFile = av.getValue();
         if (openFile == null)
           continue;
@@ -213,7 +227,8 @@ public class Commands
         }
 
         af = afMap.get(id);
         }
 
         af = afMap.get(id);
-        if (af == null)
+        if (af == null || "true".equals(av.getSubVal("new"))
+                || a == Arg.OPENNEW || format == FileFormat.Jalview)
         {
           /*
            * this approach isn't working yet
         {
           /*
            * this approach isn't working yet
index 9e488dc..bc8c997 100755 (executable)
@@ -649,14 +649,16 @@ public class Jalview
                   .println("CMD [-noquestionnaire] executed successfully!");
         }
 
                   .println("CMD [-noquestionnaire] executed successfully!");
         }
 
-        if (!aparser.contains("nonews")
-                || Cache.getProperty("NONEWS") == null)
+        if ((!aparser.contains("nonews")
+                && Cache.getProperty("NONEWS") == null
+                && !"false".equals(bootstrapArgs.get(Arg.NEWS)))
+                || "true".equals(bootstrapArgs.get(Arg.NEWS)))
         {
           desktop.checkForNews();
         }
 
         if (!aparser.contains("nohtmltemplates")
         {
           desktop.checkForNews();
         }
 
         if (!aparser.contains("nohtmltemplates")
-                || Cache.getProperty("NOHTMLTEMPLATES") == null)
+                && Cache.getProperty("NOHTMLTEMPLATES") == null)
         {
           BioJsHTMLOutput.updateBioJS();
         }
         {
           BioJsHTMLOutput.updateBioJS();
         }
index a13acd2..4c2465c 100644 (file)
@@ -10,11 +10,11 @@ public enum Arg
   HELP("h"), CALCULATION, MENUBAR, STATUS, SHOWOVERVIEW, ANNOTATIONS,
   COLOUR, FEATURES, GROOVY, GROUPS, HEADLESS, JABAWS, ANNOTATION,
   ANNOTATION2, DISPLAY, GUI, NEWS, NOQUESTIONNAIRE, SORTBYTREE, USAGESTATS,
   HELP("h"), CALCULATION, MENUBAR, STATUS, SHOWOVERVIEW, ANNOTATIONS,
   COLOUR, FEATURES, GROOVY, GROUPS, HEADLESS, JABAWS, ANNOTATION,
   ANNOTATION2, DISPLAY, GUI, NEWS, NOQUESTIONNAIRE, SORTBYTREE, USAGESTATS,
-  OPEN, OPEN2, PROPS, QUESTIONNAIRE, SETPROP, TREE, VDOC, VSESS, OUTPUT,
+  OPEN, OPENNEW, PROPS, QUESTIONNAIRE, SETPROP, TREE, VDOC, VSESS, OUTPUT,
   OUTPUTTYPE, SSANNOTATION, NOTEMPFAC, TEMPFAC, TEMPFAC_LABEL, TEMPFAC_DESC,
   TEMPFAC_SHADING, TITLE, PAEMATRIX, WRAP, NOSTRUCTURE, STRUCTURE, IMAGE,
   QUIT, CLOSE, DEBUG("d"), QUIET("q"), ARGFILE, INCREMENT, NPP("n++"),
   OUTPUTTYPE, SSANNOTATION, NOTEMPFAC, TEMPFAC, TEMPFAC_LABEL, TEMPFAC_DESC,
   TEMPFAC_SHADING, TITLE, PAEMATRIX, WRAP, NOSTRUCTURE, STRUCTURE, IMAGE,
   QUIT, CLOSE, DEBUG("d"), QUIET("q"), ARGFILE, INCREMENT, NPP("n++"),
-  SUBSTITUTIONS, NIL;
+  SUBSTITUTIONS, NIL, SPLASH;
 
   protected static enum Opt
   {
 
   protected static enum Opt
   {
@@ -43,14 +43,17 @@ public enum Arg
     ANNOTATION2.setOptions(true, Opt.BOOLEAN, Opt.LINKED);
     DISPLAY.setOptions(true, Opt.BOOLEAN);
     GUI.setOptions(true, Opt.BOOLEAN);
     ANNOTATION2.setOptions(true, Opt.BOOLEAN, Opt.LINKED);
     DISPLAY.setOptions(true, Opt.BOOLEAN);
     GUI.setOptions(true, Opt.BOOLEAN);
-    NEWS.setOptions(true, Opt.BOOLEAN);
-    NOQUESTIONNAIRE.setOptions(Opt.UNARY); // unary as --questionnaire=val
-                                           // expects a string value
+    NEWS.setOptions(true, Opt.BOOLEAN, Opt.BOOTSTRAP);
+    SPLASH.setOptions(true, Opt.BOOLEAN, Opt.BOOTSTRAP);
+    NOQUESTIONNAIRE.setOptions(Opt.UNARY, Opt.BOOTSTRAP); // unary as
+                                                          // --questionnaire=val
+    // expects a string value
     SORTBYTREE.setOptions(true, Opt.BOOLEAN);
     USAGESTATS.setOptions(true, Opt.BOOLEAN);
     OPEN.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.GLOB,
             Opt.ALLOWSUBSTITUTIONS);
     SORTBYTREE.setOptions(true, Opt.BOOLEAN);
     USAGESTATS.setOptions(true, Opt.BOOLEAN);
     OPEN.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.GLOB,
             Opt.ALLOWSUBSTITUTIONS);
-    OPEN2.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS);
+    OPENNEW.setOptions(Opt.STRING, Opt.MULTI, Opt.GLOB,
+            Opt.ALLOWSUBSTITUTIONS);
     PROPS.setOptions(Opt.STRING, Opt.BOOTSTRAP);
     QUESTIONNAIRE.setOptions(Opt.STRING);
     SETPROP.setOptions(Opt.STRING);
     PROPS.setOptions(Opt.STRING, Opt.BOOTSTRAP);
     QUESTIONNAIRE.setOptions(Opt.STRING);
     SETPROP.setOptions(Opt.STRING);
index c6580a7..f22ca7f 100644 (file)
@@ -49,6 +49,12 @@ public class ArgParser
   // the counter added to the default linked id prefix
   private int defaultLinkedIdCounter = 0;
 
   // the counter added to the default linked id prefix
   private int defaultLinkedIdCounter = 0;
 
+  // the linked id prefix used for --opennew files
+  protected static final String OPENNEWLINKEDIDPREFIX = "OPENNEW:";
+
+  // the counter added to the default linked id prefix
+  private int opennewLinkedIdCounter = 0;
+
   // the linked id used to increment the idCounter (and use the incremented
   // value)
   private static final String INCREMENTAUTOCOUNTERLINKEDID = "{++n}";
   // the linked id used to increment the idCounter (and use the incremented
   // value)
   private static final String INCREMENTAUTOCOUNTERLINKEDID = "{++n}";
@@ -115,26 +121,26 @@ public class ArgParser
   private void parse(List<String> args)
   {
     int argIndex = 0;
   private void parse(List<String> args)
   {
     int argIndex = 0;
-    boolean initialFilenameArgs = true;
+    boolean openEachInitialFilenames = true;
     for (int i = 0; i < args.size(); i++)
     {
       String arg = args.get(i);
 
     for (int i = 0; i < args.size(); i++)
     {
       String arg = args.get(i);
 
+      Console.debug("##### Looking at arg '" + arg + "'");
+
       // If the first arguments do not start with "--" or "-" or is "open" and
       // is a filename that exists it is probably a file/list of files to open
       // so we fake an Arg.OPEN argument and when adding files only add the
       // single arg[i] and increment the defaultLinkedIdCounter so that each of
       // these files is opened separately.
       // If the first arguments do not start with "--" or "-" or is "open" and
       // is a filename that exists it is probably a file/list of files to open
       // so we fake an Arg.OPEN argument and when adding files only add the
       // single arg[i] and increment the defaultLinkedIdCounter so that each of
       // these files is opened separately.
-      if (initialFilenameArgs && !arg.startsWith(DOUBLEDASH)
+      if (openEachInitialFilenames && !arg.startsWith(DOUBLEDASH)
               && !arg.startsWith("-") && new File(arg).exists())
       {
               && !arg.startsWith("-") && new File(arg).exists())
       {
-        arg = DOUBLEDASH + Arg.OPEN.getName();
-        Console.debug("Adding argument '" + args.get(i)
-                + "' as a file to be opened");
+        arg = DOUBLEDASH + Arg.OPENNEW.getName();
       }
       else
       {
       }
       else
       {
-        initialFilenameArgs = false;
+        openEachInitialFilenames = false;
       }
 
       String argName = null;
       }
 
       String argName = null;
@@ -223,16 +229,8 @@ public class ArgParser
           {
             // if this is the first argument with a file list at the start of
             // the args we add filenames from index i instead of i+1
           {
             // if this is the first argument with a file list at the start of
             // the args we add filenames from index i instead of i+1
-            // and assume they should be opened separately
-            if (initialFilenameArgs)
-            {
-              val = args.get(i);
-              defaultLinkedIdCounter++;
-            }
-            else
-            {
-              vals = getShellGlobbedFilenameValues(a, args, i + 1);
-            }
+            vals = getShellGlobbedFilenameValues(a, args,
+                    openEachInitialFilenames ? i : i + 1);
           }
           else
           {
           }
           else
           {
@@ -261,7 +259,14 @@ public class ArgParser
                 .append(Integer.toString(defaultLinkedIdCounter))
                 .toString();
         boolean usingDefaultLinkedId = false;
                 .append(Integer.toString(defaultLinkedIdCounter))
                 .toString();
         boolean usingDefaultLinkedId = false;
-        if (a.hasOption(Opt.LINKED))
+        if (a == Arg.OPENNEW)
+        {
+          linkedId = new StringBuilder(OPENNEWLINKEDIDPREFIX)
+                  .append(Integer.toString(opennewLinkedIdCounter))
+                  .toString();
+          opennewLinkedIdCounter++;
+        }
+        else if (a.hasOption(Opt.LINKED))
         {
           if (linkedId == null)
           {
         {
           if (linkedId == null)
           {
@@ -319,13 +324,9 @@ public class ArgParser
           continue;
         }
 
           continue;
         }
 
+        boolean argIndexIncremented = false;
         ArgValues avs = avm.getOrCreateArgValues(a);
         ArgValues avs = avm.getOrCreateArgValues(a);
-        if (avs == null)
-        {
-          avs = new ArgValues(a);
-        }
 
 
-        boolean argIndexIncremented = false;
         // store appropriate value
         if (a.hasOption(Opt.STRING))
         {
         // store appropriate value
         if (a.hasOption(Opt.STRING))
         {
@@ -358,9 +359,6 @@ public class ArgParser
         // store in appropriate place
         if (a.hasOption(Opt.LINKED))
         {
         // store in appropriate place
         if (a.hasOption(Opt.LINKED))
         {
-          // allow a default linked id for single usage
-          if (linkedId == null)
-            linkedId = defaultLinkedId;
           // store the order of linkedIds
           if (linkedOrder == null)
             linkedOrder = new ArrayList<>();
           // store the order of linkedIds
           if (linkedOrder == null)
             linkedOrder = new ArrayList<>();
index 019e7c7..2aa32df 100644 (file)
@@ -11,10 +11,13 @@ public class ArgValue
 
   private String id;
 
 
   private String id;
 
+  private SubVals subVals = null;
+
   protected ArgValue(String value, int argIndex)
   {
     this.value = value;
     this.argIndex = argIndex;
   protected ArgValue(String value, int argIndex)
   {
     this.value = value;
     this.argIndex = argIndex;
+    this.subVals = ArgParser.getSubVals(getValue());
   }
 
   public String getValue()
   }
 
   public String getValue()
@@ -39,6 +42,18 @@ public class ArgValue
 
   public SubVals getSubVals()
   {
 
   public SubVals getSubVals()
   {
-    return ArgParser.getSubVals(getValue());
+    return subVals;
+  }
+
+  public String getSubVal(String key)
+  {
+    if (subVals == null || !subVals.has(key))
+      return null;
+    return subVals.get(key);
+  }
+
+  protected void putSubVal(String key, String val)
+  {
+    this.subVals.put(key, val);
   }
 }
\ No newline at end of file
   }
 }
\ No newline at end of file
index bcb86f9..49e8686 100644 (file)
@@ -22,10 +22,10 @@ public class BootstrapArgs
 
   private BootstrapArgs(List<String> args)
   {
 
   private BootstrapArgs(List<String> args)
   {
-    init(args);
+    parse(args);
   }
 
   }
 
-  private void init(List<String> args)
+  private void parse(List<String> args)
   {
     if (args == null)
       return;
   {
     if (args == null)
       return;
@@ -36,15 +36,28 @@ public class BootstrapArgs
       String val = null;
       if (arg.startsWith(ArgParser.DOUBLEDASH))
       {
       String val = null;
       if (arg.startsWith(ArgParser.DOUBLEDASH))
       {
+        // remove "--"
+        System.out.println("###### BOOTSTRAP: '" + arg + "'");
+        arg = arg.substring(ArgParser.DOUBLEDASH.length());
         int equalPos = arg.indexOf('=');
         int equalPos = arg.indexOf('=');
-        if (equalPos > -1)
+        if (equalPos > -1
+                && ArgParser.argMap.containsKey(arg.substring(0, equalPos)))
         {
         {
-          argName = arg.substring(ArgParser.DOUBLEDASH.length(), equalPos);
+          argName = arg.substring(0, equalPos);
           val = arg.substring(equalPos + 1);
         }
           val = arg.substring(equalPos + 1);
         }
-        else
+        // check for boolean prepended by "no"
+        else if (arg.startsWith(ArgParser.NEGATESTRING)
+                && ArgParser.argMap.containsKey(
+                        arg.substring(ArgParser.NEGATESTRING.length())))
+        {
+          System.out.println("###### BOOTSTRAP IN NEGATESTRING");
+          argName = arg.substring(ArgParser.NEGATESTRING.length());
+          val = "false";
+        }
+        else if (ArgParser.argMap.containsKey(arg))
         {
         {
-          argName = arg.substring(ArgParser.DOUBLEDASH.length());
+          argName = arg;
           val = "true";
         }
 
           val = "true";
         }
 
@@ -73,6 +86,8 @@ public class BootstrapArgs
         }
         else
         {
         }
         else
         {
+          System.err.println(
+                  "###### Adding '" + a.getName() + "' with '" + val + "'");
           add(a, val);
         }
       }
           add(a, val);
         }
       }
@@ -140,4 +155,12 @@ public class BootstrapArgs
     List<String> aL = bootstrapArgMap.get(a);
     return (aL == null || aL.size() == 0) ? null : aL.get(0);
   }
     List<String> aL = bootstrapArgMap.get(a);
     return (aL == null || aL.size() == 0) ? null : aL.get(0);
   }
+
+  public boolean getBoolean(Arg a)
+  {
+    if (!bootstrapArgMap.containsKey(a)
+            || !(a.hasOption(Opt.BOOLEAN) || a.hasOption(Opt.UNARY)))
+      return false;
+    return Boolean.parseBoolean(get(a));
+  }
 }
 }
index 796c03d..e6a7cb2 100644 (file)
@@ -47,7 +47,7 @@ public class SubVals
         {
           if (subVals == null)
             subVals = new HashMap<>();
         {
           if (subVals == null)
             subVals = new HashMap<>();
-          subVals.put(subvalString.substring(0, equals),
+          this.put(subvalString.substring(0, equals),
                   subvalString.substring(equals + 1));
         }
         else
                   subvalString.substring(equals + 1));
         }
         else
@@ -58,14 +58,16 @@ public class SubVals
             setIndex = true;
           } catch (NumberFormatException e)
           {
             setIndex = true;
           } catch (NumberFormatException e)
           {
-            Console.warn("Failed to obtain subvalue or index from '" + item
-                    + "'. Setting index=0 and using content='" + content
-                    + "'.");
+            // store this non-numeric key as a "true" value
+            subVals.put(subvalsString, "true");
           }
         }
       }
       if (!setIndex)
         this.index = NOTSET;
           }
         }
       }
       if (!setIndex)
         this.index = NOTSET;
+      else
+        Console.debug("SubVals from '" + subvalsString + "' has index "
+                + this.index + " set");
     }
     else
     {
     }
     else
     {
@@ -73,6 +75,13 @@ public class SubVals
     }
   }
 
     }
   }
 
+  protected void put(String key, String val)
+  {
+    if (subVals == null)
+      subVals = new HashMap<>();
+    subVals.put(key, val);
+  }
+
   public boolean notSet()
   {
     // notSet is true if content present but nonsensical
   public boolean notSet()
   {
     // notSet is true if content present but nonsensical
index 0197db7..cd62c9f 100644 (file)
@@ -808,7 +808,7 @@ public class Desktop extends jalview.jbgui.GDesktop
     // TODO - write tests and fix AlignFrame.paste() which doesn't track if
     // clipboard has come from a different alignment window than the one where
     // paste has been called! JAL-4151
     // TODO - write tests and fix AlignFrame.paste() which doesn't track if
     // clipboard has come from a different alignment window than the one where
     // paste has been called! JAL-4151
-    
+
     if (Desktop.jalviewClipboard != null)
     {
       // The clipboard was filled from within Jalview, we must use the
     if (Desktop.jalviewClipboard != null)
     {
       // The clipboard was filled from within Jalview, we must use the
@@ -835,30 +835,32 @@ public class Desktop extends jalview.jbgui.GDesktop
       }
 
       Desktop.addInternalFrame(af, newtitle, AlignFrame.DEFAULT_WIDTH,
       }
 
       Desktop.addInternalFrame(af, newtitle, AlignFrame.DEFAULT_WIDTH,
-            AlignFrame.DEFAULT_HEIGHT);
+              AlignFrame.DEFAULT_HEIGHT);
 
 
-    } else {
-    try
+    }
+    else
     {
     {
-      Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
-      Transferable contents = c.getContents(this);
-
-      if (contents != null)
+      try
       {
       {
-        String file = (String) contents
-                .getTransferData(DataFlavor.stringFlavor);
+        Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
+        Transferable contents = c.getContents(this);
 
 
-        FileFormatI format = new IdentifyFile().identify(file,
-                DataSourceType.PASTE);
+        if (contents != null)
+        {
+          String file = (String) contents
+                  .getTransferData(DataFlavor.stringFlavor);
 
 
-        new FileLoader().LoadFile(file, DataSourceType.PASTE, format);
+          FileFormatI format = new IdentifyFile().identify(file,
+                  DataSourceType.PASTE);
 
 
+          new FileLoader().LoadFile(file, DataSourceType.PASTE, format);
+
+        }
+      } catch (Exception ex)
+      {
+        System.out.println(
+                "Unable to paste alignment from system clipboard:\n" + ex);
       }
       }
-    } catch (Exception ex)
-    {
-      System.out.println(
-              "Unable to paste alignment from system clipboard:\n" + ex);
-    }
     }
   }
 
     }
   }