JAL-629 Opening files in new windows. not working yet
[jalview.git] / src / jalview / bin / argparser / ArgParser.java
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 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}";
@@ -115,26 +121,26 @@ public class ArgParser
   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);
 
+      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 (initialFilenameArgs && !arg.startsWith(DOUBLEDASH)
+      if (openEachInitialFilenames && !arg.startsWith(DOUBLEDASH)
               && !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
       {
-        initialFilenameArgs = false;
+        openEachInitialFilenames = false;
       }
 
       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
-            // 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
           {
@@ -261,7 +259,14 @@ public class ArgParser
                 .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)
           {
@@ -319,13 +324,9 @@ public class ArgParser
           continue;
         }
 
+        boolean argIndexIncremented = false;
         ArgValues avs = avm.getOrCreateArgValues(a);
-        if (avs == null)
-        {
-          avs = new ArgValues(a);
-        }
 
-        boolean argIndexIncremented = false;
         // store appropriate value
         if (a.hasOption(Opt.STRING))
         {
@@ -358,9 +359,6 @@ public class ArgParser
         // 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<>();