1
0
mirror of synced 2025-01-11 05:42:15 +01:00

fix: Shortcuts acting as duplicates in settings

This commit is contained in:
WerWolv 2024-12-16 20:26:04 +01:00
parent 313e59d7f9
commit bb99b9a0ef
3 changed files with 29 additions and 5 deletions

View File

@ -181,6 +181,8 @@ namespace hex {
bool isLocal() const;
std::string toString() const;
const std::set<Key>& getKeys() const;
bool has(Key key) const;
bool matches(const Shortcut &other) const;
private:
friend Shortcut operator+(const Key &lhs, const Key &rhs);
@ -258,7 +260,7 @@ namespace hex {
[[nodiscard]] static std::vector<ShortcutEntry> getGlobalShortcuts();
[[nodiscard]] static std::vector<ShortcutEntry> getViewShortcuts(const View *view);
[[nodiscard]] static bool updateShortcut(Shortcut oldShortcut, Shortcut newShortcut, View *view = nullptr);
[[nodiscard]] static bool updateShortcut(const Shortcut &oldShortcut, Shortcut newShortcut, View *view = nullptr);
};
}

View File

@ -54,7 +54,26 @@ namespace hex {
return m_keys.contains(CurrentView);
}
const std::set<Key>& Shortcut::getKeys() const { return m_keys; }
const std::set<Key>& Shortcut::getKeys() const {
return m_keys;
}
bool Shortcut::has(Key key) const {
return m_keys.contains(key);
}
bool Shortcut::matches(const Shortcut& other) const {
auto left = this->m_keys;
auto right = other.m_keys;
left.erase(CurrentView);
left.erase(AllowWhileTyping);
right.erase(CurrentView);
right.erase(AllowWhileTyping);
return left == right;
}
std::string Shortcut::toString() const {
std::string result;
@ -342,10 +361,13 @@ namespace hex {
return true;
}
bool ShortcutManager::updateShortcut(const Shortcut &oldShortcut, const Shortcut &newShortcut, View *view) {
if (oldShortcut == newShortcut)
bool ShortcutManager::updateShortcut(const Shortcut &oldShortcut, Shortcut newShortcut, View *view) {
if (oldShortcut.matches(newShortcut))
return true;
if (oldShortcut.has(AllowWhileTyping))
newShortcut += AllowWhileTyping;
bool result;
if (view != nullptr) {
result = updateShortcutImpl(oldShortcut + CurrentView, newShortcut + CurrentView , view->m_shortcuts);

View File

@ -283,7 +283,7 @@ namespace hex::plugin::builtin {
bool settingChanged = false;
ImGui::BeginDisabled(m_drawShortcut.match(m_defaultShortcut));
ImGui::BeginDisabled(m_drawShortcut.matches(m_defaultShortcut));
if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
m_hasDuplicate = !ShortcutManager::updateShortcut(m_shortcut, m_defaultShortcut, m_view);