diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index ade8e9ab..7e319ad8 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -26,6 +26,7 @@ #include #include "ui_fileman.hpp" +#include "ui_text_editor.hpp" #include "string_format.hpp" #include "portapack.hpp" #include "event_m0.hpp" @@ -510,16 +511,19 @@ FileManagerView::FileManagerView( refresh_widgets(v); }; - add_children({&menu_view, - &labels, - &text_date, - &button_rename, - &button_delete, - &button_cut, - &button_copy, - &button_paste, - &button_new_dir, - &button_new_file}); + add_children({ + &menu_view, + &labels, + &text_date, + &button_rename, + &button_delete, + &button_cut, + &button_copy, + &button_paste, + &button_new_dir, + &button_new_file, + &button_open_notepad, + }); menu_view.on_highlight = [this]() { if (selected_is_valid()) @@ -578,6 +582,14 @@ FileManagerView::FileManagerView( button_new_file.on_select = [this]() { on_new_file(); }; + + button_open_notepad.on_select = [this]() { + if (selected_is_valid() && !get_selected_entry().is_directory) { + auto path = get_selected_full_path(); + nav_.replace(path); + } else + nav_.display_modal("Open in Notepad", "Can't open that in Notepad."); + }; } } // namespace ui diff --git a/firmware/application/apps/ui_fileman.hpp b/firmware/application/apps/ui_fileman.hpp index e933702f..265c6044 100644 --- a/firmware/application/apps/ui_fileman.hpp +++ b/firmware/application/apps/ui_fileman.hpp @@ -121,7 +121,7 @@ class FileManBaseView : public View { ""}; Button button_exit{ - {21 * 8, 34 * 8, 9 * 8, 32}, + {22 * 8, 34 * 8, 9 * 8, 32}, "Exit"}; }; @@ -264,6 +264,12 @@ class FileManagerView : public FileManBaseView { {}, &bitmap_icon_new_file, Color::green()}; + + NewButton button_open_notepad{ + {0 * 8, 34 * 8, 4 * 8, 32}, + {}, + &bitmap_icon_notepad, + Color::orange()}; }; } /* namespace ui */ diff --git a/firmware/application/apps/ui_text_editor.cpp b/firmware/application/apps/ui_text_editor.cpp index 83c34bc1..f33ed6b6 100644 --- a/firmware/application/apps/ui_text_editor.cpp +++ b/firmware/application/apps/ui_text_editor.cpp @@ -268,13 +268,18 @@ TextEditorView::TextEditorView(NavigationView& nav) set_focusable(true); button_open.on_select = [this](Button&) { - auto open_view = nav_.push(".TXT"); + auto open_view = nav_.push(""); open_view->on_changed = [this](std::filesystem::path path) { open_file(path); }; }; } +TextEditorView::TextEditorView(NavigationView& nav, const fs::path& path) + : TextEditorView(nav) { + open_file(path); +} + void TextEditorView::on_focus() { refresh_ui(); button_open.focus(); @@ -366,6 +371,20 @@ bool TextEditorView::apply_scrolling_constraints(int16_t delta_line, int16_t del ++new_line; } + // Snap to first/last to make navigating easier. + if (new_line < 0 && new_col > 0) { + new_line = 0; + new_col = 0; + } else if (new_line >= (int32_t)file_.line_count()) { + auto last_line = file_.line_count() - 1; + int32_t last_col = file_.line_length(last_line) - 1; + + if (new_col < last_col) { + new_line = last_line; + new_col = last_col; + } + } + if (new_line < 0 || (uint32_t)new_line >= file_.line_count()) return false; diff --git a/firmware/application/apps/ui_text_editor.hpp b/firmware/application/apps/ui_text_editor.hpp index 7c13bf9d..0c2c4b09 100644 --- a/firmware/application/apps/ui_text_editor.hpp +++ b/firmware/application/apps/ui_text_editor.hpp @@ -110,6 +110,9 @@ class FileWrapper { class TextEditorView : public View { public: TextEditorView(NavigationView& nav); + TextEditorView( + NavigationView& nav, + const std::filesystem::path& path); std::string title() const override { return "Notepad";