Breadcrumb view
This commit is contained in:
parent
1aba09a4d0
commit
209622b758
4 changed files with 134 additions and 37 deletions
38
Cargo.lock
generated
38
Cargo.lock
generated
|
|
@ -941,7 +941,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-config"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"atomicwrites",
|
||||
"cosmic-config-derive",
|
||||
|
|
@ -956,7 +956,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-config-derive"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
|
|
@ -986,7 +986,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-text"
|
||||
version = "0.10.0"
|
||||
source = "git+https://github.com/pop-os/cosmic-text.git?branch=refactor#f9a9463ea011f4f349ed6fe802179f0d24c61e7e"
|
||||
source = "git+https://github.com/pop-os/cosmic-text.git?branch=refactor#dd4c4cbbe2d5ed5046054b5361a6eeead50e0bb0"
|
||||
dependencies = [
|
||||
"bitflags 2.4.1",
|
||||
"fontdb",
|
||||
|
|
@ -1007,7 +1007,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-theme"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"almost",
|
||||
"cosmic-config",
|
||||
|
|
@ -2310,7 +2310,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"iced_accessibility",
|
||||
"iced_core",
|
||||
|
|
@ -2325,7 +2325,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_accessibility"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"accesskit_winit",
|
||||
|
|
@ -2334,7 +2334,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_core"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"instant",
|
||||
|
|
@ -2350,7 +2350,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_futures"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"iced_core",
|
||||
|
|
@ -2363,7 +2363,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_graphics"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"bytemuck",
|
||||
|
|
@ -2386,7 +2386,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_renderer"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"iced_graphics",
|
||||
"iced_tiny_skia",
|
||||
|
|
@ -2399,7 +2399,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_runtime"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"iced_core",
|
||||
"iced_futures",
|
||||
|
|
@ -2409,7 +2409,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_style"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"iced_core",
|
||||
"once_cell",
|
||||
|
|
@ -2419,7 +2419,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_tiny_skia"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"cosmic-text",
|
||||
|
|
@ -2437,7 +2437,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_wgpu"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"bytemuck",
|
||||
|
|
@ -2457,7 +2457,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_widget"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"iced_renderer",
|
||||
"iced_runtime",
|
||||
|
|
@ -2471,7 +2471,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "iced_winit"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"iced_graphics",
|
||||
"iced_runtime",
|
||||
|
|
@ -2768,7 +2768,7 @@ checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
|
|||
[[package]]
|
||||
name = "libcosmic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#6850e53855ad5884d89a5bd5eeeed08a0705004c"
|
||||
source = "git+https://github.com/pop-os/libcosmic.git#9fb3d874e18ce36fadea931e16488fdbf28d3d02"
|
||||
dependencies = [
|
||||
"apply",
|
||||
"ashpd",
|
||||
|
|
@ -6036,9 +6036,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.33"
|
||||
version = "0.5.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa"
|
||||
checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
empty-folder = Empty folder
|
||||
empty-folder-hidden = Empty folder (has hidden items)
|
||||
filesystem = Filesystem
|
||||
trash = Trash
|
||||
|
||||
# Context Pages
|
||||
|
|
|
|||
35
src/main.rs
35
src/main.rs
|
|
@ -9,8 +9,7 @@ use cosmic::{
|
|||
event,
|
||||
keyboard::{Event as KeyEvent, KeyCode, Modifiers},
|
||||
subscription::Subscription,
|
||||
widget::row,
|
||||
window, Alignment, Event, Length, Point,
|
||||
window, Event, Length, Point,
|
||||
},
|
||||
style,
|
||||
widget::{self, segmented_button},
|
||||
|
|
@ -601,17 +600,33 @@ impl Application for App {
|
|||
}
|
||||
|
||||
fn header_start(&self) -> Vec<Element<Self::Message>> {
|
||||
vec![
|
||||
menu::menu_bar().into(),
|
||||
//TODO: use theme defined space?
|
||||
widget::horizontal_space(Length::Fixed(32.0)).into(),
|
||||
]
|
||||
}
|
||||
|
||||
fn header_center(&self) -> Vec<Element<Self::Message>> {
|
||||
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
|
||||
|
||||
vec![row![
|
||||
menu::menu_bar(),
|
||||
widget::button(widget::icon::from_name("go-up-symbolic").size(16).icon())
|
||||
.on_press(Message::TabMessage(None, tab::Message::Parent))
|
||||
.padding(space_xxs)
|
||||
.style(style::Button::Icon),
|
||||
let entity = self.tab_model.active();
|
||||
let tab = match self.tab_model.data::<Tab>(entity) {
|
||||
Some(some) => some,
|
||||
None => return Vec::new(),
|
||||
};
|
||||
|
||||
vec![tab
|
||||
.breadcrumbs_view(&self.core)
|
||||
.map(move |message| Message::TabMessage(Some(entity), message))
|
||||
.into()]
|
||||
}
|
||||
|
||||
fn header_end(&self) -> Vec<Element<Self::Message>> {
|
||||
vec![
|
||||
//TODO: use defined space
|
||||
widget::horizontal_space(Length::Fixed(32.0)).into(),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.into()]
|
||||
}
|
||||
|
||||
/// Creates a view after each update.
|
||||
|
|
|
|||
97
src/tab.rs
97
src/tab.rs
|
|
@ -102,6 +102,20 @@ pub fn folder_icon_symbolic(path: &PathBuf, icon_size: u16) -> widget::icon::Han
|
|||
.handle()
|
||||
}
|
||||
|
||||
fn trash_icon_symbolic(icon_size: u16) -> widget::icon::Handle {
|
||||
let full = match trash::os_limited::list() {
|
||||
Ok(entries) => !entries.is_empty(),
|
||||
Err(_err) => false,
|
||||
};
|
||||
widget::icon::from_name(if full {
|
||||
"user-trash-full-symbolic"
|
||||
} else {
|
||||
"user-trash-symbolic"
|
||||
})
|
||||
.size(icon_size)
|
||||
.handle()
|
||||
}
|
||||
|
||||
//TODO: translate, add more levels?
|
||||
fn format_size(size: u64) -> String {
|
||||
const KIB: u64 = 1024;
|
||||
|
|
@ -352,7 +366,6 @@ impl Location {
|
|||
pub enum Message {
|
||||
Click(Option<usize>),
|
||||
Location(Location),
|
||||
Parent,
|
||||
RightClick(usize),
|
||||
View(View),
|
||||
}
|
||||
|
|
@ -556,13 +569,6 @@ impl Tab {
|
|||
Message::Location(location) => {
|
||||
cd = Some(location);
|
||||
}
|
||||
Message::Parent => {
|
||||
if let Location::Path(path) = &self.location {
|
||||
if let Some(parent) = path.parent() {
|
||||
cd = Some(Location::Path(parent.to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::RightClick(click_i) => {
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
if !items.get(click_i).map_or(false, |x| x.selected) {
|
||||
|
|
@ -597,6 +603,81 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn breadcrumbs_view(&self, core: &Core) -> Element<Message> {
|
||||
let cosmic_theme::Spacing { space_xxxs, .. } = core.system_theme().cosmic().spacing;
|
||||
|
||||
let mut children: Vec<Element<_>> = Vec::new();
|
||||
match &self.location {
|
||||
Location::Path(path) => {
|
||||
let home_dir = crate::home_dir();
|
||||
for ancestor in path.ancestors() {
|
||||
let ancestor = ancestor.to_path_buf();
|
||||
let mut found_home = false;
|
||||
let mut row = widget::row::with_capacity(2)
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(space_xxxs);
|
||||
match ancestor.file_name() {
|
||||
Some(name) => {
|
||||
if ancestor == home_dir {
|
||||
row = row.push(
|
||||
widget::icon::icon(folder_icon_symbolic(&ancestor, 16))
|
||||
.size(16),
|
||||
);
|
||||
found_home = true;
|
||||
}
|
||||
row = row.push(widget::text(name.to_string_lossy().to_string()));
|
||||
}
|
||||
None => {
|
||||
row = row.push(
|
||||
widget::icon::from_name("drive-harddisk-system-symbolic")
|
||||
.size(16)
|
||||
.icon(),
|
||||
);
|
||||
row = row.push(widget::text(fl!("filesystem")));
|
||||
}
|
||||
}
|
||||
|
||||
if !children.is_empty() {
|
||||
children.push(widget::text("/").into());
|
||||
}
|
||||
|
||||
children.push(
|
||||
widget::button(row)
|
||||
.padding(space_xxxs)
|
||||
.on_press(Message::Location(Location::Path(ancestor)))
|
||||
.style(theme::Button::Text)
|
||||
.into(),
|
||||
);
|
||||
|
||||
if found_home {
|
||||
break;
|
||||
}
|
||||
}
|
||||
children.reverse();
|
||||
}
|
||||
Location::Trash => {
|
||||
let mut row = widget::row::with_capacity(2)
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(space_xxxs);
|
||||
row = row.push(widget::icon::icon(trash_icon_symbolic(16)).size(16));
|
||||
row = row.push(widget::text(fl!("trash")));
|
||||
|
||||
children.push(
|
||||
widget::button(row)
|
||||
.padding(space_xxxs)
|
||||
.on_press(Message::Location(Location::Trash))
|
||||
.style(theme::Button::Text)
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
children.push(widget::horizontal_space(Length::Fill).into());
|
||||
|
||||
widget::container(widget::row::with_children(children).align_items(Alignment::Center))
|
||||
.style(theme::Container::Primary)
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn empty_view(&self, has_hidden: bool, core: &Core) -> Element<Message> {
|
||||
let cosmic_theme::Spacing { space_xxs, .. } = core.system_theme().cosmic().spacing;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue