forked from mia/Aegisub
Use less wxString in HotkeyDataViewModel
This commit is contained in:
parent
970dd96959
commit
745aa8fef0
2 changed files with 24 additions and 33 deletions
|
@ -14,27 +14,20 @@
|
||||||
//
|
//
|
||||||
// Aegisub Project http://www.aegisub.org/
|
// Aegisub Project http://www.aegisub.org/
|
||||||
|
|
||||||
/// @file hotkey_data_view_model.cpp
|
|
||||||
/// @see hotkey_data_view_model.h
|
|
||||||
/// @ingroup hotkey configuration_ui
|
|
||||||
///
|
|
||||||
|
|
||||||
#include "hotkey_data_view_model.h"
|
#include "hotkey_data_view_model.h"
|
||||||
|
|
||||||
#include <libaegisub/exception.h>
|
|
||||||
#include <libaegisub/hotkey.h>
|
|
||||||
#include <libaegisub/make_unique.h>
|
|
||||||
|
|
||||||
#include "command/command.h"
|
#include "command/command.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "include/aegisub/hotkey.h"
|
#include "include/aegisub/hotkey.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
|
||||||
#include <wx/dataview.h>
|
#include <libaegisub/exception.h>
|
||||||
|
#include <libaegisub/hotkey.h>
|
||||||
|
#include <libaegisub/make_unique.h>
|
||||||
|
#include <libaegisub/split.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
using namespace agi::hotkey;
|
using namespace agi::hotkey;
|
||||||
|
|
||||||
|
@ -60,20 +53,21 @@ class HotkeyModelCategory;
|
||||||
/// All actual mutation of hotkeys happens through this class
|
/// All actual mutation of hotkeys happens through this class
|
||||||
class HotkeyModelCombo final : public HotkeyModelItem {
|
class HotkeyModelCombo final : public HotkeyModelItem {
|
||||||
HotkeyModelCategory *parent; ///< The containing category
|
HotkeyModelCategory *parent; ///< The containing category
|
||||||
Combo combo; ///< The actual hotkey
|
Combo combo; ///< The actual hotkey
|
||||||
wxString cmd_name;
|
std::string cmd_name;
|
||||||
wxString cmd_str;
|
std::string cmd_str;
|
||||||
public:
|
public:
|
||||||
HotkeyModelCombo(HotkeyModelCategory *parent, Combo const& combo)
|
HotkeyModelCombo(HotkeyModelCategory *parent, Combo const& combo)
|
||||||
: parent(parent)
|
: parent(parent)
|
||||||
, combo(combo)
|
, combo(combo)
|
||||||
, cmd_name(to_wx(combo.CmdName()))
|
, cmd_name(combo.CmdName())
|
||||||
, cmd_str(to_wx(combo.Str()))
|
, cmd_str(combo.Str())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsVisible(wxString const& filter) const {
|
bool IsVisible(std::string const& filter) const {
|
||||||
return cmd_name.Lower().Contains(filter) || cmd_str.Contains(filter);
|
return boost::to_lower_copy(cmd_name).find(filter) != std::string::npos
|
||||||
|
|| boost::to_lower_copy(cmd_str).find(filter) != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Apply(Hotkey::HotkeyMap *hk_map) {
|
void Apply(Hotkey::HotkeyMap *hk_map) {
|
||||||
|
@ -114,19 +108,19 @@ public:
|
||||||
|
|
||||||
bool SetValue(wxVariant const& variant, unsigned int col) override {
|
bool SetValue(wxVariant const& variant, unsigned int col) override {
|
||||||
if (col == 0) {
|
if (col == 0) {
|
||||||
wxArrayString toks = wxSplit(variant.GetString(), '-');
|
|
||||||
std::vector<std::string> keys;
|
std::vector<std::string> keys;
|
||||||
keys.reserve(toks.size());
|
auto str = from_wx(variant.GetString());
|
||||||
transform(toks.begin(), toks.end(), back_inserter(keys), (std::string(*)(wxString const&))&from_wx);
|
for (auto tok : agi::Split(str, '-'))
|
||||||
|
keys.emplace_back(begin(tok), end(tok));
|
||||||
combo = Combo(combo.Context(), combo.CmdName(), keys);
|
combo = Combo(combo.Context(), combo.CmdName(), keys);
|
||||||
cmd_str = to_wx(combo.Str());
|
cmd_str = combo.Str();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (col == 1) {
|
else if (col == 1) {
|
||||||
wxDataViewIconText text;
|
wxDataViewIconText text;
|
||||||
text << variant;
|
text << variant;
|
||||||
combo = Combo(combo.Context(), from_wx(text.GetText()), combo.Get());
|
cmd_name = from_wx(text.GetText());
|
||||||
cmd_name = text.GetText();
|
combo = Combo(combo.Context(), cmd_name, combo.Get());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -168,7 +162,7 @@ public:
|
||||||
combo.Apply(hk_map);
|
combo.Apply(hk_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFilter(wxString const& new_filter) {
|
void SetFilter(std::string const& new_filter) {
|
||||||
std::set<HotkeyModelCombo*> old_visible;
|
std::set<HotkeyModelCombo*> old_visible;
|
||||||
for (auto item : visible_items)
|
for (auto item : visible_items)
|
||||||
old_visible.insert(static_cast<HotkeyModelCombo*>(item.GetID()));
|
old_visible.insert(static_cast<HotkeyModelCombo*>(item.GetID()));
|
||||||
|
@ -240,7 +234,7 @@ public:
|
||||||
category.Apply(hk_map);
|
category.Apply(hk_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFilter(wxString const& filter) {
|
void SetFilter(std::string const& filter) {
|
||||||
for (auto& category : categories)
|
for (auto& category : categories)
|
||||||
category.SetFilter(filter);
|
category.SetFilter(filter);
|
||||||
}
|
}
|
||||||
|
@ -331,5 +325,7 @@ void HotkeyDataViewModel::Apply() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeyDataViewModel::SetFilter(wxString const& filter) {
|
void HotkeyDataViewModel::SetFilter(wxString const& filter) {
|
||||||
root->SetFilter(filter.Lower());
|
auto str = from_wx(filter);
|
||||||
|
boost::to_lower(str);
|
||||||
|
root->SetFilter(str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,6 @@
|
||||||
//
|
//
|
||||||
// Aegisub Project http://www.aegisub.org/
|
// Aegisub Project http://www.aegisub.org/
|
||||||
|
|
||||||
/// @file hotkey_data_view_model.h
|
|
||||||
/// @see hotkey_data_view_model.cpp
|
|
||||||
/// @ingroup hotkey configuration_ui
|
|
||||||
///
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <wx/dataview.h>
|
#include <wx/dataview.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue