handle files and show separate icon
This commit is contained in:
parent
51a75e9cc1
commit
997be0290b
3 changed files with 22 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "DirectoryView.hpp"
|
||||
#include "src/Dirs.hpp"
|
||||
#include "src/Forward.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
DirectoryView::~DirectoryView() {}
|
||||
|
||||
|
@ -14,12 +15,19 @@ void DirectoryView::set_current_path(std::filesystem::path path) {
|
|||
window()->queue_microtask([this]() {
|
||||
target()->clear_children();
|
||||
for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) {
|
||||
auto button = m_target->add<FileButton>(entry.path().filename(), this);
|
||||
auto button = m_target->add<FileButton>(
|
||||
entry.path().filename(),
|
||||
entry.is_directory() ? FileButton::ButtonType::Directory : FileButton::ButtonType::File,
|
||||
this
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void DirectoryView::navigate(std::string path) {
|
||||
if (!std::filesystem::is_directory(path))
|
||||
return;
|
||||
|
||||
set_current_path(path);
|
||||
m_checkpoint_stack.push(m_current_path);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,11 @@ void FileButton::on_init() {
|
|||
layout->slot_percent(100); // icon
|
||||
layout->slot_pixel(24); // name (text)
|
||||
|
||||
add<Raven::SvgWidget>("/usr/share/icons/Papirus/64x64/places/folder-adwaita.svg");
|
||||
if (m_button_type == ButtonType::Directory) {
|
||||
add<Raven::SvgWidget>("/usr/share/icons/Papirus/64x64/places/folder-adwaita.svg");
|
||||
} else if (m_button_type == ButtonType::File) {
|
||||
add<Raven::SvgWidget>("/usr/share/icons/Papirus/64x64/mimetypes/text-x-generic.svg");
|
||||
}
|
||||
auto label = add<Raven::Label>(m_name, Raven::PaintTextAlign::Center);
|
||||
label->rect().set_max_width(rect().width());
|
||||
label->rect().set_max_height(24);
|
||||
|
|
|
@ -12,10 +12,16 @@
|
|||
class FileButton : public Raven::Widget {
|
||||
public:
|
||||
static Raven::GenericStyle style;
|
||||
|
||||
enum class ButtonType {
|
||||
Directory,
|
||||
File
|
||||
};
|
||||
public:
|
||||
FileButton(std::string name, DirectoryView* directory_view)
|
||||
FileButton(std::string name, ButtonType button_type, DirectoryView* directory_view)
|
||||
: Raven::Widget()
|
||||
, m_directory_view(directory_view)
|
||||
, m_button_type(button_type)
|
||||
, m_name(name) {}
|
||||
|
||||
std::string &name() { return m_name; }
|
||||
|
@ -24,5 +30,6 @@ protected:
|
|||
void on_activation_update(Raven::ActivationUpdateEvent &event);
|
||||
private:
|
||||
DirectoryView* m_directory_view;
|
||||
ButtonType m_button_type;
|
||||
std::string m_name;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue