2017-09-19 15:14:56 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2017 Furrtek
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2023-05-02 23:49:41 -04:00
|
|
|
/* TODO:
|
|
|
|
* - Paging menu items
|
2023-05-02 12:38:08 -04:00
|
|
|
*/
|
|
|
|
|
2023-05-01 01:42:28 -04:00
|
|
|
#include <algorithm>
|
2017-09-19 15:14:56 -04:00
|
|
|
#include "ui_fileman.hpp"
|
2023-06-28 13:02:06 -04:00
|
|
|
#include "ui_playlist.hpp"
|
2023-06-03 22:26:39 -04:00
|
|
|
#include "ui_ss_viewer.hpp"
|
2024-04-23 23:18:12 -04:00
|
|
|
#include "ui_bmp_file_viewer.hpp"
|
2023-05-23 00:40:03 -04:00
|
|
|
#include "ui_text_editor.hpp"
|
2023-10-08 15:57:59 -04:00
|
|
|
#include "ui_iq_trim.hpp"
|
2017-09-19 15:14:56 -04:00
|
|
|
#include "string_format.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "event_m0.hpp"
|
2024-04-23 23:18:12 -04:00
|
|
|
#include "file_path.hpp"
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
using namespace portapack;
|
2023-05-02 12:38:08 -04:00
|
|
|
namespace fs = std::filesystem;
|
2017-09-19 15:14:56 -04:00
|
|
|
|
2023-06-28 13:02:06 -04:00
|
|
|
namespace ui {
|
|
|
|
static const fs::path txt_ext{u".TXT"};
|
|
|
|
static const fs::path ppl_ext{u".PPL"};
|
2023-07-22 03:20:56 -04:00
|
|
|
static const fs::path c8_ext{u".C8"};
|
2023-06-28 13:02:06 -04:00
|
|
|
static const fs::path c16_ext{u".C16"};
|
2023-07-22 03:20:56 -04:00
|
|
|
static const fs::path cxx_ext{u".C*"};
|
2023-06-28 13:02:06 -04:00
|
|
|
static const fs::path png_ext{u".PNG"};
|
2023-07-05 16:45:43 -04:00
|
|
|
static const fs::path bmp_ext{u".BMP"};
|
2023-09-18 17:22:46 -04:00
|
|
|
static const fs::path rem_ext{u".REM"};
|
2023-06-28 13:02:06 -04:00
|
|
|
} // namespace ui
|
|
|
|
|
2023-05-01 01:42:28 -04:00
|
|
|
namespace {
|
|
|
|
using namespace ui;
|
|
|
|
|
2023-05-02 12:38:08 -04:00
|
|
|
bool is_hidden_file(const fs::path& path) {
|
2023-05-18 16:16:05 -04:00
|
|
|
return !path.empty() && path.native()[0] == u'.';
|
2023-05-01 01:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gets a truncated name from a path for display.
|
2023-05-02 12:38:08 -04:00
|
|
|
std::string truncate(const fs::path& path, size_t max_length) {
|
2023-05-18 16:16:05 -04:00
|
|
|
return ::truncate(path.string(), max_length);
|
2023-05-01 01:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inserts the entry into the entry list sorted directories first then by file name.
|
2024-04-02 11:02:02 -04:00
|
|
|
void insert_sorted(std::list<fileman_entry>& entries, fileman_entry&& entry) {
|
2023-06-03 22:26:39 -04:00
|
|
|
auto it = std::lower_bound(
|
|
|
|
std::begin(entries), std::end(entries), entry,
|
|
|
|
[](const fileman_entry& lhs, const fileman_entry& rhs) {
|
|
|
|
if (lhs.is_directory && !rhs.is_directory)
|
|
|
|
return true;
|
|
|
|
else if (!lhs.is_directory && rhs.is_directory)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return lhs.path < rhs.path;
|
|
|
|
});
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
entries.insert(it, std::move(entry));
|
2023-05-01 01:42:28 -04:00
|
|
|
}
|
|
|
|
|
2023-05-01 12:25:32 -04:00
|
|
|
// Returns the partner file path or an empty path if no partner is found.
|
2023-05-02 12:38:08 -04:00
|
|
|
fs::path get_partner_file(fs::path path) {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (fs::is_directory(path))
|
|
|
|
return {};
|
|
|
|
auto ext = path.extension();
|
|
|
|
|
2023-07-22 03:20:56 -04:00
|
|
|
if (is_cxx_capture_file(path))
|
|
|
|
path.replace_extension(txt_ext);
|
|
|
|
else if (path_iequal(ext, txt_ext)) {
|
|
|
|
path.replace_extension(c8_ext);
|
|
|
|
if (!fs::file_exists(path))
|
|
|
|
path.replace_extension(c16_ext);
|
|
|
|
} else
|
2023-05-18 16:16:05 -04:00
|
|
|
return {};
|
|
|
|
|
|
|
|
return fs::file_exists(path) && !fs::is_directory(path) ? path : fs::path{};
|
2023-05-01 12:25:32 -04:00
|
|
|
}
|
|
|
|
|
2023-05-02 12:38:08 -04:00
|
|
|
// Modal prompt to update the partner file if it exists.
|
|
|
|
// Runs continuation on_partner_action to update the partner file.
|
|
|
|
// Returns true is a partner is found, otherwise false.
|
2023-05-03 16:13:15 -04:00
|
|
|
// Path must be the full path to the file.
|
2023-05-02 12:38:08 -04:00
|
|
|
bool partner_file_prompt(
|
2023-05-18 16:16:05 -04:00
|
|
|
NavigationView& nav,
|
|
|
|
const fs::path& path,
|
|
|
|
std::string action_name,
|
|
|
|
std::function<void(const fs::path&, bool)> on_partner_action) {
|
|
|
|
auto partner = get_partner_file(path);
|
|
|
|
|
|
|
|
if (partner.empty())
|
|
|
|
return false;
|
|
|
|
|
2023-09-27 15:03:02 -04:00
|
|
|
// Display the continuation UI once the current has been popped.
|
|
|
|
nav.set_on_pop([&nav, partner, action_name, on_partner_action] {
|
|
|
|
nav.display_modal(
|
|
|
|
"Partner File",
|
|
|
|
partner.filename().string() + "\n" + action_name + " this file too?",
|
|
|
|
YESNO,
|
|
|
|
[&nav, partner, on_partner_action](bool choice) {
|
|
|
|
if (on_partner_action)
|
|
|
|
on_partner_action(partner, choice);
|
|
|
|
});
|
|
|
|
});
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
return true;
|
2023-05-01 12:25:32 -04:00
|
|
|
}
|
|
|
|
|
2023-05-11 16:46:38 -04:00
|
|
|
fs::path get_unique_filename(const fs::path& path, const fs::path& file) {
|
2023-05-18 16:16:05 -04:00
|
|
|
auto stem = file.stem();
|
|
|
|
auto ext = file.extension();
|
|
|
|
auto serial = 1;
|
|
|
|
fs::path new_path = file;
|
2023-05-11 16:46:38 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
while (fs::file_exists(path / new_path)) {
|
|
|
|
new_path = stem;
|
|
|
|
new_path += fs::path{u"_"};
|
|
|
|
new_path += to_string_dec_int(serial++);
|
|
|
|
new_path += ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_path;
|
2023-05-01 01:42:28 -04:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
} // namespace
|
|
|
|
|
2017-09-19 15:14:56 -04:00
|
|
|
namespace ui {
|
|
|
|
|
2023-05-03 16:13:15 -04:00
|
|
|
/* FileManBaseView ***********************************************************/
|
|
|
|
|
2024-04-02 14:19:28 -04:00
|
|
|
void FileManBaseView::load_directory_contents_unordered(const fs::path& dir_path, size_t file_cnt) {
|
2023-05-18 16:16:05 -04:00
|
|
|
current_path = dir_path;
|
|
|
|
entry_list.clear();
|
2024-04-02 11:02:02 -04:00
|
|
|
menu_view.clear();
|
2023-05-18 16:16:05 -04:00
|
|
|
auto filtering = !extension_filter.empty();
|
2023-07-22 03:20:56 -04:00
|
|
|
bool cxx_file = path_iequal(cxx_ext, extension_filter);
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
text_current.set(dir_path.empty() ? "(sd root)" : truncate(dir_path, 24));
|
|
|
|
|
2024-04-02 14:19:28 -04:00
|
|
|
nb_pages = 1 + (file_cnt / items_per_page);
|
|
|
|
size_t start = pagination * items_per_page;
|
|
|
|
size_t stop = start + items_per_page;
|
|
|
|
if (file_cnt < stop) stop = file_cnt;
|
|
|
|
if (start > file_cnt) start = 0; // shouldn't hapen but check against it won't hurt
|
|
|
|
|
|
|
|
size_t curr = 0;
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
for (const auto& entry : fs::directory_iterator(dir_path, u"*")) {
|
2024-04-02 14:19:28 -04:00
|
|
|
if (entry_list.size() >= items_per_page) {
|
|
|
|
break;
|
|
|
|
}
|
2023-05-18 16:16:05 -04:00
|
|
|
// Hide files starting with '.' (hidden / tmp).
|
2024-04-02 14:19:28 -04:00
|
|
|
if (!show_hidden_files && is_hidden_file(entry.path()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fs::is_regular_file(entry.status())) {
|
|
|
|
if (!filtering || path_iequal(entry.path().extension(), extension_filter) || (cxx_file && is_cxx_capture_file(entry.path()))) {
|
|
|
|
curr++;
|
|
|
|
if (curr >= start) insert_sorted(entry_list, {entry.path().string(), (uint32_t)entry.size(), false});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (fs::is_directory(entry.status())) {
|
|
|
|
curr++;
|
|
|
|
if (curr >= start) insert_sorted(entry_list, {entry.path().string(), 0, true});
|
2024-04-02 11:02:02 -04:00
|
|
|
}
|
2024-04-02 14:19:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add "parent" directory if not at the root.
|
|
|
|
if (!dir_path.empty() && pagination == 0)
|
|
|
|
entry_list.insert(entry_list.begin(), {parent_dir_path.string(), 0, true});
|
|
|
|
|
|
|
|
// add next page
|
|
|
|
if (file_cnt > start + items_per_page) {
|
|
|
|
entry_list.push_back({str_next, (uint32_t)pagination + 1, true});
|
|
|
|
}
|
|
|
|
|
|
|
|
// add prev page
|
|
|
|
if (pagination > 0) {
|
|
|
|
entry_list.insert(entry_list.begin(), {str_back, (uint32_t)pagination - 1, true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int FileManBaseView::file_count_filtered(const fs::path& directory) {
|
|
|
|
int count{0};
|
|
|
|
auto filtering = !extension_filter.empty();
|
|
|
|
bool cxx_file = path_iequal(cxx_ext, extension_filter);
|
|
|
|
|
|
|
|
for (auto& entry : std::filesystem::directory_iterator(directory, (const TCHAR*)u"*")) {
|
|
|
|
if (fs::is_regular_file(entry.status())) {
|
|
|
|
if (!filtering || path_iequal(entry.path().extension(), extension_filter) || (cxx_file && is_cxx_capture_file(entry.path())))
|
|
|
|
++count;
|
|
|
|
} else
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileManBaseView::load_directory_contents(const fs::path& dir_path) {
|
|
|
|
size_t file_cnt = file_count_filtered(dir_path);
|
|
|
|
if (file_cnt >= max_items_loaded) {
|
|
|
|
load_directory_contents_unordered(dir_path, file_cnt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
current_path = dir_path;
|
|
|
|
entry_list.clear();
|
|
|
|
menu_view.clear();
|
|
|
|
auto filtering = !extension_filter.empty();
|
|
|
|
bool cxx_file = path_iequal(cxx_ext, extension_filter);
|
|
|
|
|
|
|
|
text_current.set(dir_path.empty() ? "(sd root)" : truncate(dir_path, 24));
|
|
|
|
|
|
|
|
for (const auto& entry : fs::directory_iterator(dir_path, u"*")) {
|
|
|
|
// Hide files starting with '.' (hidden / tmp).
|
2023-11-06 17:33:19 -05:00
|
|
|
if (!show_hidden_files && is_hidden_file(entry.path()))
|
2023-05-18 16:16:05 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fs::is_regular_file(entry.status())) {
|
2023-07-22 03:20:56 -04:00
|
|
|
if (!filtering || path_iequal(entry.path().extension(), extension_filter) || (cxx_file && is_cxx_capture_file(entry.path())))
|
2024-04-02 11:02:02 -04:00
|
|
|
insert_sorted(entry_list, {entry.path().string(), (uint32_t)entry.size(), false});
|
2023-05-18 16:16:05 -04:00
|
|
|
} else if (fs::is_directory(entry.status())) {
|
2024-04-02 11:02:02 -04:00
|
|
|
insert_sorted(entry_list, {entry.path().string(), 0, true});
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-02 11:02:02 -04:00
|
|
|
// paginating
|
|
|
|
auto list_size = entry_list.size();
|
|
|
|
nb_pages = 1 + (list_size / items_per_page);
|
|
|
|
size_t start = pagination * items_per_page;
|
|
|
|
size_t stop = start + items_per_page;
|
|
|
|
if (list_size > start) {
|
|
|
|
if (list_size < stop)
|
|
|
|
stop = list_size;
|
|
|
|
entry_list.erase(std::next(entry_list.begin(), stop), entry_list.end());
|
|
|
|
entry_list.erase(entry_list.begin(), std::next(entry_list.begin(), start));
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
// Add "parent" directory if not at the root.
|
2024-04-02 11:02:02 -04:00
|
|
|
if (!dir_path.empty() && pagination == 0)
|
|
|
|
entry_list.insert(entry_list.begin(), {parent_dir_path.string(), 0, true});
|
|
|
|
|
|
|
|
// add next page
|
|
|
|
if (list_size > start + items_per_page) {
|
|
|
|
entry_list.push_back({str_next, (uint32_t)pagination + 1, true});
|
|
|
|
}
|
|
|
|
|
|
|
|
// add prev page
|
|
|
|
if (pagination > 0) {
|
|
|
|
entry_list.insert(entry_list.begin(), {str_back, (uint32_t)pagination - 1, true});
|
|
|
|
}
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-02 12:38:08 -04:00
|
|
|
fs::path FileManBaseView::get_selected_full_path() const {
|
2024-04-02 11:02:02 -04:00
|
|
|
if (get_selected_entry().path == parent_dir_path.string())
|
2023-05-18 16:16:05 -04:00
|
|
|
return current_path.parent_path();
|
2023-05-01 01:42:28 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
return current_path / get_selected_entry().path;
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-01 01:42:28 -04:00
|
|
|
const fileman_entry& FileManBaseView::get_selected_entry() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
// TODO: return reference to an "empty" entry on OOB?
|
2024-04-02 11:02:02 -04:00
|
|
|
auto it = entry_list.begin();
|
|
|
|
if (menu_view.highlighted_index() >= 1) std::advance(it, menu_view.highlighted_index());
|
|
|
|
return *it;
|
|
|
|
// return entry_list[menu_view.highlighted_index()];
|
2019-05-23 00:20:01 -04:00
|
|
|
}
|
|
|
|
|
2017-09-19 15:14:56 -04:00
|
|
|
FileManBaseView::FileManBaseView(
|
2023-05-18 16:16:05 -04:00
|
|
|
NavigationView& nav,
|
|
|
|
std::string filter)
|
|
|
|
: nav_{nav},
|
|
|
|
extension_filter{filter} {
|
|
|
|
add_children({&labels,
|
|
|
|
&text_current,
|
|
|
|
&button_exit});
|
|
|
|
|
2023-09-27 15:03:02 -04:00
|
|
|
button_exit.on_select = [this](Button&) {
|
|
|
|
nav_.pop();
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!sdcIsCardInserted(&SDCD1)) {
|
|
|
|
empty_ = EmptyReason::NoSDC;
|
|
|
|
text_current.set("NO SD CARD!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
load_directory_contents(current_path);
|
|
|
|
|
|
|
|
if (!entry_list.size()) {
|
|
|
|
empty_ = EmptyReason::NoFiles;
|
|
|
|
text_current.set("EMPTY SD CARD!");
|
|
|
|
} else {
|
|
|
|
menu_view.on_left = [this]() {
|
|
|
|
pop_dir();
|
|
|
|
};
|
|
|
|
}
|
2020-07-04 23:33:53 -04:00
|
|
|
}
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
void FileManBaseView::focus() {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (empty_ != EmptyReason::NotEmpty) {
|
|
|
|
button_exit.focus();
|
|
|
|
} else {
|
|
|
|
menu_view.focus();
|
|
|
|
}
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-03 16:13:15 -04:00
|
|
|
void FileManBaseView::push_dir(const fs::path& path) {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (path == parent_dir_path) {
|
|
|
|
pop_dir();
|
|
|
|
} else {
|
|
|
|
current_path /= path;
|
|
|
|
saved_index_stack.push_back(menu_view.highlighted_index());
|
|
|
|
menu_view.set_highlighted(0);
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
2023-05-03 16:13:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileManBaseView::pop_dir() {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (saved_index_stack.empty())
|
|
|
|
return;
|
2023-05-03 16:13:15 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
current_path = current_path.parent_path();
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2023-05-18 16:16:05 -04:00
|
|
|
menu_view.set_highlighted(saved_index_stack.back());
|
|
|
|
saved_index_stack.pop_back();
|
2023-05-03 16:13:15 -04:00
|
|
|
}
|
|
|
|
|
2024-04-02 11:02:02 -04:00
|
|
|
std::string get_extension(std::string t) {
|
|
|
|
const auto index = t.find_last_of(u'.');
|
|
|
|
if (index == t.npos) {
|
|
|
|
return {};
|
|
|
|
} else {
|
|
|
|
return t.substr(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string get_stem(std::string t) {
|
|
|
|
const auto index = t.find_last_of(u'.');
|
|
|
|
if (index == t.npos) {
|
|
|
|
return t;
|
|
|
|
} else {
|
|
|
|
return t.substr(0, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string get_filename(std::string _s) {
|
|
|
|
const auto index = _s.find_last_of("/");
|
|
|
|
if (index == _s.npos) {
|
|
|
|
return _s;
|
|
|
|
} else {
|
|
|
|
return _s.substr(index + 1);
|
|
|
|
}
|
|
|
|
}
|
2017-09-19 15:14:56 -04:00
|
|
|
void FileManBaseView::refresh_list() {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (on_refresh_widgets)
|
|
|
|
on_refresh_widgets(false);
|
|
|
|
|
2024-04-02 11:02:02 -04:00
|
|
|
prev_highlight = menu_view.highlighted_index();
|
2023-05-18 16:16:05 -04:00
|
|
|
menu_view.clear();
|
|
|
|
|
|
|
|
for (const auto& entry : entry_list) {
|
2024-04-02 11:02:02 -04:00
|
|
|
auto entry_name = std::string{entry.path.length() <= 20 ? entry.path : entry.path.substr(0, 20)};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
if (entry.is_directory) {
|
2024-04-02 11:02:02 -04:00
|
|
|
std::string size_str{};
|
|
|
|
if (entry.path == str_next || entry.path == str_back) {
|
|
|
|
size_str = to_string_dec_uint(1 + entry.size) + "/" + to_string_dec_uint(nb_pages); // show computed number of pages
|
|
|
|
} else {
|
|
|
|
size_str = (entry.path == parent_dir_path.string()) ? "" : to_string_dec_uint(file_count(current_path / entry.path));
|
|
|
|
}
|
2023-08-16 04:00:46 -04:00
|
|
|
|
2023-05-19 16:39:35 -04:00
|
|
|
menu_view.add_item(
|
2024-04-02 11:02:02 -04:00
|
|
|
{entry_name.substr(0, max_filename_length) + std::string(21 - entry_name.length(), ' ') + size_str,
|
2024-05-27 15:02:52 -04:00
|
|
|
Theme::getInstance()->fg_yellow->foreground,
|
2023-05-19 16:39:35 -04:00
|
|
|
&bitmap_icon_dir,
|
|
|
|
[this](KeyEvent key) {
|
|
|
|
if (on_select_entry)
|
|
|
|
on_select_entry(key);
|
|
|
|
}});
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
} else {
|
2024-04-02 11:02:02 -04:00
|
|
|
const auto& assoc = get_assoc(get_extension(entry.path));
|
2023-05-19 16:39:35 -04:00
|
|
|
auto size_str = to_string_file_size(entry.size);
|
|
|
|
|
|
|
|
menu_view.add_item(
|
2024-04-02 11:02:02 -04:00
|
|
|
{entry_name.substr(0, max_filename_length) + std::string(21 - entry_name.length(), ' ') + size_str,
|
2023-05-19 16:39:35 -04:00
|
|
|
assoc.color,
|
|
|
|
assoc.icon,
|
|
|
|
[this](KeyEvent key) {
|
|
|
|
if (on_select_entry)
|
|
|
|
on_select_entry(key);
|
|
|
|
}});
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_view.set_highlighted(prev_highlight);
|
2023-05-01 01:42:28 -04:00
|
|
|
}
|
|
|
|
|
2024-04-02 11:02:02 -04:00
|
|
|
void FileManBaseView::reload_current(bool reset_pagination) {
|
|
|
|
if (reset_pagination) pagination = 0;
|
2023-05-18 16:16:05 -04:00
|
|
|
load_directory_contents(current_path);
|
|
|
|
refresh_list();
|
2023-05-02 12:38:08 -04:00
|
|
|
}
|
|
|
|
|
2023-05-01 01:42:28 -04:00
|
|
|
const FileManBaseView::file_assoc_t& FileManBaseView::get_assoc(
|
2023-05-18 16:16:05 -04:00
|
|
|
const fs::path& ext) const {
|
|
|
|
size_t index = 0;
|
2023-05-01 01:42:28 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
for (; index < file_types.size() - 1; ++index)
|
2023-06-28 13:02:06 -04:00
|
|
|
if (path_iequal(ext, file_types[index].extension))
|
2023-05-18 16:16:05 -04:00
|
|
|
return file_types[index];
|
2023-05-01 01:42:28 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
// Default to last entry in the list.
|
|
|
|
return file_types[index];
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-03 16:13:15 -04:00
|
|
|
/* FileLoadView **************************************************************/
|
|
|
|
|
2017-09-19 15:14:56 -04:00
|
|
|
FileLoadView::FileLoadView(
|
2023-05-18 16:16:05 -04:00
|
|
|
NavigationView& nav,
|
|
|
|
std::string filter)
|
|
|
|
: FileManBaseView(nav, filter) {
|
|
|
|
on_refresh_widgets = [this](bool v) {
|
|
|
|
refresh_widgets(v);
|
|
|
|
};
|
|
|
|
|
|
|
|
add_children({&menu_view});
|
|
|
|
|
|
|
|
// Resize menu view to fill screen
|
|
|
|
menu_view.set_parent_rect({0, 3 * 8, 240, 29 * 8});
|
|
|
|
|
|
|
|
refresh_list();
|
|
|
|
|
|
|
|
on_select_entry = [this](KeyEvent) {
|
|
|
|
if (get_selected_entry().is_directory) {
|
2024-04-02 11:02:02 -04:00
|
|
|
if (get_selected_entry().path == str_full) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (get_selected_entry().path == str_back) {
|
|
|
|
pagination--;
|
|
|
|
menu_view.set_highlighted(0);
|
|
|
|
reload_current(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (get_selected_entry().path == str_next) {
|
|
|
|
pagination++;
|
|
|
|
menu_view.set_highlighted(0);
|
|
|
|
reload_current(false);
|
|
|
|
return;
|
|
|
|
}
|
2023-05-18 16:16:05 -04:00
|
|
|
push_dir(get_selected_entry().path);
|
|
|
|
} else {
|
|
|
|
if (on_changed)
|
|
|
|
on_changed(get_selected_full_path());
|
2023-09-27 15:03:02 -04:00
|
|
|
nav_.pop();
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
};
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-10 12:51:09 -04:00
|
|
|
void FileLoadView::refresh_widgets(const bool) {
|
2023-05-18 16:16:05 -04:00
|
|
|
set_dirty();
|
2023-05-10 12:51:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FileSaveView **************************************************************/
|
|
|
|
/*
|
|
|
|
FileSaveView::FileSaveView(
|
2023-05-18 16:16:05 -04:00
|
|
|
NavigationView& nav,
|
|
|
|
const fs::path& path,
|
|
|
|
const fs::path& file
|
2023-05-10 12:51:09 -04:00
|
|
|
) : nav_{ nav },
|
2023-05-18 16:16:05 -04:00
|
|
|
path_{ path },
|
|
|
|
file_{ file }
|
2023-05-10 12:51:09 -04:00
|
|
|
{
|
2023-05-18 16:16:05 -04:00
|
|
|
add_children({
|
|
|
|
&text_path,
|
|
|
|
&button_edit_path,
|
|
|
|
&text_name,
|
|
|
|
&button_edit_name,
|
|
|
|
&button_save,
|
|
|
|
&button_cancel,
|
|
|
|
});
|
|
|
|
|
|
|
|
button_edit_path.on_select = [this](Button&) {
|
|
|
|
buffer_ = path_.string();
|
|
|
|
text_prompt(nav_, buffer_, max_filename_length,
|
|
|
|
[this](std::string&) {
|
|
|
|
path_ = buffer_;
|
|
|
|
refresh_widgets();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
button_edit_name.on_select = [this](Button&) {
|
|
|
|
buffer_ = file_.string();
|
|
|
|
text_prompt(nav_, buffer_, max_filename_length,
|
|
|
|
[this](std::string&) {
|
|
|
|
file_ = buffer_;
|
|
|
|
refresh_widgets();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
button_save.on_select = [this](Button&) {
|
|
|
|
if (on_save)
|
|
|
|
on_save(path_ / file_);
|
|
|
|
else
|
|
|
|
nav_.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
button_cancel.on_select = [this](Button&) {
|
|
|
|
nav_.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
refresh_widgets();
|
2023-05-10 12:51:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSaveView::refresh_widgets() {
|
2023-05-18 16:16:05 -04:00
|
|
|
text_path.set(truncate(path_, 30));
|
|
|
|
text_name.set(truncate(file_, 30));
|
|
|
|
set_dirty();
|
2023-05-10 12:51:09 -04:00
|
|
|
}
|
|
|
|
*/
|
2023-05-03 16:13:15 -04:00
|
|
|
/* FileManagerView ***********************************************************/
|
|
|
|
|
2023-06-03 22:26:39 -04:00
|
|
|
void FileManagerView::refresh_widgets(const bool v) {
|
|
|
|
button_rename.hidden(v);
|
|
|
|
button_delete.hidden(v);
|
2024-03-13 13:06:14 -04:00
|
|
|
button_clean.hidden(v);
|
2023-06-03 22:26:39 -04:00
|
|
|
button_cut.hidden(v);
|
|
|
|
button_copy.hidden(v);
|
|
|
|
button_paste.hidden(v);
|
|
|
|
button_new_dir.hidden(v);
|
|
|
|
button_new_file.hidden(v);
|
|
|
|
|
|
|
|
set_dirty();
|
|
|
|
}
|
|
|
|
|
2023-07-28 21:53:16 -04:00
|
|
|
void FileManagerView::on_rename(std::string_view hint) {
|
2023-05-18 16:16:05 -04:00
|
|
|
auto& entry = get_selected_entry();
|
|
|
|
|
2023-07-28 21:53:16 -04:00
|
|
|
// Append the hint to the filename stem as a rename suggestion.
|
2024-04-02 11:02:02 -04:00
|
|
|
name_buffer = get_stem(entry.path);
|
2023-07-28 21:53:16 -04:00
|
|
|
if (!hint.empty())
|
|
|
|
name_buffer += "_" + std::string{hint};
|
2024-04-02 11:02:02 -04:00
|
|
|
name_buffer += get_extension(entry.path);
|
2023-07-28 21:53:16 -04:00
|
|
|
|
|
|
|
// Set the rename cursor to before the extension to make renaming simpler.
|
|
|
|
uint32_t cursor_pos = (uint32_t)name_buffer.length();
|
2023-05-18 16:16:05 -04:00
|
|
|
if (auto pos = name_buffer.find_last_of(".");
|
|
|
|
pos != name_buffer.npos && !entry.is_directory)
|
|
|
|
cursor_pos = pos;
|
|
|
|
|
2023-06-03 22:26:39 -04:00
|
|
|
text_prompt(
|
|
|
|
nav_, name_buffer, cursor_pos, max_filename_length,
|
|
|
|
[this](std::string& renamed) {
|
|
|
|
auto renamed_path = fs::path{renamed};
|
|
|
|
rename_file(get_selected_full_path(), current_path / renamed_path);
|
|
|
|
|
|
|
|
auto has_partner = partner_file_prompt(
|
|
|
|
nav_, get_selected_full_path(), "Rename",
|
|
|
|
[this, renamed_path](const fs::path& partner, bool should_rename) mutable {
|
|
|
|
if (should_rename) {
|
|
|
|
auto new_name = renamed_path.replace_extension(partner.extension());
|
|
|
|
rename_file(partner, current_path / new_name);
|
|
|
|
}
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(false);
|
2023-05-18 16:16:05 -04:00
|
|
|
});
|
2023-06-03 22:26:39 -04:00
|
|
|
|
|
|
|
if (!has_partner)
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(false);
|
2023-06-03 22:26:39 -04:00
|
|
|
});
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-01 12:25:32 -04:00
|
|
|
void FileManagerView::on_delete() {
|
2023-07-30 16:46:59 -04:00
|
|
|
if (is_directory(get_selected_full_path()) && !is_empty_directory(get_selected_full_path())) {
|
2024-03-13 17:42:40 -04:00
|
|
|
nav_.display_modal("Delete", " Folder is not empty;\n Use \"Clean\" button to\n empty it first.");
|
2023-07-30 16:46:59 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-02 11:02:02 -04:00
|
|
|
auto name = get_filename(get_selected_entry().path);
|
2023-06-03 22:26:39 -04:00
|
|
|
nav_.push<ModalMessageView>(
|
|
|
|
"Delete", "Delete " + name + "\nAre you sure?", YESNO,
|
|
|
|
[this](bool choice) {
|
|
|
|
if (choice) {
|
|
|
|
delete_file(get_selected_full_path());
|
|
|
|
|
|
|
|
auto has_partner = partner_file_prompt(
|
|
|
|
nav_, get_selected_full_path(), "Delete",
|
|
|
|
[this](const fs::path& partner, bool should_delete) {
|
|
|
|
if (should_delete)
|
|
|
|
delete_file(partner);
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2023-06-03 22:26:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!has_partner)
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2023-06-03 22:26:39 -04:00
|
|
|
}
|
|
|
|
});
|
2023-05-01 12:25:32 -04:00
|
|
|
}
|
2023-04-22 10:46:04 -04:00
|
|
|
|
2024-03-13 13:06:14 -04:00
|
|
|
void FileManagerView::on_clean() {
|
2024-03-13 17:42:40 -04:00
|
|
|
if (is_empty_directory(get_selected_full_path())) {
|
|
|
|
nav_.display_modal("Clean", "Folder is Empty;\nUse \"Delete\" button instead\nof \"Clean\" button to delete\nit.");
|
2024-03-13 13:06:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2024-03-13 17:42:40 -04:00
|
|
|
|
|
|
|
auto path_name = is_directory(get_selected_full_path()) ? get_selected_full_path() : get_selected_full_path().parent_path();
|
|
|
|
|
|
|
|
// selected either a single file (delete files in this directory) or a directory that is not empty (del sub files)
|
|
|
|
nav_.push<ModalMessageView>(
|
|
|
|
"Clean", " ALL FILES in this folder\n (excluding sub-folders)\n will be DELETED!\n\n Delete all files?", YESNO,
|
|
|
|
[this, path_name](bool choice) {
|
|
|
|
if (choice) {
|
|
|
|
std::vector<std::filesystem::path> file_list;
|
|
|
|
file_list = scan_root_files(path_name, u"*");
|
|
|
|
|
|
|
|
for (const auto& file_name : file_list) {
|
|
|
|
std::filesystem::path current_full_path = path_name / file_name;
|
|
|
|
delete_file(current_full_path);
|
|
|
|
}
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2024-03-13 17:42:40 -04:00
|
|
|
}
|
|
|
|
});
|
2024-03-13 13:06:14 -04:00
|
|
|
}
|
|
|
|
|
2023-05-01 12:25:32 -04:00
|
|
|
void FileManagerView::on_new_dir() {
|
2023-05-18 16:16:05 -04:00
|
|
|
name_buffer = "";
|
|
|
|
text_prompt(nav_, name_buffer, max_filename_length, [this](std::string& dir_name) {
|
|
|
|
make_new_directory(current_path / dir_name);
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2023-05-18 16:16:05 -04:00
|
|
|
});
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-10 12:51:09 -04:00
|
|
|
void FileManagerView::on_paste() {
|
2023-05-18 16:16:05 -04:00
|
|
|
// TODO: handle partner file. Need to fix nav stack first.
|
|
|
|
auto new_name = get_unique_filename(current_path, clipboard_path.filename());
|
|
|
|
fs::filesystem_error result;
|
|
|
|
|
|
|
|
if (clipboard_mode == ClipboardMode::Cut)
|
2024-03-29 05:44:37 -04:00
|
|
|
if ((current_path / clipboard_path.filename()) == clipboard_path)
|
|
|
|
result = FR_OK; // Skip paste to avoid renaming if path is unchanged
|
|
|
|
else
|
|
|
|
result = rename_file(clipboard_path, current_path / new_name);
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
else if (clipboard_mode == ClipboardMode::Copy)
|
|
|
|
result = copy_file(clipboard_path, current_path / new_name);
|
|
|
|
|
|
|
|
if (result.code() != FR_OK)
|
|
|
|
nav_.display_modal("Paste Failed", result.what());
|
|
|
|
|
|
|
|
clipboard_path = fs::path{};
|
|
|
|
clipboard_mode = ClipboardMode::None;
|
|
|
|
menu_view.focus();
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2023-05-10 12:51:09 -04:00
|
|
|
}
|
|
|
|
|
2023-06-03 22:26:39 -04:00
|
|
|
void FileManagerView::on_new_file() {
|
|
|
|
name_buffer = "";
|
|
|
|
text_prompt(nav_, name_buffer, max_filename_length, [this](std::string& file_name) {
|
|
|
|
make_new_file(current_path / file_name);
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(true);
|
2023-06-03 22:26:39 -04:00
|
|
|
});
|
2023-05-03 16:13:15 -04:00
|
|
|
}
|
|
|
|
|
2023-06-03 22:26:39 -04:00
|
|
|
bool FileManagerView::handle_file_open() {
|
|
|
|
if (!selected_is_valid())
|
|
|
|
return false;
|
2017-09-19 15:14:56 -04:00
|
|
|
|
2023-06-03 22:26:39 -04:00
|
|
|
auto path = get_selected_full_path();
|
|
|
|
auto ext = path.extension();
|
|
|
|
|
2023-06-28 13:02:06 -04:00
|
|
|
if (path_iequal(txt_ext, ext)) {
|
2023-06-03 22:26:39 -04:00
|
|
|
nav_.push<TextEditorView>(path);
|
|
|
|
return true;
|
2023-07-22 03:20:56 -04:00
|
|
|
} else if (is_cxx_capture_file(path) || path_iequal(ppl_ext, ext)) {
|
2023-06-28 13:02:06 -04:00
|
|
|
// TODO: Enough memory to push?
|
|
|
|
nav_.push<PlaylistView>(path);
|
|
|
|
return true;
|
|
|
|
} else if (path_iequal(png_ext, ext)) {
|
2023-06-03 22:26:39 -04:00
|
|
|
nav_.push<ScreenshotViewer>(path);
|
|
|
|
return true;
|
2023-07-05 16:45:43 -04:00
|
|
|
} else if (path_iequal(bmp_ext, ext)) {
|
2024-04-23 23:18:12 -04:00
|
|
|
if (path_iequal(current_path, u"/" + splash_dir)) {
|
|
|
|
nav_.push<SplashViewer>(path); // splash, so load that viewer
|
|
|
|
} else {
|
|
|
|
nav_.push<BMPFileViewer>(path); // any other bmp
|
|
|
|
}
|
|
|
|
|
2024-04-02 11:02:02 -04:00
|
|
|
reload_current(false);
|
2023-07-05 16:45:43 -04:00
|
|
|
return true;
|
2024-11-19 15:02:29 -05:00
|
|
|
}
|
|
|
|
/*else if (path_iequal(rem_ext, ext)) {
|
2023-09-18 17:22:46 -04:00
|
|
|
nav_.push<RemoteView>(path);
|
|
|
|
return true;
|
2024-11-19 15:02:29 -05:00
|
|
|
}*/
|
2023-06-03 22:26:39 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileManagerView::selected_is_valid() const {
|
|
|
|
return !entry_list.empty() &&
|
2024-04-02 11:02:02 -04:00
|
|
|
get_selected_entry().path != parent_dir_path.string();
|
2017-09-19 15:14:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
FileManagerView::FileManagerView(
|
|
|
|
NavigationView& nav)
|
|
|
|
: FileManBaseView(nav, "") {
|
|
|
|
// Don't bother with the UI in the case of no SDC.
|
|
|
|
if (empty_ == EmptyReason::NoSDC)
|
|
|
|
return;
|
|
|
|
|
|
|
|
on_refresh_widgets = [this](bool v) {
|
|
|
|
refresh_widgets(v);
|
|
|
|
};
|
|
|
|
|
2023-05-23 00:40:03 -04:00
|
|
|
add_children({
|
|
|
|
&menu_view,
|
|
|
|
&text_date,
|
|
|
|
&button_rename,
|
|
|
|
&button_delete,
|
2024-03-13 13:06:14 -04:00
|
|
|
&button_clean,
|
2023-05-23 00:40:03 -04:00
|
|
|
&button_cut,
|
|
|
|
&button_copy,
|
|
|
|
&button_paste,
|
|
|
|
&button_new_dir,
|
|
|
|
&button_new_file,
|
|
|
|
&button_open_notepad,
|
2023-07-28 21:53:16 -04:00
|
|
|
&button_rename_timestamp,
|
2023-10-08 15:57:59 -04:00
|
|
|
&button_open_iq_trim,
|
2023-11-06 17:33:19 -05:00
|
|
|
&button_show_hidden_files,
|
2023-05-23 00:40:03 -04:00
|
|
|
});
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
menu_view.on_highlight = [this]() {
|
2024-04-02 11:02:02 -04:00
|
|
|
if (menu_view.highlighted_index() >= max_items_loaded - 1) { // todo check this if correct
|
2024-05-27 15:02:52 -04:00
|
|
|
text_date.set_style(Theme::getInstance()->fg_red);
|
2023-08-16 04:00:46 -04:00
|
|
|
text_date.set("Too many files!");
|
|
|
|
} else {
|
2024-05-27 15:02:52 -04:00
|
|
|
text_date.set_style(Theme::getInstance()->fg_medium);
|
2024-12-07 07:13:06 -05:00
|
|
|
if (selected_is_valid()) {
|
|
|
|
if (get_selected_entry().path == str_back) {
|
|
|
|
text_date.set("Go page " + std::to_string(pagination + 1 - 1)); // for better explain, pagination start with 0 AKA real page - 1
|
|
|
|
} else if (get_selected_entry().path == str_next) {
|
|
|
|
text_date.set("Go page " + std::to_string(pagination + 1 + 1)); // when show this, it should display current AKA (pagination + 1) + 1 AKA next page
|
|
|
|
} else {
|
|
|
|
text_date.set((is_directory(get_selected_full_path()) ? "Created " : "Modified ") + to_string_FAT_timestamp(file_created_date(get_selected_full_path())));
|
|
|
|
}
|
|
|
|
} else {
|
2023-08-16 04:00:46 -04:00
|
|
|
text_date.set("");
|
2024-12-07 07:13:06 -05:00
|
|
|
}
|
2023-08-16 04:00:46 -04:00
|
|
|
}
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
refresh_list();
|
|
|
|
|
|
|
|
on_select_entry = [this](KeyEvent key) {
|
2024-04-02 11:02:02 -04:00
|
|
|
if (key == KeyEvent::Select) {
|
|
|
|
if (get_selected_entry().is_directory) {
|
|
|
|
if (get_selected_entry().path == str_full) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (get_selected_entry().path == str_back) {
|
|
|
|
pagination--;
|
|
|
|
menu_view.set_highlighted(0);
|
|
|
|
reload_current(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (get_selected_entry().path == str_next) {
|
|
|
|
pagination++;
|
|
|
|
menu_view.set_highlighted(0);
|
|
|
|
reload_current(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
push_dir(get_selected_entry().path);
|
|
|
|
return;
|
|
|
|
} else if (handle_file_open()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
2024-04-02 11:02:02 -04:00
|
|
|
button_rename.focus();
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
button_rename.on_select = [this]() {
|
|
|
|
if (selected_is_valid())
|
2023-07-28 21:53:16 -04:00
|
|
|
on_rename("");
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
button_delete.on_select = [this]() {
|
|
|
|
if (selected_is_valid())
|
|
|
|
on_delete();
|
|
|
|
};
|
|
|
|
|
2024-03-13 13:06:14 -04:00
|
|
|
button_clean.on_select = [this]() {
|
|
|
|
if (selected_is_valid())
|
|
|
|
on_clean();
|
|
|
|
};
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
button_cut.on_select = [this]() {
|
2024-03-29 05:44:37 -04:00
|
|
|
if (selected_is_valid()) {
|
2023-05-18 16:16:05 -04:00
|
|
|
clipboard_path = get_selected_full_path();
|
|
|
|
clipboard_mode = ClipboardMode::Cut;
|
|
|
|
} else
|
|
|
|
nav_.display_modal("Cut", "Can't cut that.");
|
|
|
|
};
|
|
|
|
|
|
|
|
button_copy.on_select = [this]() {
|
|
|
|
if (selected_is_valid() && !get_selected_entry().is_directory) {
|
|
|
|
clipboard_path = get_selected_full_path();
|
|
|
|
clipboard_mode = ClipboardMode::Copy;
|
|
|
|
} else
|
|
|
|
nav_.display_modal("Copy", "Can't copy that.");
|
|
|
|
};
|
|
|
|
|
|
|
|
button_paste.on_select = [this]() {
|
|
|
|
if (clipboard_mode != ClipboardMode::None)
|
|
|
|
on_paste();
|
|
|
|
else
|
2024-03-29 05:44:37 -04:00
|
|
|
nav_.display_modal("Paste", " Cut or copy a file,\n or cut a folder, first.");
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
button_new_dir.on_select = [this]() {
|
|
|
|
on_new_dir();
|
|
|
|
};
|
|
|
|
|
|
|
|
button_new_file.on_select = [this]() {
|
|
|
|
on_new_file();
|
|
|
|
};
|
2023-05-23 00:40:03 -04:00
|
|
|
|
|
|
|
button_open_notepad.on_select = [this]() {
|
|
|
|
if (selected_is_valid() && !get_selected_entry().is_directory) {
|
|
|
|
auto path = get_selected_full_path();
|
2023-09-18 17:22:46 -04:00
|
|
|
nav_.push<TextEditorView>(path);
|
2023-05-23 00:40:03 -04:00
|
|
|
} else
|
|
|
|
nav_.display_modal("Open in Notepad", "Can't open that in Notepad.");
|
|
|
|
};
|
2023-07-28 21:53:16 -04:00
|
|
|
|
|
|
|
button_rename_timestamp.on_select = [this]() {
|
2024-03-29 05:44:37 -04:00
|
|
|
if (selected_is_valid()) {
|
2023-07-28 21:53:16 -04:00
|
|
|
on_rename(::truncate(to_string_timestamp(rtc_time::now()), 8));
|
|
|
|
} else
|
|
|
|
nav_.display_modal("Timestamp Rename", "Can't rename that.");
|
|
|
|
};
|
2023-10-08 15:57:59 -04:00
|
|
|
|
|
|
|
button_open_iq_trim.on_select = [this]() {
|
|
|
|
auto path = get_selected_full_path();
|
|
|
|
if (selected_is_valid() && !get_selected_entry().is_directory && is_cxx_capture_file(path)) {
|
|
|
|
nav_.push<IQTrimView>(path);
|
|
|
|
} else
|
|
|
|
nav_.display_modal("IQ Trim", "Not a capture file.");
|
|
|
|
};
|
2023-11-06 17:33:19 -05:00
|
|
|
|
|
|
|
button_show_hidden_files.on_select = [this]() {
|
|
|
|
show_hidden_files = !show_hidden_files;
|
2024-05-27 15:02:52 -04:00
|
|
|
button_show_hidden_files.set_color(show_hidden_files ? *Theme::getInstance()->status_active : Theme::getInstance()->bg_dark->background);
|
2023-11-06 17:33:19 -05:00
|
|
|
reload_current();
|
|
|
|
};
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ui
|