#pragma once #include #include #include #include "app.h" #include "apps/note_editor.h" #include "dialog_model.h" #include "file_list.h" #include "line_editor.h" #include "list_model.h" #include "services/file_ops.h" #include "ui/theme.h" namespace roro { // Notes (docs/milestones/F1.md, Q141-Q150): plain text files in /notes, listed by their first line, // newest first. n starts one, Enter opens it in the editor, which saves by itself; r renames the // file, d deletes it after asking, s sorts by name or by date. class NotesApp : public App { public: NotesApp(FileOps& ops, StorageService& storage, ClockService& clock, PowerService& power) : ops_(ops), storage_(storage), editor_(storage, clock, power) {} void onEnter() override; void onExit() override; bool onKey(const KeyEvent& e) override; bool textEntryActive() const override { return view_ == View::Edit || view_ == View::Name; } void update(uint32_t nowMs) override; void draw(Canvas& c) override; private: enum class View { List, Edit, Name, NoMemory }; enum class Wait { None, List, Work }; static constexpr int kRows = 8; static constexpr size_t kStartFloor = 55 * 1024; // Q86, Q144 static constexpr const char* kFolder = "/notes"; void reload(const std::string& select = ""); void onFinished(const FileOps::Status& s); bool onListKey(const KeyEvent& e); bool onNameKey(const KeyEvent& e); void leaveEditor(); std::string selectedPath() const; // "" in an empty list std::string titleOf(int row); void readTitles(); void say(const std::string& text); FileOps& ops_; StorageService& storage_; NoteEditor editor_; View view_ = View::List; files::FileList list_; std::vector notes_; // the entries of list_ that are notes files::FileSort sort_ = files::FileSort::Date; ListModel rows_{kRows}; bool wantList_ = false, loaded_ = false, cardPresent_ = false, mended_ = false; std::string selectAfter_; int selectIndex_ = 0; Wait wait_ = Wait::None; std::vector titles_; // of the rows on screen int titlesFrom_ = -1; std::unique_ptr dialog_; std::string target_, question_; LineEditor name_{40}; std::string message_; uint32_t messageMs_ = 0, lastDrawMs_ = 0; }; } // namespace roro