1 #include "core/command.hpp"
2 #include "core/dispatch.hpp"
3 #include "core/mainloop.hpp"
4 #include "core/misc.hpp"
5 #include "core/moviefile.hpp"
6 #include "core/settings.hpp"
7 #include "core/window.hpp"
9 #include "platform/wxwidgets/platform.hpp"
20 #include <wx/control.h>
21 #include <wx/combobox.h>
23 class wxeditor_settings_setting
: public wxEvtHandler
26 wxeditor_settings_setting(wxSizer
* sizer
, wxWindow
* window
, const std::string
& name
);
27 void on_clear_click(wxCommandEvent
& e
);
28 void on_edit_click(wxCommandEvent
& e
);
29 void change_setting(const std::string
& setting
, const std::string
& value
);
30 void clear_setting(const std::string
& setting
);
39 class wxeditor_settings
;
41 class wxeditor_settings_listener
: public information_dispatch
44 wxeditor_settings_listener(wxeditor_settings
* _editor
);
45 ~wxeditor_settings_listener() throw();
46 void on_setting_change(const std::string
& setting
, const std::string
& value
);
47 void on_setting_clear(const std::string
& setting
);
49 wxeditor_settings
* editor
;
52 class wxeditor_settings
: public wxDialog
55 wxeditor_settings(wxWindow
* parent
);
57 bool ShouldPreventAppExit() const;
58 void on_close(wxCommandEvent
& e
);
59 void change_setting(const std::string
& setting
, const std::string
& value
);
60 void clear_setting(const std::string
& setting
);
62 wxeditor_settings_listener listener
;
63 std::vector
<wxeditor_settings_setting
*> esettings
;
64 wxScrolledWindow
* scrollwin
;
68 wxeditor_settings_setting::wxeditor_settings_setting(wxSizer
* sizer
, wxWindow
* window
, const std::string
& name
)
72 std::string pvalue
= "<unknown>";
73 runemufn([&pvalue
, a_name
]() {
75 if(!setting::is_set(a_name
))
78 pvalue
= setting::get(a_name
);
82 sizer
->Add(new wxStaticText(window
, wxID_ANY
, towxstring(name
)), 0, wxGROW
);
83 sizer
->Add(label
= new wxStaticText(window
, wxID_ANY
, towxstring(pvalue
)), 0, wxGROW
);
84 sizer
->Add(edit
= new wxButton(window
, wxID_ANY
, wxT("Edit")), 0, wxGROW
);
85 sizer
->Add(clear
= new wxButton(window
, wxID_ANY
, wxT("Clear")), 0, wxGROW
);
86 edit
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
87 wxCommandEventHandler(wxeditor_settings_setting::on_edit_click
), NULL
, this);
88 clear
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
89 wxCommandEventHandler(wxeditor_settings_setting::on_clear_click
), NULL
, this);
92 void wxeditor_settings_setting::on_clear_click(wxCommandEvent
& e
)
96 std::string faulttext
;
97 runemufn([a_name
, &fault
, &faulttext
]() {
99 setting::blank(a_name
);
100 } catch(std::exception
& e
) {
102 faulttext
= e
.what();
106 wxMessageDialog
* d
= new wxMessageDialog(parent
,
107 towxstring(std::string("Can't clear setting: ") + faulttext
), wxT("Error"), wxOK
|
112 }catch(std::exception
& e
) {
113 wxMessageDialog
* d
= new wxMessageDialog(parent
, towxstring(std::string("Can't clear setting: ") +
114 e
.what()), wxT("Error"), wxOK
| wxICON_EXCLAMATION
);
120 void wxeditor_settings_setting::on_edit_click(wxCommandEvent
& e
)
123 std::string newsetting
;
124 std::string oldvalue
= setting::get(a_name
);
125 wxTextEntryDialog
* d
= new wxTextEntryDialog(parent
, towxstring("Enter new value for " + a_name
),
126 wxT("Enter new value for setting"), towxstring(oldvalue
));
127 if(d
->ShowModal() == wxID_CANCEL
) {
131 newsetting
= tostdstring(d
->GetValue());
133 std::string faulttext
;
134 runemufn([a_name
, newsetting
, &fault
, &faulttext
]() {
136 setting::set(a_name
, newsetting
);
137 } catch(std::exception
& e
) {
139 faulttext
= e
.what();
143 wxMessageDialog
* d
= new wxMessageDialog(parent
,
144 towxstring(std::string("Can't set setting: ") + faulttext
), wxT("Error"), wxOK
|
149 } catch(std::exception
& e
) {
150 wxMessageDialog
* d
= new wxMessageDialog(parent
, towxstring(std::string("Can't set setting: ") +
151 e
.what()), wxT("Error"), wxOK
| wxICON_EXCLAMATION
);
157 void wxeditor_settings_setting::change_setting(const std::string
& _setting
, const std::string
& value
)
159 runuifun([_setting
, label
, a_name
, value
]() {
160 if(_setting
!= a_name
)
162 label
->SetLabel(towxstring(value
));
166 void wxeditor_settings_setting::clear_setting(const std::string
& _setting
)
168 runuifun([_setting
, label
, a_name
]() {
169 if(_setting
!= a_name
)
171 label
->SetLabel(wxT("<unset>"));
175 wxeditor_settings::wxeditor_settings(wxWindow
* parent
)
176 : wxDialog(parent
, wxID_ANY
, wxT("lsnes: Edit settings"), wxDefaultPosition
, wxSize(-1, -1)), listener(this)
178 std::set
<std::string
> settings_set
;
179 runemufn([&settings_set
]() { settings_set
= setting::get_settings_set(); });
181 scrollwin
= new wxScrolledWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(-1, -1), wxVSCROLL
);
182 scrollwin
->SetMinSize(wxSize(-1, 500));
185 wxFlexGridSizer
* top_s
= new wxFlexGridSizer(2, 1, 0, 0);
188 wxFlexGridSizer
* t_s
= new wxFlexGridSizer(settings_set
.size(), 4, 0, 0);
189 for(auto i
: settings_set
)
190 esettings
.push_back(new wxeditor_settings_setting(t_s
, scrollwin
, i
));
191 scrollwin
->SetSizer(t_s
);
192 top_s
->Add(scrollwin
);
193 scrollwin
->SetScrollRate(0, 20);
195 wxBoxSizer
* pbutton_s
= new wxBoxSizer(wxHORIZONTAL
);
196 pbutton_s
->AddStretchSpacer();
197 pbutton_s
->Add(close
= new wxButton(this, wxID_CANCEL
, wxT("Close")), 0, wxGROW
);
198 close
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
199 wxCommandEventHandler(wxeditor_settings::on_close
), NULL
, this);
200 top_s
->Add(pbutton_s
, 0, wxGROW
);
202 t_s
->SetSizeHints(this);
203 top_s
->SetSizeHints(this);
209 wxeditor_settings::~wxeditor_settings()
211 for(auto i
: esettings
)
215 bool wxeditor_settings::ShouldPreventAppExit() const
220 void wxeditor_settings::on_close(wxCommandEvent
& e
)
225 void wxeditor_settings::change_setting(const std::string
& _setting
, const std::string
& value
)
227 for(auto i
: esettings
)
228 i
->change_setting(_setting
, value
);
231 void wxeditor_settings::clear_setting(const std::string
& _setting
)
233 for(auto i
: esettings
)
234 i
->clear_setting(_setting
);
237 wxeditor_settings_listener::wxeditor_settings_listener(wxeditor_settings
* _editor
)
238 : information_dispatch("wxeditor_settings-listener")
243 wxeditor_settings_listener::~wxeditor_settings_listener() throw()
247 void wxeditor_settings_listener::on_setting_change(const std::string
& _setting
, const std::string
& value
)
249 editor
->change_setting(_setting
, value
);
252 void wxeditor_settings_listener::on_setting_clear(const std::string
& _setting
)
254 editor
->clear_setting(_setting
);
257 void wxeditor_settings_display(wxWindow
* parent
)
259 modal_pause_holder hld
;
262 editor
= new wxeditor_settings(parent
);