Hide warnings triggered by Ubuntu 20.04's gcc.
[dcpomatic.git] / src / wx / dir_picker_ctrl.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "dir_picker_ctrl.h"
22 #include "wx_util.h"
23 #include "static_text.h"
24 #include "dcpomatic_button.h"
25 #include "lib/warnings.h"
26 #include <wx/wx.h>
27 #include <wx/stdpaths.h>
28 DCPOMATIC_DISABLE_WARNINGS
29 #include <wx/filepicker.h>
30 DCPOMATIC_ENABLE_WARNINGS
31 #include <boost/filesystem.hpp>
32
33 using namespace std;
34 using namespace boost;
35
36 DirPickerCtrl::DirPickerCtrl (wxWindow* parent)
37         : wxPanel (parent)
38 {
39         _sizer = new wxBoxSizer (wxHORIZONTAL);
40
41         _folder = new StaticText (this, wxT(""));
42         _sizer->Add (_folder, 1, wxEXPAND | wxALL, 6);
43         _browse = new Button (this, _("Browse..."));
44         _sizer->Add (_browse, 0);
45
46         SetSizer (_sizer);
47
48         _browse->Bind (wxEVT_BUTTON, boost::bind (&DirPickerCtrl::browse_clicked, this));
49 }
50
51 void
52 DirPickerCtrl::SetPath (wxString p)
53 {
54         _path = p;
55
56         if (_path == wxStandardPaths::Get().GetDocumentsDir()) {
57                 _folder->SetLabel (_("My Documents"));
58         } else {
59                 _folder->SetLabel (std_to_wx (filesystem::path (wx_to_std (_path)).leaf().string()));
60         }
61
62         wxCommandEvent ev (wxEVT_DIRPICKER_CHANGED, wxID_ANY);
63         GetEventHandler()->ProcessEvent (ev);
64
65         _sizer->Layout ();
66         SetMinSize (wxSize (max (400, _sizer->GetSize().GetWidth()), -1));
67 }
68
69 wxString
70 DirPickerCtrl::GetPath () const
71 {
72         return _path;
73 }
74
75 void
76 DirPickerCtrl::browse_clicked ()
77 {
78         wxDirDialog* d = new wxDirDialog (this);
79         if (d->ShowModal () == wxID_OK) {
80                 SetPath (d->GetPath ());
81         }
82         d->Destroy ();
83 }