Put default app first in open with list

This commit is contained in:
Jeremy Soller 2024-03-04 11:30:51 -07:00
parent 3e1e6b090e
commit a4efff3873
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
3 changed files with 17 additions and 4 deletions

View file

@ -51,6 +51,10 @@ pending = Pending
failed = Failed
complete = Complete
## Open with
open-with = Open with
default-app = {$name} (default)
## Properties
properties = Properties
@ -71,7 +75,6 @@ light = Light
# Context menu
new-file = New file
new-folder = New folder
open-with = Open with
open-in-terminal = Open in terminal
move-to-trash = Move to trash
restore-from-trash = Restore from trash

View file

@ -6,7 +6,9 @@ use cosmic::desktop;
use cosmic::widget;
pub use mime_guess::Mime;
use once_cell::sync::Lazy;
use std::{collections::HashMap, path::PathBuf, process, sync::Mutex, time::Instant};
use std::{
cmp::Ordering, collections::HashMap, path::PathBuf, process, sync::Mutex, time::Instant,
};
#[derive(Clone, Debug)]
pub struct MimeApp {
@ -218,7 +220,11 @@ impl MimeAppCache {
// Sort apps by name
for apps in self.cache.values_mut() {
apps.sort_by(|a, b| lexical_sort::natural_lexical_cmp(&a.name, &b.name));
apps.sort_by(|a, b| match (a.is_default, b.is_default) {
(true, false) => Ordering::Less,
(false, true) => Ordering::Greater,
_ => lexical_sort::natural_lexical_cmp(&a.name, &b.name),
});
}
let elapsed = start.elapsed();

View file

@ -525,7 +525,11 @@ impl Item {
widget::button(
widget::row::with_children(vec![
widget::icon(app.icon.clone()).into(),
widget::text(&app.name).into(),
if app.is_default {
widget::text(fl!("default-app", name = app.name.as_str())).into()
} else {
widget::text(&app.name).into()
},
])
.spacing(space_xs),
)