Compare commits
No commits in common. "0b287f755b524e660d09f6e7357a025331985932" and "2d20a59a8cec7300706a42104e0068b28581ca18" have entirely different histories.
0b287f755b
...
2d20a59a8c
11 changed files with 13 additions and 167 deletions
|
@ -5,6 +5,7 @@ File Manager is a simple file manager made using Raven.
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
- [raven](https://git.hippoz.xyz/hippoz/raven)
|
- [raven](https://git.hippoz.xyz/hippoz/raven)
|
||||||
|
- librsvg
|
||||||
|
|
||||||
# Hacking
|
# Hacking
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,12 @@ project(
|
||||||
)
|
)
|
||||||
|
|
||||||
raven_dep = dependency('raven')
|
raven_dep = dependency('raven')
|
||||||
|
librsvg_dep = dependency('librsvg-2.0')
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'filemanager',
|
'filemanager',
|
||||||
'./src/FileButton.cpp',
|
'./src/FileButton.cpp',
|
||||||
'./src/DirectoryView.cpp',
|
'./src/DirectoryView.cpp',
|
||||||
'./src/TopBar.cpp',
|
|
||||||
'./src/AppWidget.cpp',
|
|
||||||
'./src/main.cpp',
|
'./src/main.cpp',
|
||||||
dependencies : [raven_dep]
|
dependencies : [raven_dep, librsvg_dep]
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
#include "AppWidget.hpp"
|
|
||||||
#include "Box.hpp"
|
|
||||||
#include "BoxLayout.hpp"
|
|
||||||
#include "DirectoryView.hpp"
|
|
||||||
#include "TopBar.hpp"
|
|
||||||
|
|
||||||
void AppWidget::on_init() {
|
|
||||||
auto layout = set_layout<Raven::BoxLayout>(Raven::Direction::Vertical);
|
|
||||||
layout->slot_pixel(32); // TopBar
|
|
||||||
layout->slot_percent(100); // DirectoryView
|
|
||||||
|
|
||||||
auto top_bar = add<TopBar>();
|
|
||||||
auto directory_view = add<DirectoryView>();
|
|
||||||
|
|
||||||
top_bar->on_action = [directory_view](TopBar::Action action) {
|
|
||||||
if (action == TopBar::Action::Back) {
|
|
||||||
directory_view->back();
|
|
||||||
} else if (action == TopBar::Action::Forward) {
|
|
||||||
directory_view->forward();
|
|
||||||
} else if (action == TopBar::Action::Home) {
|
|
||||||
directory_view->home();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
set_did_init(true);
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Widget.hpp"
|
|
||||||
|
|
||||||
class AppWidget : public Raven::Widget {
|
|
||||||
public:
|
|
||||||
AppWidget()
|
|
||||||
: Raven::Widget() {}
|
|
||||||
protected:
|
|
||||||
void on_init();
|
|
||||||
private:
|
|
||||||
};
|
|
|
@ -1,37 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
template<typename Entry>
|
|
||||||
class CheckpointStack {
|
|
||||||
public:
|
|
||||||
CheckpointStack() {}
|
|
||||||
|
|
||||||
void undo() {
|
|
||||||
if (m_history_index > 0) {
|
|
||||||
checkpoint_changed(m_history[--m_history_index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void redo() {
|
|
||||||
if (!m_history.empty() && m_history_index != (m_history.size() - 1)) {
|
|
||||||
checkpoint_changed(m_history[++m_history_index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void push(Entry entry) {
|
|
||||||
while (!m_history.empty() && (m_history.size() - 1) != m_history_index) {
|
|
||||||
m_history.erase(m_history.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_history.push_back(entry);
|
|
||||||
m_history_index = m_history.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::function<void(Entry entry)> checkpoint_changed;
|
|
||||||
private:
|
|
||||||
std::vector<Entry> m_history;
|
|
||||||
unsigned int m_history_index { 0 };
|
|
||||||
};
|
|
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
DirectoryView::~DirectoryView() {}
|
DirectoryView::~DirectoryView() {}
|
||||||
|
|
||||||
void DirectoryView::set_current_path(std::filesystem::path path) {
|
void DirectoryView::update() {
|
||||||
m_current_path = path;
|
|
||||||
|
|
||||||
// microtasks defer execution of the callback until all external events are processed.
|
// microtasks defer execution of the callback until all external events are processed.
|
||||||
// if they're not used here and update() is called in a click or hover handler,
|
// if they're not used here and update() is called in a click or hover handler,
|
||||||
// chaos will ensue, as the widget tree will be updated during event propagation
|
// chaos will ensue, as the widget tree will be updated during event propagation
|
||||||
|
@ -18,33 +16,18 @@ void DirectoryView::set_current_path(std::filesystem::path path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectoryView::navigate(std::string path) {
|
void DirectoryView::navigate(std::string path) {
|
||||||
set_current_path(path);
|
m_current_path = path;
|
||||||
m_checkpoint_stack.push(m_current_path);
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectoryView::navigate_relative(std::string path) {
|
void DirectoryView::navigate_relative(std::string path) {
|
||||||
navigate(m_current_path / path);
|
m_current_path /= path;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectoryView::on_init() {
|
void DirectoryView::on_init() {
|
||||||
m_checkpoint_stack.checkpoint_changed = [this](std::filesystem::path go) {
|
|
||||||
set_current_path(go);
|
|
||||||
};
|
|
||||||
|
|
||||||
m_target = make_target();
|
m_target = make_target();
|
||||||
m_target->set_layout<Raven::DocumentLayout>(12.0);
|
m_target->set_layout<Raven::DocumentLayout>(12.0);
|
||||||
navigate("/");
|
update();
|
||||||
set_did_init(true);
|
set_did_init(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectoryView::back() {
|
|
||||||
m_checkpoint_stack.undo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirectoryView::forward() {
|
|
||||||
m_checkpoint_stack.redo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirectoryView::home() {
|
|
||||||
std::cerr << "home(): not implemented" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stack>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "raven/Widget.hpp"
|
#include "raven/Widget.hpp"
|
||||||
#include "raven/ScrollContainer.hpp"
|
#include "raven/ScrollContainer.hpp"
|
||||||
#include "raven/DocumentLayout.hpp"
|
#include "raven/DocumentLayout.hpp"
|
||||||
#include "FileButton.hpp"
|
#include "FileButton.hpp"
|
||||||
#include "CheckpointStack.hpp"
|
|
||||||
|
|
||||||
class DirectoryView : public Raven::ScrollContainer {
|
class DirectoryView : public Raven::ScrollContainer {
|
||||||
public:
|
public:
|
||||||
|
@ -16,17 +14,12 @@ public:
|
||||||
|
|
||||||
~DirectoryView();
|
~DirectoryView();
|
||||||
|
|
||||||
|
void update();
|
||||||
void navigate(std::string path);
|
void navigate(std::string path);
|
||||||
void navigate_relative(std::string path);
|
void navigate_relative(std::string path);
|
||||||
void back();
|
|
||||||
void forward();
|
|
||||||
void home();
|
|
||||||
protected:
|
protected:
|
||||||
void set_current_path(std::filesystem::path path);
|
|
||||||
|
|
||||||
void on_init();
|
void on_init();
|
||||||
private:
|
private:
|
||||||
std::filesystem::path m_current_path { "/" };
|
std::filesystem::path m_current_path { "/" };
|
||||||
std::shared_ptr<Raven::Widget> m_target;
|
std::shared_ptr<Raven::Widget> m_target;
|
||||||
CheckpointStack<std::filesystem::path> m_checkpoint_stack {};
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,7 @@ void FileButton::on_init() {
|
||||||
layout->slot_percent(100); // icon
|
layout->slot_percent(100); // icon
|
||||||
layout->slot_pixel(24); // name (text)
|
layout->slot_pixel(24); // name (text)
|
||||||
|
|
||||||
add<Raven::SvgWidget>("/usr/share/icons/Papirus/128x128/places/folder-adwaita.svg");
|
add<Raven::SvgWidget>("folder-adwaita.svg");
|
||||||
auto label = add<Raven::Label>(m_name, Raven::PaintTextAlign::Center);
|
auto label = add<Raven::Label>(m_name, Raven::PaintTextAlign::Center);
|
||||||
label->rect().set_max_width(rect().width());
|
label->rect().set_max_width(rect().width());
|
||||||
label->rect().set_max_height(24);
|
label->rect().set_max_height(24);
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
#include "TopBar.hpp"
|
|
||||||
#include "raven/Styles.hpp"
|
|
||||||
#include "raven/Box.hpp"
|
|
||||||
#include "raven/BoxLayout.hpp"
|
|
||||||
#include "raven/SvgWidget.hpp"
|
|
||||||
#include "raven/RowLayout.hpp"
|
|
||||||
|
|
||||||
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->set_margin(4);
|
|
||||||
layout->set_spacing(8);
|
|
||||||
|
|
||||||
auto back_button = add<Raven::SvgWidget>("/usr/share/icons/Papirus/24x24/actions/back.svg");
|
|
||||||
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 home_button = add<Raven::SvgWidget>("/usr/share/icons/Papirus/24x24/actions/go-home.svg");
|
|
||||||
home_button->set_style(&Raven::default_button_style);
|
|
||||||
|
|
||||||
back_button->on_click = [this]() {
|
|
||||||
on_action(Action::Back);
|
|
||||||
};
|
|
||||||
forward_button->on_click = [this]() {
|
|
||||||
on_action(Action::Forward);
|
|
||||||
};
|
|
||||||
home_button->on_click = [this]() {
|
|
||||||
on_action(Action::Home);
|
|
||||||
};
|
|
||||||
|
|
||||||
set_did_init(true);
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Widget.hpp"
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
class TopBar : public Raven::Widget {
|
|
||||||
public:
|
|
||||||
enum class Action {
|
|
||||||
Back = 0,
|
|
||||||
Forward,
|
|
||||||
Home
|
|
||||||
};
|
|
||||||
public:
|
|
||||||
TopBar()
|
|
||||||
: Raven::Widget() {}
|
|
||||||
|
|
||||||
std::function<void(Action)> on_action { [](Action _){} };
|
|
||||||
protected:
|
|
||||||
void on_init();
|
|
||||||
private:
|
|
||||||
};
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "AppWidget.hpp"
|
#include "DirectoryView.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Raven::Window window {};
|
Raven::Window window {};
|
||||||
window.spawn_window();
|
window.spawn_window();
|
||||||
|
|
||||||
window.set_main_widget<AppWidget>();
|
window.set_main_widget<DirectoryView>();
|
||||||
|
|
||||||
window.run(true);
|
window.run(true);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue