windows: Show the open dialog on a separate thread.

Allows the screen to continue rendering, which should prevent black
screens, etc. while browsing.

May help #2755.
This commit is contained in:
Unknown W. Brackets committed 2014-01-19 20:15:08 -08:00
1 parent 6c90f4bcf7
commit 360068075b
4 files changed
+121 -38

No files matched your search

+42 -1
View File
@@ -3,6 +3,8 @@
#include "stdafx.h"
#include "shlobj.h"
#include "base/functional.h"
#include "thread/thread.h"
#include "util/text/utf8.h"
#include "ShellUtil.h"
#include "CommDlg.h"
@@ -15,11 +17,15 @@ namespace W32Util
std::string BrowseForFolder(HWND parent, const char *title)
{
std::wstring titleString = ConvertUTF8ToWString(title);
return BrowseForFolder(parent, titleString.c_str());
}
std::string BrowseForFolder(HWND parent, const wchar_t *title)
{
BROWSEINFO info;
memset(&info,0,sizeof(info));
info.hwndOwner = parent;
info.lpszTitle = titleString.c_str();
info.lpszTitle = title;
info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
//info.pszDisplayName
@@ -119,4 +125,39 @@ namespace W32Util
else
return std::vector<std::string>(); // empty vector;
}
AsyncBrowseDialog::AsyncBrowseDialog(HWND parent, UINT completeMsg, std::wstring title)
: type_(DIR), parent_(parent), completeMsg_(completeMsg), title_(title), complete_(false) {
thread_ = new std::thread(std::bind(&AsyncBrowseDialog::Execute, this));
thread_->detach();
}
AsyncBrowseDialog::AsyncBrowseDialog(Type type, HWND parent, UINT completeMsg, std::wstring title, std::wstring initialFolder, std::wstring filter, std::wstring extension)
: type_(type), parent_(parent), completeMsg_(completeMsg), title_(title), initialFolder_(initialFolder), filter_(filter), extension_(extension), complete_(false) {
thread_ = new std::thread(std::bind(&AsyncBrowseDialog::Execute, this));
thread_->detach();
}
bool AsyncBrowseDialog::GetResult(std::string &filename) {
filename = filename_;
return result_;
}
void AsyncBrowseDialog::Execute() {
switch (type_) {
case DIR:
filename_ = BrowseForFolder(parent_, title_.c_str());
result_ = filename_ != "";
complete_ = true;
break;
case OPEN:
case SAVE:
result_ = BrowseForFileName(type_ == OPEN, parent_, title_.c_str(), initialFolder_.size() ? initialFolder_.c_str() : 0, filter_.c_str(), extension_.c_str(), filename_);
complete_ = true;
break;
}
PostMessage(parent_, completeMsg_, 0, 0);
}
}