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

@ -75,9 +75,11 @@ class NavigationView : public View {
// Pushes a new view under the current on the stack so the current view returns into this new one.
template <class T, class... Args>
void push_under_current(Args&&... args) {
T* push_under_current(Args&&... args) {
auto new_view = std::unique_ptr<View>(new T(*this, std::forward<Args>(args)...));
view_stack.insert(view_stack.end() - 1, std::move(new_view));
auto new_view_ptr = new_view.get();
view_stack.insert(view_stack.end() - 1, ViewState{std::move(new_view), {}});
return reinterpret_cast<T*>(new_view_ptr);
}
template <class T, class... Args>
@ -97,12 +99,22 @@ class NavigationView : public View {
void focus() override;
/* Sets the 'on_pop' handler for the current view.
* Returns true if the handler was bound successfully. */
bool set_on_pop(std::function<void()> on_pop);
private:
std::vector<std::unique_ptr<View>> view_stack{};
struct ViewState {
std::unique_ptr<View> view;
std::function<void()> on_pop;
};
std::vector<ViewState> view_stack{};
Widget* modal_view{nullptr};
Widget* view() const;
void pop(bool update);
void free_view();
void update_view();
View* push_view(std::unique_ptr<View> new_view);