Working hotkey reset.

This commit is contained in:
casey langen 2018-06-03 01:27:14 -07:00
parent f1c39e2038
commit e36fa357b9
3 changed files with 11 additions and 3 deletions

View File

@ -70,6 +70,10 @@ static void confirmResetHotkeys() {
static void checkConflictAndSave(Hotkeys::Id id, const std::string& key) {
const std::string existing = Hotkeys::Existing(key);
if (existing == Hotkeys::Name(id)) {
return;
}
if (existing.size()) {
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
@ -99,7 +103,7 @@ static void checkConflictAndSave(Hotkeys::Id id, const std::string& key) {
HotkeysLayout::HotkeysLayout() {
auto adapter = std::make_shared<HotkeysAdapter>();
adapter->SetItemDecorator([&adapter, this](ScrollableWindow*, size_t index, size_t, Entry) -> int64_t {
adapter->SetItemDecorator([this](ScrollableWindow*, size_t index, size_t, Entry) -> int64_t {
if (this->listWindow->GetSelectedIndex() == index) {
return COLOR_PAIR(CURSESPP_HIGHLIGHTED_LIST_ITEM);
}
@ -142,6 +146,7 @@ void HotkeysLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) {
bool HotkeysLayout::KeyPress(const std::string& kn) {
if (kn == "M-r") {
confirmResetHotkeys();
this->listWindow->OnAdapterChanged();
return true;
}
else if (Hotkeys::Is(Hotkeys::NavigateSettings, kn)) {

View File

@ -125,6 +125,7 @@ void ReassignHotkeyOverlay::InitViews() {
this->hotkeyInput->SetRawKeyBlacklist({ "KEY_ENTER", "^[" });
this->hotkeyInput->SetFocusOrder(0);
this->hotkeyInput->SetFocusedFrameColor(CURSESPP_OVERLAY_INPUT_FRAME);
this->hotkeyInput->SetText(Hotkeys::Get(this->id));
this->hotkeyInput->SetFocusedContentColor(CURSESPP_OVERLAY_CONTENT);
this->shortcuts = std::make_shared<ShortcutsWindow>();

View File

@ -204,7 +204,7 @@ static std::unordered_map<Id, std::string, EnumHasher> customIdToKey;
static std::shared_ptr<Preferences> prefs;
static void savePreferences() {
for (const std::pair<std::string, Id>& pair : NAME_TO_ID) {
for (const auto& pair : NAME_TO_ID) {
prefs->SetString(
pair.first.c_str(),
Hotkeys::Get(pair.second).c_str());
@ -302,7 +302,9 @@ void Hotkeys::Set(Id id, const std::string& kn) {
}
void Hotkeys::Reset() {
/* CAL TODO */
customIdToKey.clear();
savePreferences();
loadPreferences();
}
std::string Hotkeys::Existing(const std::string& kn) {