Bug 784842 - Add the new async nsIFilePicker::open to the XUL file picker. r=roc
authorBrian R. Bondy <netzen@gmail.com>
Fri, 24 Aug 2012 07:55:08 -0400
changeset 105499 730c4f0ec3ae03637cd8d79135d10fa125677640
parent 105498 af3d980899704fa608576eb27c5a97088311a315
child 105500 b543ecb718e3dd5e51b43942a137f75d86c1c2ed
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersroc
bugs784842
milestone17.0a1
Bug 784842 - Add the new async nsIFilePicker::open to the XUL file picker. r=roc
toolkit/components/filepicker/nsFilePicker.js
--- a/toolkit/components/filepicker/nsFilePicker.js
+++ b/toolkit/components/filepicker/nsFilePicker.js
@@ -178,16 +178,29 @@ nsFilePicker.prototype = {
     }
   },
 
   appendFilter: function(title, extensions) {
     this.mFilterTitles.push(title);
     this.mFilters.push(extensions);
   },
 
+  open: function(aFilePickerShownCallback) {
+    var tm = Components.classes["@mozilla.org/thread-manager;1"]
+                       .getService(Components.interfaces.nsIThreadManager);
+    tm.mainThread.dispatch(function() {
+      try {
+        let result = this.show();
+        aFilePickerShownCallback.done(result);
+      } catch(ex) {
+        aFilePickerShownCallback.done(this.returnCancel);
+      }
+    }.bind(this), Components.interfaces.nsIThread.DISPATCH_NORMAL);
+  },
+
   show: function() {
     var o = new Object();
     o.title = this.mTitle;
     o.mode = this.mMode;
     o.displayDirectory = this.mDisplayDirectory;
     o.defaultString = this.mDefaultString;
     o.filterIndex = this.mFilterIndex;
     o.filters = new Object();