Add properties to bread crumbs context menu

This commit is contained in:
Jason Rodney Hansen 2024-06-30 13:33:44 -06:00 committed by Jeremy Soller
parent 26423beaac
commit 419a4dcdc7
4 changed files with 46 additions and 0 deletions

View file

@ -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::<Tab>() {
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));
}

View file

@ -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));
}

View file

@ -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))

View file

@ -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 {