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;
|
||||
|
||||
Reference in New Issue
Block a user