Configurable movie/ROM paths
[lsnes.git] / src / plat-wxwidgets / editor-paths.cpp
blob217313ee93d6bbba76ce90ca5b4e2730fa25c6db
1 #include "plat-wxwidgets/platform.hpp"
2 #include "core/settings.hpp"
3 #include "library/string.hpp"
5 #include <wx/wx.h>
6 #include <wx/event.h>
7 #include <wx/control.h>
8 #include <wx/combobox.h>
9 #include <vector>
10 #include <string>
12 #include <boost/lexical_cast.hpp>
13 #include <sstream>
15 #define FIRMWAREPATH "firmwarepath"
16 #define ROMPATH "rompath"
17 #define MOVIEPATH "moviepath"
19 class wxeditor_paths : public wxDialog
21 public:
22 wxeditor_paths(wxWindow* parent);
23 ~wxeditor_paths();
24 bool ShouldPreventAppExit() const;
25 void on_cancel(wxCommandEvent& e);
26 void on_ok(wxCommandEvent& e);
27 private:
28 wxButton* okbutton;
29 wxButton* cancel;
30 wxTextCtrl* rompath;
31 wxTextCtrl* moviepath;
32 wxTextCtrl* firmwarepath;
35 wxeditor_paths::wxeditor_paths(wxWindow* parent)
36 : wxDialog(parent, wxID_ANY, wxT("lsnes: Paths"), wxDefaultPosition, wxSize(-1, -1))
38 std::string cur_rompath, cur_moviepath, cur_firmwarepath;
39 runemufn([&cur_firmwarepath, &cur_moviepath, &cur_rompath]() {
40 cur_firmwarepath = setting::get(FIRMWAREPATH);
41 cur_rompath = setting::get(ROMPATH);
42 cur_moviepath = setting::get(MOVIEPATH);
43 });
45 Centre();
46 wxFlexGridSizer* top_s = new wxFlexGridSizer(2, 1, 0, 0);
47 SetSizer(top_s);
49 wxFlexGridSizer* t_s = new wxFlexGridSizer(3, 2, 0, 0);
50 t_s->Add(new wxStaticText(this, wxID_ANY, wxT("ROMs:")), 0, wxGROW);
51 t_s->Add(rompath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_rompath), wxDefaultPosition, wxSize(400, -1)),
52 1, wxGROW);
53 t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Movies:")), 0, wxGROW);
54 t_s->Add(moviepath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_moviepath), wxDefaultPosition,
55 wxSize(400, -1)), 1, wxGROW);
56 t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Firmware:")), 0, wxGROW);
57 t_s->Add(firmwarepath = new wxTextCtrl(this, wxID_ANY, towxstring(cur_firmwarepath), wxDefaultPosition,
58 wxSize(400, -1)), 1, wxGROW);
59 top_s->Add(t_s);
61 wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
62 pbutton_s->AddStretchSpacer();
63 pbutton_s->Add(okbutton = new wxButton(this, wxID_OK, wxT("OK")), 0, wxGROW);
64 pbutton_s->Add(cancel = new wxButton(this, wxID_CANCEL, wxT("Cancel")), 0, wxGROW);
65 okbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_paths::on_ok), NULL, this);
66 cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
67 wxCommandEventHandler(wxeditor_paths::on_cancel), NULL, this);
68 top_s->Add(pbutton_s, 0, wxGROW);
70 t_s->SetSizeHints(this);
71 top_s->SetSizeHints(this);
72 Fit();
75 wxeditor_paths::~wxeditor_paths()
79 bool wxeditor_paths::ShouldPreventAppExit() const
81 return false;
84 void wxeditor_paths::on_cancel(wxCommandEvent& e)
86 EndModal(wxID_CANCEL);
89 void wxeditor_paths::on_ok(wxCommandEvent& e)
91 std::string cur_rompath = tostdstring(rompath->GetValue());
92 std::string cur_moviepath = tostdstring(moviepath->GetValue());
93 std::string cur_firmwarepath = tostdstring(firmwarepath->GetValue());
94 runemufn([cur_firmwarepath, cur_moviepath, cur_rompath]() {
95 setting::set(ROMPATH, cur_rompath);
96 setting::set(MOVIEPATH, cur_moviepath);
97 setting::set(FIRMWAREPATH, cur_firmwarepath);
98 });
99 EndModal(wxID_OK);
102 void wxeditor_paths_display(wxWindow* parent)
104 modal_pause_holder hld;
105 wxDialog* editor;
106 try {
107 editor = new wxeditor_paths(parent);
108 editor->ShowModal();
109 } catch(...) {
111 editor->Destroy();