Skip to content

Commit

Permalink
hidden-files: Allow toggling hidden files visibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 9, 2024
1 parent da1a367 commit e6844df
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/apps/hideo-browser/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <karm-ui/popover.h>
#include <karm-ui/scroll.h>
#include <mdi/alert-decagram.h>
#include <mdi/arrow-left.h>
#include <mdi/bookmark-outline.h>
#include <mdi/bookmark.h>
#include <mdi/button-cursor.h>
#include <mdi/chevron-left.h>
#include <mdi/code-tags.h>
#include <mdi/cog.h>
#include <mdi/dots-horizontal.h>
Expand Down Expand Up @@ -126,7 +126,7 @@ Ui::Child addressBar(Mime::Url const &url) {
Ui::Child contextMenu(State const &s) {
return Kr::contextMenuContent({
Kr::contextMenuDock({
Kr::contextMenuIcon(Ui::NOP, Mdi::CHEVRON_LEFT),
Kr::contextMenuIcon(Ui::NOP, Mdi::ARROW_LEFT),
Kr::contextMenuIcon(Ui::NOP, Mdi::REFRESH),
}),
Ui::separator(),
Expand Down Expand Up @@ -216,7 +216,7 @@ Ui::Child app(Mime::Url url, Res<Strong<Vaev::Markup::Document>> dom) {
.icon = Mdi::SURFING,
.title = "Vaev"s,
.startTools = slots$(
Ui::button(Model::bindIf<GoBack>(s.canGoBack()), Ui::ButtonStyle::subtle(), Mdi::CHEVRON_LEFT),
Ui::button(Model::bindIf<GoBack>(s.canGoBack()), Ui::ButtonStyle::subtle(), Mdi::ARROW_LEFT),
),
.midleTools = slots$(addressBar(s.url) | Ui::grow()),
.endTools = slots$(
Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-files/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Ui::Child app() {
goParentTool(s)
),
.midleTools = slots$(breadcrumb(s) | Ui::grow()),
.endTools = slots$(refreshTool()),
.endTools = slots$(moreTool(s)),
.sidebar = slot$(sidebar(s)),
.body = slot$(pageContent(s)),
});
Expand Down
3 changes: 3 additions & 0 deletions src/apps/hideo-files/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void reduce(State &s, Action a) {
},
[&](AddBookmark) {
},
[&](ToggleHidden) {
s.showHidden = not s.showHidden;
},
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/apps/hideo-files/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Hideo::Files {
struct State {
Vec<Mime::Url> history;
usize currentIndex = 0;
bool showHidden = false;

State(Mime::Url path)
: history({path}) {}
Expand Down Expand Up @@ -54,7 +55,9 @@ struct Refresh {

struct AddBookmark {};

using Action = Union<GoRoot, GoBack, GoForward, GoParent, Navigate, GoTo, Refresh, AddBookmark>;
struct ToggleHidden {};

using Action = Union<GoRoot, GoBack, GoForward, GoParent, Navigate, GoTo, Refresh, AddBookmark, ToggleHidden>;

void reduce(State &, Action);

Expand Down
63 changes: 46 additions & 17 deletions src/apps/hideo-files/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
#include <karm-ui/dialog.h>
#include <karm-ui/input.h>
#include <karm-ui/layout.h>
#include <karm-ui/popover.h>
#include <karm-ui/scroll.h>
#include <mdi/alert-decagram.h>
#include <mdi/alert-outline.h>
#include <mdi/arrow-left.h>
#include <mdi/arrow-right.h>
#include <mdi/arrow-up.h>
#include <mdi/bookmark-outline.h>
#include <mdi/bookmark.h>
#include <mdi/checkbox-blank-outline.h>
#include <mdi/checkbox-marked.h>
#include <mdi/chevron-right.h>
#include <mdi/content-copy.h>
#include <mdi/content-cut.h>
#include <mdi/content-paste.h>
#include <mdi/delete-outline.h>
#include <mdi/dots-horizontal.h>
#include <mdi/download.h>
#include <mdi/file-document.h>
#include <mdi/film.h>
Expand Down Expand Up @@ -111,6 +116,8 @@ Ui::Child directoryListing(State const &s, Sys::Dir const &dir) {
Ui::Children children;
bool odd = true;
for (auto const &entry : dir.entries()) {
if (entry.hidden() and not s.showHidden)
continue;
children.pushBack(directorEntry(entry, odd));
odd = !odd;
}
Expand Down Expand Up @@ -184,14 +191,14 @@ Ui::Child breadcrumbRoot(Mime::Url const &url) {
);
}

Ui::Child breadcrumb(State const &state) {
Ui::Child breadcrumb(State const &s) {
Ui::Children items;
items.pushBack(breadcrumbRoot(state.currentUrl()));
state
items.pushBack(breadcrumbRoot(s.currentUrl()));
s
.currentUrl()
.iter()
.mapi([&](auto const &text, usize i) {
items.pushBack(breadcrumbItem(text, state.currentUrl().len() - i - 1));
items.pushBack(breadcrumbItem(text, s.currentUrl().len() - i - 1));
return true;
})
.collect();
Expand All @@ -207,30 +214,30 @@ Ui::Child breadcrumb(State const &state) {
Ui::hflow(items) |
Ui::hscroll() |
Ui::grow(),
Ui::button(Model::bind<AddBookmark>(), Ui::ButtonStyle::subtle(), Mdi::BOOKMARK_OUTLINE)
refreshTool()
)
);
}

Ui::Child goBackTool(State const &state) {
Ui::Child goBackTool(State const &s) {
return Ui::button(
Model::bindIf<GoBack>(state.canGoBack()),
Model::bindIf<GoBack>(s.canGoBack()),
Ui::ButtonStyle::subtle(),
Mdi::ARROW_LEFT
);
}

Ui::Child goForwardTool(State const &state) {
Ui::Child goForwardTool(State const &s) {
return Ui::button(
Model::bindIf<GoForward>(state.canGoForward()),
Model::bindIf<GoForward>(s.canGoForward()),
Ui::ButtonStyle::subtle(),
Mdi::ARROW_RIGHT
);
}

Ui::Child goParentTool(State const &state) {
Ui::Child goParentTool(State const &s) {
return Ui::button(
Model::bindIf<GoParent>(state.canGoParent(), 1),
Model::bindIf<GoParent>(s.canGoParent(), 1),
Ui::ButtonStyle::subtle(),
Mdi::ARROW_UP
);
Expand All @@ -244,13 +251,35 @@ Ui::Child refreshTool() {
);
}

Ui::Child toolbar(State const &state) {
Ui::Child mainMenu([[maybe_unused]] State const &s) {
return Kr::contextMenuContent({
Kr::contextMenuItem(
Ui::NOP,
Mdi::BOOKMARK_OUTLINE, "Add bookmark..."
),
Kr::contextMenuItem(Ui::NOP, Mdi::BOOKMARK, "Bookmarks"),
Ui::separator(),
Kr::contextMenuItem(Model::bind<ToggleHidden>(), s.showHidden ? Mdi::CHECKBOX_MARKED : Mdi::CHECKBOX_BLANK_OUTLINE, "Show hidden"),
});
}

Ui::Child moreTool(State const &s) {
return Ui::button(
[&](Ui::Node &n) {
Ui::showPopover(n, n.bound().bottomEnd(), mainMenu(s));
},
Ui::ButtonStyle::subtle(),
Mdi::DOTS_HORIZONTAL
);
}

Ui::Child toolbar(State const &s) {
return Kr::toolbar({
Ui::button(Model::bindIf<GoBack>(state.canGoBack()), Ui::ButtonStyle::subtle(), Mdi::ARROW_LEFT),
Ui::button(Model::bindIf<GoForward>(state.canGoForward()), Ui::ButtonStyle::subtle(), Mdi::ARROW_RIGHT),
Ui::button(Model::bindIf<GoParent>(state.canGoParent(), 1), Ui::ButtonStyle::subtle(), Mdi::ARROW_UP),
Ui::grow(breadcrumb(state)),
Ui::button(Model::bind<Refresh>(), Ui::ButtonStyle::subtle(), Mdi::REFRESH),
goBackTool(s),
goForwardTool(s),
goParentTool(s),
Ui::grow(breadcrumb(s)),
moreTool(s),
});
}

Expand Down
16 changes: 9 additions & 7 deletions src/apps/hideo-files/widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ namespace Hideo::Files {

// MARK: Common Widgets --------------------------------------------------------

Ui::Child directoryListing(State const &, Sys::Dir const &);
Ui::Child directoryListing(State const &s, Sys::Dir const &);

Ui::Child breadcrumb(State const &);
Ui::Child breadcrumb(State const &s);

Ui::Child goBackTool(State const &state);
Ui::Child goBackTool(State const &s);

Ui::Child goForwardTool(State const &state);
Ui::Child goForwardTool(State const &s);

Ui::Child goParentTool(State const &state);
Ui::Child goParentTool(State const &s);

Ui::Child refreshTool();

Ui::Child toolbar(State const &);
Ui::Child moreTool(State const &s);

Ui::Child alert(State const &state, String title, String body);
Ui::Child toolbar(State const &s);

Ui::Child alert(State const &s, String title, String body);

// MARK: Dialogs -------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions src/libs/karm-sys/dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Karm::Sys {
struct DirEntry {
String name;
Type type;

bool hidden() const {
return name[0] == '.';
}
};

struct Dir {
Expand Down

0 comments on commit e6844df

Please sign in to comment.