1 #include "core/zip.hpp"
3 #include "plat-wxwidgets/common.hpp"
4 #include "plat-wxwidgets/filenamebox.hpp"
8 #include <wx/control.h>
9 #include <wx/combobox.h>
11 filenamebox::filenamebox(wxSizer
* sizer
, wxWindow
* parent
, const std::string
& initial_label
, int flags
,
12 wxEvtHandler
* dispatch_to
, wxObjectEventFunction on_fn_change
)
14 wxSizer
* inner
= sizer
;
16 inner
= new wxFlexGridSizer(1, 3, 0, 0);
18 last_label
= initial_label
;
19 label
= new wxStaticText(parent
, wxID_ANY
, towxstring(last_label
));
20 filename
= new wxTextCtrl(parent
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(500, -1));
21 file_select
= new wxButton(parent
, wxID_ANY
, wxT("..."));
22 inner
->Add(label
, 0, wxGROW
);
23 inner
->Add(filename
, 1, wxGROW
);
24 inner
->Add(file_select
, 0, wxGROW
);
25 if((flags
& FNBF_NN
) == 0)
26 filename
->Connect(wxEVT_COMMAND_TEXT_UPDATED
, on_fn_change
, NULL
, dispatch_to
);
27 file_select
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEventHandler(filenamebox::on_file_select
), NULL
,
32 inner
->SetSizeHints(parent
);
33 sizer
->Add(inner
, 0, wxGROW
);
36 enabled
= ((flags
& FNBF_SD
) == 0);
39 filenamebox::~filenamebox()
41 //Wxwidgets destroys the subwidgets.
45 void filenamebox::on_file_select(wxCommandEvent
& e
)
48 wxFileDialog
* d
= new wxFileDialog(pwindow
, towxstring("Choose " + last_label
), wxT("."));
49 if(d
->ShowModal() == wxID_CANCEL
) {
53 fname
= tostdstring(d
->GetPath());
55 if(given_flags
& FNBF_PZ
) {
56 //Did we pick a .zip file?
59 std::vector
<wxString
> files
;
61 files
.push_back(towxstring(i
));
62 wxSingleChoiceDialog
* d2
= new wxSingleChoiceDialog(pwindow
, wxT("Select file within .zip"),
63 wxT("Select member"), files
.size(), &files
[0]);
64 if(d2
->ShowModal() == wxID_CANCEL
) {
68 fname
= fname
+ "/" + tostdstring(d2
->GetStringSelection());
74 filename
->SetValue(towxstring(fname
));
77 std::string
filenamebox::get_file()
82 return tostdstring(filename
->GetValue());
85 bool filenamebox::is_enabled()
90 void filenamebox::enable(const std::string
& new_label
)
92 change_label(new_label
);
96 void filenamebox::change_label(const std::string
& new_label
)
98 last_label
= new_label
;
99 if(enabled
|| (given_flags
& FNBF_PL
))
100 label
->SetLabel(towxstring(last_label
));
103 void filenamebox::disable()
107 file_select
->Disable();
108 if((given_flags
& FNBF_PL
) == 0)
109 label
->SetLabel(wxT(""));
113 void filenamebox::enable()
115 if((given_flags
& FNBF_PL
) == 0)
116 label
->SetLabel(towxstring(last_label
));
119 file_select
->Enable();
123 bool filenamebox::is_nonblank()
127 return (filename
->GetValue().Length() != 0);
130 bool filenamebox::is_nonblank_or_disabled()
134 return (filename
->GetValue().Length() != 0);
137 void filenamebox::clear()
139 filename
->SetValue(wxT(""));