-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDirDialogShowWindowModal.cpp
More file actions
48 lines (43 loc) · 1.98 KB
/
DirDialogShowWindowModal.cpp
File metadata and controls
48 lines (43 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <wx/wx.h>
#include <wx/dirdlg.h>
#include <wx/stdpaths.h>
#include <wx/windowptr.h>
// Workaround : with wxWidgets version <= 3.2.0 wxDirDialog ShowWindowModal method doesn't exists on other platform that macOS
#if defined(__APPLE__)
using DirDialog = wxDirDialog;
#else
class DirDialog : public wxDirDialog {
public:
DirDialog(wxWindow* parent, const wxString& message = wxDirSelectorPromptStr, const wxString& defaultPath = "", long style = wxDD_DEFAULT_STYLE, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, const wxString& name = wxDirDialogNameStr) : wxDirDialog(parent, message, defaultPath, style, pos, size, name) {}
void ShowWindowModal() {
SetReturnCode(ShowModal());
wxWindowModalDialogEvent event(wxEVT_WINDOW_MODAL_DIALOG_CLOSED, this->GetId());
event.SetEventObject(this);
wxPostEvent(this, event);
}
};
#endif
namespace DirDialogShowWindowModalExample {
class Frame : public wxFrame {
public:
Frame() : wxFrame(nullptr, wxID_ANY, "DirDialog (ShowWindowModal) example") {
button->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) {
wxWindowPtr<DirDialog> folderBrowserDialog(new DirDialog(this, wxEmptyString));
folderBrowserDialog->SetPath(wxStandardPaths::Get().GetDocumentsDir());
folderBrowserDialog->ShowWindowModal();
folderBrowserDialog->Bind(wxEVT_WINDOW_MODAL_DIALOG_CLOSED, [this,folderBrowserDialog](wxWindowModalDialogEvent& event) {
if (event.GetReturnCode() == wxID_OK)
label->SetLabel(wxString::Format("Path = %s", folderBrowserDialog->GetPath()));
});
});
}
private:
wxPanel* panel = new wxPanel {this};
wxButton* button = new wxButton(panel, wxID_ANY, "Folder...", {10, 10});
wxStaticText* label = new wxStaticText(panel, wxID_ANY, "Path = ", {10, 40});
};
class Application : public wxApp {
auto OnInit() -> bool override {return (new Frame)->Show();}
};
}
wxIMPLEMENT_APP(DirDialogShowWindowModalExample::Application);