mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
Implemented Hotkeys::Set() and related functionality.
This commit is contained in:
parent
e36fa357b9
commit
4a22c48293
@ -67,7 +67,7 @@ static void confirmResetHotkeys() {
|
|||||||
App::Overlays().Push(dialog);
|
App::Overlays().Push(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkConflictAndSave(Hotkeys::Id id, const std::string& key) {
|
static void checkConflictAndSave(Hotkeys::Id id, const std::string& key, std::function<void()> cb) {
|
||||||
const std::string existing = Hotkeys::Existing(key);
|
const std::string existing = Hotkeys::Existing(key);
|
||||||
|
|
||||||
if (existing == Hotkeys::Name(id)) {
|
if (existing == Hotkeys::Name(id)) {
|
||||||
@ -89,14 +89,20 @@ static void checkConflictAndSave(Hotkeys::Id id, const std::string& key) {
|
|||||||
"KEY_ENTER",
|
"KEY_ENTER",
|
||||||
"ENTER",
|
"ENTER",
|
||||||
_TSTR("button_yes"),
|
_TSTR("button_yes"),
|
||||||
[id, key](const std::string& str) {
|
[id, key, cb](const std::string& str) {
|
||||||
Hotkeys::Set(id, key);
|
Hotkeys::Set(id, key);
|
||||||
|
if (cb) {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
App::Overlays().Push(dialog);
|
App::Overlays().Push(dialog);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Hotkeys::Set(id, key);
|
Hotkeys::Set(id, key);
|
||||||
|
if (cb) {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,16 +128,24 @@ HotkeysLayout::HotkeysLayout() {
|
|||||||
HotkeysLayout::~HotkeysLayout() {
|
HotkeysLayout::~HotkeysLayout() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeysLayout::OnEntryActivated(cursespp::ListWindow* w, size_t index) {
|
void HotkeysLayout::OnEntryActivated(cursespp::ListWindow* list, size_t index) {
|
||||||
Hotkeys::Id id = static_cast<Hotkeys::Id>(index);
|
Hotkeys::Id id = static_cast<Hotkeys::Id>(index);
|
||||||
|
auto shortcuts = this->shortcuts;
|
||||||
|
|
||||||
ReassignHotkeyOverlay::Show(id, [id](std::string key) {
|
ReassignHotkeyOverlay::Show(id, [this, list, id](std::string key) {
|
||||||
checkConflictAndSave(id, key);
|
checkConflictAndSave(id, key, [this, list]() {
|
||||||
|
list->OnAdapterChanged();
|
||||||
|
this->SetShortcutsWindow(this->shortcuts);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeysLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) {
|
void HotkeysLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) {
|
||||||
|
this->shortcuts = shortcuts;
|
||||||
|
|
||||||
if (shortcuts) {
|
if (shortcuts) {
|
||||||
|
shortcuts->RemoveAll();
|
||||||
|
|
||||||
shortcuts->AddShortcut("M-r", _TSTR("hotkeys_reset_defaults"));
|
shortcuts->AddShortcut("M-r", _TSTR("hotkeys_reset_defaults"));
|
||||||
shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateLibrary), _TSTR("shortcuts_library"));
|
shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateLibrary), _TSTR("shortcuts_library"));
|
||||||
shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateSettings), _TSTR("shortcuts_settings"));
|
shortcuts->AddShortcut(Hotkeys::Get(Hotkeys::NavigateSettings), _TSTR("shortcuts_settings"));
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <cursespp/LayoutBase.h>
|
#include <cursespp/LayoutBase.h>
|
||||||
#include <cursespp/ListWindow.h>
|
#include <cursespp/ListWindow.h>
|
||||||
|
#include <cursespp/ShortcutsWindow.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "ITopLevelLayout.h"
|
#include "ITopLevelLayout.h"
|
||||||
@ -67,6 +68,7 @@ namespace musik {
|
|||||||
void OnEntryActivated(cursespp::ListWindow* w, size_t index);
|
void OnEntryActivated(cursespp::ListWindow* w, size_t index);
|
||||||
|
|
||||||
std::shared_ptr<cursespp::ListWindow> listWindow;
|
std::shared_ptr<cursespp::ListWindow> listWindow;
|
||||||
|
cursespp::ShortcutsWindow* shortcuts;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -272,14 +272,13 @@ std::string find(Id id, T& map) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void findMany(const std::string& kn, T& map, std::vector<std::string>& target) {
|
Hotkeys::Id find(const std::string& kn, T& map) {
|
||||||
for (int i = 0; i < Id::COUNT; i++) {
|
for (auto it : map) {
|
||||||
Id id = static_cast<Id>(i);
|
if (it.second == kn) {
|
||||||
std::string thisKn = find(id, map);
|
return it.first;
|
||||||
if (thisKn == kn) {
|
|
||||||
target.push_back(thisKn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Hotkeys::COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Hotkeys::Default(Id id) {
|
std::string Hotkeys::Default(Id id) {
|
||||||
@ -298,7 +297,8 @@ std::string Hotkeys::Get(Id id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Hotkeys::Set(Id id, const std::string& kn) {
|
void Hotkeys::Set(Id id, const std::string& kn) {
|
||||||
/* CAL TODO */
|
customIdToKey[id] = kn;
|
||||||
|
savePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hotkeys::Reset() {
|
void Hotkeys::Reset() {
|
||||||
@ -308,7 +308,17 @@ void Hotkeys::Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string Hotkeys::Existing(const std::string& kn) {
|
std::string Hotkeys::Existing(const std::string& kn) {
|
||||||
return "TODO!!";
|
auto id = find(kn, customIdToKey);
|
||||||
|
if (id == Hotkeys::COUNT) {
|
||||||
|
id = find(kn, ID_TO_DEFAULT);
|
||||||
|
if (customIdToKey.find(id) != customIdToKey.end()) {
|
||||||
|
/* we found a default key for this one, but that default
|
||||||
|
binding has already been overridden! ensure we return
|
||||||
|
that it's available. */
|
||||||
|
id = Hotkeys::COUNT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id != Hotkeys::COUNT ? Name(id) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Hotkeys::Name(Id id) {
|
std::string Hotkeys::Name(Id id) {
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
"hotkeys_reset_all_title": "reset hotkeys",
|
"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_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_title": "hotkey conflict",
|
||||||
"hotkeys_conflict_message": "the hotkey '{{hotkey}}' conflicts with '{{existing}}'.\n\nare you sure you want to assign this binding?",
|
"hotkeys_conflict_message": "the hotkey '{{hotkey}}' *may* conflict with '{{existing}}', depending on context.\n\nare you sure you want to assign this binding?",
|
||||||
|
|
||||||
"settings_space_to_add": "browse (SPACE to add)",
|
"settings_space_to_add": "browse (SPACE to add)",
|
||||||
"settings_backspace_to_remove": "indexed paths (BACKSPACE to remove)",
|
"settings_backspace_to_remove": "indexed paths (BACKSPACE to remove)",
|
||||||
|
Loading…
Reference in New Issue
Block a user