2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "dcpomatic_button.h"
23 #include "file_dialog.h"
24 #include "file_picker_ctrl.h"
26 #include <dcp/warnings.h>
27 LIBDCP_DISABLE_WARNINGS
28 #include <wx/filepicker.h>
29 #include <wx/stdpaths.h>
31 LIBDCP_ENABLE_WARNINGS
32 #include <boost/filesystem.hpp>
36 using namespace boost;
39 FilePickerCtrl::FilePickerCtrl(
45 std::string initial_path_key,
46 optional<std::string> initial_filename,
47 optional<filesystem::path> override_path
51 , _wildcard (wildcard)
53 , _warn_overwrite (warn_overwrite)
54 , _initial_path_key(initial_path_key)
55 , _initial_filename(initial_filename)
56 , _override_path(override_path)
58 _sizer = new wxBoxSizer (wxHORIZONTAL);
60 wxClientDC dc (parent);
61 wxSize size = dc.GetTextExtent (wxT ("This is the length of the file label it should be quite long"));
64 _file = new Button (this, _("(None)"), wxDefaultPosition, size, wxBU_LEFT);
65 _sizer->Add (_file, 1, wxEXPAND, 0);
67 SetSizerAndFit (_sizer);
68 _file->Bind (wxEVT_BUTTON, boost::bind (&FilePickerCtrl::browse_clicked, this));
70 set_filename(_initial_filename);
75 FilePickerCtrl::set_filename(optional<string> filename)
78 _file->SetLabel(std_to_wx(*filename));
80 _file->SetLabel(_("None"));
86 FilePickerCtrl::set_path(optional<boost::filesystem::path> path)
91 set_filename(_path->filename().string());
96 wxCommandEvent ev (wxEVT_FILEPICKER_CHANGED, wxID_ANY);
97 GetEventHandler()->ProcessEvent (ev);
101 boost::optional<boost::filesystem::path>
102 FilePickerCtrl::path() const
109 FilePickerCtrl::browse_clicked ()
111 long style = _open ? wxFD_OPEN : wxFD_SAVE;
112 if (_warn_overwrite) {
113 style |= wxFD_OVERWRITE_PROMPT;
115 FileDialog dialog(this, _prompt, _wildcard, style, _initial_path_key, _initial_filename, _path);
117 set_path(dialog.path());
122 FilePickerCtrl::set_wildcard(wxString w)