feat(color): warning when duplicating theme if name exists (#4694)
This commit is contained in:
@@ -123,7 +123,7 @@ class ThemeDetailsDialog : public BaseDialog
|
||||
public:
|
||||
ThemeDetailsDialog(
|
||||
Window *parent, ThemeFile theme,
|
||||
std::function<void(ThemeFile theme)> saveHandler = nullptr) :
|
||||
std::function<bool(ThemeFile theme)> saveHandler = nullptr) :
|
||||
BaseDialog(parent, STR_EDIT_THEME_DETAILS, false, DIALOG_DEFAULT_WIDTH,
|
||||
LV_SIZE_CONTENT),
|
||||
theme(theme),
|
||||
@@ -175,7 +175,9 @@ class ThemeDetailsDialog : public BaseDialog
|
||||
|
||||
button =
|
||||
new TextButton(line, rect_t{0, 0, lv_pct(30), 32}, STR_SAVE, [=]() {
|
||||
if (saveHandler != nullptr) saveHandler(this->theme);
|
||||
if (saveHandler != nullptr)
|
||||
if (!saveHandler(this->theme))
|
||||
return 0;
|
||||
deleteLater();
|
||||
return 0;
|
||||
});
|
||||
@@ -185,7 +187,7 @@ class ThemeDetailsDialog : public BaseDialog
|
||||
|
||||
protected:
|
||||
ThemeFile theme;
|
||||
std::function<void(ThemeFile theme)> saveHandler = nullptr;
|
||||
std::function<bool(ThemeFile theme)> saveHandler = nullptr;
|
||||
};
|
||||
|
||||
class ColorEditPage : public Page
|
||||
@@ -397,6 +399,7 @@ class ThemeEditPage : public Page
|
||||
// update the theme name
|
||||
_themeName->setText(_theme.getName());
|
||||
_dirty = true;
|
||||
return true;
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
@@ -544,19 +547,22 @@ void ThemeSetupPage::displayThemeMenu(Window *window, ThemePersistance *tp)
|
||||
|
||||
// use the selected themes color list to make the new theme
|
||||
auto themeIdx = listBox->getSelected();
|
||||
if (themeIdx < 0) return;
|
||||
if (themeIdx < 0) return true;
|
||||
|
||||
auto selTheme = tp->getThemeByIndex(themeIdx);
|
||||
if (selTheme == nullptr) return;
|
||||
if (selTheme == nullptr) return true;
|
||||
|
||||
for (auto color : selTheme->getColorList())
|
||||
theme.setColor(color.colorNumber, color.colorValue);
|
||||
|
||||
tp->createNewTheme(name, theme);
|
||||
if (!tp->createNewTheme(name, theme))
|
||||
return false;
|
||||
|
||||
tp->refresh();
|
||||
listBox->setNames(tp->getNames());
|
||||
listBox->setSelected(currentTheme);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -409,6 +409,11 @@ bool ThemePersistance::deleteThemeByIndex(int index)
|
||||
strAppend(newFile, theme->getPath().c_str(), FF_MAX_LFN);
|
||||
strcat(newFile, ".deleted");
|
||||
|
||||
if (isFileAvailable(newFile, true)) {
|
||||
// .deleted file already exists, remove it
|
||||
f_unlink(newFile);
|
||||
}
|
||||
|
||||
// for now we are just renaming the file so we don't find it
|
||||
FRESULT status = f_rename(theme->getPath().c_str(), newFile);
|
||||
refresh();
|
||||
@@ -434,9 +439,14 @@ bool ThemePersistance::createNewTheme(std::string name, ThemeFile& theme)
|
||||
}
|
||||
|
||||
FRESULT result = f_mkdir(fullPath);
|
||||
if (result != FR_OK) return false;
|
||||
s = strAppend(s, "/", FF_MAX_LFN - (s - fullPath));
|
||||
strAppend(s, "theme.yml", FF_MAX_LFN - (s - fullPath));
|
||||
if (result == FR_EXIST) {
|
||||
if (isFileAvailable(fullPath, true)) {
|
||||
POPUP_WARNING(STR_THEME_EXISTS);
|
||||
return false;
|
||||
}
|
||||
} else if (result != FR_OK) return false;
|
||||
theme.setPath(fullPath);
|
||||
theme.serialize();
|
||||
return true;
|
||||
|
||||
@@ -489,17 +489,21 @@ FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len)
|
||||
FRESULT f_mkdir (const TCHAR * name)
|
||||
{
|
||||
std::string path = convertToSimuPath(name);
|
||||
if (f_stat(name, nullptr) != FR_OK) {
|
||||
#if defined(WIN32) && defined(__GNUC__)
|
||||
if (mkdir(path.c_str())) {
|
||||
if (mkdir(path.c_str())) {
|
||||
#else
|
||||
if (mkdir(path.c_str(), 0777)) {
|
||||
if (mkdir(path.c_str(), 0777)) {
|
||||
#endif
|
||||
TRACE_SIMPGMSPACE("mkdir(%s) = error %d (%s)", path.c_str(), errno, strerror(errno));
|
||||
return FR_INVALID_NAME;
|
||||
}
|
||||
else {
|
||||
TRACE_SIMPGMSPACE("mkdir(%s) = OK", path.c_str());
|
||||
return FR_OK;
|
||||
TRACE_SIMPGMSPACE("mkdir(%s) = error %d (%s)", path.c_str(), errno, strerror(errno));
|
||||
return FR_INVALID_NAME;
|
||||
}
|
||||
else {
|
||||
TRACE_SIMPGMSPACE("mkdir(%s) = OK", path.c_str());
|
||||
return FR_OK;
|
||||
}
|
||||
} else {
|
||||
return FR_EXIST;
|
||||
}
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
@@ -1094,6 +1094,7 @@ const char STR_SELECT_MENU_INV[] = TR_SELECT_MENU_INV;
|
||||
ISTR(SORT_ORDERS);
|
||||
const char STR_SORT_MODELS_BY[] = TR_SORT_MODELS_BY;
|
||||
const char STR_CREATE_NEW[] = TR_CREATE_NEW;
|
||||
const char STR_THEME_EXISTS[] = TR_THEME_EXISTS;
|
||||
#endif
|
||||
|
||||
const char STR_MIX_SLOW_PREC[] = TR_MIX_SLOW_PREC;
|
||||
|
||||
@@ -1285,6 +1285,7 @@ extern const char STR_SELECT_MENU_INV[];
|
||||
extern const char* const STR_SORT_ORDERS[];
|
||||
extern const char STR_SORT_MODELS_BY[];
|
||||
extern const char STR_CREATE_NEW[];
|
||||
extern const char STR_THEME_EXISTS[];
|
||||
#endif
|
||||
|
||||
extern const char STR_MIX_SLOW_PREC[];
|
||||
|
||||
@@ -1284,4 +1284,6 @@
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("慢放精度", "慢放精度 上行/下行")
|
||||
|
||||
#define TR_THEME_EXISTS "已存在同名主题目录 !"
|
||||
|
||||
#define ROTORFLIGHT_LUA_CH "按败板半保备闭标表并波补不菜参叉差偿超车持池出存打大带待怠单到等低地点电调定动度舵二翻方放飞副复负高跟关管航号何合后护环缓回混火或机积集几计加间减件降交角教接阶截进救距开控宽馈拉来累类连练量零灵率滤螺落门面敏模目逆爬盘偏频平其启器前曲取确然入刹上设身升失时使式释试数衰水瞬顺速缩他态体停通退陀微尾位文稳误息熄下陷限线相响向消小校斜新心信型行悬旋循压页一移仪益翼因应用油右预援源载增针正直值止置制中重轴主转准子自踪总最左耦"
|
||||
|
||||
@@ -1298,3 +1298,5 @@
|
||||
#define TR_CREATE_NEW "Vytvořit"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Přesnost zpomal", "Přesnost zpomalení")
|
||||
|
||||
#define TR_THEME_EXISTS "Adresář vzhledu s tímto názvem již existuje."
|
||||
|
||||
@@ -1298,3 +1298,5 @@
|
||||
#define TR_CREATE_NEW "Opret"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Træg præc", "Træg op/ned præcision")
|
||||
|
||||
#define TR_THEME_EXISTS "Der findes allerede et katalog med samme navn."
|
||||
|
||||
@@ -1294,3 +1294,5 @@
|
||||
#define TR_CREATE_NEW "Erstelle"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Langs. Vorlauf", "Langs. Vor-/Rücklauf")
|
||||
|
||||
#define TR_THEME_EXISTS "Ein Theme-Verzeichnis mit demselben Namen existiert bereits"
|
||||
|
||||
@@ -1286,3 +1286,5 @@
|
||||
#define TR_CREATE_NEW "Create"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")
|
||||
|
||||
#define TR_THEME_EXISTS "A theme directory with the same name already exists."
|
||||
|
||||
@@ -1286,3 +1286,5 @@
|
||||
#define TR_CREATE_NEW "Create"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")
|
||||
|
||||
#define TR_THEME_EXISTS "A theme directory with the same name already exists."
|
||||
|
||||
@@ -1302,3 +1302,5 @@
|
||||
#define TR_CREATE_NEW "Create"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")
|
||||
|
||||
#define TR_THEME_EXISTS "A theme directory with the same name already exists."
|
||||
|
||||
@@ -1303,3 +1303,5 @@
|
||||
#define TR_CREATE_NEW "Créer"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")
|
||||
|
||||
#define TR_THEME_EXISTS "Un thème avec le même nom existe déjà."
|
||||
|
||||
@@ -1289,3 +1289,5 @@
|
||||
#define TR_CREATE_NEW "יצירה חדשה"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")
|
||||
|
||||
#define TR_THEME_EXISTS "כבר קיימת ערכת נושא עם אותו שם"
|
||||
|
||||
@@ -1281,3 +1281,5 @@
|
||||
#define TR_CREATE_NEW "Crea"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Prec. lenta", "Prec. su/giù lenta")
|
||||
|
||||
#define TR_THEME_EXISTS "Esiste già una cartella di temi con lo stesso nome."
|
||||
|
||||
@@ -1285,3 +1285,5 @@
|
||||
#define TR_CREATE_NEW "作成"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")
|
||||
|
||||
#define TR_THEME_EXISTS "同じ名前のテーマディレクトリが既に存在します。"
|
||||
|
||||
@@ -1293,3 +1293,5 @@
|
||||
#define TR_CREATE_NEW "Create"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Slow prec", "Slow up/dn prec")
|
||||
|
||||
#define TR_THEME_EXISTS "A theme directory with the same name already exists."
|
||||
|
||||
@@ -1285,3 +1285,5 @@
|
||||
#define TR_CREATE_NEW "Utwórz"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Wolna prec.", "Wolna prec. góra/dół")
|
||||
|
||||
#define TR_THEME_EXISTS "Folder szablonów o takiej samej nazwie już istnieje."
|
||||
|
||||
@@ -1289,3 +1289,5 @@
|
||||
#define TR_CREATE_NEW "Criar"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Prec. Lento", "Prec. mais/menos lento")
|
||||
|
||||
#define TR_THEME_EXISTS "Já existe um diretório de tema com o mesmo nome."
|
||||
|
||||
@@ -1288,3 +1288,5 @@
|
||||
#define TR_CREATE_NEW "Создать"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Точн замедл", "Точность замедления")
|
||||
|
||||
#define TR_THEME_EXISTS "Уже есть каталог с таким названием"
|
||||
|
||||
@@ -1322,3 +1322,5 @@
|
||||
#define TR_CREATE_NEW "Skapa"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Dröj preci.", "Fördröj upp/ner precision")
|
||||
|
||||
#define TR_THEME_EXISTS "Det finns redan ett tema med samma namn"
|
||||
|
||||
@@ -1289,4 +1289,6 @@
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("慢放精度", "慢放精度 上行/下行")
|
||||
|
||||
#define TR_THEME_EXISTS "已存在同名主題目錄 !"
|
||||
|
||||
#define ROTORFLIGHT_LUA_CH "按敗板半保備閉標表並波補不菜參叉差償超車持池出存打大帶待怠單到等低地點電調定動度舵二翻方放飛副復負高跟關管航號何合后護環緩回混火或機積集幾計加間減件降交角教接階截進救距開控寬饋拉來累類連練量零靈率濾螺落門面敏模目逆爬盤偏頻平其啟器前曲取確然入剎上設身升失時使式釋試數衰水瞬順速縮他態體停通退陀微尾位文穩誤息熄下陷限線相響向消小校斜新心信型行懸旋循壓頁一移儀益翼因應用油右預援源載增針正直值止置制中重軸主轉准子自蹤總最左耦"
|
||||
|
||||
@@ -1278,3 +1278,5 @@
|
||||
#define TR_CREATE_NEW "Створити"
|
||||
|
||||
#define TR_MIX_SLOW_PREC TR("Точн. уповільн.", "Точність уповільнення")
|
||||
|
||||
#define TR_THEME_EXISTS "A theme directory with the same name already exists."
|
||||
|
||||
Reference in New Issue
Block a user