mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
- added UI to set/replace hotkey values and also reset all to default
(not wired up yet) - stubbed Hotkeys::Set() and Hotkeys::Reset() - fixed TextInput::KeyPress in InputRaw mode.
This commit is contained in:
parent
89dbbb5aee
commit
f1c39e2038
@ -34,7 +34,10 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "HotkeysLayout.h"
|
||||
#include <core/support/Common.h>
|
||||
#include <cursespp/App.h>
|
||||
#include <cursespp/Colors.h>
|
||||
#include <cursespp/DialogOverlay.h>
|
||||
#include <app/util/Hotkeys.h>
|
||||
#include <app/model/HotkeysAdapter.h>
|
||||
#include <app/overlay/ReassignHotkeyOverlay.h>
|
||||
@ -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<DialogOverlay> 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<DialogOverlay> 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<HotkeysAdapter>();
|
||||
|
||||
@ -69,7 +120,9 @@ HotkeysLayout::~HotkeysLayout() {
|
||||
|
||||
void HotkeysLayout::OnEntryActivated(cursespp::ListWindow* w, size_t index) {
|
||||
Hotkeys::Id id = static_cast<Hotkeys::Id>(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)) {
|
||||
|
@ -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,8 +78,13 @@ bool ReassignHotkeyOverlay::KeyPress(const std::string& key) {
|
||||
return true;
|
||||
}
|
||||
else if (key == "KEY_ENTER") {
|
||||
auto current = this->hotkeyInput->GetText();
|
||||
if (u8len(current)) {
|
||||
callback(current);
|
||||
this->Dismiss();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return LayoutBase::KeyPress(key);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -189,6 +189,10 @@ void TextInput::SetRawKeyBlacklist(const std::vector<std::string>&& blacklist) {
|
||||
}
|
||||
|
||||
bool TextInput::KeyPress(const std::string& key) {
|
||||
if (this->inputMode == InputMode::InputRaw) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key == "M-KEY_BACKSPACE") {
|
||||
this->SetText("");
|
||||
return true;
|
||||
|
@ -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)",
|
||||
|
Loading…
Reference in New Issue
Block a user