fix: Shortcuts acting as duplicates in settings
This commit is contained in:
parent
313e59d7f9
commit
bb99b9a0ef
@ -181,6 +181,8 @@ namespace hex {
|
|||||||
bool isLocal() const;
|
bool isLocal() const;
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
const std::set<Key>& getKeys() const;
|
const std::set<Key>& getKeys() const;
|
||||||
|
bool has(Key key) const;
|
||||||
|
bool matches(const Shortcut &other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend Shortcut operator+(const Key &lhs, const Key &rhs);
|
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> getGlobalShortcuts();
|
||||||
[[nodiscard]] static std::vector<ShortcutEntry> getViewShortcuts(const View *view);
|
[[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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -54,7 +54,26 @@ namespace hex {
|
|||||||
return m_keys.contains(CurrentView);
|
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 Shortcut::toString() const {
|
||||||
std::string result;
|
std::string result;
|
||||||
@ -342,10 +361,13 @@ namespace hex {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShortcutManager::updateShortcut(const Shortcut &oldShortcut, const Shortcut &newShortcut, View *view) {
|
bool ShortcutManager::updateShortcut(const Shortcut &oldShortcut, Shortcut newShortcut, View *view) {
|
||||||
if (oldShortcut == newShortcut)
|
if (oldShortcut.matches(newShortcut))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (oldShortcut.has(AllowWhileTyping))
|
||||||
|
newShortcut += AllowWhileTyping;
|
||||||
|
|
||||||
bool result;
|
bool result;
|
||||||
if (view != nullptr) {
|
if (view != nullptr) {
|
||||||
result = updateShortcutImpl(oldShortcut + CurrentView, newShortcut + CurrentView , view->m_shortcuts);
|
result = updateShortcutImpl(oldShortcut + CurrentView, newShortcut + CurrentView , view->m_shortcuts);
|
||||||
|
@ -283,7 +283,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
bool settingChanged = false;
|
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))) {
|
if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
||||||
m_hasDuplicate = !ShortcutManager::updateShortcut(m_shortcut, m_defaultShortcut, m_view);
|
m_hasDuplicate = !ShortcutManager::updateShortcut(m_shortcut, m_defaultShortcut, m_view);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user