Nav stack cleanup (#1460)

* Minor nav stack fixes
* Nav stack cleanup
* Additional cleanup, fix notepad crash
* Fix abort/cancel
* Fix for nasty focus bug
* Format
This commit is contained in:
Kyle Reed 2023-09-27 12:03:02 -07:00 committed by GitHub
parent a6a1483083
commit fb00bfac3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 116 additions and 185 deletions

View file

@ -29,14 +29,6 @@
using namespace portapack;
namespace fs = std::filesystem;
namespace {
/*void log(const std::string& msg) {
LogFile log{};
log.append("LOGS/Notepad.txt");
log.write_entry(msg);
}*/
} // namespace
namespace ui {
/* TextViewer *******************************************************/
@ -413,16 +405,9 @@ TextEditorView::TextEditorView(NavigationView& nav)
};
menu.on_open() = [this]() {
/*show_save_prompt([this]() {
show_save_prompt([this]() {
show_file_picker();
});*/
// HACK: above should work but it's faulting.
if (!file_dirty_) {
show_file_picker();
} else {
show_save_prompt(nullptr);
show_file_picker(false);
}
});
};
menu.on_save() = [this]() {
@ -530,16 +515,16 @@ void TextEditorView::hide_menu(bool hidden) {
set_dirty();
}
void TextEditorView::show_file_picker(bool immediate) {
// TODO: immediate is a hack until nav_.on_pop is fixed.
auto open_view = immediate ? nav_.push<FileLoadView>("") : nav_.push_under_current<FileLoadView>("");
if (open_view) {
open_view->on_changed = [this](std::filesystem::path path) {
open_file(path);
void TextEditorView::show_file_picker() {
auto open_view = nav_.push<FileLoadView>("");
open_view->on_changed = [this](std::filesystem::path path) {
// Can't update the UI focus while the FileLoadView is still up.
// Do this on a continuation instead of in on_changed.
nav_.set_on_pop([this, p = std::move(path)]() {
open_file(p);
hide_menu();
};
}
});
};
}
void TextEditorView::show_edit_line() {