Add edit support for Notepad (#1093)

* WIP file editing

* WIP file editing

* Add "on_pop" handler to navigation.

* WIP Editing

* WIP for draft

* Fix mock and unit tests,  support +newline at end.

* Clean up Painter API and use string_view

* Fix optional rvalue functions

* Fix Result 'take' to be more standard

* FileWrapper stack buffer reads

* Grasping at straws

* Nit

* Move set_on_pop impl to cpp

* Workaround "Open" when file not dirty.

---------

Co-authored-by: kallanreed <kallanreed@outlook.com>
This commit is contained in:
Kyle Reed 2023-06-01 15:45:55 -07:00 committed by GitHub
parent 69011754c9
commit 8d7fdeb633
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 847 additions and 148 deletions

View file

@ -236,10 +236,8 @@ void SystemStatusView::refresh() {
if (portapack::clock_manager.get_reference().source == ClockManager::ReferenceSource::External) {
button_clock_status.set_bitmap(&bitmap_icon_clk_ext);
// button_bias_tee.set_foreground(ui::Color::green()); Typo?
} else {
button_clock_status.set_bitmap(&bitmap_icon_clk_int);
// button_bias_tee.set_foreground(ui::Color::green());
}
if (portapack::persistent_memory::clkout_enabled()) {
@ -420,7 +418,7 @@ View* NavigationView::push_view(std::unique_ptr<View> new_view) {
free_view();
const auto p = new_view.get();
view_stack.emplace_back(std::move(new_view));
view_stack.emplace_back(ViewState{std::move(new_view), {}});
update_view();
@ -428,34 +426,14 @@ View* NavigationView::push_view(std::unique_ptr<View> new_view) {
}
void NavigationView::pop() {
if (view() == modal_view) {
modal_view = nullptr;
}
// Can't pop last item from stack.
if (view_stack.size() > 1) {
free_view();
view_stack.pop_back();
update_view();
}
pop(true);
}
void NavigationView::pop_modal() {
if (view() == modal_view) {
modal_view = nullptr;
}
// Pop modal view + underlying app view
if (view_stack.size() > 2) {
free_view();
view_stack.pop_back();
free_view();
view_stack.pop_back();
update_view();
}
// Pop modal view + underlying app view.
// TODO: this shouldn't be necessary.
pop(false);
pop(true);
}
void NavigationView::display_modal(
@ -475,12 +453,31 @@ void NavigationView::display_modal(
}
}
void NavigationView::pop(bool update) {
if (view() == modal_view) {
modal_view = nullptr;
}
// Can't pop last item from stack.
if (view_stack.size() > 1) {
auto on_pop = view_stack.back().on_pop;
free_view();
view_stack.pop_back();
if (update)
update_view();
if (on_pop) on_pop();
}
}
void NavigationView::free_view() {
remove_child(view());
}
void NavigationView::update_view() {
const auto new_view = view_stack.back().get();
const auto new_view = view_stack.back().view.get();
add_child(new_view);
new_view->set_parent_rect({{0, 0}, size()});
@ -503,6 +500,18 @@ void NavigationView::focus() {
}
}
bool NavigationView::set_on_pop(std::function<void()> on_pop) {
if (view_stack.size() <= 1)
return false;
auto& top = view_stack.back();
if (top.on_pop)
return false;
top.on_pop = on_pop;
return true;
}
/* ReceiversMenuView *****************************************************/
ReceiversMenuView::ReceiversMenuView(NavigationView& nav) {