2024-01-05 11:18:38 -07:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
|
|
|
|
use cosmic::{
|
2024-09-11 19:02:47 +02:00
|
|
|
iced::{Alignment, Background, Border, Length},
|
2024-01-05 11:18:38 -07:00
|
|
|
theme,
|
2024-09-11 19:02:47 +02:00
|
|
|
widget::{
|
2024-09-11 14:22:40 -06:00
|
|
|
self, button, column, container, divider, horizontal_space,
|
2024-09-11 19:02:47 +02:00
|
|
|
menu::{self, key_bind::KeyBind, ItemHeight, ItemWidth, MenuBar},
|
|
|
|
|
text, Row,
|
|
|
|
|
},
|
2024-01-05 11:18:38 -07:00
|
|
|
Element,
|
|
|
|
|
};
|
2024-08-15 12:32:12 -05:00
|
|
|
use mime_guess::Mime;
|
2024-01-29 12:21:54 -07:00
|
|
|
use std::collections::HashMap;
|
2024-01-05 11:18:38 -07:00
|
|
|
|
2024-02-01 15:14:14 -07:00
|
|
|
use crate::{
|
2024-02-13 12:29:50 -07:00
|
|
|
app::{Action, Message},
|
2024-03-16 00:52:32 -04:00
|
|
|
config::TabConfig,
|
2024-02-01 15:14:14 -07:00
|
|
|
fl,
|
2024-07-12 19:40:46 +02:00
|
|
|
tab::{self, HeadingOptions, Location, LocationMenuAction, Tab},
|
2024-02-01 15:14:14 -07:00
|
|
|
};
|
2024-01-05 11:18:38 -07:00
|
|
|
|
|
|
|
|
macro_rules! menu_button {
|
|
|
|
|
($($x:expr),+ $(,)?) => (
|
2024-09-11 19:02:47 +02:00
|
|
|
button(
|
|
|
|
|
Row::with_children(
|
2024-01-05 11:18:38 -07:00
|
|
|
vec![$(Element::from($x)),+]
|
|
|
|
|
)
|
2024-09-11 19:02:47 +02:00
|
|
|
.height(Length::Fixed(24.0))
|
2024-01-05 11:18:38 -07:00
|
|
|
.align_items(Alignment::Center)
|
|
|
|
|
)
|
2024-09-11 19:02:47 +02:00
|
|
|
.padding([theme::active().cosmic().spacing.space_xxxs, 16])
|
2024-01-05 11:18:38 -07:00
|
|
|
.width(Length::Fill)
|
|
|
|
|
.style(theme::Button::MenuItem)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 15:46:23 -07:00
|
|
|
pub fn context_menu<'a>(
|
|
|
|
|
tab: &Tab,
|
|
|
|
|
key_binds: &HashMap<KeyBind, Action>,
|
|
|
|
|
) -> Element<'a, tab::Message> {
|
|
|
|
|
let find_key = |action: &Action| -> String {
|
|
|
|
|
for (key_bind, key_action) in key_binds.iter() {
|
|
|
|
|
if action == key_action {
|
|
|
|
|
return key_bind.to_string();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String::new()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let menu_item = |label, action| {
|
|
|
|
|
let key = find_key(&action);
|
|
|
|
|
menu_button!(
|
2024-09-11 19:02:47 +02:00
|
|
|
text::body(label),
|
|
|
|
|
horizontal_space(Length::Fill),
|
|
|
|
|
text::body(key)
|
2024-02-28 15:46:23 -07:00
|
|
|
)
|
|
|
|
|
.on_press(tab::Message::ContextAction(action))
|
2024-01-05 11:18:38 -07:00
|
|
|
};
|
|
|
|
|
|
2024-03-16 00:52:32 -04:00
|
|
|
let TabConfig {
|
|
|
|
|
sort_name,
|
|
|
|
|
sort_direction,
|
|
|
|
|
..
|
|
|
|
|
} = tab.config;
|
|
|
|
|
let sort_item = |label, variant| {
|
|
|
|
|
menu_item(
|
|
|
|
|
format!(
|
|
|
|
|
"{} {}",
|
|
|
|
|
label,
|
|
|
|
|
match (sort_name == variant, sort_direction) {
|
|
|
|
|
(true, true) => "\u{2B07}",
|
|
|
|
|
(true, false) => "\u{2B06}",
|
|
|
|
|
_ => "",
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
Action::ToggleSort(variant),
|
|
|
|
|
)
|
|
|
|
|
.into()
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-04 10:28:16 -07:00
|
|
|
let mut selected_dir = 0;
|
|
|
|
|
let mut selected = 0;
|
2024-08-15 12:32:12 -05:00
|
|
|
let mut selected_types: Vec<Mime> = vec![];
|
2024-03-04 10:28:16 -07:00
|
|
|
tab.items_opt().map(|items| {
|
|
|
|
|
for item in items.iter() {
|
|
|
|
|
if item.selected {
|
|
|
|
|
selected += 1;
|
|
|
|
|
if item.metadata.is_dir() {
|
|
|
|
|
selected_dir += 1;
|
|
|
|
|
}
|
2024-08-15 12:32:12 -05:00
|
|
|
selected_types.push(item.mime.clone());
|
2024-03-04 10:28:16 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-08-15 12:32:12 -05:00
|
|
|
selected_types.sort_unstable();
|
|
|
|
|
selected_types.dedup();
|
2024-01-10 10:15:16 -07:00
|
|
|
|
|
|
|
|
let mut children: Vec<Element<_>> = Vec::new();
|
2024-08-20 13:26:10 -06:00
|
|
|
match (&tab.mode, &tab.location) {
|
|
|
|
|
(
|
|
|
|
|
tab::Mode::App | tab::Mode::Desktop,
|
|
|
|
|
Location::Path(_) | Location::Search(_, _) | Location::Recents,
|
|
|
|
|
) => {
|
2024-01-10 10:15:16 -07:00
|
|
|
if selected > 0 {
|
2024-06-30 10:05:58 -06:00
|
|
|
if selected_dir == 1 && selected == 1 || selected_dir == 0 {
|
|
|
|
|
children.push(menu_item(fl!("open"), Action::Open).into());
|
|
|
|
|
}
|
2024-03-01 16:10:30 -07:00
|
|
|
if selected == 1 {
|
|
|
|
|
children.push(menu_item(fl!("open-with"), Action::OpenWith).into());
|
2024-03-04 10:28:16 -07:00
|
|
|
if selected_dir == 1 {
|
|
|
|
|
children
|
|
|
|
|
.push(menu_item(fl!("open-in-terminal"), Action::OpenTerminal).into());
|
|
|
|
|
}
|
2024-03-01 16:10:30 -07:00
|
|
|
}
|
2024-08-19 09:15:28 -06:00
|
|
|
if matches!(tab.location, Location::Search(_, _)) {
|
|
|
|
|
children.push(
|
|
|
|
|
menu_item(fl!("open-item-location"), Action::OpenItemLocation).into(),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-06-30 10:05:58 -06:00
|
|
|
// All selected items are directories
|
|
|
|
|
if selected == selected_dir {
|
|
|
|
|
children.push(menu_item(fl!("open-in-new-tab"), Action::OpenInNewTab).into());
|
|
|
|
|
children
|
|
|
|
|
.push(menu_item(fl!("open-in-new-window"), Action::OpenInNewWindow).into());
|
|
|
|
|
}
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-02-28 15:46:23 -07:00
|
|
|
children.push(menu_item(fl!("rename"), Action::Rename).into());
|
|
|
|
|
children.push(menu_item(fl!("cut"), Action::Cut).into());
|
|
|
|
|
children.push(menu_item(fl!("copy"), Action::Copy).into());
|
2024-08-15 12:32:12 -05:00
|
|
|
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-09-10 11:50:14 -06:00
|
|
|
let supported_archive_types = [
|
2024-09-17 12:31:54 -06:00
|
|
|
"application/gzip",
|
2024-09-10 11:50:14 -06:00
|
|
|
"application/x-compressed-tar",
|
|
|
|
|
"application/x-tar",
|
|
|
|
|
"application/zip",
|
2024-09-17 12:31:54 -06:00
|
|
|
#[cfg(feature = "bzip2")]
|
|
|
|
|
"application/x-bzip",
|
|
|
|
|
#[cfg(feature = "bzip2")]
|
|
|
|
|
"application/x-bzip-compressed-tar",
|
|
|
|
|
#[cfg(feature = "liblzma")]
|
|
|
|
|
"application/x-xz",
|
|
|
|
|
#[cfg(feature = "liblzma")]
|
|
|
|
|
"application/x-xz-compressed-tar",
|
2024-09-10 11:50:14 -06:00
|
|
|
]
|
|
|
|
|
.iter()
|
|
|
|
|
.filter_map(|mime_type| mime_type.parse::<Mime>().ok())
|
|
|
|
|
.collect::<Vec<_>>();
|
2024-08-15 12:32:12 -05:00
|
|
|
selected_types.retain(|t| !supported_archive_types.contains(t));
|
|
|
|
|
if selected_types.is_empty() {
|
|
|
|
|
children.push(menu_item(fl!("extract-here"), Action::ExtractHere).into());
|
|
|
|
|
}
|
2024-09-05 17:34:03 -05:00
|
|
|
children.push(menu_item(fl!("compress"), Action::Compress).into());
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-08-15 12:32:12 -05:00
|
|
|
|
2024-02-28 15:46:23 -07:00
|
|
|
//TODO: Print?
|
2024-08-08 15:50:16 +02:00
|
|
|
children.push(menu_item(fl!("show-details"), Action::Properties).into());
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-05-09 12:48:33 -06:00
|
|
|
children.push(menu_item(fl!("add-to-sidebar"), Action::AddToSidebar).into());
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-02-28 15:46:23 -07:00
|
|
|
children.push(menu_item(fl!("move-to-trash"), Action::MoveToTrash).into());
|
|
|
|
|
} else {
|
|
|
|
|
//TODO: need better designs for menu with no selection
|
|
|
|
|
//TODO: have things like properties but they apply to the folder?
|
|
|
|
|
children.push(menu_item(fl!("new-folder"), Action::NewFolder).into());
|
2024-09-11 09:52:45 -06:00
|
|
|
children.push(menu_item(fl!("new-file"), Action::NewFile).into());
|
2024-03-04 10:28:16 -07:00
|
|
|
children.push(menu_item(fl!("open-in-terminal"), Action::OpenTerminal).into());
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-08-20 13:26:10 -06:00
|
|
|
if tab.mode.multiple() {
|
|
|
|
|
children.push(menu_item(fl!("select-all"), Action::SelectAll).into());
|
|
|
|
|
}
|
2024-02-28 15:46:23 -07:00
|
|
|
children.push(menu_item(fl!("paste"), Action::Paste).into());
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-03-16 00:52:32 -04:00
|
|
|
// TODO: Nested menu
|
|
|
|
|
children.push(sort_item(fl!("sort-by-name"), HeadingOptions::Name));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-modified"), HeadingOptions::Modified));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-size"), HeadingOptions::Size));
|
2024-01-10 10:15:16 -07:00
|
|
|
}
|
2024-01-10 09:47:47 -07:00
|
|
|
}
|
2024-08-20 13:26:10 -06:00
|
|
|
(
|
|
|
|
|
tab::Mode::Dialog(dialog_kind),
|
|
|
|
|
Location::Path(_) | Location::Search(_, _) | Location::Recents,
|
|
|
|
|
) => {
|
2024-01-10 10:15:16 -07:00
|
|
|
if selected > 0 {
|
2024-08-20 13:26:10 -06:00
|
|
|
if selected_dir == 1 && selected == 1 || selected_dir == 0 {
|
|
|
|
|
children.push(menu_item(fl!("open"), Action::Open).into());
|
|
|
|
|
}
|
|
|
|
|
if matches!(tab.location, Location::Search(_, _)) {
|
|
|
|
|
children.push(
|
|
|
|
|
menu_item(fl!("open-item-location"), Action::OpenItemLocation).into(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if dialog_kind.save() {
|
|
|
|
|
children.push(menu_item(fl!("new-folder"), Action::NewFolder).into());
|
|
|
|
|
}
|
|
|
|
|
if tab.mode.multiple() {
|
|
|
|
|
children.push(menu_item(fl!("select-all"), Action::SelectAll).into());
|
|
|
|
|
}
|
|
|
|
|
if !children.is_empty() {
|
|
|
|
|
children.push(divider::horizontal::light().into());
|
|
|
|
|
}
|
|
|
|
|
children.push(sort_item(fl!("sort-by-name"), HeadingOptions::Name));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-modified"), HeadingOptions::Modified));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-size"), HeadingOptions::Size));
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-13 15:13:37 -06:00
|
|
|
(_, Location::Network(_, _)) => {
|
2024-09-16 09:09:21 -06:00
|
|
|
if selected > 0 {
|
|
|
|
|
if selected_dir == 1 && selected == 1 || selected_dir == 0 {
|
|
|
|
|
children.push(menu_item(fl!("open"), Action::Open).into());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if tab.mode.multiple() {
|
|
|
|
|
children.push(menu_item(fl!("select-all"), Action::SelectAll).into());
|
|
|
|
|
}
|
|
|
|
|
if !children.is_empty() {
|
|
|
|
|
children.push(divider::horizontal::light().into());
|
|
|
|
|
}
|
|
|
|
|
children.push(sort_item(fl!("sort-by-name"), HeadingOptions::Name));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-modified"), HeadingOptions::Modified));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-size"), HeadingOptions::Size));
|
|
|
|
|
}
|
2024-09-12 15:54:54 -06:00
|
|
|
}
|
2024-08-20 13:26:10 -06:00
|
|
|
(_, Location::Trash) => {
|
|
|
|
|
if tab.mode.multiple() {
|
|
|
|
|
children.push(menu_item(fl!("select-all"), Action::SelectAll).into());
|
|
|
|
|
}
|
|
|
|
|
if !children.is_empty() {
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-08-20 13:26:10 -06:00
|
|
|
}
|
|
|
|
|
if selected > 0 {
|
2024-08-08 15:50:16 +02:00
|
|
|
children.push(menu_item(fl!("show-details"), Action::Properties).into());
|
2024-09-11 19:02:47 +02:00
|
|
|
children.push(divider::horizontal::light().into());
|
2024-01-10 10:15:16 -07:00
|
|
|
children
|
2024-02-28 15:46:23 -07:00
|
|
|
.push(menu_item(fl!("restore-from-trash"), Action::RestoreFromTrash).into());
|
2024-08-20 13:26:10 -06:00
|
|
|
} else {
|
|
|
|
|
// TODO: Nested menu
|
|
|
|
|
children.push(sort_item(fl!("sort-by-name"), HeadingOptions::Name));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-modified"), HeadingOptions::Modified));
|
|
|
|
|
children.push(sort_item(fl!("sort-by-size"), HeadingOptions::Size));
|
2024-01-10 10:15:16 -07:00
|
|
|
}
|
2024-01-05 11:18:38 -07:00
|
|
|
}
|
2024-01-10 10:15:16 -07:00
|
|
|
}
|
2024-01-10 09:47:47 -07:00
|
|
|
|
2024-09-11 19:02:47 +02:00
|
|
|
container(column::with_children(children))
|
2024-01-10 09:47:47 -07:00
|
|
|
.padding(1)
|
|
|
|
|
//TODO: move style to libcosmic
|
|
|
|
|
.style(theme::Container::custom(|theme| {
|
|
|
|
|
let cosmic = theme.cosmic();
|
|
|
|
|
let component = &cosmic.background.component;
|
2024-09-11 19:02:47 +02:00
|
|
|
container::Appearance {
|
2024-01-10 09:47:47 -07:00
|
|
|
icon_color: Some(component.on.into()),
|
|
|
|
|
text_color: Some(component.on.into()),
|
|
|
|
|
background: Some(Background::Color(component.base.into())),
|
2024-02-09 07:09:51 -07:00
|
|
|
border: Border {
|
|
|
|
|
radius: 8.0.into(),
|
|
|
|
|
width: 1.0,
|
|
|
|
|
color: component.divider.into(),
|
|
|
|
|
},
|
|
|
|
|
..Default::default()
|
2024-01-10 09:47:47 -07:00
|
|
|
}
|
|
|
|
|
}))
|
2024-06-30 10:13:35 -06:00
|
|
|
.width(Length::Fixed(260.0))
|
2024-01-10 09:47:47 -07:00
|
|
|
.into()
|
2024-01-05 11:18:38 -07:00
|
|
|
}
|
2024-01-10 11:39:04 -07:00
|
|
|
|
2024-09-11 14:22:40 -06:00
|
|
|
pub fn dialog_menu<'a>(
|
|
|
|
|
tab: &Tab,
|
|
|
|
|
key_binds: &HashMap<KeyBind, Action>,
|
|
|
|
|
) -> Element<'static, Message> {
|
|
|
|
|
let sort_item = |label, sort, dir| {
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
label,
|
|
|
|
|
tab.config.sort_name == sort && tab.config.sort_direction == dir,
|
|
|
|
|
Action::SetSort(sort, dir),
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MenuBar::new(vec![
|
|
|
|
|
menu::Tree::with_children(
|
|
|
|
|
widget::button::icon(widget::icon::from_name(match tab.config.view {
|
|
|
|
|
tab::View::Grid => "view-grid-symbolic",
|
|
|
|
|
tab::View::List => "view-list-symbolic",
|
|
|
|
|
})),
|
|
|
|
|
menu::items(
|
|
|
|
|
key_binds,
|
|
|
|
|
vec![
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
fl!("grid-view"),
|
|
|
|
|
matches!(tab.config.view, tab::View::Grid),
|
|
|
|
|
Action::TabViewGrid,
|
|
|
|
|
),
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
fl!("list-view"),
|
|
|
|
|
matches!(tab.config.view, tab::View::List),
|
|
|
|
|
Action::TabViewList,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
menu::Tree::with_children(
|
|
|
|
|
widget::button::icon(widget::icon::from_name(if tab.config.sort_direction {
|
|
|
|
|
"view-sort-ascending-symbolic"
|
|
|
|
|
} else {
|
|
|
|
|
"view-sort-descending-symbolic"
|
|
|
|
|
})),
|
|
|
|
|
menu::items(
|
|
|
|
|
key_binds,
|
|
|
|
|
vec![
|
|
|
|
|
sort_item(fl!("sort-a-z"), tab::HeadingOptions::Name, true),
|
|
|
|
|
sort_item(fl!("sort-z-a"), tab::HeadingOptions::Name, false),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-newest-first"),
|
|
|
|
|
tab::HeadingOptions::Modified,
|
|
|
|
|
false,
|
|
|
|
|
),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-oldest-first"),
|
|
|
|
|
tab::HeadingOptions::Modified,
|
|
|
|
|
true,
|
|
|
|
|
),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-smallest-to-largest"),
|
|
|
|
|
tab::HeadingOptions::Size,
|
|
|
|
|
true,
|
|
|
|
|
),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-largest-to-smallest"),
|
|
|
|
|
tab::HeadingOptions::Size,
|
|
|
|
|
false,
|
|
|
|
|
),
|
|
|
|
|
//TODO: sort by type
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
.item_height(ItemHeight::Dynamic(40))
|
|
|
|
|
.item_width(ItemWidth::Uniform(240))
|
|
|
|
|
.spacing(theme::active().cosmic().spacing.space_xxxs.into())
|
|
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 10:40:36 -06:00
|
|
|
pub fn menu_bar<'a>(
|
|
|
|
|
tab_opt: Option<&Tab>,
|
|
|
|
|
key_binds: &HashMap<KeyBind, Action>,
|
|
|
|
|
) -> Element<'a, Message> {
|
2024-09-11 13:29:00 -06:00
|
|
|
let sort_item = |label, sort, dir| {
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
label,
|
|
|
|
|
tab_opt.map_or(false, |tab| {
|
|
|
|
|
tab.config.sort_name == sort && tab.config.sort_direction == dir
|
|
|
|
|
}),
|
|
|
|
|
Action::SetSort(sort, dir),
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-10 11:39:04 -07:00
|
|
|
MenuBar::new(vec![
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Tree::with_children(
|
|
|
|
|
menu::root(fl!("file")),
|
|
|
|
|
menu::items(
|
2024-03-17 14:49:24 -07:00
|
|
|
key_binds,
|
|
|
|
|
vec![
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Item::Button(fl!("new-tab"), Action::TabNew),
|
|
|
|
|
menu::Item::Button(fl!("new-window"), Action::WindowNew),
|
|
|
|
|
menu::Item::Button(fl!("new-folder"), Action::NewFolder),
|
2024-09-11 09:52:45 -06:00
|
|
|
menu::Item::Button(fl!("new-file"), Action::NewFile),
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Item::Button(fl!("open"), Action::Open),
|
2024-08-08 15:50:16 +02:00
|
|
|
menu::Item::Button(fl!("open-with"), Action::OpenWith),
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::Button(fl!("rename"), Action::Rename),
|
2024-08-08 15:50:16 +02:00
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::Button(fl!("menu-show-details"), Action::Properties),
|
|
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::Button(fl!("add-to-sidebar"), Action::AddToSidebar),
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::Button(fl!("move-to-trash"), Action::MoveToTrash),
|
|
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::Button(fl!("close-tab"), Action::TabClose),
|
|
|
|
|
menu::Item::Button(fl!("quit"), Action::WindowClose),
|
2024-03-17 14:49:24 -07:00
|
|
|
],
|
|
|
|
|
),
|
2024-01-10 11:39:04 -07:00
|
|
|
),
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Tree::with_children(
|
|
|
|
|
menu::root(fl!("edit")),
|
|
|
|
|
menu::items(
|
2024-03-17 14:49:24 -07:00
|
|
|
key_binds,
|
|
|
|
|
vec![
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Item::Button(fl!("cut"), Action::Cut),
|
|
|
|
|
menu::Item::Button(fl!("copy"), Action::Copy),
|
|
|
|
|
menu::Item::Button(fl!("paste"), Action::Paste),
|
|
|
|
|
menu::Item::Button(fl!("select-all"), Action::SelectAll),
|
|
|
|
|
menu::Item::Divider,
|
2024-07-11 15:32:21 -06:00
|
|
|
menu::Item::Button(fl!("history"), Action::EditHistory),
|
2024-03-17 14:49:24 -07:00
|
|
|
],
|
|
|
|
|
),
|
2024-01-10 11:39:04 -07:00
|
|
|
),
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Tree::with_children(
|
|
|
|
|
menu::root(fl!("view")),
|
|
|
|
|
menu::items(
|
2024-03-17 14:49:24 -07:00
|
|
|
key_binds,
|
|
|
|
|
vec![
|
2024-05-28 10:40:36 -06:00
|
|
|
menu::Item::Button(fl!("zoom-in"), Action::ZoomIn),
|
|
|
|
|
menu::Item::Button(fl!("default-size"), Action::ZoomDefault),
|
|
|
|
|
menu::Item::Button(fl!("zoom-out"), Action::ZoomOut),
|
|
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
fl!("grid-view"),
|
2024-05-29 23:33:12 +02:00
|
|
|
tab_opt.map_or(false, |tab| matches!(tab.config.view, tab::View::Grid)),
|
2024-05-28 10:40:36 -06:00
|
|
|
Action::TabViewGrid,
|
|
|
|
|
),
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
fl!("list-view"),
|
2024-05-29 23:33:12 +02:00
|
|
|
tab_opt.map_or(false, |tab| matches!(tab.config.view, tab::View::List)),
|
2024-05-28 10:40:36 -06:00
|
|
|
Action::TabViewList,
|
|
|
|
|
),
|
|
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
fl!("show-hidden-files"),
|
|
|
|
|
tab_opt.map_or(false, |tab| tab.config.show_hidden),
|
|
|
|
|
Action::ToggleShowHidden,
|
|
|
|
|
),
|
|
|
|
|
menu::Item::CheckBox(
|
|
|
|
|
fl!("list-directories-first"),
|
|
|
|
|
tab_opt.map_or(false, |tab| tab.config.folders_first),
|
|
|
|
|
Action::ToggleFoldersFirst,
|
|
|
|
|
),
|
2024-04-22 23:14:44 +02:00
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::Button(fl!("menu-settings"), Action::Settings),
|
|
|
|
|
menu::Item::Divider,
|
|
|
|
|
menu::Item::Button(fl!("menu-about"), Action::About),
|
2024-03-17 14:49:24 -07:00
|
|
|
],
|
|
|
|
|
),
|
2024-01-10 11:39:04 -07:00
|
|
|
),
|
2024-09-11 13:29:00 -06:00
|
|
|
menu::Tree::with_children(
|
|
|
|
|
menu::root(fl!("sort")),
|
|
|
|
|
menu::items(
|
|
|
|
|
key_binds,
|
|
|
|
|
vec![
|
|
|
|
|
sort_item(fl!("sort-a-z"), tab::HeadingOptions::Name, true),
|
|
|
|
|
sort_item(fl!("sort-z-a"), tab::HeadingOptions::Name, false),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-newest-first"),
|
|
|
|
|
tab::HeadingOptions::Modified,
|
|
|
|
|
false,
|
|
|
|
|
),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-oldest-first"),
|
|
|
|
|
tab::HeadingOptions::Modified,
|
|
|
|
|
true,
|
|
|
|
|
),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-smallest-to-largest"),
|
|
|
|
|
tab::HeadingOptions::Size,
|
|
|
|
|
true,
|
|
|
|
|
),
|
|
|
|
|
sort_item(
|
|
|
|
|
fl!("sort-largest-to-smallest"),
|
|
|
|
|
tab::HeadingOptions::Size,
|
|
|
|
|
false,
|
|
|
|
|
),
|
|
|
|
|
//TODO: sort by type
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-01-10 11:39:04 -07:00
|
|
|
])
|
|
|
|
|
.item_height(ItemHeight::Dynamic(40))
|
|
|
|
|
.item_width(ItemWidth::Uniform(240))
|
2024-09-11 19:02:47 +02:00
|
|
|
.spacing(theme::active().cosmic().spacing.space_xxxs.into())
|
2024-01-10 11:39:04 -07:00
|
|
|
.into()
|
|
|
|
|
}
|
2024-06-30 10:05:58 -06:00
|
|
|
|
|
|
|
|
pub fn location_context_menu<'a>(ancestor_index: usize) -> Element<'a, tab::Message> {
|
|
|
|
|
let children = vec![
|
2024-09-11 19:02:47 +02:00
|
|
|
menu_button!(text::body(fl!("open-in-new-tab")))
|
2024-06-30 10:05:58 -06:00
|
|
|
.on_press(tab::Message::LocationMenuAction(
|
|
|
|
|
LocationMenuAction::OpenInNewTab(ancestor_index),
|
|
|
|
|
))
|
|
|
|
|
.into(),
|
2024-09-11 19:02:47 +02:00
|
|
|
menu_button!(text::body(fl!("open-in-new-window")))
|
2024-06-30 10:05:58 -06:00
|
|
|
.on_press(tab::Message::LocationMenuAction(
|
|
|
|
|
LocationMenuAction::OpenInNewWindow(ancestor_index),
|
|
|
|
|
))
|
|
|
|
|
.into(),
|
2024-09-11 19:02:47 +02:00
|
|
|
divider::horizontal::light().into(),
|
|
|
|
|
menu_button!(text::body(fl!("show-details")))
|
2024-06-30 13:33:44 -06:00
|
|
|
.on_press(tab::Message::LocationMenuAction(
|
|
|
|
|
LocationMenuAction::Properties(ancestor_index),
|
|
|
|
|
))
|
|
|
|
|
.into(),
|
2024-06-30 10:05:58 -06:00
|
|
|
];
|
|
|
|
|
|
2024-09-11 19:02:47 +02:00
|
|
|
container(column::with_children(children))
|
2024-06-30 10:05:58 -06:00
|
|
|
.padding(1)
|
|
|
|
|
.style(theme::Container::custom(|theme| {
|
|
|
|
|
let cosmic = theme.cosmic();
|
|
|
|
|
let component = &cosmic.background.component;
|
2024-09-11 19:02:47 +02:00
|
|
|
container::Appearance {
|
2024-06-30 10:05:58 -06:00
|
|
|
icon_color: Some(component.on.into()),
|
|
|
|
|
text_color: Some(component.on.into()),
|
|
|
|
|
background: Some(Background::Color(component.base.into())),
|
|
|
|
|
border: Border {
|
|
|
|
|
radius: 8.0.into(),
|
|
|
|
|
width: 1.0,
|
|
|
|
|
color: component.divider.into(),
|
|
|
|
|
},
|
|
|
|
|
..Default::default()
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
.width(Length::Fixed(240.0))
|
|
|
|
|
.into()
|
|
|
|
|
}
|