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 "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<TextEditorView>(path);
} else
nav_.display_modal("Open in Notepad", "Can't open that in Notepad.");
};
}
} // namespace ui

View File

@ -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 */

View File

@ -268,13 +268,18 @@ TextEditorView::TextEditorView(NavigationView& nav)
set_focusable(true);
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_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;

View File

@ -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";