1 #include "filenamebox.hpp"
6 #include <wx/control.h>
7 #include <wx/combobox.h>
9 filenamebox::filenamebox(wxSizer
* sizer
, wxWindow
* parent
, const std::string
& initial_label
, int flags
,
10 wxEvtHandler
* dispatch_to
, wxObjectEventFunction on_fn_change
)
12 wxSizer
* inner
= sizer
;
14 inner
= new wxFlexGridSizer(1, 3, 0, 0);
16 last_label
= initial_label
;
17 label
= new wxStaticText(parent
, wxID_ANY
, towxstring(last_label
));
18 filename
= new wxTextCtrl(parent
, wxID_ANY
, wxT(""), wxDefaultPosition
, wxSize(500, -1));
19 file_select
= new wxButton(parent
, wxID_ANY
, wxT("..."));
20 inner
->Add(label
, 0, wxGROW
);
21 inner
->Add(filename
, 1, wxGROW
);
22 inner
->Add(file_select
, 0, wxGROW
);
23 if((flags
& FNBF_NN
) == 0)
24 filename
->Connect(wxEVT_COMMAND_TEXT_UPDATED
, on_fn_change
, NULL
, dispatch_to
);
25 file_select
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEventHandler(filenamebox::on_file_select
), NULL
,
30 inner
->SetSizeHints(parent
);
31 sizer
->Add(inner
, 0, wxGROW
);
34 enabled
= ((flags
& FNBF_SD
) == 0);
37 filenamebox::~filenamebox()
39 //Wxwidgets destroys the subwidgets.
43 void filenamebox::on_file_select(wxCommandEvent
& e
)
46 wxFileDialog
* d
= new wxFileDialog(pwindow
, towxstring("Choose " + last_label
), wxT("."));
47 if(d
->ShowModal() == wxID_CANCEL
) {
51 fname
= tostdstring(d
->GetPath());
53 if(given_flags
& FNBF_PZ
) {
54 //Did we pick a .zip file?
57 std::vector
<wxString
> files
;
59 files
.push_back(towxstring(i
));
60 wxSingleChoiceDialog
* d2
= new wxSingleChoiceDialog(pwindow
, wxT("Select file within .zip"),
61 wxT("Select member"), files
.size(), &files
[0]);
62 if(d2
->ShowModal() == wxID_CANCEL
) {
66 fname
= fname
+ "/" + tostdstring(d2
->GetStringSelection());
72 filename
->SetValue(towxstring(fname
));
75 std::string
filenamebox::get_file()
80 return tostdstring(filename
->GetValue());
83 bool filenamebox::is_enabled()
88 void filenamebox::enable(const std::string
& new_label
)
90 change_label(new_label
);
94 void filenamebox::change_label(const std::string
& new_label
)
96 last_label
= new_label
;
97 if(enabled
|| (given_flags
& FNBF_PL
))
98 label
->SetLabel(towxstring(last_label
));
101 void filenamebox::disable()
105 file_select
->Disable();
106 if((given_flags
& FNBF_PL
) == 0)
107 label
->SetLabel(wxT(""));
111 void filenamebox::enable()
113 if((given_flags
& FNBF_PL
) == 0)
114 label
->SetLabel(towxstring(last_label
));
117 file_select
->Enable();
121 bool filenamebox::is_nonblank()
125 return (filename
->GetValue().Length() != 0);
128 bool filenamebox::is_nonblank_or_disabled()
132 return (filename
->GetValue().Length() != 0);
135 void filenamebox::clear()
137 filename
->SetValue(wxT(""));