From 24280aef43d5a1e43bbe8923615bf76c2aed5e7d Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Wed, 29 Aug 2012 17:04:38 +0300 Subject: [PATCH 1/2] wxwidgets: Cleanup the shown bindings a bit --- src/platform/wxwidgets/settings.cpp | 50 +++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index c6977abd..20f6f2e1 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -13,6 +13,7 @@ #include #include +#include "library/string.hpp" #include #include @@ -74,6 +75,48 @@ namespace } } keygrabber; + std::string clean_keystring(const std::string& in) + { + regex_results tmp = regex("(.*)/(.*)\\|(.*)", in); + if(!tmp) + return in; + std::string mods = tmp[1]; + std::string mask = tmp[2]; + std::string key = tmp[3]; + std::set _mods, _mask; + std::string tmp2; + while(mods != "") { + extract_token(mods, tmp2, ","); + _mods.insert(tmp2); + } + while(mask != "") { + extract_token(mask, tmp2, ","); + _mask.insert(tmp2); + } + for(auto i : _mods) + if(!_mask.count(i)) + return in; + std::string out; + for(auto i : _mask) + if(!_mods.count(i)) + out = out + "!" + i + "+"; + else + out = out + i + "+"; + out = out + key; + return out; + } + +/** + * Extract token out of string. + * + * Parameter str: The original string and the rest of the string on return. + * Parameter tok: The extracted token will be written here. + * Parameter sep: The characters to split on (empty always extracts the rest). + * Parameter seq: If true, skip whole sequence of token ending characters. + * Returns: The character token splitting occured on (-1 if end of string, -2 if string is empty). + */ +int extract_token(std::string& str, std::string& tok, const char* sep, bool seq = false) throw(std::bad_alloc); + class wxdialog_pressbutton : public wxDialog { public: @@ -1348,9 +1391,10 @@ void wxeditor_esettings_hotkeys::refresh() if(data[i.second].first == "") text = text + " (not set)"; else if(data[i.second].second == "") - text = text + " (" + data[i.second].first + ")"; + text = text + " (" + clean_keystring(data[i.second].first) + ")"; else - text = text + " (" + data[i.second].first + " or " + data[i.second].second + ")"; + text = text + " (" + clean_keystring(data[i.second].first) + " or " + + clean_keystring(data[i.second].second) + ")"; itemlabels[std::make_pair(cat_set[j.first], cat_assign[j.first])] = text; cat_assign[j.first]++; } @@ -1500,7 +1544,7 @@ void wxeditor_esettings_bindings::refresh() bind[i] = keymapper::get_command_for(i); for(auto i : bind) { numbers[choices.size()] = i.first; - choices.push_back(towxstring(i.first + " (" + i.second + ")")); + choices.push_back(towxstring(clean_keystring(i.first) + " (" + i.second + ")")); } select->Set(choices.size(), &choices[0]); if(n == wxNOT_FOUND && select->GetCount()) From 54172ebc5f27101ef5073356b32603fbfdc514e3 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Wed, 29 Aug 2012 17:21:51 +0300 Subject: [PATCH 2/2] wxwidgets: Clean up key configuration dialog --- src/platform/wxwidgets/settings.cpp | 75 +++++------------------------ 1 file changed, 13 insertions(+), 62 deletions(-) diff --git a/src/platform/wxwidgets/settings.cpp b/src/platform/wxwidgets/settings.cpp index 20f6f2e1..a63265b8 100644 --- a/src/platform/wxwidgets/settings.cpp +++ b/src/platform/wxwidgets/settings.cpp @@ -241,7 +241,6 @@ int extract_token(std::string& str, std::string& tok, const char* sep, bool seq struct keyentry_mod_data { wxCheckBox* pressed; - wxCheckBox* unmasked; unsigned tmpflags; }; @@ -302,22 +301,21 @@ int extract_token(std::string& str, std::string& tok, const char* sep, bool seq } Centre(); - top_s = new wxFlexGridSizer(2, 1, 0, 0); + top_s = new wxFlexGridSizer(3, 1, 0, 0); SetSizer(top_s); - t_s = new wxFlexGridSizer(mods.size() + 1, 3, 0, 0); + t_s = new wxFlexGridSizer(1, 3, 0, 0); + wxFlexGridSizer* t2_s = new wxFlexGridSizer(mods.size(), 1, 0, 0); for(auto i : mods) { - t_s->Add(new wxStaticText(this, wxID_ANY, towxstring(i)), 0, wxGROW); keyentry_mod_data m; - t_s->Add(m.pressed = new wxCheckBox(this, wxID_ANY, wxT("Pressed")), 0, wxGROW); - t_s->Add(m.unmasked = new wxCheckBox(this, wxID_ANY, wxT("Unmasked")), 1, wxGROW); - m.pressed->Disable(); + t2_s->Add(m.pressed = new wxCheckBox(this, wxID_ANY, towxstring(i), wxDefaultPosition, + wxDefaultSize, wxCHK_3STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER), 1, wxGROW); + m.pressed->Set3StateValue(wxCHK_UNDETERMINED); modifiers[i] = m; m.pressed->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); - m.unmasked->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, - wxCommandEventHandler(wxdialog_keyentry::on_change_setting), NULL, this); } + top_s->Add(t2_s); t_s->Add(new wxStaticText(this, wxID_ANY, wxT("Key")), 0, wxGROW); t_s->Add(mainclass = new wxComboBox(this, wxID_ANY, classeslist[0], wxDefaultPosition, wxDefaultSize, classeslist.size(), &classeslist[0], wxCB_READONLY), 0, wxGROW); @@ -370,9 +368,9 @@ int extract_token(std::string& str, std::string& tok, const char* sep, bool seq { if(!modifiers.count(mod)) return; - if(modifiers[mod].unmasked->IsEnabled()) { + if(modifiers[mod].pressed->Get3StateValue() == wxCHK_UNDETERMINED) { wxCommandEvent e; - modifiers[mod].unmasked->SetValue(true); + modifiers[mod].pressed->Set3StateValue(wxCHK_UNCHECKED); on_change_setting(e); } } @@ -381,9 +379,9 @@ int extract_token(std::string& str, std::string& tok, const char* sep, bool seq { if(!modifiers.count(mod)) return; - if(modifiers[mod].pressed->IsEnabled()) { + if(modifiers[mod].pressed->Get3StateValue() != wxCHK_UNDETERMINED) { wxCommandEvent e; - modifiers[mod].pressed->SetValue(true); + modifiers[mod].pressed->Set3StateValue(wxCHK_CHECKED); on_change_setting(e); } } @@ -432,53 +430,6 @@ int extract_token(std::string& str, std::string& tok, const char* sep, bool seq void wxdialog_keyentry::on_change_setting(wxCommandEvent& e) { - for(auto& i : modifiers) - i.second.tmpflags = 0; - for(auto& i : modifiers) { - modifier* m = NULL; - try { - m = &modifier::lookup(i.first); - } catch(...) { - i.second.pressed->Disable(); - i.second.unmasked->Disable(); - continue; - } - std::string j = m->linked_name(); - if(i.second.unmasked->GetValue()) - i.second.tmpflags |= TMPFLAG_UNMASKED; - if(j != "") { - if(modifiers[j].unmasked->GetValue()) - i.second.tmpflags |= TMPFLAG_UNMASKED_LINK_PARENT; - if(i.second.unmasked->GetValue()) - modifiers[j].tmpflags |= TMPFLAG_UNMASKED_LINK_CHILD; - } - if(i.second.pressed->GetValue()) - i.second.tmpflags |= TMPFLAG_PRESSED; - if(j != "") { - if(modifiers[j].pressed->GetValue()) - i.second.tmpflags |= TMPFLAG_PRESSED_LINK_PARENT; - if(i.second.pressed->GetValue()) - modifiers[j].tmpflags |= TMPFLAG_PRESSED_LINK_CHILD; - } - } - for(auto& i : modifiers) { - //Unmasked is to be enabled if neither unmasked link flag is set. - if(i.second.tmpflags & ((TMPFLAG_UNMASKED_LINK_CHILD | TMPFLAG_UNMASKED_LINK_PARENT) & ~64)) { - i.second.unmasked->SetValue(false); - i.second.unmasked->Disable(); - } else - i.second.unmasked->Enable(); - //Pressed is to be enabled if: - //- This modifier is unmasked or parent is unmasked. - //- Parent nor child is not pressed. - if(((i.second.tmpflags & (TMPFLAG_UNMASKED | TMPFLAG_UNMASKED_LINK_PARENT | - TMPFLAG_PRESSED_LINK_CHILD | TMPFLAG_PRESSED_LINK_PARENT)) & 112) == 64) - i.second.pressed->Enable(); - else { - i.second.pressed->SetValue(false); - i.second.pressed->Disable(); - } - } } void wxdialog_keyentry::on_pressbutton(wxCommandEvent& e) @@ -543,7 +494,7 @@ int extract_token(std::string& str, std::string& tok, const char* sep, bool seq bool f; f = true; for(auto i : modifiers) { - if(i.second.pressed->GetValue()) { + if(i.second.pressed->Get3StateValue() == wxCHK_CHECKED) { if(!f) x = x + ","; f = false; @@ -553,7 +504,7 @@ int extract_token(std::string& str, std::string& tok, const char* sep, bool seq x = x + "/"; f = true; for(auto i : modifiers) { - if(i.second.unmasked->GetValue()) { + if(i.second.pressed->Get3StateValue() != wxCHK_UNDETERMINED) { if(!f) x = x + ","; f = false;