feat: add open-with in multi preview
Adds the ability to set the open-with setting for multiple selected items. This setting will only appear if all selected items have the same mime type.
This commit is contained in:
parent
e50c41aa24
commit
17325a5f5a
3 changed files with 43 additions and 3 deletions
|
|
@ -2010,7 +2010,7 @@ impl App {
|
|||
|
||||
match (selected.next(), selected.next()) {
|
||||
// At least two selected items
|
||||
(Some(_), Some(_)) => Some(tab.multi_preview_view()),
|
||||
(Some(_), Some(_)) => Some(tab.multi_preview_view(Some(&self.mime_app_cache))),
|
||||
// Exactly one selected item
|
||||
(Some(item), None) => {
|
||||
Some(item.preview_view(Some(&self.mime_app_cache), military_time))
|
||||
|
|
|
|||
|
|
@ -717,7 +717,7 @@ impl App {
|
|||
|
||||
match (selected.next(), selected.next()) {
|
||||
// At least two selected items
|
||||
(Some(_), Some(_)) => Some(self.tab.multi_preview_view()),
|
||||
(Some(_), Some(_)) => Some(self.tab.multi_preview_view(None)),
|
||||
// Exactly one selected item
|
||||
(Some(item), None) => Some(item.preview_view(None, military_time)),
|
||||
// No selected items
|
||||
|
|
|
|||
42
src/tab.rs
42
src/tab.rs
|
|
@ -6248,7 +6248,10 @@ impl Tab {
|
|||
|
||||
dnd_dest.into()
|
||||
}
|
||||
pub fn multi_preview_view<'a>(&'a self) -> Element<'a, Message> {
|
||||
pub fn multi_preview_view<'a>(
|
||||
&'a self,
|
||||
mime_app_cache_opt: Option<&'a mime_app::MimeAppCache>,
|
||||
) -> Element<'a, Message> {
|
||||
let cosmic_theme::Spacing {
|
||||
space_xxxs,
|
||||
space_m,
|
||||
|
|
@ -6362,6 +6365,43 @@ impl Tab {
|
|||
|
||||
column = column.push(widget::button::standard(fl!("open")).on_press(Message::Open(None)));
|
||||
|
||||
let mut settings = Vec::new();
|
||||
if mime_types.len() == 1 {
|
||||
if let Some(mime) = mime_types
|
||||
.get(0)
|
||||
.and_then(|(mime, _)| mime.parse::<Mime>().ok())
|
||||
{
|
||||
if let Some(mime_app_cache) = mime_app_cache_opt {
|
||||
let mime_apps = mime_app_cache.get(&mime);
|
||||
if !mime_apps.is_empty() {
|
||||
let mime_closure = mime.clone();
|
||||
settings.push(
|
||||
widget::settings::item::builder(fl!("open-with")).control(
|
||||
Element::from(
|
||||
widget::dropdown(
|
||||
mime_apps,
|
||||
mime_apps.iter().position(|x| x.is_default),
|
||||
move |index| (index, mime_closure.clone()),
|
||||
)
|
||||
.icons(Cow::Borrowed(mime_app_cache.icons(&mime))),
|
||||
)
|
||||
.map(|(index, mime)| {
|
||||
let mime_app = &mime_apps[index];
|
||||
Message::SetOpenWith(mime, mime_app.id.clone())
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !settings.is_empty() {
|
||||
let mut section = widget::settings::section();
|
||||
section = section.extend(settings);
|
||||
column = column.push(section);
|
||||
}
|
||||
|
||||
column.into()
|
||||
}
|
||||
pub fn view<'a>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue