Support open in notepad from fileman (#1052)

* Support open in notepad from fileman
* Align Filename Exit button with UI
This commit is contained in:
Kyle Reed 2023-05-22 21:40:03 -07:00 committed by GitHub
parent 1cb682473a
commit c2314f4838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 12 deletions

View File

@ -26,6 +26,7 @@
#include <algorithm> #include <algorithm>
#include "ui_fileman.hpp" #include "ui_fileman.hpp"
#include "ui_text_editor.hpp"
#include "string_format.hpp" #include "string_format.hpp"
#include "portapack.hpp" #include "portapack.hpp"
#include "event_m0.hpp" #include "event_m0.hpp"
@ -510,7 +511,8 @@ FileManagerView::FileManagerView(
refresh_widgets(v); refresh_widgets(v);
}; };
add_children({&menu_view, add_children({
&menu_view,
&labels, &labels,
&text_date, &text_date,
&button_rename, &button_rename,
@ -519,7 +521,9 @@ FileManagerView::FileManagerView(
&button_copy, &button_copy,
&button_paste, &button_paste,
&button_new_dir, &button_new_dir,
&button_new_file}); &button_new_file,
&button_open_notepad,
});
menu_view.on_highlight = [this]() { menu_view.on_highlight = [this]() {
if (selected_is_valid()) if (selected_is_valid())
@ -578,6 +582,14 @@ FileManagerView::FileManagerView(
button_new_file.on_select = [this]() { button_new_file.on_select = [this]() {
on_new_file(); 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<TextEditorView>(path);
} else
nav_.display_modal("Open in Notepad", "Can't open that in Notepad.");
};
} }
} // namespace ui } // namespace ui

View File

@ -121,7 +121,7 @@ class FileManBaseView : public View {
""}; ""};
Button button_exit{ Button button_exit{
{21 * 8, 34 * 8, 9 * 8, 32}, {22 * 8, 34 * 8, 9 * 8, 32},
"Exit"}; "Exit"};
}; };
@ -264,6 +264,12 @@ class FileManagerView : public FileManBaseView {
{}, {},
&bitmap_icon_new_file, &bitmap_icon_new_file,
Color::green()}; Color::green()};
NewButton button_open_notepad{
{0 * 8, 34 * 8, 4 * 8, 32},
{},
&bitmap_icon_notepad,
Color::orange()};
}; };
} /* namespace ui */ } /* namespace ui */

View File

@ -268,13 +268,18 @@ TextEditorView::TextEditorView(NavigationView& nav)
set_focusable(true); set_focusable(true);
button_open.on_select = [this](Button&) { button_open.on_select = [this](Button&) {
auto open_view = nav_.push<FileLoadView>(".TXT"); auto open_view = nav_.push<FileLoadView>("");
open_view->on_changed = [this](std::filesystem::path path) { open_view->on_changed = [this](std::filesystem::path path) {
open_file(path); open_file(path);
}; };
}; };
} }
TextEditorView::TextEditorView(NavigationView& nav, const fs::path& path)
: TextEditorView(nav) {
open_file(path);
}
void TextEditorView::on_focus() { void TextEditorView::on_focus() {
refresh_ui(); refresh_ui();
button_open.focus(); button_open.focus();
@ -366,6 +371,20 @@ bool TextEditorView::apply_scrolling_constraints(int16_t delta_line, int16_t del
++new_line; ++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()) if (new_line < 0 || (uint32_t)new_line >= file_.line_count())
return false; return false;

View File

@ -110,6 +110,9 @@ class FileWrapper {
class TextEditorView : public View { class TextEditorView : public View {
public: public:
TextEditorView(NavigationView& nav); TextEditorView(NavigationView& nav);
TextEditorView(
NavigationView& nav,
const std::filesystem::path& path);
std::string title() const override { std::string title() const override {
return "Notepad"; return "Notepad";