Commits

ryanackley committed f6124d3

File dialog in windows. Modal file/folder select dialogs for windows

Comments (0)

Files changed (2)

Win/DialogManagerWin.cpp

     static DialogManagerWin inst;
     return &inst;
 }
+void DialogManagerWin::OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
+	_showDialog(FALSE, host, win, cb);
+}
 
 void DialogManagerWin::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
-    FB::PluginWindowWin* wndWin = dynamic_cast<FB::PluginWindowWin*>(win);
+    _showDialog(TRUE, host, win, cb);
+}
+
+void DialogManagerWin::_showDialog(const BOOL isFolder, const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
+	/*FB::PluginWindowWin* wndWin = dynamic_cast<FB::PluginWindowWin*>(win);
     FB::PluginWindowlessWin* wndlessWin = dynamic_cast<FB::PluginWindowlessWin*>(win);
 
-    HWND browserWindow = wndWin ? wndWin->getBrowserHWND() : wndlessWin->getHWND();
-    boost::thread dlgThread(&DialogManagerWin::_showFolderDialog, this, browserWindow, cb);
+    HWND browserWindow = wndWin ? wndWin->getBrowserHWND() : wndlessWin->getHWND();*/
+	HWND browserWindow = GetForegroundWindow();
+	if(isFolder)
+	{
+		boost::thread dlgThread(&DialogManagerWin::_showFolderDialog, this, browserWindow, cb);
+	}
+	else
+	{
+		boost::thread dlgThread(&DialogManagerWin::_showFileDialog, this, browserWindow, cb);
+	}
 }
 
 void DialogManagerWin::_showFolderDialog(HWND wnd, const PathCallback& cb) {
         cb("");
     }
 }
-void DialogManagerWin::_showFileDialog(HWND wnd, const std::string& path, const std::string& filter, const PathCallback& cb)
+void DialogManagerWin::_showFileDialog(HWND wnd,const PathCallback& cb)
 {
-    wchar_t Filestring[256];
+    wchar_t Filestring[4096];
     std::string out;
 
-    std::wstring wFilter(FB::utf8_to_wstring(filter));
-    std::wstring wPath(FB::utf8_to_wstring(filter));
+    //std::wstring wFilter(FB::utf8_to_wstring(filter));
+    //std::wstring wPath(FB::utf8_to_wstring(filter));
 
     OPENFILENAME opf;
     opf.hwndOwner = wnd;
-    opf.lpstrFilter = wFilter.c_str();
+    opf.lpstrFilter = NULL;
     opf.lpstrCustomFilter = 0;
     opf.nMaxCustFilter = 0L;
     opf.nFilterIndex = 1L;
     opf.lpstrFile = Filestring;
     opf.lpstrFile[0] = '\0';
-    opf.nMaxFile = 256;
+    opf.nMaxFile = 4096;
     opf.lpstrFileTitle = 0;
     opf.nMaxFileTitle=50;
-    opf.lpstrInitialDir = wPath.c_str();
-    opf.lpstrTitle = L"Choose directory to import";
+    opf.lpstrInitialDir = NULL;
+    opf.lpstrTitle = L"Select file";
     opf.nFileOffset = 0;
     opf.nFileExtension = 0;
     opf.lpstrDefExt = L"*.*";

Win/DialogManagerWin.h

 {
 public:
     void OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
+	void OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
 
 protected:
     DialogManagerWin() {};
     ~DialogManagerWin() {};
-    void _showFileDialog(HWND wnd, const std::string& path, const std::string& filter, const PathCallback& cb);
+    void _showFileDialog(HWND wnd, const PathCallback& cb);
     void _showFolderDialog(HWND wnd, const PathCallback& cb);
+	void _showDialog(const BOOL isFolder, const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
     friend class DialogManager;
 };
 #endif // DialogManagerWin_h__