Revision: 4701
          http://sourceforge.net/p/vexi/code/4701
Author:   mkpg2
Date:     2014-06-01 20:29:14 +0000 (Sun, 01 Jun 2014)
Log Message:
-----------
vexi.file.loadMultiple(). Select multiple files in a file dialog.

Modified Paths:
--------------
    branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java
    branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java
    branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java
    branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp
    
branches/vexi3/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/filedialogs.t

Modified: 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java
===================================================================
--- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java  
2014-05-24 00:02:26 UTC (rev 4700)
+++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java  
2014-06-01 20:29:14 UTC (rev 4701)
@@ -52,13 +52,13 @@
 import java.awt.image.MemoryImageSource;
 import java.awt.image.PixelGrabber;
 import java.io.File;
-import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.ImageIcon;
 
 import org.ibex.js.JS;
-import org.ibex.js.JSExn;
 import org.ibex.util.Callable;
 import org.ibex.util.IOUtil;
 import org.ibex.util.Semaphore;
@@ -178,7 +178,7 @@
 
     static class FileDialogHelper extends FileDialog implements 
WindowListener, ComponentListener {
         Semaphore s;
-        public FileDialogHelper(String suggestedFileName, Semaphore s, boolean 
write) {
+        public FileDialogHelper(String suggestedFileName, Semaphore s, boolean 
write, boolean multiple) {
             super(new Frame(), write ? "Save" : "Open", write ? 
FileDialog.SAVE : FileDialog.LOAD);
             this.s = s;
             addWindowListener(this);
@@ -189,6 +189,10 @@
                 setDirectory(suggestedFileName.substring(0, 
suggestedFileName.lastIndexOf(File.separatorChar)));
                 
setFile(suggestedFileName.substring(suggestedFileName.lastIndexOf(File.separatorChar)
 + 1));
             }
+            // checked like this so java 1.6 can still run if multiple=false
+            if(multiple){ 
+               setMultipleMode(true);
+            }
             setVisible(true);
         }
         public void windowActivated(WindowEvent e) { }
@@ -204,10 +208,17 @@
         public void componentShown(ComponentEvent e) { }
     };
 
-    protected String _fileDialog(String suggestedFileName, boolean write) {
+    protected Object _fileDialog(String suggestedFileName, boolean write, 
boolean multiple) {
         final Semaphore s = new Semaphore();
-        FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, 
write);
+        FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, 
write, multiple);
         s.block();
+        // checked like this so java 1.6 can still run if multiple=false
+        if(multiple){
+               File[] files = fd.getFiles();
+               List<String> r = new ArrayList(files.length);
+               for(File f: files) r.add(f.getAbsolutePath());
+               return r;
+        }
         return fd.getDirectory() == null ? null : (fd.getDirectory() + 
File.separatorChar + fd.getFile());
     }
 

Modified: 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java
===================================================================
--- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java  
2014-05-24 00:02:26 UTC (rev 4700)
+++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java  
2014-06-01 20:29:14 UTC (rev 4701)
@@ -32,6 +32,7 @@
                if("edit".equals(key)) return METHOD;
                if("email".equals(key)) return METHOD;
                if("open".equals(key)) return METHOD;
+               if("openMultiple".equals(key)) return METHOD;
                if("print".equals(key)) return METHOD;
                return super.get(jskey);
        }
@@ -59,6 +60,10 @@
                                                desktop.open(expectFile(arg, 
true));
                                                return null;
                                        }
