Merge branch 'rr1-maint'

This commit is contained in:
Ilari Liusvaara 2012-04-09 13:25:27 +03:00
commit 9bffe5c504
7 changed files with 128 additions and 43 deletions

View file

@ -28,10 +28,17 @@ public:
/**
* Set the setting to special blank state. Not all settings can be blanked.
*
* Parameter really: Do dummy clear if false, otherwise try it for real.
* Returns: True on success, false on failure.
* throws std::bad_alloc: Not enough memory.
* throws std::runtime_error: Blanking this setting is not allowed (currently).
*/
virtual void blank() throw(std::bad_alloc, std::runtime_error) = 0;
virtual bool blank(bool really) throw(std::bad_alloc, std::runtime_error);
/**
* Can the setting be blanked?
*/
static bool blankable(const std::string& name) throw(std::bad_alloc, std::runtime_error);
/**
* Look up setting and try to blank it.
@ -119,10 +126,6 @@ public:
* throws std::bad_alloc: Not enough memory.
*/
numeric_setting(const std::string& sname, int32_t minv, int32_t maxv, int32_t dflt) throw(std::bad_alloc);
/**
* Raises std::runtime_error as these settings can't be blanked.
*/
void blank() throw(std::bad_alloc, std::runtime_error);
/**
* Returns true (these settings are always set).
*/
@ -168,10 +171,6 @@ public:
* throws std::bad_alloc: Not enough memory.
*/
boolean_setting(const std::string& sname, bool dflt) throw(std::bad_alloc);
/**
* Raises std::runtime_error as these settings can't be blanked.
*/
void blank() throw(std::bad_alloc, std::runtime_error);
/**
* Returns true (these settings are always set).
*/
@ -211,7 +210,7 @@ class path_setting : public setting
{
public:
path_setting(const std::string& sname) throw(std::bad_alloc);
void blank() throw(std::bad_alloc, std::runtime_error);
bool blank(bool really) throw(std::bad_alloc, std::runtime_error);
bool is_set() throw();
void set(const std::string& value) throw(std::bad_alloc, std::runtime_error);
std::string get() throw(std::bad_alloc);

View file

@ -383,6 +383,10 @@ SDL: Use SDL for joystick (requires SDL graphics)
EVDEV: Use EVDEV for joystick (Linux only).
\end_layout
\begin_layout Itemize
WIN32MM: Use Win32mm for joystick (Windows only).
\end_layout
\begin_layout Itemize
DUMMY: Disable joystick support.
\end_layout

View file

@ -152,6 +152,8 @@ Building is via makefile, the following options are available:
EVDEV: Use EVDEV for joystick (Linux only).
WIN32MM: Use Win32mm for joystick (Windows only).
DUMMY: Disable joystick support.
Default is SDL.

View file

@ -61,11 +61,14 @@ namespace
{
}
void blank() throw(std::bad_alloc, std::runtime_error)
bool blank(bool really) throw(std::bad_alloc, std::runtime_error)
{
if(!really)
return true;
target_nominal = true;
target_infinite = false;
target_fps = 100.0;
return true;
}
bool is_set() throw()

View file

@ -61,9 +61,12 @@ namespace
{
_set = false;
}
void blank() throw(std::bad_alloc, std::runtime_error)
bool blank(bool really) throw(std::bad_alloc, std::runtime_error)
{
if(!really)
return true;
_set = false;
return true;
}
bool is_set() throw()
{

View file

@ -76,17 +76,34 @@ void setting::set(const std::string& _setting, const std::string& value) throw(s
}
}
bool setting::blank(bool really) throw(std::bad_alloc, std::runtime_error)
{
return false;
}
bool setting::blankable(const std::string& _setting) throw(std::bad_alloc, std::runtime_error)
{
if(!settings().count(_setting))
throw std::runtime_error("No such setting '" + _setting + "'");
try {
return settings()[_setting]->blank(false);
} catch(...) {
return false;
}
}
void setting::blank(const std::string& _setting) throw(std::bad_alloc, std::runtime_error)
{
if(!settings().count(_setting))
throw std::runtime_error("No such setting '" + _setting + "'");
try {
settings()[_setting]->blank();
if(!settings()[_setting]->blank(true))
throw std::runtime_error("This setting can't be cleared");
information_dispatch::do_setting_clear(_setting);
} catch(std::bad_alloc& e) {
throw;
} catch(std::exception& e) {
throw std::runtime_error("Can't blank setting '" + _setting + "': " + e.what());
throw std::runtime_error("Can't clear setting '" + _setting + "': " + e.what());
}
}
@ -122,11 +139,6 @@ numeric_setting::numeric_setting(const std::string& sname, int32_t minv, int32_t
value = dflt;
}
void numeric_setting::blank() throw(std::bad_alloc, std::runtime_error)
{
throw std::runtime_error("This setting can't be blanked");
}
bool numeric_setting::is_set() throw()
{
return true;
@ -160,10 +172,6 @@ boolean_setting::boolean_setting(const std::string& sname, bool dflt) throw(std:
{
value = dflt;
}
void boolean_setting::blank() throw(std::bad_alloc, std::runtime_error)
{
throw std::runtime_error("This setting can't be unset");
}
bool boolean_setting::is_set() throw()
{
@ -204,10 +212,13 @@ path_setting::path_setting(const std::string& sname) throw(std::bad_alloc)
_default = true;
}
void path_setting::blank() throw(std::bad_alloc, std::runtime_error)
bool path_setting::blank(bool really) throw(std::bad_alloc, std::runtime_error)
{
if(!really)
return true;
path = ".";
_default = true;
return true;
}
bool path_setting::is_set() throw()

View file

@ -847,9 +847,12 @@ public:
void on_add(wxCommandEvent& e);
void on_edit(wxCommandEvent& e);
void on_delete(wxCommandEvent& e);
void on_change(wxCommandEvent& e);
private:
std::map<int, std::string> numbers;
wxListBox* select;
wxButton* editbutton;
wxButton* deletebutton;
void refresh();
std::string selected();
};
@ -863,21 +866,25 @@ wxeditor_esettings_aliases::wxeditor_esettings_aliases(wxWindow* parent)
SetSizer(top_s);
top_s->Add(select = new wxListBox(this, wxID_ANY), 1, wxGROW);
select->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(wxeditor_esettings_aliases::on_change),
NULL, this);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Add")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_aliases::on_add), NULL,
this);
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Edit")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_aliases::on_edit), NULL,
this);
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Delete")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_aliases::on_delete), NULL,
this);
pbutton_s->Add(editbutton = new wxButton(this, wxID_ANY, wxT("Edit")), 0, wxGROW);
editbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_aliases::on_edit),
NULL, this);
pbutton_s->Add(deletebutton = new wxButton(this, wxID_ANY, wxT("Delete")), 0, wxGROW);
deletebutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings_aliases::on_delete), NULL, this);
top_s->Add(pbutton_s, 0, wxGROW);
refresh();
wxCommandEvent e;
on_change(e);
top_s->SetSizeHints(this);
Fit();
}
@ -886,6 +893,13 @@ wxeditor_esettings_aliases::~wxeditor_esettings_aliases()
{
}
void wxeditor_esettings_aliases::on_change(wxCommandEvent& e)
{
bool enable = (selected() != "");
editbutton->Enable(enable);
deletebutton->Enable(enable);
}
void wxeditor_esettings_aliases::on_add(wxCommandEvent& e)
{
try {
@ -950,6 +964,8 @@ void wxeditor_esettings_aliases::refresh()
select->SetSelection(select->GetCount() ? (select->GetCount() - 1) : wxNOT_FOUND);
else
select->SetSelection(n);
wxCommandEvent e;
on_change(e);
select->Refresh();
}
@ -969,6 +985,7 @@ public:
~wxeditor_esettings_hotkeys();
void on_primary(wxCommandEvent& e);
void on_secondary(wxCommandEvent& e);
void on_change(wxCommandEvent& e);
private:
std::map<std::string, wxTreeItemId> items;
std::map<std::string, inverse_key*> realitems;
@ -989,6 +1006,8 @@ wxeditor_esettings_hotkeys::wxeditor_esettings_hotkeys(wxWindow* parent)
top_s->Add(select = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS |
wxTR_HIDE_ROOT | wxTR_LINES_AT_ROOT), 1, wxGROW);
select->Connect(wxEVT_COMMAND_TREE_SEL_CHANGED, wxCommandEventHandler(wxeditor_esettings_hotkeys::on_change),
NULL, this);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
@ -1003,10 +1022,19 @@ wxeditor_esettings_hotkeys::wxeditor_esettings_hotkeys(wxWindow* parent)
items[""] = select->AddRoot(wxT("<root>"));
refresh();
wxCommandEvent e;
on_change(e);
top_s->SetSizeHints(this);
Fit();
}
void wxeditor_esettings_hotkeys::on_change(wxCommandEvent& e)
{
bool enable = (selected() != "");
pri_button->Enable(enable);
sec_button->Enable(enable);
}
wxeditor_esettings_hotkeys::~wxeditor_esettings_hotkeys()
{
}
@ -1163,6 +1191,7 @@ public:
void on_add(wxCommandEvent& e);
void on_edit(wxCommandEvent& e);
void on_delete(wxCommandEvent& e);
void on_change(wxCommandEvent& e);
private:
std::map<int, std::string> numbers;
wxListBox* select;
@ -1171,6 +1200,8 @@ private:
std::map<std::string, std::string> values;
std::map<int, std::string> selections;
std::string selected();
wxButton* editbutton;
wxButton* deletebutton;
wxListBox* _settings;
};
@ -1183,21 +1214,25 @@ wxeditor_esettings_bindings::wxeditor_esettings_bindings(wxWindow* parent)
SetSizer(top_s);
top_s->Add(select = new wxListBox(this, wxID_ANY), 1, wxGROW);
select->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(wxeditor_esettings_bindings::on_change),
NULL, this);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Add")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_bindings::on_add), NULL,
this);
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Edit")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_bindings::on_edit), NULL,
this);
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Delete")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_bindings::on_delete), NULL,
this);
pbutton_s->Add(editbutton = new wxButton(this, wxID_ANY, wxT("Edit")), 0, wxGROW);
editbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_bindings::on_edit),
NULL, this);
pbutton_s->Add(deletebutton = new wxButton(this, wxID_ANY, wxT("Delete")), 0, wxGROW);
deletebutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings_bindings::on_delete), NULL, this);
top_s->Add(pbutton_s, 0, wxGROW);
refresh();
wxCommandEvent e;
on_change(e);
top_s->SetSizeHints(this);
Fit();
}
@ -1206,6 +1241,13 @@ wxeditor_esettings_bindings::~wxeditor_esettings_bindings()
{
}
void wxeditor_esettings_bindings::on_change(wxCommandEvent& e)
{
bool enable = (selected() != "");
editbutton->Enable(enable);
deletebutton->Enable(enable);
}
void wxeditor_esettings_bindings::on_add(wxCommandEvent& e)
{
try {
@ -1299,6 +1341,8 @@ void wxeditor_esettings_bindings::refresh()
select->SetSelection(select->GetCount() ? (select->GetCount() - 1) : wxNOT_FOUND);
else
select->SetSelection(n);
wxCommandEvent e;
on_change(e);
select->Refresh();
}
@ -1318,6 +1362,7 @@ public:
~wxeditor_esettings_advanced();
void on_change(wxCommandEvent& e);
void on_clear(wxCommandEvent& e);
void on_selchange(wxCommandEvent& e);
void on_setting_change(const std::string& setting, const std::string& value);
void on_setting_clear(const std::string& setting);
void _refresh();
@ -1326,7 +1371,10 @@ private:
std::set<std::string> settings;
std::map<std::string, std::string> values;
std::map<int, std::string> selections;
std::set<std::string> blankables;
std::string selected();
wxButton* changebutton;
wxButton* clearbutton;
wxListBox* _settings;
};
@ -1339,18 +1387,22 @@ wxeditor_esettings_advanced::wxeditor_esettings_advanced(wxWindow* parent)
SetSizer(top_s);
top_s->Add(_settings = new wxListBox(this, wxID_ANY), 1, wxGROW);
_settings->Connect(wxEVT_COMMAND_LISTBOX_SELECTED,
wxCommandEventHandler(wxeditor_esettings_advanced::on_selchange), NULL, this);
wxBoxSizer* pbutton_s = new wxBoxSizer(wxHORIZONTAL);
pbutton_s->AddStretchSpacer();
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Change")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_advanced::on_change), NULL,
this);
pbutton_s->Add(tmp = new wxButton(this, wxID_ANY, wxT("Clear")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxeditor_esettings_advanced::on_clear), NULL,
this);
pbutton_s->Add(changebutton = new wxButton(this, wxID_ANY, wxT("Change")), 0, wxGROW);
changebutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings_advanced::on_change), NULL, this);
pbutton_s->Add(clearbutton = new wxButton(this, wxID_ANY, wxT("Clear")), 0, wxGROW);
clearbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxeditor_esettings_advanced::on_clear), NULL, this);
top_s->Add(pbutton_s, 0, wxGROW);
refresh();
wxCommandEvent e;
on_selchange(e);
top_s->SetSizeHints(this);
Fit();
}
@ -1379,6 +1431,14 @@ void wxeditor_esettings_advanced::on_change(wxCommandEvent& e)
wxMessageBox(towxstring(err), wxT("Error setting value"), wxICON_EXCLAMATION | wxOK);
}
void wxeditor_esettings_advanced::on_selchange(wxCommandEvent& e)
{
std::string sel = selected();
bool enable = (sel != "");
changebutton->Enable(enable);
clearbutton->Enable(enable && blankables.count(sel));
}
void wxeditor_esettings_advanced::on_clear(wxCommandEvent& e)
{
std::string name = selected();
@ -1408,11 +1468,14 @@ void wxeditor_esettings_advanced::on_setting_clear(const std::string& setting)
void wxeditor_esettings_advanced::refresh()
{
runemufn([&settings, &values]() {
runemufn([&settings, &values, &blankables]() {
settings = setting::get_settings_set();
blankables.clear();
for(auto i : settings) {
if(setting::is_set(i))
values[i] = setting::get(i);
if(setting::blankable(i))
blankables.insert(i);
}
});
_refresh();