Commits

ryanackley committed 10a9c95

Added a file select for tincr 2.0

  • Participants
  • Parent commits 545df03

Comments (0)

Files changed (5)

File DialogManager.h

 public:
     static DialogManager* get();
     virtual void OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) = 0;
+    virtual void OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) = 0;
     
 protected:
     DialogManager() {}

File Mac/DialogManagerMac.h

 {
 public:
     void OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
-    void _showFolderDialog(FB::PluginWindow* win, const PathCallback& cb);
+    void OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
+    void _showFolderDialog(FB::PluginWindow* win, const PathCallback& cb, BOOL forFolder);
     
 protected:
     DialogManagerMac() {};

File Mac/DialogManagerMac.mm

 
 void DialogManagerMac::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb)
 {
-    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerMac>(), boost::bind(&DialogManagerMac::_showFolderDialog, this, win, cb));
+    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerMac>(), boost::bind(&DialogManagerMac::_showFolderDialog, this, win, cb, TRUE));
 }
 
-void DialogManagerMac::_showFolderDialog(FB::PluginWindow* win, const PathCallback& cb)
+void DialogManagerMac::OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb)
 {
-    FBLOG_INFO("DialogManagerMac", "Showing folder dialog");
+    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerMac>(), boost::bind(&DialogManagerMac::_showFolderDialog, this, win, cb, FALSE));
+}
+
+
+void DialogManagerMac::_showFolderDialog(FB::PluginWindow* win, const PathCallback& cb, BOOL forFolder)
+{
+    FBLOG_INFO("DialogManagerMac", "Showing file/folder select dialog");
     std::string out;
     int result;
     NSAutoreleasePool* pool = [NSAutoreleasePool new];
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     
     [oPanel setAllowsMultipleSelection:NO];
-    [oPanel setCanChooseFiles:NO];
-    [oPanel setCanChooseDirectories:YES];
+    if (forFolder)
+    {
+        [oPanel setCanChooseFiles:NO];
+        [oPanel setCanChooseDirectories:YES];
+    }
+    else
+    {
+        [oPanel setCanChooseFiles:YES];
+        [oPanel setCanChooseDirectories:NO];
+    }
     result = [oPanel runModalForDirectory:nil
                                      file:nil types:nil];
     

File NPAPIFileIOforChromeAPI.cpp

     path p(strPath);
     return remove_all(p) != 0;
 }
-void NPAPIFileIOforChromeAPI::launchFileSelect(JSObjectPtr callback)
+
+void NPAPIFileIOforChromeAPI::launchFolderSelect(JSObjectPtr callback)
 {
     DialogManager* dlgMgr = DialogManager::get();
 	NPAPIFileIOforChromePtr plugin = m_plugin.lock();
     dlgMgr->OpenFolderDialog(m_host, plugin->GetWindow(), boost::bind(&NPAPIFileIOforChromeAPI::fileSelectCallback, this, _1, callback));
 }
+
+void NPAPIFileIOforChromeAPI::launchFileSelect(JSObjectPtr callback)
+{
+    DialogManager* dlgMgr = DialogManager::get();
+	NPAPIFileIOforChromePtr plugin = m_plugin.lock();
+    dlgMgr->OpenFileDialog(m_host, plugin->GetWindow(), boost::bind(&NPAPIFileIOforChromeAPI::fileSelectCallback, this, _1, callback));
+}
+
 void NPAPIFileIOforChromeAPI::fileSelectCallback(const std::string &path, JSObjectPtr callback)
 {
     callback->Invoke("",FB::variant_list_of(path));

File NPAPIFileIOforChromeAPI.h

         registerMethod("echo",      make_method(this, &NPAPIFileIOforChromeAPI::echo));
         registerMethod("testEvent", make_method(this, &NPAPIFileIOforChromeAPI::testEvent));
         //registerMethod("saveToFileUrl",      make_method(this, &NPAPIFileIOforChromeAPI::saveToFileUrl));
+        registerMethod("launchFolderSelect",     make_method(this, &NPAPIFileIOforChromeAPI::launchFolderSelect));
         registerMethod("launchFileSelect",     make_method(this, &NPAPIFileIOforChromeAPI::launchFileSelect));
         registerMethod("watchDirectory",     make_method(this, &NPAPIFileIOforChromeAPI::watchDirectory));
         registerMethod("stopWatching",     make_method(this, &NPAPIFileIOforChromeAPI::stopWatching));
     bool isDirectory(std::string path);
     bool fileExists(std::string path);
     bool removeRecursively(std::string path);
+    void launchFolderSelect(FB::JSObjectPtr callback);
     void launchFileSelect(FB::JSObjectPtr callback); 
     void watchDirectory(std::string key, std::string path, FB::JSObjectPtr callback);
     void stopWatching(std::string key);