Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui) - Convert theme save and delete dialogs to use ConfirmDialog popup. #3062

Merged
merged 8 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions radio/src/gui/colorlcd/confirm_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,42 @@

ConfirmDialog::ConfirmDialog(Window* parent, const char* title,
const char* message,
std::function<void(void)> confirmHandler) :
std::function<void(void)> confirmHandler,
std::function<void(void)> 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();
}
8 changes: 6 additions & 2 deletions radio/src/gui/colorlcd/confirm_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ class ConfirmDialog : public Dialog
{
public:
ConfirmDialog(Window* parent, const char* title, const char* message,
std::function<void(void)> confirmHandler);
std::function<void(void)> confirmHandler,
std::function<void(void)> cancelHandler = nullptr);

protected:
std::function<void(void)> confirmHandler;
std::function<void(void)> cancelHandler;

void onCancel() override;
};

#endif // _CONFIRM_DIALOG_H_
#endif // _CONFIRM_DIALOG_H_
5 changes: 3 additions & 2 deletions radio/src/gui/colorlcd/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,7 +76,8 @@ void Page::paint(BitmapBuffer * dc)

void Page::onCancel()
{
deleteLater();
if (canCancel())
deleteLater();
}

void Page::onClicked()
Expand Down
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 24 additions & 19 deletions radio/src/gui/colorlcd/radio_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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},
Expand Down Expand Up @@ -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<int>(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<int>(currentTheme, tp->getNames().size() - 1);
listBox->setSelected(currentTheme);
});
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/cn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "快速选择模型"
Expand Down
10 changes: 6 additions & 4 deletions radio/src/translations/cz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/da.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/de.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/en.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/es.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/fi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/it.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/jp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "モデル クイックセレクト"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/nl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/se.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions radio/src/translations/tw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "快速選擇模型"
Expand Down