mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-13 05:11:26 -05:00
Add button to prompt rename with a timestamp. (#1315)
This commit is contained in:
parent
e7c5a862da
commit
f24523c2f1
@ -403,11 +403,17 @@ void FileManagerView::refresh_widgets(const bool v) {
|
|||||||
set_dirty();
|
set_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManagerView::on_rename() {
|
void FileManagerView::on_rename(std::string_view hint) {
|
||||||
auto& entry = get_selected_entry();
|
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(".");
|
if (auto pos = name_buffer.find_last_of(".");
|
||||||
pos != name_buffer.npos && !entry.is_directory)
|
pos != name_buffer.npos && !entry.is_directory)
|
||||||
cursor_pos = pos;
|
cursor_pos = pos;
|
||||||
@ -545,6 +551,7 @@ FileManagerView::FileManagerView(
|
|||||||
&button_new_dir,
|
&button_new_dir,
|
||||||
&button_new_file,
|
&button_new_file,
|
||||||
&button_open_notepad,
|
&button_open_notepad,
|
||||||
|
&button_rename_timestamp,
|
||||||
});
|
});
|
||||||
|
|
||||||
menu_view.on_highlight = [this]() {
|
menu_view.on_highlight = [this]() {
|
||||||
@ -568,7 +575,7 @@ FileManagerView::FileManagerView(
|
|||||||
|
|
||||||
button_rename.on_select = [this]() {
|
button_rename.on_select = [this]() {
|
||||||
if (selected_is_valid())
|
if (selected_is_valid())
|
||||||
on_rename();
|
on_rename("");
|
||||||
};
|
};
|
||||||
|
|
||||||
button_delete.on_select = [this]() {
|
button_delete.on_select = [this]() {
|
||||||
@ -614,6 +621,13 @@ FileManagerView::FileManagerView(
|
|||||||
} else
|
} else
|
||||||
nav_.display_modal("Open in Notepad", "Can't open that in Notepad.");
|
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
|
} // namespace ui
|
||||||
|
@ -207,7 +207,7 @@ class FileManagerView : public FileManBaseView {
|
|||||||
ClipboardMode clipboard_mode{ClipboardMode::None};
|
ClipboardMode clipboard_mode{ClipboardMode::None};
|
||||||
|
|
||||||
void refresh_widgets(const bool v);
|
void refresh_widgets(const bool v);
|
||||||
void on_rename();
|
void on_rename(std::string_view hint);
|
||||||
void on_delete();
|
void on_delete();
|
||||||
void on_paste();
|
void on_paste();
|
||||||
void on_new_dir();
|
void on_new_dir();
|
||||||
@ -272,6 +272,12 @@ class FileManagerView : public FileManBaseView {
|
|||||||
{},
|
{},
|
||||||
&bitmap_icon_notepad,
|
&bitmap_icon_notepad,
|
||||||
Color::orange()};
|
Color::orange()};
|
||||||
|
|
||||||
|
NewButton button_rename_timestamp{
|
||||||
|
{4 * 8, 34 * 8, 4 * 8, 32},
|
||||||
|
{},
|
||||||
|
&bitmap_icon_options_datetime,
|
||||||
|
Color::orange()};
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user