fix: Binding shortcuts to already existing shortcuts behaving weirdly
This commit is contained in:
parent
a1ef567ecd
commit
c6b9b947fb
@ -192,13 +192,13 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
class KeybindingWidget : public ContentRegistry::Settings::Widgets::Widget {
|
class KeybindingWidget : public ContentRegistry::Settings::Widgets::Widget {
|
||||||
public:
|
public:
|
||||||
KeybindingWidget(View *view, const Shortcut &shortcut) : m_view(view), m_shortcut(shortcut), m_defaultShortcut(shortcut) {}
|
KeybindingWidget(View *view, const Shortcut &shortcut) : m_view(view), m_shortcut(shortcut), m_drawShortcut(shortcut), m_defaultShortcut(shortcut) {}
|
||||||
|
|
||||||
bool draw(const std::string &name) override {
|
bool draw(const std::string &name) override {
|
||||||
std::string label;
|
std::string label;
|
||||||
|
|
||||||
if (!this->m_editing)
|
if (!this->m_editing)
|
||||||
label = this->m_shortcut.toString();
|
label = this->m_drawShortcut.toString();
|
||||||
else
|
else
|
||||||
label = "...";
|
label = "...";
|
||||||
|
|
||||||
@ -226,12 +226,16 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
bool settingChanged = false;
|
bool settingChanged = false;
|
||||||
|
|
||||||
ImGui::BeginDisabled(this->m_shortcut == this->m_defaultShortcut);
|
ImGui::BeginDisabled(this->m_drawShortcut == this->m_defaultShortcut);
|
||||||
if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
||||||
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, this->m_defaultShortcut, this->m_view);
|
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, this->m_defaultShortcut, this->m_view);
|
||||||
this->m_shortcut = this->m_defaultShortcut;
|
|
||||||
|
|
||||||
settingChanged = true;
|
this->m_drawShortcut = this->m_defaultShortcut;
|
||||||
|
if (!this->m_hasDuplicate) {
|
||||||
|
this->m_shortcut = this->m_defaultShortcut;
|
||||||
|
settingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
@ -251,7 +255,9 @@ namespace hex::plugin::builtin {
|
|||||||
this->m_editing = false;
|
this->m_editing = false;
|
||||||
ShortcutManager::resumeShortcuts();
|
ShortcutManager::resumeShortcuts();
|
||||||
|
|
||||||
settingChanged = true;
|
if (!this->m_hasDuplicate) {
|
||||||
|
settingChanged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,6 +276,7 @@ namespace hex::plugin::builtin {
|
|||||||
auto newShortcut = Shortcut(keys);
|
auto newShortcut = Shortcut(keys);
|
||||||
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
|
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
|
||||||
this->m_shortcut = std::move(newShortcut);
|
this->m_shortcut = std::move(newShortcut);
|
||||||
|
this->m_drawShortcut = this->m_shortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json store() override {
|
nlohmann::json store() override {
|
||||||
@ -286,7 +293,6 @@ namespace hex::plugin::builtin {
|
|||||||
private:
|
private:
|
||||||
bool detectShortcut() {
|
bool detectShortcut() {
|
||||||
if (const auto &shortcut = ShortcutManager::getPreviousShortcut(); shortcut.has_value()) {
|
if (const auto &shortcut = ShortcutManager::getPreviousShortcut(); shortcut.has_value()) {
|
||||||
log::info("Changed shortcut to {}", shortcut->toString());
|
|
||||||
auto keys = this->m_shortcut.getKeys();
|
auto keys = this->m_shortcut.getKeys();
|
||||||
std::erase_if(keys, [](Key key) {
|
std::erase_if(keys, [](Key key) {
|
||||||
return key != AllowWhileTyping && key != CurrentView;
|
return key != AllowWhileTyping && key != CurrentView;
|
||||||
@ -298,11 +304,16 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
auto newShortcut = Shortcut(std::move(keys));
|
auto newShortcut = Shortcut(std::move(keys));
|
||||||
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
|
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view);
|
||||||
|
this->m_drawShortcut = std::move(newShortcut);
|
||||||
|
|
||||||
if (!this->m_hasDuplicate) {
|
if (!this->m_hasDuplicate) {
|
||||||
this->m_shortcut = std::move(newShortcut);
|
this->m_shortcut = this->m_drawShortcut;
|
||||||
return true;
|
log::info("Changed shortcut to {}", shortcut->toString());
|
||||||
|
} else {
|
||||||
|
log::warn("Changing shortcut failed as it overlapped with another one", shortcut->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -310,7 +321,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
View *m_view = nullptr;
|
View *m_view = nullptr;
|
||||||
Shortcut m_shortcut, m_defaultShortcut;
|
Shortcut m_shortcut, m_drawShortcut, m_defaultShortcut;
|
||||||
bool m_editing = false;
|
bool m_editing = false;
|
||||||
bool m_hasDuplicate = false;
|
bool m_hasDuplicate = false;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user