diff --git a/radio/src/gui/colorlcd/confirm_dialog.cpp b/radio/src/gui/colorlcd/confirm_dialog.cpp index 453daf182d6..0508401da9c 100644 --- a/radio/src/gui/colorlcd/confirm_dialog.cpp +++ b/radio/src/gui/colorlcd/confirm_dialog.cpp @@ -26,35 +26,42 @@ ConfirmDialog::ConfirmDialog(Window* parent, const char* title, const char* message, - std::function confirmHandler) : + std::function confirmHandler, + std::function cancelHandler) : Dialog(parent, title, rect_t{}), - confirmHandler(std::move(confirmHandler)) + confirmHandler(std::move(confirmHandler)), + cancelHandler(std::move(cancelHandler)) { auto form = &content->form; auto msg = new StaticText(form, rect_t{}, message); msg->padAll(lv_dpx(16)); - lv_obj_set_style_bg_color(content->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY3), 0); + lv_obj_set_style_bg_color(content->getLvObj(), + makeLvColor(COLOR_THEME_SECONDARY3), 0); auto box = new FormGroup(form, rect_t{}); box->setFlexLayout(LV_FLEX_FLOW_ROW); + lv_obj_set_style_flex_main_place(box->getLvObj(), LV_FLEX_ALIGN_SPACE_EVENLY, 0); - auto box_obj = box->getLvObj(); - lv_obj_set_style_flex_main_place(box_obj, LV_FLEX_ALIGN_SPACE_EVENLY, 0); - auto btn = new TextButton(box, rect_t{}, STR_NO, [=]() -> int8_t { - this->deleteLater(); + onCancel(); return 0; }); - lv_obj_set_width(btn->getLvObj(), LV_DPI_DEF); + btn->setWidth(LV_DPI_DEF); btn = new TextButton(box, rect_t{}, STR_YES, [=]() -> int8_t { this->deleteLater(); this->confirmHandler(); return 0; }); - lv_obj_set_width(btn->getLvObj(), LV_DPI_DEF); + btn->setWidth(LV_DPI_DEF); content->setWidth(LCD_W * 0.8); content->updateSize(); } + +void ConfirmDialog::onCancel() +{ + deleteLater(); + if (cancelHandler) cancelHandler(); +} diff --git a/radio/src/gui/colorlcd/confirm_dialog.h b/radio/src/gui/colorlcd/confirm_dialog.h index 3db62ec85a4..6940af6221c 100644 --- a/radio/src/gui/colorlcd/confirm_dialog.h +++ b/radio/src/gui/colorlcd/confirm_dialog.h @@ -28,10 +28,14 @@ class ConfirmDialog : public Dialog { public: ConfirmDialog(Window* parent, const char* title, const char* message, - std::function confirmHandler); + std::function confirmHandler, + std::function cancelHandler = nullptr); protected: std::function confirmHandler; + std::function cancelHandler; + + void onCancel() override; }; -#endif // _CONFIRM_DIALOG_H_ +#endif // _CONFIRM_DIALOG_H_ diff --git a/radio/src/gui/colorlcd/page.cpp b/radio/src/gui/colorlcd/page.cpp index ec95c8546b3..7d682e3a945 100644 --- a/radio/src/gui/colorlcd/page.cpp +++ b/radio/src/gui/colorlcd/page.cpp @@ -31,7 +31,7 @@ PageHeader::PageHeader(Page * parent, uint8_t icon): #if defined(HARDWARE_TOUCH) new Button(this, { 0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT }, [=]() -> uint8_t { - parent->deleteLater(); + parent->onCancel(); return 0; }, NO_FOCUS | FORM_NO_BORDER); #endif @@ -76,7 +76,8 @@ void Page::paint(BitmapBuffer * dc) void Page::onCancel() { - deleteLater(); + if (canCancel()) + deleteLater(); } void Page::onClicked() diff --git a/radio/src/gui/colorlcd/page.h b/radio/src/gui/colorlcd/page.h index ee85f14d4ae..3a267f19a5d 100644 --- a/radio/src/gui/colorlcd/page.h +++ b/radio/src/gui/colorlcd/page.h @@ -58,6 +58,8 @@ class Page : public Window void paint(BitmapBuffer* dc) override; void deleteLater(bool detach = true, bool trash = true) override; + virtual bool canCancel() { return true; } + protected: PageHeader header; FormWindow body; diff --git a/radio/src/gui/colorlcd/radio_theme.cpp b/radio/src/gui/colorlcd/radio_theme.cpp index acfae23cf6e..0e5ae1fd050 100644 --- a/radio/src/gui/colorlcd/radio_theme.cpp +++ b/radio/src/gui/colorlcd/radio_theme.cpp @@ -293,17 +293,23 @@ class ThemeEditPage : public Page buildHeader(&header); } - void deleteLater(bool detach = true, bool trash = true) override + bool canCancel() override { if (_dirty) { - if (confirmationDialog("Save Theme?", _theme.getName())) { - if (saveHandler != nullptr) { - saveHandler(_theme); - } - } + new ConfirmDialog( + this, STR_SAVE_THEME, _theme.getName(), + [=]() { + if (saveHandler != nullptr) { + saveHandler(_theme); + } + deleteLater(); + }, + [=]() { + deleteLater(); + }); + return false; } - - Page::deleteLater(detach, trash); + return true; } void editColorPage() @@ -326,10 +332,7 @@ class ThemeEditPage : public Page } // page title - new StaticText(window, - {PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT, - PAGE_LINE_HEIGHT}, - STR_EDIT_THEME, 0, COLOR_THEME_PRIMARY2 | flags); + header.setTitle(STR_EDIT_THEME); _themeName = new StaticText(window, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT, LCD_W - PAGE_TITLE_LEFT, PAGE_LINE_HEIGHT}, @@ -486,15 +489,17 @@ void ThemeSetupPage::displayThemeMenu(Window *window, ThemePersistance *tp) }); }); - // you cant delete the default theme or the currently active theme + // you can't delete the default theme or the currently active theme if (listBox->getSelected() != 0 && listBox->getSelected() != tp->getThemeIndex()) { menu->addLine(STR_DELETE, [=] () { - if (confirmationDialog("Delete Theme?", tp->getThemeByIndex(listBox->getSelected())->getName())) { - tp->deleteThemeByIndex(listBox->getSelected()); - listBox->setNames(tp->getNames()); - currentTheme = min(currentTheme, tp->getNames().size() - 1); - listBox->setSelected(currentTheme); - } + new ConfirmDialog( + window, STR_DELETE_THEME, + tp->getThemeByIndex(listBox->getSelected())->getName(), [=] { + tp->deleteThemeByIndex(listBox->getSelected()); + listBox->setNames(tp->getNames()); + currentTheme = min(currentTheme, tp->getNames().size() - 1); + listBox->setSelected(currentTheme); + }); }); } } diff --git a/radio/src/translations.cpp b/radio/src/translations.cpp index 940aa626c78..20a8a510d2e 100644 --- a/radio/src/translations.cpp +++ b/radio/src/translations.cpp @@ -820,6 +820,8 @@ const char STR_LEFT_STICK[] = TR_LEFT_STICK; const char STR_SHOW_MIXER_MONITORS[] = TR_SHOW_MIXER_MONITORS; const char STR_MODEL_QUICK_SELECT[] = TR_MODEL_QUICK_SELECT; const char STR_LOADING[] = TR_LOADING; +const char STR_DELETE_THEME[] = TR_DELETE_THEME; +const char STR_SAVE_THEME[] = TR_SAVE_THEME; #endif #if !defined(COLORLCD) diff --git a/radio/src/translations.h b/radio/src/translations.h index 72b1d133424..01714ba3d2c 100644 --- a/radio/src/translations.h +++ b/radio/src/translations.h @@ -742,6 +742,8 @@ extern const char STR_LEFT_STICK[]; extern const char STR_SHOW_MIXER_MONITORS[]; extern const char STR_MODEL_QUICK_SELECT[]; extern const char STR_LOADING[]; +extern const char STR_DELETE_THEME[]; +extern const char STR_SAVE_THEME[]; #endif extern const char STR_EXECUTE_FILE[]; extern const char STR_DELETE_FILE[]; diff --git a/radio/src/translations/cn.h b/radio/src/translations/cn.h index e02bca06fac..229d4f1b3d5 100644 --- a/radio/src/translations/cn.h +++ b/radio/src/translations/cn.h @@ -774,6 +774,8 @@ #define TR_SAMPLE_MODE "采样模式" #define TR_SAMPLE_MODES "标准","OneBit" #define TR_LOADING "加载中..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "快速选择模型" diff --git a/radio/src/translations/cz.h b/radio/src/translations/cz.h index fc3f85af0cb..d3646e888b3 100644 --- a/radio/src/translations/cz.h +++ b/radio/src/translations/cz.h @@ -680,7 +680,7 @@ #define TR_COPY_MODEL "Kopírovat" #define TR_MOVE_MODEL "Přesunout model" #define TR_BACKUP_MODEL "Zálohovat na SD kartu" -#define TR_DELETE_MODEL "Smaž model" +#define TR_DELETE_MODEL "Smazat model" #define TR_RESTORE_MODEL "Obnov model z SD karty" #define TR_DELETE_ERROR "Nelze odstranit" #define TR_SDCARD_ERROR "Chyba SD karty" @@ -790,9 +790,11 @@ #define TR_TIME "Čas" #define TR_MAXBAUDRATE "Max baudů" #define TR_BAUDRATE "Baudrate" -#define TR_SAMPLE_MODE "Sample Mode" -#define TR_SAMPLE_MODES "Normal","OneBit" +#define TR_SAMPLE_MODE "Vzorkovací režim" +#define TR_SAMPLE_MODES "Normální","OneBit" #define TR_LOADING "Načítání..." +#define TR_DELETE_THEME "Smazat motiv?" +#define TR_SAVE_THEME "Uložit motiv?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Rychlý výběr modelu" @@ -1165,7 +1167,7 @@ #define TR_REMOVE_SCREEN "Odstranit panel" #define TR_SETUP_WIDGETS "Nastavit widgety" #define TR_USER_INTERFACE "Uživatelské rozhraní" -#define TR_THEME "Téma" +#define TR_THEME "Motiv" #define TR_SETUP "Nastavení" #define TR_LAYOUT "Rozložení" #define TR_ADD_MAIN_VIEW "Přidat hlavní panel" diff --git a/radio/src/translations/da.h b/radio/src/translations/da.h index 26bd590ea7b..260430411d8 100644 --- a/radio/src/translations/da.h +++ b/radio/src/translations/da.h @@ -780,6 +780,8 @@ #define TR_SAMPLE_MODE "Måle tilstand" #define TR_SAMPLE_MODES "Normal","EnBit" #define TR_LOADING "Indlæser..." +#define TR_DELETE_THEME "Slet tema?" +#define TR_SAVE_THEME "Gem tema?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Hurtigvalg af model" diff --git a/radio/src/translations/de.h b/radio/src/translations/de.h index 0d875b1b4de..e479cb5dccf 100644 --- a/radio/src/translations/de.h +++ b/radio/src/translations/de.h @@ -775,6 +775,8 @@ #define TR_SAMPLE_MODE "Abtastmodus" #define TR_SAMPLE_MODES "Normal","OneBit" #define TR_LOADING "Wird geladen..." +#define TR_DELETE_THEME "Theme löschen?" +#define TR_SAVE_THEME "Theme speichern?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "schnelle Modellauswahl" diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index c6ef6bf6ed8..71b33ddcb6c 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -773,6 +773,8 @@ #define TR_SAMPLE_MODE "Sample Mode" #define TR_SAMPLE_MODES "Normal","OneBit" #define TR_LOADING "Loading..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Model quick select" diff --git a/radio/src/translations/es.h b/radio/src/translations/es.h index dee67f7effd..d9903e98808 100644 --- a/radio/src/translations/es.h +++ b/radio/src/translations/es.h @@ -774,6 +774,8 @@ #define TR_SAMPLE_MODE "Modo de muestra" #define TR_SAMPLE_MODES "Normal","OneBit" #define TR_LOADING "Loading..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Model quick select" diff --git a/radio/src/translations/fi.h b/radio/src/translations/fi.h index 136bbd3f778..a91679d7fed 100644 --- a/radio/src/translations/fi.h +++ b/radio/src/translations/fi.h @@ -802,6 +802,8 @@ #define TR_SAMPLE_MODE "Sample Mode" #define TR_SAMPLE_MODES "Normal","OneBit" #define TR_LOADING "Loading..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Mallin pikavalinta" diff --git a/radio/src/translations/fr.h b/radio/src/translations/fr.h index 444a88a67d7..8f2337b02c6 100644 --- a/radio/src/translations/fr.h +++ b/radio/src/translations/fr.h @@ -795,6 +795,8 @@ #define TR_SAMPLE_MODE "Sample Mode" #define TR_SAMPLE_MODES "Normal""OneBit" #define TR_LOADING "Loading..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Model quick select" diff --git a/radio/src/translations/it.h b/radio/src/translations/it.h index f5af140b170..fdfe8cf664f 100644 --- a/radio/src/translations/it.h +++ b/radio/src/translations/it.h @@ -775,6 +775,8 @@ #define TR_SAMPLE_MODE "Modo Semplice" #define TR_SAMPLE_MODES "Normale","OneBit" #define TR_LOADING "Caricamento..." +#define TR_DELETE_THEME "Cancello Tema?" +#define TR_SAVE_THEME "Salvo Tema?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Selezione veloce modello" diff --git a/radio/src/translations/jp.h b/radio/src/translations/jp.h index e103b1fc829..7f3817186af 100644 --- a/radio/src/translations/jp.h +++ b/radio/src/translations/jp.h @@ -774,6 +774,8 @@ #define TR_SAMPLE_MODE "サンプルモード" #define TR_SAMPLE_MODES "標準","OneBit" #define TR_LOADING "読み込み中..." +#define TR_DELETE_THEME "テーマを削除しますか?" +#define TR_SAVE_THEME "テーマを保存しますか?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "モデル クイックセレクト" diff --git a/radio/src/translations/nl.h b/radio/src/translations/nl.h index 858303c82b1..0ca1d14555c 100644 --- a/radio/src/translations/nl.h +++ b/radio/src/translations/nl.h @@ -779,6 +779,8 @@ #define TR_SAMPLE_MODE "Sample Mode" #define TR_SAMPLE_MODES "Normal""OneBit" #define TR_LOADING "Loading..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Model quick select" diff --git a/radio/src/translations/pl.h b/radio/src/translations/pl.h index 2c5bf44a4e2..d7b74bf3a61 100644 --- a/radio/src/translations/pl.h +++ b/radio/src/translations/pl.h @@ -771,6 +771,8 @@ #define TR_SAMPLE_MODE "Sample Mode" #define TR_SAMPLE_MODES "Normal","OneBit" #define TR_LOADING "Ładowanie..." +#define TR_DELETE_THEME "Usunąć motyw?" +#define TR_SAVE_THEME "Zapisać motyw?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Szybki wybór modelu" diff --git a/radio/src/translations/pt.h b/radio/src/translations/pt.h index f41a9d87ed3..9371f245f4d 100644 --- a/radio/src/translations/pt.h +++ b/radio/src/translations/pt.h @@ -778,6 +778,8 @@ #define TR_SAMPLE_MODE "Sample Mode" #define TR_SAMPLE_MODES "Normal","OneBit" #define TR_LOADING "Loading..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Model quick select" diff --git a/radio/src/translations/se.h b/radio/src/translations/se.h index 9e85dbfd054..88ace1af31b 100644 --- a/radio/src/translations/se.h +++ b/radio/src/translations/se.h @@ -816,6 +816,8 @@ #define TR_SAMPLE_MODE TR("Sample mod.", "Sample Mode") #define TR_SAMPLE_MODES "Normal","OneBit" #define TR_LOADING "Laddar..." +#define TR_DELETE_THEME "Radera tema?" +#define TR_SAVE_THEME "Spara tema?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "Snabbval av modell" diff --git a/radio/src/translations/tw.h b/radio/src/translations/tw.h index 51fdfe3bd99..a4bb832c7f0 100644 --- a/radio/src/translations/tw.h +++ b/radio/src/translations/tw.h @@ -774,6 +774,8 @@ #define TR_SAMPLE_MODE "採樣模式" #define TR_SAMPLE_MODES "標準","OneBit" #define TR_LOADING "加載中..." +#define TR_DELETE_THEME "Delete Theme?" +#define TR_SAVE_THEME "Save Theme?" #if defined(COLORLCD) #define TR_MODEL_QUICK_SELECT "快速選擇模型"