fix(color): Only create a new model if the user actually selects a template (#3323)
Cancelling from the template select page will no longer create a blank model.
This commit is contained in:
@@ -707,21 +707,44 @@ void ModelLabelsWindow::newModel()
|
||||
storageFlushCurrentModel();
|
||||
storageCheck(true);
|
||||
|
||||
// Create a new blank ModelCell and activate it first, createmodel() will modify
|
||||
// the model in memory.
|
||||
auto newCell = modelslist.addModel("", false);
|
||||
modelslist.setCurrentModel(newCell);
|
||||
new SelectTemplateFolder([=](std::string folder, std::string name) {
|
||||
// Create a new blank ModelCell and activate it first, createmodel() will modify
|
||||
// the model in memory.
|
||||
auto newCell = modelslist.addModel("", false);
|
||||
modelslist.setCurrentModel(newCell);
|
||||
|
||||
// Make the new model
|
||||
createModel();
|
||||
|
||||
new SelectTemplateFolder([=]() {
|
||||
// On complete update the current cell's data
|
||||
modelslist.updateCurrentModelCell();
|
||||
// Make the new model
|
||||
createModel();
|
||||
|
||||
// Close Window
|
||||
auto w = Layer::back();
|
||||
if (w) w->onCancel();
|
||||
|
||||
// Check for not 'Blank Model'
|
||||
if (name.size() > 0)
|
||||
{
|
||||
static constexpr size_t LEN_BUFFER = sizeof(TEMPLATES_PATH) + 2 * TEXT_FILENAME_MAXLEN + 1;
|
||||
|
||||
char path[LEN_BUFFER + 1];
|
||||
snprintf(path, LEN_BUFFER, "%s/%s", TEMPLATES_PATH, folder.c_str());
|
||||
|
||||
// Read model template
|
||||
loadModelTemplate((name + YAML_EXT).c_str(), path);
|
||||
storageFlushCurrentModel();
|
||||
storageCheck(true);
|
||||
|
||||
// Update the current cell's data
|
||||
modelslist.updateCurrentModelCell();
|
||||
|
||||
#if defined(LUA)
|
||||
// If there is a wizard Lua script, fire it up
|
||||
snprintf(path, LEN_BUFFER, "%s/%s%s", path, name.c_str(), SCRIPT_EXT);
|
||||
if (f_stat(path, 0) == FR_OK) {
|
||||
luaExec(path);
|
||||
StandaloneLuaWindow::instance()->attach();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include "standalone_lua.h"
|
||||
#include "str_functions.h"
|
||||
|
||||
std::function<void(void)> TemplatePage::update = nullptr;
|
||||
|
||||
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
|
||||
@@ -96,7 +94,7 @@ void TemplatePage::onEvent(event_t event)
|
||||
class SelectTemplate : public TemplatePage
|
||||
{
|
||||
public:
|
||||
SelectTemplate(TemplatePage* tp, std::string folder) : templateFolderPage(tp)
|
||||
SelectTemplate(SelectTemplateFolder* tp, std::string folder) : templateFolderPage(tp)
|
||||
{
|
||||
header.setTitle(STR_SELECT_TEMPLATE);
|
||||
|
||||
@@ -138,26 +136,8 @@ class SelectTemplate : public TemplatePage
|
||||
auto tb = new TextButton(
|
||||
listWindow, rect_t{0, 0, lv_pct(100), PAGE_LINE_HEIGHT * 2}, name,
|
||||
[=]() -> uint8_t {
|
||||
// Read model template
|
||||
loadModelTemplate((name + YAML_EXT).c_str(), path);
|
||||
storageDirty(EE_MODEL);
|
||||
storageCheck(true);
|
||||
// Dismiss template pages
|
||||
deleteLater();
|
||||
templateFolderPage->deleteLater();
|
||||
#if defined(LUA)
|
||||
// If there is a wizard Lua script, fire it up
|
||||
snprintf(buffer, LEN_BUFFER, "%s/%s%s", path, name.c_str(),
|
||||
SCRIPT_EXT);
|
||||
if (f_stat(buffer, 0) == FR_OK) {
|
||||
luaExec(buffer);
|
||||
// Need to update() the ModelCategoryPageBody before attaching
|
||||
// StandaloneLuaWindow to not mess up focus
|
||||
update();
|
||||
update = nullptr;
|
||||
StandaloneLuaWindow::instance()->attach();
|
||||
}
|
||||
#endif
|
||||
templateFolderPage->doUpdate(folder, name);
|
||||
return 0;
|
||||
});
|
||||
tb->setFocusHandler([=](bool active) {
|
||||
@@ -183,19 +163,19 @@ class SelectTemplate : public TemplatePage
|
||||
}
|
||||
|
||||
protected:
|
||||
TemplatePage* templateFolderPage;
|
||||
SelectTemplateFolder* templateFolderPage;
|
||||
};
|
||||
|
||||
SelectTemplateFolder::SelectTemplateFolder(std::function<void(void)> update)
|
||||
SelectTemplateFolder::SelectTemplateFolder(std::function<void(std::string folder, std::string)> update)
|
||||
{
|
||||
TemplatePage::update = update;
|
||||
this->update = update;
|
||||
|
||||
header.setTitle(STR_SELECT_TEMPLATE_FOLDER);
|
||||
|
||||
auto tfb = new TextButton(listWindow,
|
||||
rect_t{0, 0, lv_pct(100), PAGE_LINE_HEIGHT * 2},
|
||||
STR_BLANK_MODEL, [=]() -> uint8_t {
|
||||
deleteLater();
|
||||
doUpdate("", "");
|
||||
return 0;
|
||||
});
|
||||
tfb->setFocusHandler([=](bool active) {
|
||||
@@ -259,8 +239,3 @@ SelectTemplateFolder::SelectTemplateFolder(std::function<void(void)> update)
|
||||
|
||||
lv_group_focus_obj(tfb->getLvObj());
|
||||
}
|
||||
|
||||
SelectTemplateFolder::~SelectTemplateFolder()
|
||||
{
|
||||
if (update) update();
|
||||
}
|
||||
|
||||
@@ -27,37 +27,42 @@
|
||||
|
||||
class TemplatePage : public Page
|
||||
{
|
||||
public:
|
||||
TemplatePage();
|
||||
public:
|
||||
TemplatePage();
|
||||
|
||||
void updateInfo();
|
||||
void updateInfo();
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
void onEvent(event_t event) override;
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const { return "TemplatePage"; }
|
||||
std::string getName() const { return "TemplatePage"; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
FormWindow* listWindow = nullptr;
|
||||
lv_obj_t* infoLabel = nullptr;
|
||||
protected:
|
||||
FormWindow* listWindow = nullptr;
|
||||
lv_obj_t* infoLabel = nullptr;
|
||||
|
||||
static constexpr size_t LEN_INFO_TEXT = 300;
|
||||
static constexpr size_t LEN_PATH =
|
||||
sizeof(TEMPLATES_PATH) + TEXT_FILENAME_MAXLEN;
|
||||
static constexpr size_t LEN_BUFFER =
|
||||
sizeof(TEMPLATES_PATH) + 2 * TEXT_FILENAME_MAXLEN + 1;
|
||||
static constexpr size_t LEN_INFO_TEXT = 300;
|
||||
static constexpr size_t LEN_PATH = sizeof(TEMPLATES_PATH) + TEXT_FILENAME_MAXLEN;
|
||||
static constexpr size_t LEN_BUFFER = sizeof(TEMPLATES_PATH) + 2 * TEXT_FILENAME_MAXLEN + 1;
|
||||
|
||||
char buffer[LEN_BUFFER + 1] = "";
|
||||
char infoText[LEN_INFO_TEXT + 1] = "";
|
||||
static std::function<void(void)> update;
|
||||
char buffer[LEN_BUFFER + 1] = "";
|
||||
char infoText[LEN_INFO_TEXT + 1] = "";
|
||||
};
|
||||
|
||||
class SelectTemplateFolder : public TemplatePage
|
||||
{
|
||||
public:
|
||||
SelectTemplateFolder(std::function<void(void)> update);
|
||||
~SelectTemplateFolder();
|
||||
SelectTemplateFolder(std::function<void(std::string, std::string)> update);
|
||||
|
||||
void doUpdate(std::string folder, std::string name) {
|
||||
deleteLater();
|
||||
if (update)
|
||||
update(folder, name);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void(std::string, std::string)> update;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user