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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui.hpp"
|
|
|
|
#include "ui_widget.hpp"
|
|
|
|
#include "ui_painter.hpp"
|
|
|
|
#include "ui_menu.hpp"
|
|
|
|
#include "file.hpp"
|
|
|
|
#include "ui_navigation.hpp"
|
|
|
|
#include "ui_textentry.hpp"
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
struct fileman_entry {
|
2023-05-01 01:42:28 -04:00
|
|
|
std::filesystem::path path { };
|
2017-09-19 15:14:56 -04:00
|
|
|
uint32_t size { };
|
|
|
|
bool is_directory { };
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileManBaseView : public View {
|
|
|
|
public:
|
|
|
|
FileManBaseView(
|
2017-12-06 19:58:25 -05:00
|
|
|
NavigationView& nav,
|
|
|
|
std::string filter
|
2017-09-19 15:14:56 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
void focus() override;
|
|
|
|
|
|
|
|
void load_directory_contents(const std::filesystem::path& dir_path);
|
2023-05-01 01:42:28 -04:00
|
|
|
std::filesystem::path get_selected_full_path() const;
|
|
|
|
const fileman_entry& get_selected_entry() const;
|
2017-09-19 15:14:56 -04:00
|
|
|
|
2023-03-22 03:46:58 -04:00
|
|
|
std::string title() const override { return "Fileman"; };
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
protected:
|
2023-05-01 12:25:32 -04:00
|
|
|
static constexpr size_t max_filename_length = 64; // Necessary?
|
2023-05-01 01:42:28 -04:00
|
|
|
|
2017-12-06 19:58:25 -05:00
|
|
|
struct file_assoc_t {
|
2023-05-01 01:42:28 -04:00
|
|
|
std::filesystem::path extension;
|
2017-12-06 19:58:25 -05:00
|
|
|
const Bitmap* icon;
|
|
|
|
ui::Color color;
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::vector<file_assoc_t> file_types = {
|
2023-05-01 01:42:28 -04:00
|
|
|
{ u".TXT", &bitmap_icon_file_text, ui::Color::white() },
|
|
|
|
{ u".PNG", &bitmap_icon_file_image, ui::Color::green() },
|
|
|
|
{ u".BMP", &bitmap_icon_file_image, ui::Color::green() },
|
|
|
|
{ u".C8", &bitmap_icon_file_iq, ui::Color::dark_cyan() },
|
|
|
|
{ u".C16", &bitmap_icon_file_iq, ui::Color::dark_cyan() },
|
|
|
|
{ u".WAV", &bitmap_icon_file_wav, ui::Color::dark_magenta() },
|
|
|
|
{ u"", &bitmap_icon_file, ui::Color::light_grey() } // NB: Must be last.
|
2017-12-06 19:58:25 -05:00
|
|
|
};
|
2023-05-01 01:42:28 -04:00
|
|
|
|
|
|
|
void refresh_list();
|
|
|
|
const file_assoc_t& get_assoc(const std::filesystem::path& ext) const;
|
|
|
|
|
|
|
|
NavigationView& nav_;
|
|
|
|
|
2017-09-20 02:50:59 -04:00
|
|
|
bool empty_root { false };
|
2017-09-19 15:14:56 -04:00
|
|
|
std::function<void(void)> on_select_entry { nullptr };
|
|
|
|
std::function<void(bool)> on_refresh_widgets { nullptr };
|
2023-05-01 01:42:28 -04:00
|
|
|
|
2017-09-19 15:14:56 -04:00
|
|
|
std::vector<fileman_entry> entry_list { };
|
2023-05-01 12:25:32 -04:00
|
|
|
const std::filesystem::path parent_dir_path { u".." };
|
2017-09-19 15:14:56 -04:00
|
|
|
std::filesystem::path current_path { u"" };
|
2023-05-01 01:42:28 -04:00
|
|
|
std::filesystem::path extension_filter { u"" };
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
Labels labels {
|
2020-05-31 19:59:40 -04:00
|
|
|
{ { 0, 0 }, "Path:", Color::light_grey() }
|
2017-09-19 15:14:56 -04:00
|
|
|
};
|
2023-05-01 01:42:28 -04:00
|
|
|
|
2017-09-19 15:14:56 -04:00
|
|
|
Text text_current {
|
2020-05-31 19:59:40 -04:00
|
|
|
{ 6 * 8, 0 * 8, 24 * 8, 16 },
|
2017-09-19 15:14:56 -04:00
|
|
|
"",
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuView menu_view {
|
|
|
|
{ 0, 2 * 8, 240, 26 * 8 },
|
|
|
|
true
|
|
|
|
};
|
|
|
|
|
|
|
|
Button button_exit {
|
2020-05-29 19:39:08 -04:00
|
|
|
{ 16 * 8, 34 * 8, 14 * 8, 32 },
|
2017-09-19 15:14:56 -04:00
|
|
|
"Exit"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-09-20 02:50:59 -04:00
|
|
|
/*class FileSaveView : public FileManBaseView {
|
2017-09-19 15:14:56 -04:00
|
|
|
public:
|
|
|
|
FileSaveView(NavigationView& nav);
|
|
|
|
~FileSaveView();
|
|
|
|
|
|
|
|
private:
|
2017-09-20 02:50:59 -04:00
|
|
|
std::string name_buffer { };
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
void on_save_name();
|
|
|
|
|
|
|
|
Text text_save {
|
|
|
|
{ 4 * 8, 15 * 8, 8 * 8, 16 },
|
|
|
|
"Save as:",
|
|
|
|
};
|
|
|
|
Button button_save_name {
|
|
|
|
{ 4 * 8, 18 * 8, 12 * 8, 32 },
|
|
|
|
"Name (set)"
|
|
|
|
};
|
2017-09-20 02:50:59 -04:00
|
|
|
LiveDateTime live_timestamp {
|
|
|
|
{ 17 * 8, 24 * 8, 11 * 8, 16 }
|
2017-09-19 15:14:56 -04:00
|
|
|
};
|
2017-09-20 02:50:59 -04:00
|
|
|
};*/
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
class FileLoadView : public FileManBaseView {
|
|
|
|
public:
|
|
|
|
std::function<void(std::filesystem::path)> on_changed { };
|
|
|
|
|
2017-12-06 19:58:25 -05:00
|
|
|
FileLoadView(NavigationView& nav, std::string filter);
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void refresh_widgets(const bool v);
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileManagerView : public FileManBaseView {
|
|
|
|
public:
|
|
|
|
FileManagerView(NavigationView& nav);
|
|
|
|
~FileManagerView();
|
|
|
|
|
|
|
|
private:
|
2017-09-20 02:50:59 -04:00
|
|
|
std::string name_buffer { };
|
2023-04-26 00:54:07 -04:00
|
|
|
std::string extension_buffer { };
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
void refresh_widgets(const bool v);
|
2023-05-01 12:25:32 -04:00
|
|
|
void on_rename();
|
2017-09-19 15:14:56 -04:00
|
|
|
void on_delete();
|
2023-05-01 12:25:32 -04:00
|
|
|
void on_new_dir();
|
2018-01-09 16:12:19 -05:00
|
|
|
|
|
|
|
Labels labels {
|
|
|
|
{ { 0, 26 * 8 }, "Created ", Color::light_grey() }
|
|
|
|
};
|
|
|
|
|
|
|
|
Text text_date {
|
|
|
|
{ 8 * 8, 26 * 8 , 19 * 8, 16 },
|
|
|
|
""
|
|
|
|
};
|
2017-09-19 15:14:56 -04:00
|
|
|
|
|
|
|
Button button_rename {
|
2023-04-22 10:46:04 -04:00
|
|
|
{ 0 * 8, 29 * 8, 9 * 8, 32 },
|
2017-09-19 15:14:56 -04:00
|
|
|
"Rename"
|
|
|
|
};
|
2023-04-22 05:10:43 -04:00
|
|
|
|
2023-05-01 12:25:32 -04:00
|
|
|
/*Button button_copy {
|
2023-04-22 05:50:21 -04:00
|
|
|
{ 10 * 8, 29 * 8, 10 * 8, 32 },
|
2023-05-01 01:42:28 -04:00
|
|
|
"Copy"
|
|
|
|
};
|
|
|
|
|
|
|
|
Button button_move {
|
|
|
|
{ 10 * 8, 29 * 8, 10 * 8, 32 },
|
|
|
|
"Move"
|
2023-05-01 12:25:32 -04:00
|
|
|
};*/
|
2023-04-22 05:10:43 -04:00
|
|
|
|
2018-01-09 16:12:19 -05:00
|
|
|
Button button_delete {
|
2023-04-22 10:46:04 -04:00
|
|
|
{ 21 * 8, 29 * 8, 9 * 8, 32 },
|
2018-01-09 16:12:19 -05:00
|
|
|
"Delete"
|
|
|
|
};
|
2017-09-19 15:14:56 -04:00
|
|
|
|
2023-05-01 01:42:28 -04:00
|
|
|
/*Button button_new_file {
|
|
|
|
{ 0 * 8, 34 * 8, 14 * 8, 32 },
|
|
|
|
"New File"
|
|
|
|
};*/
|
|
|
|
|
2017-09-19 15:14:56 -04:00
|
|
|
Button button_new_dir {
|
2018-01-09 16:12:19 -05:00
|
|
|
{ 0 * 8, 34 * 8, 14 * 8, 32 },
|
2023-05-01 01:42:28 -04:00
|
|
|
"New Dir"
|
2017-09-19 15:14:56 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ui */
|