diff --git a/src/musikcube/app/layout/HotkeysLayout.cpp b/src/musikcube/app/layout/HotkeysLayout.cpp index bb5711b6d..6fafe27a0 100644 --- a/src/musikcube/app/layout/HotkeysLayout.cpp +++ b/src/musikcube/app/layout/HotkeysLayout.cpp @@ -34,7 +34,10 @@ #include "stdafx.h" #include "HotkeysLayout.h" +#include +#include #include +#include #include #include #include @@ -42,9 +45,57 @@ using namespace cursespp; using namespace musik::cube; +using namespace musik::core; using Entry = IScrollAdapter::EntryPtr; +static void confirmResetHotkeys() { + std::shared_ptr dialog(new DialogOverlay()); + + (*dialog) + .SetTitle(_TSTR("hotkeys_reset_all_title")) + .SetMessage(_TSTR("hotkeys_reset_all_message")) + .AddButton("^[", "ESC", _TSTR("button_no")) + .AddButton( + "KEY_ENTER", + "ENTER", + _TSTR("button_yes"), + [](const std::string& str) { + Hotkeys::Reset(); + }); + + App::Overlays().Push(dialog); +} + +static void checkConflictAndSave(Hotkeys::Id id, const std::string& key) { + const std::string existing = Hotkeys::Existing(key); + + if (existing.size()) { + std::shared_ptr dialog(new DialogOverlay()); + + std::string message = _TSTR("hotkeys_conflict_message"); + ReplaceAll(message, "{{hotkey}}", key); + ReplaceAll(message, "{{existing}}", existing); + + (*dialog) + .SetTitle(_TSTR("hotkeys_conflict_title")) + .SetMessage(message) + .AddButton("^[", "ESC", _TSTR("button_no")) + .AddButton( + "KEY_ENTER", + "ENTER", + _TSTR("button_yes"), + [id, key](const std::string& str) { + Hotkeys::Set(id, key); + }); + + App::Overlays().Push(dialog); + } + else { + Hotkeys::Set(id, key); + } +} + HotkeysLayout::HotkeysLayout() { auto adapter = std::make_shared(); @@ -69,7 +120,9 @@ HotkeysLayout::~HotkeysLayout() { void HotkeysLayout::OnEntryActivated(cursespp::ListWindow* w, size_t index) { Hotkeys::Id id = static_cast(index); - ReassignHotkeyOverlay::Show(id, [](std::string) { + + ReassignHotkeyOverlay::Show(id, [id](std::string key) { + checkConflictAndSave(id, key); }); } @@ -88,6 +141,7 @@ void HotkeysLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { bool HotkeysLayout::KeyPress(const std::string& kn) { if (kn == "M-r") { + confirmResetHotkeys(); return true; } else if (Hotkeys::Is(Hotkeys::NavigateSettings, kn)) { diff --git a/src/musikcube/app/overlay/ReassignHotkeyOverlay.cpp b/src/musikcube/app/overlay/ReassignHotkeyOverlay.cpp index 6407102e8..50598b415 100644 --- a/src/musikcube/app/overlay/ReassignHotkeyOverlay.cpp +++ b/src/musikcube/app/overlay/ReassignHotkeyOverlay.cpp @@ -70,9 +70,6 @@ void ReassignHotkeyOverlay::Layout() { this->hotkeyLabel->MoveAndResize(1, 2, clientWidth - 2, 3); this->hotkeyInput->MoveAndResize(1, 3, clientWidth - 2, 3); this->shortcuts->MoveAndResize(0, clientHeight - 1, clientWidth, 1); - - int x = 1; - int y = 2; } bool ReassignHotkeyOverlay::KeyPress(const std::string& key) { @@ -81,13 +78,18 @@ bool ReassignHotkeyOverlay::KeyPress(const std::string& key) { return true; } else if (key == "KEY_ENTER") { - return true; + auto current = this->hotkeyInput->GetText(); + if (u8len(current)) { + callback(current); + this->Dismiss(); + return true; + } } return LayoutBase::KeyPress(key); } -ReassignHotkeyOverlay::ReassignHotkeyOverlay(Hotkeys::Id id, Callback callback) +ReassignHotkeyOverlay::ReassignHotkeyOverlay(Hotkeys::Id id, Callback callback) : id(id), callback(callback) { LayoutBase(); this->InitViews(); diff --git a/src/musikcube/app/overlay/ReassignHotkeyOverlay.h b/src/musikcube/app/overlay/ReassignHotkeyOverlay.h index 556f9c41d..95b293ed5 100644 --- a/src/musikcube/app/overlay/ReassignHotkeyOverlay.h +++ b/src/musikcube/app/overlay/ReassignHotkeyOverlay.h @@ -62,7 +62,7 @@ namespace musik { void RecalculateSize(); void InitViews(); - + Hotkeys::Id id; Callback callback; int width, height, x, y; diff --git a/src/musikcube/app/util/Hotkeys.cpp b/src/musikcube/app/util/Hotkeys.cpp index d029c561c..22047519e 100755 --- a/src/musikcube/app/util/Hotkeys.cpp +++ b/src/musikcube/app/util/Hotkeys.cpp @@ -301,6 +301,14 @@ void Hotkeys::Set(Id id, const std::string& kn) { /* CAL TODO */ } +void Hotkeys::Reset() { + /* CAL TODO */ +} + +std::string Hotkeys::Existing(const std::string& kn) { + return "TODO!!"; +} + std::string Hotkeys::Name(Id id) { for (auto entry : NAME_TO_ID) { if (entry.second == id) { diff --git a/src/musikcube/app/util/Hotkeys.h b/src/musikcube/app/util/Hotkeys.h index a9fc2dc57..4c6ccb5d3 100755 --- a/src/musikcube/app/util/Hotkeys.h +++ b/src/musikcube/app/util/Hotkeys.h @@ -120,6 +120,7 @@ namespace musik { static std::string Get(Id id); static void Set(Id id, const std::string& kn); static void Reset(); + static std::string Existing(const std::string& kn); static std::string Name(Id id); static std::string Default(Id id); static std::string Custom(Id id); diff --git a/src/musikcube/cursespp/TextInput.cpp b/src/musikcube/cursespp/TextInput.cpp index 8a1bcb19f..2627a56dd 100755 --- a/src/musikcube/cursespp/TextInput.cpp +++ b/src/musikcube/cursespp/TextInput.cpp @@ -189,6 +189,10 @@ void TextInput::SetRawKeyBlacklist(const std::vector&& blacklist) { } bool TextInput::KeyPress(const std::string& key) { + if (this->inputMode == InputMode::InputRaw) { + return false; + } + if (key == "M-KEY_BACKSPACE") { this->SetText(""); return true; diff --git a/src/musikcube/data/locales/en_US.json b/src/musikcube/data/locales/en_US.json index a24ce274e..7f1bcd77b 100644 --- a/src/musikcube/data/locales/en_US.json +++ b/src/musikcube/data/locales/en_US.json @@ -40,6 +40,10 @@ "hotkeys_title": "hotkey configuration", "hotkeys_reset_defaults": "reset all", "hotkeys_reassign_overlay_title": "reassign hotkey", + "hotkeys_reset_all_title": "reset hotkeys", + "hotkeys_reset_all_message": "are you sure you want to reset all hotkeys to their default values?\n\nexisting custom hotkeys will be forgotten!", + "hotkeys_conflict_title": "hotkey conflict", + "hotkeys_conflict_message": "the hotkey '{{hotkey}}' conflicts with '{{existing}}'.\n\nare you sure you want to assign this binding?", "settings_space_to_add": "browse (SPACE to add)", "settings_backspace_to_remove": "indexed paths (BACKSPACE to remove)",