From 419a4dcdc7a8ce315064898e5eed1267b9e6acff Mon Sep 17 00:00:00 2001 From: Jason Rodney Hansen Date: Sun, 30 Jun 2024 13:33:44 -0600 Subject: [PATCH] Add properties to bread crumbs context menu --- src/app.rs | 32 ++++++++++++++++++++++++++++++++ src/dialog.rs | 3 +++ src/menu.rs | 6 ++++++ src/tab.rs | 5 +++++ 4 files changed, 46 insertions(+) diff --git a/src/app.rs b/src/app.rs index 6957242..c035a18 100644 --- a/src/app.rs +++ b/src/app.rs @@ -177,6 +177,7 @@ impl MenuAction for Action { pub enum ContextItem { NavBar(segmented_button::Entity), TabBar(segmented_button::Entity), + BreadCrumbs(usize), } #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -695,6 +696,31 @@ impl App { widget::settings::view_column(children).into() } + + Some(ContextItem::BreadCrumbs(index)) => { + let mut children = Vec::new(); + + if let Some(tab) = self.tab_model.active_data::() { + let path = match tab.location { + Location::Path(ref path) => Some(path), + Location::Search(ref path, _) => Some(path), + _ => None, + } + .and_then(|path| path.ancestors().nth(index)) + .map(|path| path.to_path_buf()); + if let Some(ref path) = path { + let parent = path.parent().unwrap_or(path); + + for item in Location::Path(parent.to_owned()).scan(IconSizes::default()) { + if item.path_opt.as_deref() == Some(path) { + children.push(item.property_view(IconSizes::default())); + } + } + }; + } + + widget::settings::view_column(children).into() + } } } @@ -1751,6 +1777,12 @@ impl Application for App { log::error!("failed to get current executable path: {}", err); } }, + tab::Command::LocationProperties(index) => { + self.context_page = + ContextPage::Properties(Some(ContextItem::BreadCrumbs(index))); + self.core.window.show_context = true; + self.set_context_title(self.context_page.title()); + } tab::Command::Scroll(id, offset) => { commands.push(scrollable::scroll_to(id, offset)); } diff --git a/src/dialog.rs b/src/dialog.rs index c1204a3..9b74145 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -644,6 +644,9 @@ impl Application for App { tab::Command::OpenInNewWindow(_path) => { log::warn!("OpenInNewWindow not supported in dialog"); } + tab::Command::LocationProperties(_path) => { + log::warn!("LocationProperties not supported in dialog"); + } tab::Command::Scroll(id, offset) => { commands.push(scrollable::scroll_to(id, offset)); } diff --git a/src/menu.rs b/src/menu.rs index e57bb2f..33460c0 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -275,6 +275,12 @@ pub fn location_context_menu<'a>(ancestor_index: usize) -> Element<'a, tab::Mess LocationMenuAction::OpenInNewWindow(ancestor_index), )) .into(), + horizontal_rule(1).into(), + menu_button!(widget::text(fl!("properties"))) + .on_press(tab::Message::LocationMenuAction( + LocationMenuAction::Properties(ancestor_index), + )) + .into(), ]; widget::container(widget::column::with_children(children)) diff --git a/src/tab.rs b/src/tab.rs index 5339e72..8f097d9 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -540,6 +540,7 @@ pub enum Command { OpenFile(PathBuf), OpenInNewTab(PathBuf), OpenInNewWindow(PathBuf), + LocationProperties(usize), Scroll(widget::Id, AbsoluteOffset), DropFiles(PathBuf, ClipboardPaste), Timeout(Duration, Message), @@ -592,6 +593,7 @@ pub enum Message { pub enum LocationMenuAction { OpenInNewTab(usize), OpenInNewWindow(usize), + Properties(usize), } impl MenuAction for LocationMenuAction { @@ -1297,6 +1299,9 @@ impl Tab { commands.push(Command::OpenInNewWindow(path)); } } + LocationMenuAction::Properties(ancestor_index) => { + commands.push(Command::LocationProperties(ancestor_index)); + } } } Message::Drag(rect_opt) => match rect_opt {