Compare commits
3 commits
0b287f755b
...
96cd01bc77
Author | SHA1 | Date | |
---|---|---|---|
|
96cd01bc77 | ||
|
a1e0e82da3 | ||
|
e413a7d69d |
8 changed files with 44 additions and 13 deletions
|
@ -8,6 +8,7 @@ raven_dep = dependency('raven')
|
|||
|
||||
executable(
|
||||
'filemanager',
|
||||
'./src/Dirs.cpp',
|
||||
'./src/FileButton.cpp',
|
||||
'./src/DirectoryView.cpp',
|
||||
'./src/TopBar.cpp',
|
||||
|
|
|
@ -14,11 +14,13 @@ void AppWidget::on_init() {
|
|||
|
||||
top_bar->on_action = [directory_view](TopBar::Action action) {
|
||||
if (action == TopBar::Action::Back) {
|
||||
directory_view->back();
|
||||
directory_view->go_back();
|
||||
} else if (action == TopBar::Action::Forward) {
|
||||
directory_view->forward();
|
||||
directory_view->go_forward();
|
||||
} else if (action == TopBar::Action::Home) {
|
||||
directory_view->home();
|
||||
directory_view->navigate_home();
|
||||
} else if (action == TopBar::Action::ParentDirectory) {
|
||||
directory_view->navigate_parent_directory();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "DirectoryView.hpp"
|
||||
#include "src/Dirs.hpp"
|
||||
#include "src/Forward.hpp"
|
||||
|
||||
DirectoryView::~DirectoryView() {}
|
||||
|
@ -33,18 +34,22 @@ void DirectoryView::on_init() {
|
|||
|
||||
m_target = make_target();
|
||||
m_target->set_layout<Raven::DocumentLayout>(12.0);
|
||||
navigate("/");
|
||||
navigate_home();
|
||||
set_did_init(true);
|
||||
}
|
||||
|
||||
void DirectoryView::back() {
|
||||
void DirectoryView::go_back() {
|
||||
m_checkpoint_stack.undo();
|
||||
}
|
||||
|
||||
void DirectoryView::forward() {
|
||||
void DirectoryView::go_forward() {
|
||||
m_checkpoint_stack.redo();
|
||||
}
|
||||
|
||||
void DirectoryView::home() {
|
||||
std::cerr << "home(): not implemented" << std::endl;
|
||||
void DirectoryView::navigate_home() {
|
||||
navigate(get_home_directory());
|
||||
}
|
||||
|
||||
void DirectoryView::navigate_parent_directory() {
|
||||
navigate(m_current_path.parent_path());
|
||||
}
|
||||
|
|
|
@ -18,9 +18,10 @@ public:
|
|||
|
||||
void navigate(std::string path);
|
||||
void navigate_relative(std::string path);
|
||||
void back();
|
||||
void forward();
|
||||
void home();
|
||||
void go_back();
|
||||
void go_forward();
|
||||
void navigate_home();
|
||||
void navigate_parent_directory();
|
||||
protected:
|
||||
void set_current_path(std::filesystem::path path);
|
||||
|
||||
|
|
11
src/Dirs.cpp
Normal file
11
src/Dirs.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "Dirs.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
std::filesystem::path get_home_directory() {
|
||||
auto home_env = std::getenv("HOME");
|
||||
if (!home_env || !std::filesystem::exists(home_env)) {
|
||||
return "/";
|
||||
}
|
||||
return home_env;
|
||||
}
|
5
src/Dirs.hpp
Normal file
5
src/Dirs.hpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
std::filesystem::path get_home_directory();
|
|
@ -9,7 +9,7 @@ void TopBar::on_init() {
|
|||
set_style(&Raven::accent_widget_style);
|
||||
|
||||
auto layout = set_layout<Raven::BoxLayout>(Raven::Direction::Horizontal);
|
||||
layout->slot_pixel(24, 3);
|
||||
layout->slot_pixel(24, 4);
|
||||
layout->set_margin(4);
|
||||
layout->set_spacing(8);
|
||||
|
||||
|
@ -17,6 +17,8 @@ void TopBar::on_init() {
|
|||
back_button->set_style(&Raven::default_button_style);
|
||||
auto forward_button = add<Raven::SvgWidget>("/usr/share/icons/Papirus/24x24/actions/next.svg");
|
||||
forward_button->set_style(&Raven::default_button_style);
|
||||
auto parent_button = add<Raven::SvgWidget>("/usr/share/icons/Papirus/24x24/actions/up.svg");
|
||||
parent_button->set_style(&Raven::default_button_style);
|
||||
auto home_button = add<Raven::SvgWidget>("/usr/share/icons/Papirus/24x24/actions/go-home.svg");
|
||||
home_button->set_style(&Raven::default_button_style);
|
||||
|
||||
|
@ -29,6 +31,9 @@ void TopBar::on_init() {
|
|||
home_button->on_click = [this]() {
|
||||
on_action(Action::Home);
|
||||
};
|
||||
parent_button->on_click = [this]() {
|
||||
on_action(Action::ParentDirectory);
|
||||
};
|
||||
|
||||
set_did_init(true);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ public:
|
|||
enum class Action {
|
||||
Back = 0,
|
||||
Forward,
|
||||
Home
|
||||
Home,
|
||||
ParentDirectory
|
||||
};
|
||||
public:
|
||||
TopBar()
|
||||
|
|
Loading…
Reference in a new issue