+                                       if("openMultiple".equals(method)) {
+                                               desktop.open(expectFile(arg, 
true));
+                                               return null;
+                                       }
                                        if("print".equals(method)) {
                                                desktop.print(expectFile(arg));
                                                return null;

Modified: 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java
===================================================================
--- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java 
2014-05-24 00:02:26 UTC (rev 4700)
+++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java 
2014-06-01 20:29:14 UTC (rev 4701)
@@ -238,10 +238,11 @@
     public static synchronized void decodeJPEG(InputStream is, Picture p) { 
platform._decodeJPEG(is, p); }
     protected abstract void _decodeJPEG(InputStream is, Picture p);
 
-    /** displays a platform-specific "open file" dialog and returns the chosen 
filename, or null if the user hit cancel */
-    protected String _fileDialog(String suggestedFileName, boolean write) { 
return null; }
-    public static String fileDialog(String suggestedFileName, boolean write) 
throws org.ibex.js.JSExn {
-        return platform._fileDialog(suggestedFileName, write);
+    /** displays a platform-specific "open file" dialog and returns the chosen
+     * either a list of filenames (multiple), a filename (not multiple) or 
null if the user hit cancel */
+    protected Object _fileDialog(String suggestedFileName, boolean write, 
boolean multiple) { return null; }
+    public static Object fileDialog(String suggestedFileName, boolean write, 
boolean multiple) throws org.ibex.js.JSExn {
+        return platform._fileDialog(suggestedFileName, write, multiple);
     }
 
     /** opens a new browser window */

Modified: branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp
===================================================================
--- branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp       
2014-05-24 00:02:26 UTC (rev 4700)
+++ branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp       
2014-06-01 20:29:14 UTC (rev 4701)
@@ -18,6 +18,7 @@
 import org.vexi.plat.Platform;
 import org.vexi.graphics.Color;
 import org.vexi.util.Log;
+import java.util.List;
 
 
 /** Singleton class that provides all functionality in the vexi.* namespace */
@@ -385,6 +386,7 @@
         case "debug": return Main.debug ? JSU.T : JSU.F;
         case "exit": return METHOD;
         case "file.load": return METHOD;
+        case "file.loadMultiple": return METHOD;
         case "file.remove": return METHOD;
         case "file.save": return METHOD;
         case "file.temp":    return METHOD;
@@ -700,20 +702,31 @@
     }
     
     private Fountain.File accessFile(JS[] args, boolean write) throws JSExn {
-        String f = Platform.fileDialog(args.length>0?JSU.toString(args[0]):"", 
write);
+        Object f = Platform.fileDialog(args.length>0?JSU.toString(args[0]):"", 
write, false);
         if (f==null) {
             return null;
         }
-        return new Fountain.File(f,write,false);
+        return new Fountain.File((String)f,write,false);
     }
     
+    private JSArray accessFiles(JS[] args, boolean write) throws JSExn {
+        List<String> fs = 
(List)Platform.fileDialog(args.length>0?JSU.toString(args[0]):"", write, true);
+        JSArray r = new JSArray(fs.size());
+        for(String f: fs){
+               r.add(new Fountain.File(f,write,false));
+        }
+        return r;        
+    }
+    
+    
     public JS callMethod(JS this_, JS method, JS[] args) throws JSExn {
         try {
             //#switch(JSU.toString(method))
             case "bless":           return bless_jsthread(this_, 
args[0],(args.length<2)?null:args[1]);
             case "cache":           return Resources.cache(args);
             case "date":            return new ECMADate(args);
-            case "file.load":       return accessFile(args,false);
+            case "file.load":          return accessFile(args,false);
+            case "file.loadMultiple":  return accessFiles(args,false);
             case "file.save":       return accessFile(args,true);
             case "file.temp":       return Resources.createTempFile(args);
             case "js.eval":         return Methods.eval(args);

Modified: 
branches/vexi3/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/filedialogs.t
===================================================================
--- 
branches/vexi3/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/filedialogs.t  
    2014-05-24 00:02:26 UTC (rev 4700)
+++ 
branches/vexi3/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/filedialogs.t  
    2014-06-01 20:29:14 UTC (rev 4701)
@@ -16,6 +16,7 @@
             <ui:box />
             <textfield id="filename"/>
             <button id="open" text="Open" />
+            <button id="openMultiple" text="Open Multiple" />
             <button id="save" text="Save" />
             <ui:box />
         </ui:box>
@@ -37,12 +38,35 @@
                 name = ss[ss.length-1];
                 
                 $filename.text = name;
-                var text = vexi.stream.parse.utf8(stream);
+                var text = vexi.stream.utf8reader(stream).all;
                 $text.text = text;
             }
             return;
         }
         
+        $openMultiple.action ++= function(v) {
+            vexi.thread = function() {
+                var streams = vexi.file.loadMultiple($filename.text);
+                var text = [];
+                for(var i,stream in streams){
+                       var name = vexi.stream.nameOf(stream);
+                       // FIXME - use regex
+                       // FIXME - support full path, rather than just the
+                       // filename (requires change to file dialog support)
+                       var ss = name.split("\\");
+                       name = ss[ss.length-1];
+                       ss = name.split("/");
+                       name = ss[ss.length-1];
+                       
+                       text.push("**** "+name);
+                       text.push(vexi.stream.utf8reader(stream).all);
+                } 
+                trace(text);
+                $text.text = text.join("\n");                
+            }
+            return;
+        }
+        
         $save.action ++= function(v) {
             vexi.thread = function() {
                 var stream = vexi.file.save($filename.text);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to