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.
This commit is contained in:
casey langen 2018-12-22 11:49:28 -08:00
parent 2872627190
commit c06c774bd7
10 changed files with 25 additions and 10 deletions

View File

@ -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);

View File

@ -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 {

View File

@ -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);

View File

@ -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 {

View File

@ -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);

View File

@ -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";
} } }

View File

@ -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;
}
} } }

View File

@ -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") {

View File

@ -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)

View File

@ -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;