From c06c774bd7a69a4a20a2b3662e365699dead06bd Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 22 Dec 2018 11:49:28 -0800 Subject: [PATCH] Allow for customizing the quit key via `settings.json` using the `AppQuitKey` property. Right now there's no UI for it, and it may stay this way because it's an uncommon use case and I have some concerns about users accidentally binding it to an important key and making the app difficult to start/navigate. --- src/musikcube/Main.cpp | 3 +++ src/musikcube/app/layout/ConsoleLayout.cpp | 4 ++-- src/musikcube/app/layout/HotkeysLayout.cpp | 2 +- src/musikcube/app/layout/LibraryLayout.cpp | 4 ++-- src/musikcube/app/layout/SettingsLayout.cpp | 4 ++-- src/musikcube/app/util/PreferenceKeys.cpp | 1 + src/musikcube/app/util/PreferenceKeys.h | 1 + src/musikcube/cursespp/App.cpp | 10 +++++++++- src/musikcube/cursespp/Checkbox.cpp | 3 +-- src/musikcube/cursespp/cursespp/App.h | 3 +++ 10 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/musikcube/Main.cpp b/src/musikcube/Main.cpp index d81f42113..9ee7feb6a 100644 --- a/src/musikcube/Main.cpp +++ b/src/musikcube/Main.cpp @@ -151,6 +151,9 @@ int main(int argc, char* argv[]) { app.SetIcon(IDI_ICON1); app.SetSingleInstanceId("musikcube"); #endif + + app.SetQuitKey(prefs->GetString(keys::AppQuitKey, "^D")); + /* fire up the indexer if configured to run on startup */ if (prefs->GetBool(musik::core::prefs::keys::SyncOnStartup, true)) { library->Indexer()->Schedule(IIndexer::SyncType::All); diff --git a/src/musikcube/app/layout/ConsoleLayout.cpp b/src/musikcube/app/layout/ConsoleLayout.cpp index af9cc41bd..cf25f86de 100755 --- a/src/musikcube/app/layout/ConsoleLayout.cpp +++ b/src/musikcube/app/layout/ConsoleLayout.cpp @@ -120,7 +120,7 @@ void ConsoleLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateConsole), _TSTR("shortcuts_console")); shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateLibrary), _TSTR("shortcuts_library")); shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateSettings), _TSTR("shortcuts_settings")); - shortcuts->AddShortcut("^D", _TSTR("shortcuts_quit")); + shortcuts->AddShortcut(App::Instance().GetQuitKey(), _TSTR("shortcuts_quit")); shortcuts->SetChangedCallback([this](std::string key) { if (Hotkeys::Is(Hotkeys::NavigateSettings, key)) { @@ -129,7 +129,7 @@ void ConsoleLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { if (Hotkeys::Is(Hotkeys::NavigateLibrary, key)) { this->Broadcast(message::JumpToLibrary); } - else if (key == "^D") { + else if (key == App::Instance().GetQuitKey()) { App::Instance().Quit(); } else { diff --git a/src/musikcube/app/layout/HotkeysLayout.cpp b/src/musikcube/app/layout/HotkeysLayout.cpp index e8d7e68c4..9265e98e4 100644 --- a/src/musikcube/app/layout/HotkeysLayout.cpp +++ b/src/musikcube/app/layout/HotkeysLayout.cpp @@ -228,7 +228,7 @@ void HotkeysLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { Hotkeys::Get(Hotkeys::NavigateSettings), _TSTR("shortcuts_settings")); - shortcuts->AddShortcut("^D", _TSTR("shortcuts_quit")); + shortcuts->AddShortcut(App::Instance().GetQuitKey(), _TSTR("shortcuts_quit")); shortcuts->SetChangedCallback([this](std::string key) { this->KeyPress(key); diff --git a/src/musikcube/app/layout/LibraryLayout.cpp b/src/musikcube/app/layout/LibraryLayout.cpp index 04c055b83..95dced3cb 100755 --- a/src/musikcube/app/layout/LibraryLayout.cpp +++ b/src/musikcube/app/layout/LibraryLayout.cpp @@ -247,13 +247,13 @@ void LibraryLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { this->shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateLibraryTracks), _TSTR("shortcuts_tracks")); this->shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateLibraryPlayQueue), _TSTR("shortcuts_play_queue")); this->shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateSettings), _TSTR("shortcuts_settings")); - this->shortcuts->AddShortcut("^D", _TSTR("shortcuts_quit")); + this->shortcuts->AddShortcut(App::Instance().GetQuitKey(), _TSTR("shortcuts_quit")); this->shortcuts->SetChangedCallback([this](std::string key) { if (Hotkeys::Is(Hotkeys::NavigateSettings, key)) { this->Broadcast(message::JumpToSettings); } - else if (key == "^D") { + else if (key == App::Instance().GetQuitKey()) { App::Instance().Quit(); } else { diff --git a/src/musikcube/app/layout/SettingsLayout.cpp b/src/musikcube/app/layout/SettingsLayout.cpp index 6dc7408bc..ef2af5a00 100755 --- a/src/musikcube/app/layout/SettingsLayout.cpp +++ b/src/musikcube/app/layout/SettingsLayout.cpp @@ -512,7 +512,7 @@ void SettingsLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateSettings), _TSTR("shortcuts_settings")); shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateLibrary), _TSTR("shortcuts_library")); shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateConsole), _TSTR("shortcuts_console")); - shortcuts->AddShortcut("^D", _TSTR("shortcuts_quit")); + shortcuts->AddShortcut(App::Instance().GetQuitKey(), _TSTR("shortcuts_quit")); shortcuts->SetChangedCallback([this](std::string key) { if (Hotkeys::Is(Hotkeys::NavigateConsole, key)) { @@ -521,7 +521,7 @@ void SettingsLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { if (Hotkeys::Is(Hotkeys::NavigateLibrary, key)) { this->Broadcast(message::JumpToLibrary); } - else if (key == "^D") { + else if (key == App::Instance().GetQuitKey()) { app.Quit(); } this->KeyPress(key); diff --git a/src/musikcube/app/util/PreferenceKeys.cpp b/src/musikcube/app/util/PreferenceKeys.cpp index 29ec20245..8147f3cb8 100644 --- a/src/musikcube/app/util/PreferenceKeys.cpp +++ b/src/musikcube/app/util/PreferenceKeys.cpp @@ -52,6 +52,7 @@ namespace musik { namespace cube { namespace prefs { const std::string keys::LastBrowseDirectoryRoot = "LastBrowseDirectoryRoot"; const std::string keys::LastCategoryFilter = "LastCategoryFilter"; const std::string keys::LastTrackFilter = "LastTrackFilter"; + const std::string keys::AppQuitKey = "AppQuitKey"; } } } diff --git a/src/musikcube/app/util/PreferenceKeys.h b/src/musikcube/app/util/PreferenceKeys.h index 8789df985..7507de3e0 100644 --- a/src/musikcube/app/util/PreferenceKeys.h +++ b/src/musikcube/app/util/PreferenceKeys.h @@ -54,6 +54,7 @@ namespace musik { namespace cube { namespace prefs { extern const std::string LastBrowseDirectoryRoot; extern const std::string LastCategoryFilter; extern const std::string LastTrackFilter; + extern const std::string AppQuitKey; } } } } diff --git a/src/musikcube/cursespp/App.cpp b/src/musikcube/cursespp/App.cpp index e6abdd743..08f2deeb4 100755 --- a/src/musikcube/cursespp/App.cpp +++ b/src/musikcube/cursespp/App.cpp @@ -234,6 +234,14 @@ void App::OnResized() { } } +void App::SetQuitKey(const std::string& kn) { + this->quitKey = kn; +} + +std::string App::GetQuitKey() { + return this->quitKey; +} + void App::InjectKeyPress(const std::string& key) { this->injectedKeys.push(key); } @@ -325,7 +333,7 @@ process: else if (kn == "KEY_BTAB") { /* shift-tab */ this->FocusPrevInLayout(); } - else if (kn == "^D") { /* ctrl+d quits */ + else if (kn == this->quitKey) { /* ctrl+d quits */ this->quit = true; } else if (kn == "KEY_RESIZE") { diff --git a/src/musikcube/cursespp/Checkbox.cpp b/src/musikcube/cursespp/Checkbox.cpp index affa06d67..7a75fb465 100755 --- a/src/musikcube/cursespp/Checkbox.cpp +++ b/src/musikcube/cursespp/Checkbox.cpp @@ -55,8 +55,7 @@ Checkbox::Checkbox() Checkbox::Checkbox(const std::string& value) : TextLabel(decorate(value, false)) -, originalText(value) -, checked(checked) { +, originalText(value) { } Checkbox::Checkbox(const std::string& value, const text::TextAlign alignment) diff --git a/src/musikcube/cursespp/cursespp/App.h b/src/musikcube/cursespp/cursespp/App.h index 1602c5185..cc62c20ff 100644 --- a/src/musikcube/cursespp/cursespp/App.h +++ b/src/musikcube/cursespp/cursespp/App.h @@ -63,6 +63,8 @@ namespace cursespp { void SetMouseEnabled(bool enabled); bool IsOverlayVisible() { return this->state.overlay != nullptr; } void SetMinimizeToTray(bool minimizeToTray); + std::string GetQuitKey(); + void SetQuitKey(const std::string& kn); void Minimize(); void Restore(); @@ -117,6 +119,7 @@ namespace cursespp { Colors::Mode colorMode { Colors::Palette }; Colors::BgType bgType { Colors::Theme }; std::string colorTheme; + std::string quitKey{"^D"}; int minWidth, minHeight; bool mouseEnabled; bool quit;