allow creating an new model in an empty category

This commit is contained in:
Raphael Coeffic
2021-04-09 13:14:18 +02:00
parent e87405e732
commit 9579e5d833
2 changed files with 50 additions and 8 deletions
+46 -6
View File
@@ -287,12 +287,7 @@ class ModelCategoryPageBody: public FormWindow {
});
}
menu->addLine(STR_CREATE_MODEL, [=]() {
storageCheck(true);
modelslist.setCurrentModel(modelslist.addModel(category, createModel()));
#if defined(LUA)
// chainMenu(menuModelWizard);
#endif
update(category->size() - 1);
this->createModelAction();
});
menu->addLine(STR_DUPLICATE_MODEL, [=]() {
char duplicatedFilename[LEN_MODEL_FILENAME + 1];
@@ -342,11 +337,56 @@ class ModelCategoryPageBody: public FormWindow {
}
setInnerHeight(y);
if (category->empty()) {
setFocus();
}
}
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override
{
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
Menu * menu = new Menu(this);
menu->addLine(STR_CREATE_MODEL, [=]() {
this->createModelAction();
});
//TODO: create category?
}
else {
FormWindow::onEvent(event);
}
}
#endif
void setFocus(uint8_t flag = SET_FOCUS_DEFAULT, Window * from = nullptr) override
{
if (category->empty()) {
// use Window::setFocus() to avoid forwarding focus to nowhere
// this crashes currently in libopenui
Window::setFocus(flag,from);
}
else {
FormWindow::setFocus(flag,from);
}
}
protected:
ModelsCategory * category;
ModelSelectFooter * footer;
void createModelAction()
{
storageCheck(true);
modelslist.setCurrentModel(modelslist.addModel(category, createModel()));
#if defined(LUA)
// chainMenu(menuModelWizard);
#endif
update(category->size() - 1);
}
};
class ModelCategoryPage: public PageTab {
+4 -2
View File
@@ -257,8 +257,10 @@ class SetupWidgetsPage: public FormWindow
#if defined(HARDWARE_TOUCH)
Keyboard::hide();
#endif
// give it back to its old parent before it gets deleted
screen->attach(oldParent);
if (oldParent) {
// give it back to its old parent before it gets deleted
screen->attach(oldParent);
}
FormWindow::deleteLater(detach, trash);
}