From b069829a5dfc0a22ad3124d8c843ed6f23b6b61f Mon Sep 17 00:00:00 2001 From: "bsongis@gmail.com" Date: Thu, 25 Jul 2013 20:45:32 +0000 Subject: [PATCH] [Taranis] Copy/Paste/Delete contextual menu in Custom Switches screen --- src/gui/menu_model.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ src/translations.cpp | 1 + src/translations.h | 1 + 3 files changed, 46 insertions(+) diff --git a/src/gui/menu_model.cpp b/src/gui/menu_model.cpp index e59e56f8d..d106bb261 100644 --- a/src/gui/menu_model.cpp +++ b/src/gui/menu_model.cpp @@ -3990,6 +3990,39 @@ void menuModelCustomSwitches(uint8_t event) #else +#if defined(PCBTARANIS) +enum ClipboardType { + CLIPBOARD_TYPE_NONE, + CLIPBOARD_TYPE_CUSTOM_SWITCH, +}; + +struct Clipboard { + ClipboardType type; + union { + CustomSwData csw; + } data; +}; + +Clipboard clipboard; + +void onCustomSwitchesMenu(const char *result) +{ + int8_t sub = m_posVert-1; + CustomSwData * cs = cswAddress(sub); + + if (result == STR_COPY) { + clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH; + clipboard.data.csw = *cs; + } + else if (result == STR_PASTE) { + *cs = clipboard.data.csw; + } + else if (result == STR_DELETE) { + memset(cs, 0, sizeof(CustomSwData)); + } +} +#endif + void menuModelCustomSwitches(uint8_t event) { INCDEC_DECLARE_VARS(); @@ -4007,6 +4040,17 @@ void menuModelCustomSwitches(uint8_t event) } #endif +#if defined(PCBTARANIS) + if (sub >= 0 && event == EVT_KEY_LONG(KEY_ENTER)) { + killEvents(event); + MENU_ADD_ITEM(STR_COPY); + if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) + MENU_ADD_ITEM(STR_PASTE); + MENU_ADD_ITEM(STR_DELETE); + menuHandler = onCustomSwitchesMenu; + } +#endif + for (uint8_t i=0; i