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();
|
storageFlushCurrentModel();
|
||||||
storageCheck(true);
|
storageCheck(true);
|
||||||
|
|
||||||
// Create a new blank ModelCell and activate it first, createmodel() will modify
|
new SelectTemplateFolder([=](std::string folder, std::string name) {
|
||||||
// the model in memory.
|
// Create a new blank ModelCell and activate it first, createmodel() will modify
|
||||||
auto newCell = modelslist.addModel("", false);
|
// the model in memory.
|
||||||
modelslist.setCurrentModel(newCell);
|
auto newCell = modelslist.addModel("", false);
|
||||||
|
modelslist.setCurrentModel(newCell);
|
||||||
|
|
||||||
// Make the new model
|
// Make the new model
|
||||||
createModel();
|
createModel();
|
||||||
|
|
||||||
new SelectTemplateFolder([=]() {
|
|
||||||
// On complete update the current cell's data
|
|
||||||
modelslist.updateCurrentModelCell();
|
|
||||||
|
|
||||||
// Close Window
|
// Close Window
|
||||||
auto w = Layer::back();
|
auto w = Layer::back();
|
||||||
if (w) w->onCancel();
|
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 "standalone_lua.h"
|
||||||
#include "str_functions.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),
|
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
|
||||||
LV_GRID_TEMPLATE_LAST};
|
LV_GRID_TEMPLATE_LAST};
|
||||||
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, 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
|
class SelectTemplate : public TemplatePage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SelectTemplate(TemplatePage* tp, std::string folder) : templateFolderPage(tp)
|
SelectTemplate(SelectTemplateFolder* tp, std::string folder) : templateFolderPage(tp)
|
||||||
{
|
{
|
||||||
header.setTitle(STR_SELECT_TEMPLATE);
|
header.setTitle(STR_SELECT_TEMPLATE);
|
||||||
|
|
||||||
@@ -138,26 +136,8 @@ class SelectTemplate : public TemplatePage
|
|||||||
auto tb = new TextButton(
|
auto tb = new TextButton(
|
||||||
listWindow, rect_t{0, 0, lv_pct(100), PAGE_LINE_HEIGHT * 2}, name,
|
listWindow, rect_t{0, 0, lv_pct(100), PAGE_LINE_HEIGHT * 2}, name,
|
||||||
[=]() -> uint8_t {
|
[=]() -> uint8_t {
|
||||||
// Read model template
|
|
||||||
loadModelTemplate((name + YAML_EXT).c_str(), path);
|
|
||||||
storageDirty(EE_MODEL);
|
|
||||||
storageCheck(true);
|
|
||||||
// Dismiss template pages
|
|
||||||
deleteLater();
|
deleteLater();
|
||||||
templateFolderPage->deleteLater();
|
templateFolderPage->doUpdate(folder, name);
|
||||||
#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
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
tb->setFocusHandler([=](bool active) {
|
tb->setFocusHandler([=](bool active) {
|
||||||
@@ -183,19 +163,19 @@ class SelectTemplate : public TemplatePage
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
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);
|
header.setTitle(STR_SELECT_TEMPLATE_FOLDER);
|
||||||
|
|
||||||
auto tfb = new TextButton(listWindow,
|
auto tfb = new TextButton(listWindow,
|
||||||
rect_t{0, 0, lv_pct(100), PAGE_LINE_HEIGHT * 2},
|
rect_t{0, 0, lv_pct(100), PAGE_LINE_HEIGHT * 2},
|
||||||
STR_BLANK_MODEL, [=]() -> uint8_t {
|
STR_BLANK_MODEL, [=]() -> uint8_t {
|
||||||
deleteLater();
|
doUpdate("", "");
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
tfb->setFocusHandler([=](bool active) {
|
tfb->setFocusHandler([=](bool active) {
|
||||||
@@ -259,8 +239,3 @@ SelectTemplateFolder::SelectTemplateFolder(std::function<void(void)> update)
|
|||||||
|
|
||||||
lv_group_focus_obj(tfb->getLvObj());
|
lv_group_focus_obj(tfb->getLvObj());
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectTemplateFolder::~SelectTemplateFolder()
|
|
||||||
{
|
|
||||||
if (update) update();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,37 +27,42 @@
|
|||||||
|
|
||||||
class TemplatePage : public Page
|
class TemplatePage : public Page
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TemplatePage();
|
TemplatePage();
|
||||||
|
|
||||||
void updateInfo();
|
void updateInfo();
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
void onEvent(event_t event) override;
|
void onEvent(event_t event) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const { return "TemplatePage"; }
|
std::string getName() const { return "TemplatePage"; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FormWindow* listWindow = nullptr;
|
FormWindow* listWindow = nullptr;
|
||||||
lv_obj_t* infoLabel = nullptr;
|
lv_obj_t* infoLabel = nullptr;
|
||||||
|
|
||||||
static constexpr size_t LEN_INFO_TEXT = 300;
|
static constexpr size_t LEN_INFO_TEXT = 300;
|
||||||
static constexpr size_t LEN_PATH =
|
static constexpr size_t LEN_PATH = sizeof(TEMPLATES_PATH) + TEXT_FILENAME_MAXLEN;
|
||||||
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_BUFFER =
|
|
||||||
sizeof(TEMPLATES_PATH) + 2 * TEXT_FILENAME_MAXLEN + 1;
|
|
||||||
|
|
||||||
char buffer[LEN_BUFFER + 1] = "";
|
char buffer[LEN_BUFFER + 1] = "";
|
||||||
char infoText[LEN_INFO_TEXT + 1] = "";
|
char infoText[LEN_INFO_TEXT + 1] = "";
|
||||||
static std::function<void(void)> update;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SelectTemplateFolder : public TemplatePage
|
class SelectTemplateFolder : public TemplatePage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SelectTemplateFolder(std::function<void(void)> update);
|
SelectTemplateFolder(std::function<void(std::string, std::string)> update);
|
||||||
~SelectTemplateFolder();
|
|
||||||
|
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