From f24523c2f134de943c0438ab4913830a118d6602 Mon Sep 17 00:00:00 2001 From: Kyle Reed <3761006+kallanreed@users.noreply.github.com> Date: Fri, 28 Jul 2023 18:53:16 -0700 Subject: [PATCH] Add button to prompt rename with a timestamp. (#1315) --- firmware/application/apps/ui_fileman.cpp | 22 ++++++++++++++++++---- firmware/application/apps/ui_fileman.hpp | 8 +++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 7d8b3ad6..029fc895 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -403,11 +403,17 @@ void FileManagerView::refresh_widgets(const bool v) { set_dirty(); } -void FileManagerView::on_rename() { +void FileManagerView::on_rename(std::string_view hint) { auto& entry = get_selected_entry(); - name_buffer = entry.path.filename().string(); - uint32_t cursor_pos = (uint32_t)name_buffer.length(); + // Append the hint to the filename stem as a rename suggestion. + name_buffer = entry.path.stem().string(); + if (!hint.empty()) + name_buffer += "_" + std::string{hint}; + name_buffer += entry.path.extension().string(); + + // Set the rename cursor to before the extension to make renaming simpler. + uint32_t cursor_pos = (uint32_t)name_buffer.length(); if (auto pos = name_buffer.find_last_of("."); pos != name_buffer.npos && !entry.is_directory) cursor_pos = pos; @@ -545,6 +551,7 @@ FileManagerView::FileManagerView( &button_new_dir, &button_new_file, &button_open_notepad, + &button_rename_timestamp, }); menu_view.on_highlight = [this]() { @@ -568,7 +575,7 @@ FileManagerView::FileManagerView( button_rename.on_select = [this]() { if (selected_is_valid()) - on_rename(); + on_rename(""); }; button_delete.on_select = [this]() { @@ -614,6 +621,13 @@ FileManagerView::FileManagerView( } else nav_.display_modal("Open in Notepad", "Can't open that in Notepad."); }; + + button_rename_timestamp.on_select = [this]() { + if (selected_is_valid() && !get_selected_entry().is_directory) { + on_rename(::truncate(to_string_timestamp(rtc_time::now()), 8)); + } else + nav_.display_modal("Timestamp Rename", "Can't rename that."); + }; } } // namespace ui diff --git a/firmware/application/apps/ui_fileman.hpp b/firmware/application/apps/ui_fileman.hpp index 13bd43b0..3eadd749 100644 --- a/firmware/application/apps/ui_fileman.hpp +++ b/firmware/application/apps/ui_fileman.hpp @@ -207,7 +207,7 @@ class FileManagerView : public FileManBaseView { ClipboardMode clipboard_mode{ClipboardMode::None}; void refresh_widgets(const bool v); - void on_rename(); + void on_rename(std::string_view hint); void on_delete(); void on_paste(); void on_new_dir(); @@ -272,6 +272,12 @@ class FileManagerView : public FileManBaseView { {}, &bitmap_icon_notepad, Color::orange()}; + + NewButton button_rename_timestamp{ + {4 * 8, 34 * 8, 4 * 8, 32}, + {}, + &bitmap_icon_options_datetime, + Color::orange()}; }; } /* namespace ui */