JAL-1460 process .lnk files dragged to Jalview when on Windows using WindowsShortCutH...
[jalview.git] / src / jalview / gui / Desktop.java
index 9598f60..e14e991 100644 (file)
@@ -32,6 +32,7 @@ import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
 import jalview.io.FileFormats;
 import jalview.io.FileLoader;
+import jalview.io.FormatAdapter;
 import jalview.io.IdentifyFile;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
@@ -116,6 +117,8 @@ import javax.swing.event.InternalFrameEvent;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
+import org.stackoverflowusers.file.WindowsShortcut;
+
 /**
  * Jalview Desktop
  * 
@@ -3404,6 +3407,28 @@ public class Desktop extends jalview.jbgui.GDesktop
           files.add(file.toString());
         }
       }
+      if (Platform.isWindows())
+      {
+        Cache.log.debug("Scanning dropped content for Windows Link Files");
+
+         // resolve any .lnk files in the file drop
+        for (int f=0;f<files.size();f++)
+        {
+          if (protocols.get(f).equals(DataSourceType.FILE)) {
+              File lf = new File(files.get(f));
+              if (WindowsShortcut.isPotentialValidLink(lf)) {
+                // process link file to get a URL
+                Cache.log.debug("Found potential link file: "+lf);
+                WindowsShortcut wscfile = new WindowsShortcut(lf);
+                String fullname = wscfile.getRealFilename();
+                protocols.set(f,FormatAdapter.checkProtocol(fullname));
+                files.set(f,fullname);
+                Cache.log.debug("Parsed real filename "+fullname+" to extract protocol: "+protocols.get(f));
+            }
+          }
+        }
+      }
+        
       if (Cache.log.isDebugEnabled())
       {
         if (data == null || !added)