Merge remote-tracking branch 'upstream/master' into auth-dialog-submit
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
commit
16d6316118
52 changed files with 2139 additions and 1113 deletions
519
src/app.rs
519
src/app.rs
File diff suppressed because it is too large
Load diff
|
|
@ -28,6 +28,8 @@ impl ClipboardCopy {
|
|||
pub fn new<P: AsRef<Path>>(kind: ClipboardKind, paths: &[P]) -> Self {
|
||||
let available = vec![
|
||||
"text/plain".to_string(),
|
||||
"text/plain;charset=utf-8".to_string(),
|
||||
"UTF8_STRING".to_string(),
|
||||
"text/uri-list".to_string(),
|
||||
"x-special/gnome-copied-files".to_string(),
|
||||
];
|
||||
|
|
@ -94,7 +96,9 @@ impl AsMimeTypes for ClipboardCopy {
|
|||
|
||||
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>> {
|
||||
match mime_type {
|
||||
"text/plain" => Some(self.text_plain.clone()),
|
||||
"text/plain" | "text/plain;charset=utf-8" | "UTF8_STRING" => {
|
||||
Some(self.text_plain.clone())
|
||||
}
|
||||
"text/uri-list" => Some(self.text_uri_list.clone()),
|
||||
"x-special/gnome-copied-files" => Some(self.x_special_gnome_copied_files.clone()),
|
||||
_ => None,
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ impl Favorite {
|
|||
Self::Videos,
|
||||
] {
|
||||
if let Some(favorite_path) = favorite.path_opt() {
|
||||
if &favorite_path == &path {
|
||||
if favorite_path == path {
|
||||
return favorite.clone();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
109
src/dialog.rs
109
src/dialog.rs
|
|
@ -157,13 +157,15 @@ impl<M: Send + 'static> Dialog<M> {
|
|||
|
||||
let (config_handler, config) = Config::load();
|
||||
|
||||
let mut settings = window::Settings::default();
|
||||
settings.decorations = false;
|
||||
settings.exit_on_close_request = false;
|
||||
settings.min_size = Some(Size::new(360.0, 180.0));
|
||||
settings.resizable = true;
|
||||
settings.size = Size::new(1024.0, 640.0);
|
||||
settings.transparent = true;
|
||||
let mut settings = window::Settings {
|
||||
decorations: false,
|
||||
exit_on_close_request: false,
|
||||
min_size: Some(Size::new(360.0, 180.0)),
|
||||
resizable: true,
|
||||
size: Size::new(1024.0, 640.0),
|
||||
transparent: true,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
|
|
@ -251,7 +253,8 @@ impl<M: Send + 'static> Dialog<M> {
|
|||
self.cosmic
|
||||
.subscription()
|
||||
.map(DialogMessage)
|
||||
.map(self.mapper)
|
||||
.with(self.mapper)
|
||||
.map(|(mapper, message)| mapper(message))
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: DialogMessage) -> Task<M> {
|
||||
|
|
@ -295,6 +298,7 @@ struct Flags {
|
|||
kind: DialogKind,
|
||||
path_opt: Option<PathBuf>,
|
||||
window_id: window::Id,
|
||||
#[allow(dead_code)]
|
||||
config_handler: Option<cosmic_config::Config>,
|
||||
config: Config,
|
||||
}
|
||||
|
|
@ -323,6 +327,7 @@ enum Message {
|
|||
SearchActivate,
|
||||
SearchClear,
|
||||
SearchInput(String),
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
TabMessage(tab::Message),
|
||||
TabRescan(Location, Option<tab::Item>, Vec<tab::Item>),
|
||||
TabView(tab::View),
|
||||
|
|
@ -344,6 +349,7 @@ impl From<AppMessage> for Message {
|
|||
AppMessage::ZoomDefault(_entity_opt) => Message::ZoomDefault,
|
||||
AppMessage::ZoomIn(_entity_opt) => Message::ZoomIn,
|
||||
AppMessage::ZoomOut(_entity_opt) => Message::ZoomOut,
|
||||
AppMessage::NewItem(_entity_opt, true) => Message::NewFolder,
|
||||
unsupported => {
|
||||
log::warn!("{unsupported:?} not supported in dialog mode");
|
||||
Message::None
|
||||
|
|
@ -465,17 +471,17 @@ impl App {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn preview<'a>(&'a self, kind: &'a PreviewKind) -> Element<'a, AppMessage> {
|
||||
fn preview<'a>(&'a self, kind: &'a PreviewKind) -> Element<'a, tab::Message> {
|
||||
let mut children = Vec::with_capacity(1);
|
||||
match kind {
|
||||
PreviewKind::Custom(PreviewItem(item)) => {
|
||||
children.push(item.preview_view(IconSizes::default()));
|
||||
children.push(item.preview_view(None, IconSizes::default()));
|
||||
}
|
||||
PreviewKind::Location(location) => {
|
||||
if let Some(items) = self.tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.location_opt.as_ref() == Some(location) {
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes));
|
||||
children.push(item.preview_view(None, self.tab.config.icon_sizes));
|
||||
// Only show one property view to avoid issues like hangs when generating
|
||||
// preview images on thousands of files
|
||||
break;
|
||||
|
|
@ -487,7 +493,7 @@ impl App {
|
|||
if let Some(items) = self.tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes));
|
||||
children.push(item.preview_view(None, self.tab.config.icon_sizes));
|
||||
// Only show one property view to avoid issues like hangs when generating
|
||||
// preview images on thousands of files
|
||||
break;
|
||||
|
|
@ -495,7 +501,7 @@ impl App {
|
|||
}
|
||||
if children.is_empty() {
|
||||
if let Some(item) = &self.tab.parent_item_opt {
|
||||
children.push(item.preview_view(self.tab.config.icon_sizes));
|
||||
children.push(item.preview_view(None, self.tab.config.icon_sizes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -596,7 +602,7 @@ impl App {
|
|||
.data(Location::Recents)
|
||||
});
|
||||
|
||||
for (_favorite_i, favorite) in self.flags.config.favorites.iter().enumerate() {
|
||||
for favorite in self.flags.config.favorites.iter() {
|
||||
if let Some(path) = favorite.path_opt() {
|
||||
let name = if matches!(favorite, Favorite::Home) {
|
||||
fl!("home")
|
||||
|
|
@ -808,14 +814,14 @@ impl Application for App {
|
|||
actions.extend(
|
||||
item.preview_header()
|
||||
.into_iter()
|
||||
.map(|element| element.map(Message::from)),
|
||||
.map(|element| element.map(Message::TabMessage)),
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
Some(
|
||||
context_drawer::context_drawer(
|
||||
self.preview(kind).map(Message::from),
|
||||
self.preview(kind).map(Message::TabMessage),
|
||||
Message::Preview,
|
||||
)
|
||||
.header_actions(actions),
|
||||
|
|
@ -972,11 +978,8 @@ impl Application for App {
|
|||
ContextPage::Preview(..) => self.core.window.show_context,
|
||||
_ => false,
|
||||
};
|
||||
elements.push(
|
||||
menu::dialog_menu(&self.tab, &self.key_binds, show_details)
|
||||
.map(Message::from)
|
||||
.into(),
|
||||
);
|
||||
elements
|
||||
.push(menu::dialog_menu(&self.tab, &self.key_binds, show_details).map(Message::from));
|
||||
|
||||
elements
|
||||
}
|
||||
|
|
@ -1025,7 +1028,7 @@ impl Application for App {
|
|||
return self.update(message);
|
||||
}
|
||||
|
||||
if let Some(data) = self.nav_model.data::<MounterData>(entity).clone() {
|
||||
if let Some(data) = self.nav_model.data::<MounterData>(entity) {
|
||||
if let Some(mounter) = MOUNTERS.get(&data.0) {
|
||||
return mounter.mount(data.1.clone()).map(|_| message::none());
|
||||
}
|
||||
|
|
@ -1167,11 +1170,9 @@ impl Application for App {
|
|||
let mut still_mounted = false;
|
||||
for item in mounter_items.iter() {
|
||||
if let Some(path) = item.path() {
|
||||
if path == old_path {
|
||||
if item.is_mounted() {
|
||||
still_mounted = true;
|
||||
break;
|
||||
}
|
||||
if path == old_path && item.is_mounted() {
|
||||
still_mounted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1219,7 +1220,7 @@ impl Application for App {
|
|||
let mut contains_change = false;
|
||||
for event in events.iter() {
|
||||
for event_path in event.paths.iter() {
|
||||
if event_path.starts_with(&path) {
|
||||
if event_path.starts_with(path) {
|
||||
match event.kind {
|
||||
notify::EventKind::Modify(
|
||||
notify::event::ModifyKind::Metadata(_),
|
||||
|
|
@ -1233,14 +1234,14 @@ impl Application for App {
|
|||
for item in items.iter_mut() {
|
||||
if item.path_opt() == Some(event_path) {
|
||||
//TODO: reload more, like mime types?
|
||||
match fs::metadata(&event_path) {
|
||||
match fs::metadata(event_path) {
|
||||
Ok(new_metadata) => {
|
||||
match &mut item.metadata {
|
||||
ItemMetadata::Path {
|
||||
metadata,
|
||||
..
|
||||
} => *metadata = new_metadata,
|
||||
_ => {}
|
||||
if let ItemMetadata::Path {
|
||||
metadata,
|
||||
..
|
||||
} = &mut item.metadata
|
||||
{
|
||||
*metadata = new_metadata;
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
|
|
@ -1320,12 +1321,9 @@ impl Application for App {
|
|||
|
||||
// If we are in directory mode, return the current directory
|
||||
if self.flags.kind.is_dir() {
|
||||
match &self.tab.location {
|
||||
Location::Path(tab_path) => {
|
||||
self.result_opt = Some(DialogResult::Open(vec![tab_path.clone()]));
|
||||
return window::close(self.flags.window_id);
|
||||
}
|
||||
_ => {}
|
||||
if let Location::Path(tab_path) = &self.tab.location {
|
||||
self.result_opt = Some(DialogResult::Open(vec![tab_path.clone()]));
|
||||
return window::close(self.flags.window_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1342,7 +1340,7 @@ impl Application for App {
|
|||
if let DialogKind::SaveFile { filename } = &self.flags.kind {
|
||||
if !filename.is_empty() {
|
||||
if let Some(tab_path) = self.tab.location.path_opt() {
|
||||
let path = tab_path.join(&filename);
|
||||
let path = tab_path.join(filename);
|
||||
if path.is_dir() {
|
||||
// cd to directory
|
||||
let message = Message::TabMessage(tab::Message::Location(
|
||||
|
|
@ -1590,11 +1588,7 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
|
||||
col = col.push(
|
||||
self.tab
|
||||
.view(&self.key_binds)
|
||||
.map(move |message| Message::TabMessage(message)),
|
||||
);
|
||||
col = col.push(self.tab.view(&self.key_binds).map(Message::TabMessage));
|
||||
|
||||
col.into()
|
||||
}
|
||||
|
|
@ -1708,16 +1702,17 @@ impl Application for App {
|
|||
];
|
||||
|
||||
for (key, mounter) in MOUNTERS.iter() {
|
||||
let key = *key;
|
||||
subscriptions.push(mounter.subscription().map(move |mounter_message| {
|
||||
match mounter_message {
|
||||
MounterMessage::Items(items) => Message::MounterItems(key, items),
|
||||
_ => {
|
||||
log::warn!("{:?} not supported in dialog mode", mounter_message);
|
||||
Message::None
|
||||
}
|
||||
}
|
||||
}));
|
||||
subscriptions.push(
|
||||
mounter.subscription().with(*key).map(
|
||||
|(key, mounter_message)| match mounter_message {
|
||||
MounterMessage::Items(items) => Message::MounterItems(key, items),
|
||||
_ => {
|
||||
log::warn!("{:?} not supported in dialog mode", mounter_message);
|
||||
Message::None
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Subscription::batch(subscriptions)
|
||||
|
|
|
|||
|
|
@ -29,10 +29,14 @@ pub fn key_binds(mode: &tab::Mode) -> HashMap<KeyBind, Action> {
|
|||
bind!([], Key::Named(Named::ArrowLeft), ItemLeft);
|
||||
bind!([], Key::Named(Named::ArrowRight), ItemRight);
|
||||
bind!([], Key::Named(Named::ArrowUp), ItemUp);
|
||||
bind!([], Key::Named(Named::Home), SelectFirst);
|
||||
bind!([], Key::Named(Named::End), SelectLast);
|
||||
bind!([Shift], Key::Named(Named::ArrowDown), ItemDown);
|
||||
bind!([Shift], Key::Named(Named::ArrowLeft), ItemLeft);
|
||||
bind!([Shift], Key::Named(Named::ArrowRight), ItemRight);
|
||||
bind!([Shift], Key::Named(Named::ArrowUp), ItemUp);
|
||||
bind!([Shift], Key::Named(Named::Home), SelectFirst);
|
||||
bind!([Shift], Key::Named(Named::End), SelectLast);
|
||||
bind!([Ctrl, Shift], Key::Character("n".into()), NewFolder);
|
||||
bind!([], Key::Named(Named::Enter), Open);
|
||||
bind!([Ctrl], Key::Named(Named::Space), Preview);
|
||||
|
|
|
|||
15
src/lib.rs
15
src/lib.rs
|
|
@ -98,10 +98,21 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
} else if &arg == "--trash" {
|
||||
Location::Trash
|
||||
} else {
|
||||
match fs::canonicalize(&arg) {
|
||||
//TODO: support more URLs
|
||||
let path = match url::Url::parse(&arg) {
|
||||
Ok(url) => match url.to_file_path() {
|
||||
Ok(path) => path,
|
||||
Err(()) => {
|
||||
log::warn!("invalid argument {:?}", arg);
|
||||
continue;
|
||||
}
|
||||
},
|
||||
Err(_) => PathBuf::from(arg),
|
||||
};
|
||||
match fs::canonicalize(&path) {
|
||||
Ok(absolute) => Location::Path(absolute),
|
||||
Err(err) => {
|
||||
log::warn!("failed to canonicalize {:?}: {}", arg, err);
|
||||
log::warn!("failed to canonicalize {:?}: {}", path, err);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
src/menu.rs
28
src/menu.rs
|
|
@ -89,7 +89,7 @@ pub fn context_menu<'a>(
|
|||
let mut selected_trash_only = false;
|
||||
let mut selected_desktop_entry = None;
|
||||
let mut selected_types: Vec<Mime> = vec![];
|
||||
tab.items_opt().map(|items| {
|
||||
if let Some(items) = tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
selected += 1;
|
||||
|
|
@ -110,7 +110,7 @@ pub fn context_menu<'a>(
|
|||
selected_types.push(item.mime.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
selected_types.sort_unstable();
|
||||
selected_types.dedup();
|
||||
selected_trash_only = selected_trash_only && selected == 1;
|
||||
|
|
@ -157,13 +157,13 @@ pub fn context_menu<'a>(
|
|||
children.push(menu_item(fl!("open"), Action::Open).into());
|
||||
}
|
||||
if selected == 1 {
|
||||
children.push(menu_item(fl!("open-with"), Action::OpenWith).into());
|
||||
children.push(menu_item(fl!("menu-open-with"), Action::OpenWith).into());
|
||||
if selected_dir == 1 {
|
||||
children
|
||||
.push(menu_item(fl!("open-in-terminal"), Action::OpenTerminal).into());
|
||||
}
|
||||
}
|
||||
if matches!(tab.location, Location::Search(..)) {
|
||||
if matches!(tab.location, Location::Search(..) | Location::Recents) {
|
||||
children.push(
|
||||
menu_item(fl!("open-item-location"), Action::OpenItemLocation).into(),
|
||||
);
|
||||
|
|
@ -260,7 +260,7 @@ pub fn context_menu<'a>(
|
|||
if selected_dir == 1 && selected == 1 || selected_dir == 0 {
|
||||
children.push(menu_item(fl!("open"), Action::Open).into());
|
||||
}
|
||||
if matches!(tab.location, Location::Search(..)) {
|
||||
if matches!(tab.location, Location::Search(..) | Location::Recents) {
|
||||
children.push(
|
||||
menu_item(fl!("open-item-location"), Action::OpenItemLocation).into(),
|
||||
);
|
||||
|
|
@ -342,7 +342,7 @@ pub fn context_menu<'a>(
|
|||
.into()
|
||||
}
|
||||
|
||||
pub fn dialog_menu<'a>(
|
||||
pub fn dialog_menu(
|
||||
tab: &Tab,
|
||||
key_binds: &HashMap<KeyBind, Action>,
|
||||
show_details: bool,
|
||||
|
|
@ -359,15 +359,13 @@ pub fn dialog_menu<'a>(
|
|||
let in_trash = tab.location == Location::Trash;
|
||||
|
||||
let mut selected_gallery = 0;
|
||||
tab.items_opt().map(|items| {
|
||||
if let Some(items) = tab.items_opt() {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
if item.can_gallery() {
|
||||
selected_gallery += 1;
|
||||
}
|
||||
if item.selected && item.can_gallery() {
|
||||
selected_gallery += 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
MenuBar::new(vec![
|
||||
menu::Tree::with_children(
|
||||
|
|
@ -504,7 +502,7 @@ pub fn menu_bar<'a>(
|
|||
let mut selected_dir = 0;
|
||||
let mut selected = 0;
|
||||
let mut selected_gallery = 0;
|
||||
tab_opt.and_then(|tab| tab.items_opt()).map(|items| {
|
||||
if let Some(items) = tab_opt.and_then(|tab| tab.items_opt()) {
|
||||
for item in items.iter() {
|
||||
if item.selected {
|
||||
selected += 1;
|
||||
|
|
@ -516,7 +514,7 @@ pub fn menu_bar<'a>(
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
MenuBar::new(vec![
|
||||
menu::Tree::with_children(
|
||||
|
|
@ -533,7 +531,7 @@ pub fn menu_bar<'a>(
|
|||
Action::Open,
|
||||
(selected > 0 && selected_dir == 0) || (selected_dir == 1 && selected == 1),
|
||||
),
|
||||
menu_button_optional(fl!("open-with"), Action::OpenWith, selected == 1),
|
||||
menu_button_optional(fl!("menu-open-with"), Action::OpenWith, selected == 1),
|
||||
menu::Item::Divider,
|
||||
menu_button_optional(fl!("rename"), Action::Rename, selected > 0),
|
||||
menu::Item::Divider,
|
||||
|
|
|
|||
120
src/mime_app.rs
120
src/mime_app.rs
|
|
@ -5,9 +5,8 @@
|
|||
use cosmic::desktop;
|
||||
use cosmic::widget;
|
||||
pub use mime_guess::Mime;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::{
|
||||
cmp::Ordering, collections::HashMap, env, ffi::OsString, path::PathBuf, process, sync::Mutex,
|
||||
cmp::Ordering, collections::HashMap, env, ffi::OsString, fs, io, path::PathBuf, process,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
|
|
@ -52,6 +51,13 @@ impl MimeApp {
|
|||
}
|
||||
}
|
||||
|
||||
// This allows usage of MimeApp in a dropdown
|
||||
impl AsRef<str> for MimeApp {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
impl From<&desktop::DesktopEntryData> for MimeApp {
|
||||
fn from(app: &desktop::DesktopEntryData) -> Self {
|
||||
|
|
@ -82,6 +88,7 @@ fn filename_eq(path_opt: &Option<PathBuf>, filename: &str) -> bool {
|
|||
|
||||
pub struct MimeAppCache {
|
||||
cache: HashMap<Mime, Vec<MimeApp>>,
|
||||
icons: HashMap<Mime, Vec<widget::icon::Handle>>,
|
||||
terminals: Vec<MimeApp>,
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +96,7 @@ impl MimeAppCache {
|
|||
pub fn new() -> Self {
|
||||
let mut mime_app_cache = Self {
|
||||
cache: HashMap::new(),
|
||||
icons: HashMap::new(),
|
||||
terminals: Vec::new(),
|
||||
};
|
||||
mime_app_cache.reload();
|
||||
|
|
@ -106,6 +114,7 @@ impl MimeAppCache {
|
|||
let start = Instant::now();
|
||||
|
||||
self.cache.clear();
|
||||
self.icons.clear();
|
||||
self.terminals.clear();
|
||||
|
||||
//TODO: get proper locale?
|
||||
|
|
@ -120,7 +129,7 @@ impl MimeAppCache {
|
|||
.cache
|
||||
.entry(mime.clone())
|
||||
.or_insert_with(|| Vec::with_capacity(1));
|
||||
if apps.iter().find(|x| x.id == app.id).is_none() {
|
||||
if !apps.iter().any(|x| x.id == app.id) {
|
||||
apps.push(MimeApp::from(app));
|
||||
}
|
||||
}
|
||||
|
|
@ -191,11 +200,7 @@ impl MimeAppCache {
|
|||
.cache
|
||||
.entry(mime.clone())
|
||||
.or_insert_with(|| Vec::with_capacity(1));
|
||||
if apps
|
||||
.iter()
|
||||
.find(|x| filename_eq(&x.path, filename))
|
||||
.is_none()
|
||||
{
|
||||
if !apps.iter().any(|x| filename_eq(&x.path, filename)) {
|
||||
if let Some(app) =
|
||||
all_apps.iter().find(|x| filename_eq(&x.path, filename))
|
||||
{
|
||||
|
|
@ -258,39 +263,94 @@ impl MimeAppCache {
|
|||
});
|
||||
}
|
||||
|
||||
// Copy icons to special cache
|
||||
//TODO: adjust dropdown API so this is no longer needed
|
||||
for (mime, apps) in self.cache.iter() {
|
||||
self.icons.insert(
|
||||
mime.clone(),
|
||||
apps.iter().map(|app| app.icon.clone()).collect(),
|
||||
);
|
||||
}
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
log::info!("loaded mime app cache in {:?}", elapsed);
|
||||
}
|
||||
|
||||
pub fn get(&self, key: &Mime) -> Vec<MimeApp> {
|
||||
self.cache
|
||||
.get(&key)
|
||||
.map_or_else(|| Vec::new(), |x| x.clone())
|
||||
pub fn get(&self, key: &Mime) -> &[MimeApp] {
|
||||
static EMPTY: Vec<MimeApp> = Vec::new();
|
||||
self.cache.get(key).unwrap_or(&EMPTY)
|
||||
}
|
||||
}
|
||||
|
||||
static MIME_APP_CACHE: Lazy<Mutex<MimeAppCache>> = Lazy::new(|| Mutex::new(MimeAppCache::new()));
|
||||
pub fn icons(&self, key: &Mime) -> &[widget::icon::Handle] {
|
||||
static EMPTY: Vec<widget::icon::Handle> = Vec::new();
|
||||
self.icons.get(key).unwrap_or(&EMPTY)
|
||||
}
|
||||
|
||||
pub fn mime_apps(mime: &Mime) -> Vec<MimeApp> {
|
||||
let mime_app_cache = MIME_APP_CACHE.lock().unwrap();
|
||||
mime_app_cache.get(mime)
|
||||
}
|
||||
pub fn terminal(&self) -> Option<&MimeApp> {
|
||||
//TODO: consider rules in https://github.com/Vladimir-csp/xdg-terminal-exec
|
||||
|
||||
pub fn terminal() -> Option<MimeApp> {
|
||||
let mime_app_cache = MIME_APP_CACHE.lock().unwrap();
|
||||
// Look for and return preferred terminals
|
||||
//TODO: fallback order beyond cosmic-term?
|
||||
for id in &["com.system76.CosmicTerm"] {
|
||||
for terminal in self.terminals.iter() {
|
||||
if &terminal.id == id {
|
||||
return Some(terminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: consider rules in https://github.com/Vladimir-csp/xdg-terminal-exec
|
||||
// Return whatever was the first terminal found
|
||||
self.terminals.first()
|
||||
}
|
||||
|
||||
// Look for and return preferred terminals
|
||||
//TODO: fallback order beyond cosmic-term?
|
||||
for id in &["com.system76.CosmicTerm"] {
|
||||
for terminal in mime_app_cache.terminals.iter() {
|
||||
if &terminal.id == id {
|
||||
return Some(terminal.clone());
|
||||
#[cfg(not(feature = "desktop"))]
|
||||
pub fn set_default(&mut self, mime: Mime, id: String) {
|
||||
log::warn!(
|
||||
"failed to set default handler for {mime:?} to {id:?}: desktop feature not enabled"
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "desktop")]
|
||||
pub fn set_default(&mut self, mime: Mime, mut id: String) {
|
||||
let Some(path) = cosmic_mime_apps::local_list_path() else {
|
||||
log::warn!("failed to find mimeapps.list path");
|
||||
return;
|
||||
};
|
||||
|
||||
let mut list = cosmic_mime_apps::List::default();
|
||||
match fs::read_to_string(&path) {
|
||||
Ok(string) => {
|
||||
list.load_from(&string);
|
||||
}
|
||||
Err(err) => {
|
||||
if err.kind() != io::ErrorKind::NotFound {
|
||||
log::warn!("failed to read {path:?}: {err}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let suffix = ".desktop";
|
||||
if !id.ends_with(suffix) {
|
||||
id.push_str(suffix);
|
||||
}
|
||||
list.set_default_app(mime, id);
|
||||
|
||||
let mut string = list.to_string();
|
||||
string.push('\n');
|
||||
match fs::write(&path, string) {
|
||||
Ok(()) => {
|
||||
self.reload();
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("failed to write {path:?}: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return whatever was the first terminal found
|
||||
mime_app_cache.terminals.first().map(|x| x.clone())
|
||||
}
|
||||
|
||||
impl Default for MimeAppCache {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ fn network_scan(uri: &str, sizes: IconSizes) -> Result<Vec<tab::Item>, String> {
|
|||
info.icon()
|
||||
.as_ref()
|
||||
.and_then(|icon| gio_icon_to_path(icon, size))
|
||||
.map(|path| widget::icon::from_path(path))
|
||||
.map(widget::icon::from_path)
|
||||
.unwrap_or(
|
||||
widget::icon::from_name(if metadata.is_dir() {
|
||||
"folder"
|
||||
|
|
@ -127,7 +127,6 @@ fn network_scan(uri: &str, sizes: IconSizes) -> Result<Vec<tab::Item>, String> {
|
|||
icon_handle_grid,
|
||||
icon_handle_list,
|
||||
icon_handle_list_condensed,
|
||||
open_with: Vec::new(),
|
||||
thumbnail_opt: Some(ItemThumbnail::NotImage),
|
||||
button_id: widget::Id::unique(),
|
||||
pos_opt: Cell::new(None),
|
||||
|
|
@ -388,10 +387,7 @@ impl Gvfs {
|
|||
let file = gio::File::for_uri(&uri);
|
||||
let needs_mount = match file.find_enclosing_mount(gio::Cancellable::NONE) {
|
||||
Ok(_) => false,
|
||||
Err(err) => match err.kind::<gio::IOErrorEnum>() {
|
||||
Some(gio::IOErrorEnum::NotMounted) => true,
|
||||
_ => false
|
||||
}
|
||||
Err(err) => matches!(err.kind::<gio::IOErrorEnum>(), Some(gio::IOErrorEnum::NotMounted))
|
||||
};
|
||||
if needs_mount {
|
||||
let mount_op = mount_op(uri.clone(), event_tx.clone());
|
||||
|
|
@ -468,7 +464,6 @@ impl Mounter for Gvfs {
|
|||
Task::perform(
|
||||
async move {
|
||||
command_tx.send(Cmd::Mount(item)).unwrap();
|
||||
()
|
||||
},
|
||||
|x| x,
|
||||
)
|
||||
|
|
@ -479,7 +474,6 @@ impl Mounter for Gvfs {
|
|||
Task::perform(
|
||||
async move {
|
||||
command_tx.send(Cmd::NetworkDrive(uri)).unwrap();
|
||||
()
|
||||
},
|
||||
|x| x,
|
||||
)
|
||||
|
|
@ -498,7 +492,6 @@ impl Mounter for Gvfs {
|
|||
Task::perform(
|
||||
async move {
|
||||
command_tx.send(Cmd::Unmount(item)).unwrap();
|
||||
()
|
||||
},
|
||||
|x| x,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -117,4 +117,4 @@ pub fn mounters() -> Mounters {
|
|||
Mounters::new(mounters)
|
||||
}
|
||||
|
||||
pub static MOUNTERS: Lazy<Mounters> = Lazy::new(|| mounters());
|
||||
pub static MOUNTERS: Lazy<Mounters> = Lazy::new(mounters);
|
||||
|
|
|
|||
|
|
@ -31,156 +31,150 @@ use crate::tab::DOUBLE_CLICK_DURATION;
|
|||
pub struct MouseArea<'a, Message> {
|
||||
id: Id,
|
||||
content: Element<'a, Message>,
|
||||
on_drag: Option<Box<dyn Fn(Option<Rectangle>) -> Message + 'a>>,
|
||||
on_double_click: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_press: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_drag_end: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_release: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_resize: Option<Box<dyn Fn(Size) -> Message + 'a>>,
|
||||
on_right_press: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_right_press_no_capture: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_right_release: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_middle_press: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_middle_release: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_back_press: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_back_release: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_forward_press: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_forward_release: Option<Box<dyn Fn(Option<Point>) -> Message + 'a>>,
|
||||
on_scroll: Option<Box<dyn Fn(mouse::ScrollDelta, Modifiers) -> Option<Message> + 'a>>,
|
||||
on_enter: Option<Box<dyn Fn() -> Message + 'a>>,
|
||||
on_exit: Option<Box<dyn Fn() -> Message + 'a>>,
|
||||
on_drag: Option<Box<dyn OnDrag<'a, Message>>>,
|
||||
on_double_click: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_press: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_drag_end: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_release: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_resize: Option<Box<dyn OnResize<'a, Message>>>,
|
||||
on_right_press: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_right_press_no_capture: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_right_release: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_middle_press: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_middle_release: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_back_press: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_back_release: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_forward_press: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_forward_release: Option<Box<dyn OnMouseButton<'a, Message>>>,
|
||||
on_scroll: Option<Box<dyn OnScroll<'a, Message>>>,
|
||||
on_enter: Option<Box<dyn OnEnterExit<'a, Message>>>,
|
||||
on_exit: Option<Box<dyn OnEnterExit<'a, Message>>>,
|
||||
show_drag_rect: bool,
|
||||
}
|
||||
|
||||
impl<'a, Message> MouseArea<'a, Message> {
|
||||
/// The message to emit when a drag is initiated.
|
||||
#[must_use]
|
||||
pub fn on_drag(mut self, message: impl Fn(Option<Rectangle>) -> Message + 'a) -> Self {
|
||||
pub fn on_drag(mut self, message: impl OnDrag<'a, Message>) -> Self {
|
||||
self.on_drag = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit when a drag ends.
|
||||
#[must_use]
|
||||
pub fn on_drag_end(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_drag_end(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_drag_end = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a double click.
|
||||
#[must_use]
|
||||
pub fn on_double_click(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_double_click(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_double_click = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a left button press.
|
||||
#[must_use]
|
||||
pub fn on_press(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_press(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_press = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a left button release.
|
||||
#[must_use]
|
||||
pub fn on_release(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_release(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_release = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on resizing.
|
||||
#[must_use]
|
||||
pub fn on_resize(mut self, message: impl Fn(Size) -> Message + 'a) -> Self {
|
||||
pub fn on_resize(mut self, message: impl OnResize<'a, Message>) -> Self {
|
||||
self.on_resize = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a right button press.
|
||||
#[must_use]
|
||||
pub fn on_right_press(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_right_press(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_right_press = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a right button press without capturing.
|
||||
#[must_use]
|
||||
pub fn on_right_press_no_capture(
|
||||
mut self,
|
||||
message: impl Fn(Option<Point>) -> Message + 'a,
|
||||
) -> Self {
|
||||
pub fn on_right_press_no_capture(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_right_press_no_capture = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a right button release.
|
||||
#[must_use]
|
||||
pub fn on_right_release(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_right_release(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_right_release = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a middle button press.
|
||||
#[must_use]
|
||||
pub fn on_middle_press(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_middle_press(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_middle_press = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a middle button release.
|
||||
#[must_use]
|
||||
pub fn on_middle_release(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_middle_release(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_middle_release = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a back button press.
|
||||
#[must_use]
|
||||
pub fn on_back_press(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_back_press(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_back_press = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a back button release.
|
||||
#[must_use]
|
||||
pub fn on_back_release(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_back_release(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_back_release = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a forward button press.
|
||||
#[must_use]
|
||||
pub fn on_forward_press(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_forward_press(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_forward_press = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a forward button release.
|
||||
#[must_use]
|
||||
pub fn on_forward_release(mut self, message: impl Fn(Option<Point>) -> Message + 'a) -> Self {
|
||||
pub fn on_forward_release(mut self, message: impl OnMouseButton<'a, Message>) -> Self {
|
||||
self.on_forward_release = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit on a scroll.
|
||||
#[must_use]
|
||||
pub fn on_scroll(
|
||||
mut self,
|
||||
message: impl Fn(mouse::ScrollDelta, Modifiers) -> Option<Message> + 'a,
|
||||
) -> Self {
|
||||
pub fn on_scroll(mut self, message: impl OnScroll<'a, Message>) -> Self {
|
||||
self.on_scroll = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit when a mouse enters the area.
|
||||
#[must_use]
|
||||
pub fn on_enter(mut self, message: impl Fn() -> Message + 'a) -> Self {
|
||||
pub fn on_enter(mut self, message: impl OnEnterExit<'a, Message>) -> Self {
|
||||
self.on_enter = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
||||
/// The message to emit when a mouse exits the area.
|
||||
#[must_use]
|
||||
pub fn on_exit(mut self, message: impl Fn() -> Message + 'a) -> Self {
|
||||
pub fn on_exit(mut self, message: impl OnEnterExit<'a, Message>) -> Self {
|
||||
self.on_exit = Some(Box::new(message));
|
||||
self
|
||||
}
|
||||
|
|
@ -199,6 +193,24 @@ impl<'a, Message> MouseArea<'a, Message> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait OnMouseButton<'a, Message>: Fn(Option<Point>) -> Message + 'a {}
|
||||
impl<'a, Message, F> OnMouseButton<'a, Message> for F where F: Fn(Option<Point>) -> Message + 'a {}
|
||||
|
||||
pub trait OnDrag<'a, Message>: Fn(Option<Rectangle>) -> Message + 'a {}
|
||||
impl<'a, Message, F> OnDrag<'a, Message> for F where F: Fn(Option<Rectangle>) -> Message + 'a {}
|
||||
|
||||
pub trait OnResize<'a, Message>: Fn(Size) -> Message + 'a {}
|
||||
impl<'a, Message, F> OnResize<'a, Message> for F where F: Fn(Size) -> Message + 'a {}
|
||||
|
||||
pub trait OnScroll<'a, Message>: Fn(mouse::ScrollDelta, Modifiers) -> Option<Message> + 'a {}
|
||||
impl<'a, Message, F> OnScroll<'a, Message> for F where
|
||||
F: Fn(mouse::ScrollDelta, Modifiers) -> Option<Message> + 'a
|
||||
{
|
||||
}
|
||||
|
||||
pub trait OnEnterExit<'a, Message>: Fn() -> Message + 'a {}
|
||||
impl<'a, Message, F> OnEnterExit<'a, Message> for F where F: Fn() -> Message + 'a {}
|
||||
|
||||
/// Local state of the [`MouseArea`].
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
|
|
@ -250,7 +262,7 @@ impl State {
|
|||
} else {
|
||||
mouse::Click::new(pos, mouse::Button::Left, None)
|
||||
};
|
||||
self.prev_click = Some((new.clone(), now));
|
||||
self.prev_click = Some((new, now));
|
||||
new
|
||||
}
|
||||
}
|
||||
|
|
@ -284,7 +296,7 @@ impl<'a, Message> MouseArea<'a, Message> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Message> Widget<Message, Theme, Renderer> for MouseArea<'a, Message>
|
||||
impl<Message> Widget<Message, Theme, Renderer> for MouseArea<'_, Message>
|
||||
where
|
||||
Message: Clone,
|
||||
{
|
||||
|
|
@ -659,7 +671,7 @@ fn update<Message: Clone>(
|
|||
|
||||
if let Some(on_scroll) = widget.on_scroll.as_ref() {
|
||||
if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event {
|
||||
if let Some(message) = on_scroll(delta.clone(), state.modifiers) {
|
||||
if let Some(message) = on_scroll(*delta, state.modifiers) {
|
||||
shell.publish(message);
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ pub struct Controller {
|
|||
inner: Arc<ControllerInner>,
|
||||
}
|
||||
|
||||
impl Controller {
|
||||
pub fn new() -> Self {
|
||||
impl Default for Controller {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
primary: true,
|
||||
inner: Arc::new(ControllerInner {
|
||||
|
|
@ -33,7 +33,9 @@ impl Controller {
|
|||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Controller {
|
||||
pub fn check(&self) -> Result<(), String> {
|
||||
let mut state = self.inner.state.lock().unwrap();
|
||||
loop {
|
||||
|
|
|
|||
|
|
@ -67,11 +67,20 @@ fn handle_replace(
|
|||
}
|
||||
|
||||
fn get_directory_name(file_name: &str) -> &str {
|
||||
const SUPPORTED_EXTENSIONS: [&str; 4] = [".tar.gz", ".tgz", ".tar", ".zip"];
|
||||
// TODO: Chain with COMPOUND_EXTENSIONS once more formats are supported
|
||||
const SUPPORTED_EXTENSIONS: &[&str] = &[
|
||||
".tar.bz2",
|
||||
".tar.gz",
|
||||
".tar.lzma",
|
||||
".tar.xz",
|
||||
".tgz",
|
||||
".tar",
|
||||
".zip",
|
||||
];
|
||||
|
||||
for ext in &SUPPORTED_EXTENSIONS {
|
||||
if file_name.ends_with(ext) {
|
||||
return &file_name[..file_name.len() - ext.len()];
|
||||
for ext in SUPPORTED_EXTENSIONS {
|
||||
if let Some(stripped) = file_name.strip_suffix(ext) {
|
||||
return stripped;
|
||||
}
|
||||
}
|
||||
file_name
|
||||
|
|
@ -245,7 +254,7 @@ async fn copy_or_move(
|
|||
if matches!(from.parent(), Some(parent) if parent == to) && !moving {
|
||||
// `from`'s parent is equal to `to` which means we're copying to the same
|
||||
// directory (duplicating files)
|
||||
let to = copy_unique_path(&from, &to);
|
||||
let to = copy_unique_path(&from, to);
|
||||
Some((from, to))
|
||||
} else if let Some(name) = from.file_name() {
|
||||
let to = to.join(name);
|
||||
|
|
@ -361,12 +370,12 @@ fn copy_unique_path(from: &Path, to: &Path) -> PathBuf {
|
|||
to
|
||||
}
|
||||
|
||||
fn file_name<'a>(path: &'a Path) -> Cow<'a, str> {
|
||||
fn file_name(path: &Path) -> Cow<'_, str> {
|
||||
path.file_name()
|
||||
.map_or_else(|| fl!("unknown-folder").into(), |x| x.to_string_lossy())
|
||||
}
|
||||
|
||||
fn parent_name<'a>(path: &'a Path) -> Cow<'a, str> {
|
||||
fn parent_name(path: &Path) -> Cow<'_, str> {
|
||||
let Some(parent) = path.parent() else {
|
||||
return fl!("unknown-folder").into();
|
||||
};
|
||||
|
|
@ -374,7 +383,7 @@ fn parent_name<'a>(path: &'a Path) -> Cow<'a, str> {
|
|||
file_name(parent)
|
||||
}
|
||||
|
||||
fn paths_parent_name<'a>(paths: &'a Vec<PathBuf>) -> Cow<'a, str> {
|
||||
fn paths_parent_name(paths: &[PathBuf]) -> Cow<'_, str> {
|
||||
let Some(first_path) = paths.first() else {
|
||||
return fl!("unknown-folder").into();
|
||||
};
|
||||
|
|
@ -674,7 +683,7 @@ impl Operation {
|
|||
path.strip_prefix(relative_root).map_err(err_str)?.to_str()
|
||||
{
|
||||
if path.is_file() {
|
||||
let mut file = fs::File::open(&path).map_err(err_str)?;
|
||||
let mut file = fs::File::open(path).map_err(err_str)?;
|
||||
let metadata = file.metadata().map_err(err_str)?;
|
||||
let total = metadata.len();
|
||||
if total >= 4 * 1024 * 1024 * 1024 {
|
||||
|
|
@ -777,8 +786,6 @@ impl Operation {
|
|||
|
||||
controller.set_progress((i as f32) / total_paths as f32);
|
||||
|
||||
let to = to.to_owned();
|
||||
|
||||
if let Some(file_name) = path.file_name().and_then(|f| f.to_str()) {
|
||||
let dir_name = get_directory_name(file_name);
|
||||
let mut new_dir = to.join(dir_name);
|
||||
|
|
@ -793,7 +800,7 @@ impl Operation {
|
|||
op_sel.selected.push(new_dir.clone());
|
||||
|
||||
let controller = controller.clone();
|
||||
let mime = mime_for_path(&path);
|
||||
let mime = mime_for_path(path);
|
||||
match mime.essence_str() {
|
||||
"application/gzip" | "application/x-compressed-tar" => {
|
||||
OpReader::new(path, controller)
|
||||
|
|
@ -953,7 +960,7 @@ mod tests {
|
|||
};
|
||||
|
||||
use cosmic::iced::futures::{channel::mpsc, StreamExt};
|
||||
use log::{debug, trace};
|
||||
use log::debug;
|
||||
use test_log::test;
|
||||
use tokio::sync;
|
||||
|
||||
|
|
@ -961,8 +968,8 @@ mod tests {
|
|||
use crate::{
|
||||
app::{
|
||||
test_utils::{
|
||||
empty_fs, filter_dirs, filter_files, read_dir_sorted, simple_fs, NAME_LEN,
|
||||
NUM_DIRS, NUM_FILES, NUM_HIDDEN, NUM_NESTED,
|
||||
empty_fs, filter_dirs, filter_files, simple_fs, NAME_LEN, NUM_DIRS, NUM_FILES,
|
||||
NUM_HIDDEN, NUM_NESTED,
|
||||
},
|
||||
DialogPage, Message,
|
||||
},
|
||||
|
|
@ -986,7 +993,7 @@ mod tests {
|
|||
paths: paths_clone,
|
||||
to: to_clone,
|
||||
}
|
||||
.perform(&sync::Mutex::new(tx).into(), Controller::new())
|
||||
.perform(&sync::Mutex::new(tx).into(), Controller::default())
|
||||
.await
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,18 @@ use super::{copy_unique_path, Controller, OperationSelection, ReplaceResult};
|
|||
pub struct Context {
|
||||
buf: Vec<u8>,
|
||||
controller: Controller,
|
||||
on_progress: Box<dyn Fn(&Op, &Progress) + 'static>,
|
||||
on_replace: Box<dyn Fn(&Op) -> ReplaceResult + 'static>,
|
||||
on_progress: Box<dyn OnProgress>,
|
||||
on_replace: Box<dyn OnReplace>,
|
||||
pub(crate) op_sel: OperationSelection,
|
||||
replace_result_opt: Option<ReplaceResult>,
|
||||
}
|
||||
|
||||
pub trait OnProgress: Fn(&Op, &Progress) + 'static {}
|
||||
impl<F> OnProgress for F where F: Fn(&Op, &Progress) + 'static {}
|
||||
|
||||
pub trait OnReplace: Fn(&Op) -> ReplaceResult + 'static {}
|
||||
impl<F> OnReplace for F where F: Fn(&Op) -> ReplaceResult + 'static {}
|
||||
|
||||
impl Context {
|
||||
pub fn new(controller: Controller) -> Self {
|
||||
Self {
|
||||
|
|
@ -67,7 +73,7 @@ impl Context {
|
|||
OpKind::Symlink { target }
|
||||
} else {
|
||||
//TODO: present dialog and allow continue
|
||||
return Err(format!("{} is not a known file type", from.display()).into());
|
||||
return Err(format!("{} is not a known file type", from.display()));
|
||||
};
|
||||
let to = if from == from_parent {
|
||||
// When copying a file, from matches from_parent, and to_parent must be used
|
||||
|
|
@ -130,12 +136,12 @@ impl Context {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
pub fn on_progress<F: Fn(&Op, &Progress) + 'static>(mut self, f: F) -> Self {
|
||||
pub fn on_progress<F: OnProgress>(mut self, f: F) -> Self {
|
||||
self.on_progress = Box::new(f);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_replace<F: Fn(&Op) -> ReplaceResult + 'static>(mut self, f: F) -> Self {
|
||||
pub fn on_replace<F: OnReplace>(mut self, f: F) -> Self {
|
||||
self.on_replace = Box::new(f);
|
||||
self
|
||||
}
|
||||
|
|
@ -153,9 +159,7 @@ impl Context {
|
|||
Ok(ControlFlow::Continue(op.to.clone()))
|
||||
}
|
||||
ReplaceResult::KeepBoth => match op.to.parent() {
|
||||
Some(to_parent) => Ok(ControlFlow::Continue(copy_unique_path(
|
||||
&op.from, &to_parent,
|
||||
))),
|
||||
Some(to_parent) => Ok(ControlFlow::Continue(copy_unique_path(&op.from, to_parent))),
|
||||
None => Err(format!("failed to get parent of {:?}", op.to).into()),
|
||||
},
|
||||
ReplaceResult::Skip(apply_to_all) => {
|
||||
|
|
@ -216,7 +220,7 @@ impl Op {
|
|||
let metadata = from_file.metadata()?;
|
||||
// Remove `to` if overwriting and it is an existing file
|
||||
if self.to.is_file() {
|
||||
match ctx.replace(&self)? {
|
||||
match ctx.replace(self)? {
|
||||
ControlFlow::Continue(to) => {
|
||||
self.to = to;
|
||||
}
|
||||
|
|
@ -226,7 +230,7 @@ impl Op {
|
|||
}
|
||||
}
|
||||
progress.total_bytes = Some(metadata.len());
|
||||
(ctx.on_progress)(&self, &progress);
|
||||
(ctx.on_progress)(self, &progress);
|
||||
// This is atomic and ensures `to` is not created by any other process
|
||||
let mut to_file = fs::OpenOptions::new()
|
||||
.create_new(true)
|
||||
|
|
@ -242,14 +246,14 @@ impl Op {
|
|||
}
|
||||
to_file.write_all(&ctx.buf[..count])?;
|
||||
progress.current_bytes += count as u64;
|
||||
(ctx.on_progress)(&self, &progress);
|
||||
(ctx.on_progress)(self, &progress);
|
||||
}
|
||||
to_file.sync_all()?;
|
||||
}
|
||||
OpKind::Move => {
|
||||
// Remove `to` if overwriting and it is an existing file
|
||||
if self.to.is_file() {
|
||||
match ctx.replace(&self)? {
|
||||
match ctx.replace(self)? {
|
||||
ControlFlow::Continue(to) => {
|
||||
self.to = to;
|
||||
}
|
||||
|
|
@ -289,7 +293,7 @@ impl Op {
|
|||
OpKind::Symlink { ref target } => {
|
||||
// Remove `to` if overwriting and it is an existing file
|
||||
if self.to.is_file() {
|
||||
match ctx.replace(&self)? {
|
||||
match ctx.replace(self)? {
|
||||
ControlFlow::Continue(to) => {
|
||||
self.to = to;
|
||||
}
|
||||
|
|
@ -298,8 +302,18 @@ impl Op {
|
|||
}
|
||||
}
|
||||
}
|
||||
//TODO: use OS-specific function
|
||||
fs::soft_link(&target, &self.to)?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
std::os::unix::fs::symlink(target, &self.to)?;
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if target.is_dir() {
|
||||
std::os::windows::fs::symlink_dir(target, &self.to)?;
|
||||
} else {
|
||||
std::os::windows::fs::symlink_file(target, &self.to)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
|
|
|
|||
117
src/tab.rs
117
src/tab.rs
|
|
@ -58,14 +58,13 @@ use tokio::sync::mpsc;
|
|||
use walkdir::WalkDir;
|
||||
|
||||
use crate::{
|
||||
app::{self, Action, PreviewItem, PreviewKind},
|
||||
app::{Action, PreviewItem, PreviewKind},
|
||||
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
|
||||
config::{DesktopConfig, IconSizes, TabConfig, ICON_SCALE_MAX, ICON_SIZE_GRID},
|
||||
dialog::DialogKind,
|
||||
fl,
|
||||
localize::{LANGUAGE_CHRONO, LANGUAGE_SORTER},
|
||||
menu,
|
||||
mime_app::{mime_apps, MimeApp},
|
||||
menu, mime_app,
|
||||
mime_icon::{mime_for_path, mime_icon},
|
||||
mounter::MOUNTERS,
|
||||
mouse_area,
|
||||
|
|
@ -459,8 +458,6 @@ pub fn item_from_entry(
|
|||
}
|
||||
};
|
||||
|
||||
let open_with = mime_apps(&mime);
|
||||
|
||||
let children = if metadata.is_dir() {
|
||||
//TODO: calculate children in the background (and make it cancellable?)
|
||||
match fs::read_dir(&path) {
|
||||
|
|
@ -475,7 +472,7 @@ pub fn item_from_entry(
|
|||
};
|
||||
|
||||
let dir_size = if metadata.is_dir() {
|
||||
DirSize::Calculating(Controller::new())
|
||||
DirSize::Calculating(Controller::default())
|
||||
} else {
|
||||
DirSize::NotDirectory
|
||||
};
|
||||
|
|
@ -490,7 +487,6 @@ pub fn item_from_entry(
|
|||
icon_handle_grid,
|
||||
icon_handle_list,
|
||||
icon_handle_list_condensed,
|
||||
open_with,
|
||||
thumbnail_opt: None,
|
||||
button_id: widget::Id::unique(),
|
||||
pos_opt: Cell::new(None),
|
||||
|
|
@ -720,7 +716,6 @@ pub fn scan_trash(sizes: IconSizes) -> Vec<Item> {
|
|||
icon_handle_grid,
|
||||
icon_handle_list,
|
||||
icon_handle_list_condensed,
|
||||
open_with: Vec::new(),
|
||||
thumbnail_opt: Some(ItemThumbnail::NotImage),
|
||||
button_id: widget::Id::unique(),
|
||||
pos_opt: Cell::new(None),
|
||||
|
|
@ -904,7 +899,6 @@ pub fn scan_desktop(
|
|||
icon_handle_grid,
|
||||
icon_handle_list,
|
||||
icon_handle_list_condensed,
|
||||
open_with: Vec::new(),
|
||||
thumbnail_opt: Some(ItemThumbnail::NotImage),
|
||||
button_id: widget::Id::unique(),
|
||||
pos_opt: Cell::new(None),
|
||||
|
|
@ -1027,6 +1021,7 @@ pub enum Command {
|
|||
OpenInNewWindow(PathBuf),
|
||||
OpenTrash,
|
||||
Preview(PreviewKind),
|
||||
SetOpenWith(Mime, String),
|
||||
WindowDrag,
|
||||
WindowToggleMaximize,
|
||||
}
|
||||
|
|
@ -1071,6 +1066,9 @@ pub enum Message {
|
|||
SearchContext(Location, SearchContextWrapper),
|
||||
SearchReady(bool),
|
||||
SelectAll,
|
||||
SelectFirst,
|
||||
SelectLast,
|
||||
SetOpenWith(Mime, String),
|
||||
SetSort(HeadingOptions, bool),
|
||||
Thumbnail(PathBuf, ItemThumbnail),
|
||||
ToggleShowHidden,
|
||||
|
|
@ -1316,7 +1314,6 @@ pub struct Item {
|
|||
pub icon_handle_grid: widget::icon::Handle,
|
||||
pub icon_handle_list: widget::icon::Handle,
|
||||
pub icon_handle_list_condensed: widget::icon::Handle,
|
||||
pub open_with: Vec<MimeApp>,
|
||||
pub thumbnail_opt: Option<ItemThumbnail>,
|
||||
pub button_id: widget::Id,
|
||||
pub pos_opt: Cell<Option<(usize, usize)>>,
|
||||
|
|
@ -1341,7 +1338,7 @@ impl Item {
|
|||
self.mime.type_() == mime::IMAGE || self.mime.type_() == mime::TEXT
|
||||
}
|
||||
|
||||
fn preview<'a>(&'a self, sizes: IconSizes) -> Element<'a, app::Message> {
|
||||
fn preview<'a>(&'a self, sizes: IconSizes) -> Element<'a, Message> {
|
||||
let spacing = cosmic::theme::active().cosmic().spacing;
|
||||
// This loads the image only if thumbnailing worked
|
||||
let icon = widget::icon::icon(self.icon_handle_grid.clone())
|
||||
|
|
@ -1374,23 +1371,23 @@ impl Item {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn preview_header(&self) -> Vec<Element<app::Message>> {
|
||||
pub fn preview_header(&self) -> Vec<Element<Message>> {
|
||||
let mut row = Vec::with_capacity(3);
|
||||
row.push(
|
||||
widget::button::icon(widget::icon::from_name("go-previous-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::ItemLeft))
|
||||
.on_press(Message::ItemLeft)
|
||||
.into(),
|
||||
);
|
||||
row.push(
|
||||
widget::button::icon(widget::icon::from_name("go-next-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::ItemRight))
|
||||
.on_press(Message::ItemRight)
|
||||
.into(),
|
||||
);
|
||||
if self.can_gallery() {
|
||||
if let Some(_path) = self.path_opt() {
|
||||
row.push(
|
||||
widget::button::icon(widget::icon::from_name("view-fullscreen-symbolic"))
|
||||
.on_press(app::Message::TabMessage(None, Message::Gallery(true)))
|
||||
.on_press(Message::Gallery(true))
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
|
|
@ -1398,7 +1395,11 @@ impl Item {
|
|||
row
|
||||
}
|
||||
|
||||
pub fn preview_view<'a>(&'a self, sizes: IconSizes) -> Element<'a, app::Message> {
|
||||
pub fn preview_view<'a>(
|
||||
&'a self,
|
||||
mime_app_cache_opt: Option<&'a mime_app::MimeAppCache>,
|
||||
sizes: IconSizes,
|
||||
) -> Element<'a, Message> {
|
||||
let cosmic_theme::Spacing {
|
||||
space_xxxs,
|
||||
space_m,
|
||||
|
|
@ -1420,6 +1421,24 @@ impl Item {
|
|||
mime = self.mime.to_string()
|
||||
)));
|
||||
let mut settings = Vec::new();
|
||||
if let Some(mime_app_cache) = mime_app_cache_opt {
|
||||
let mime_apps = mime_app_cache.get(&self.mime);
|
||||
if !mime_apps.is_empty() {
|
||||
settings.push(
|
||||
widget::settings::item::builder(fl!("open-with")).control(
|
||||
widget::dropdown(
|
||||
mime_apps,
|
||||
mime_apps.iter().position(|x| x.is_default),
|
||||
|index| {
|
||||
let mime_app = &mime_apps[index];
|
||||
Message::SetOpenWith(self.mime.clone(), mime_app.id.clone())
|
||||
},
|
||||
)
|
||||
.icons(mime_app_cache.icons(&self.mime)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
match &self.metadata {
|
||||
ItemMetadata::Path { metadata, children } => {
|
||||
if metadata.is_dir() {
|
||||
|
|
@ -1507,9 +1526,10 @@ impl Item {
|
|||
column = column.push(details);
|
||||
|
||||
if let Some(path) = self.path_opt() {
|
||||
column = column.push(widget::button::standard(fl!("open")).on_press(
|
||||
app::Message::TabMessage(None, Message::Open(Some(path.to_path_buf()))),
|
||||
));
|
||||
column = column.push(
|
||||
widget::button::standard(fl!("open"))
|
||||
.on_press(Message::Open(Some(path.to_path_buf()))),
|
||||
);
|
||||
}
|
||||
|
||||
if !settings.is_empty() {
|
||||
|
|
@ -1523,11 +1543,7 @@ impl Item {
|
|||
column.into()
|
||||
}
|
||||
|
||||
pub fn replace_view<'a>(
|
||||
&'a self,
|
||||
heading: String,
|
||||
sizes: IconSizes,
|
||||
) -> Element<'a, app::Message> {
|
||||
pub fn replace_view<'a>(&'a self, heading: String, sizes: IconSizes) -> Element<'a, Message> {
|
||||
let cosmic_theme::Spacing { space_xxxs, .. } = theme::active().cosmic().spacing;
|
||||
|
||||
let mut row = widget::row().spacing(space_xxxs);
|
||||
|
|
@ -2243,8 +2259,8 @@ impl Tab {
|
|||
if !item.selected {
|
||||
self.clicked = click_i_opt;
|
||||
item.selected = true;
|
||||
self.select_range = Some((i, i));
|
||||
}
|
||||
self.select_range = Some((i, i));
|
||||
self.select_focus = click_i_opt;
|
||||
self.selected_clicked = true;
|
||||
} else if !dont_unset && item.selected {
|
||||
|
|
@ -2752,9 +2768,7 @@ impl Tab {
|
|||
if let Some(items) = &mut self.items_opt {
|
||||
if finished || context.ready.swap(false, atomic::Ordering::SeqCst) {
|
||||
let duration = Instant::now();
|
||||
while let Some((path, name, metadata)) =
|
||||
context.results_rx.blocking_recv()
|
||||
{
|
||||
while let Ok((path, name, metadata)) = context.results_rx.try_recv() {
|
||||
//TODO: combine this with column_sort logic, they must match!
|
||||
let item_modified = metadata.modified().ok();
|
||||
let index = match items.binary_search_by(|other| {
|
||||
|
|
@ -2801,6 +2815,39 @@ impl Tab {
|
|||
));
|
||||
}
|
||||
}
|
||||
Message::SelectFirst => {
|
||||
if self.select_position(0, 0, mod_shift) {
|
||||
if let Some(offset) = self.select_focus_scroll() {
|
||||
commands.push(Command::Iced(
|
||||
scrollable::scroll_to(self.scrollable_id.clone(), offset).into(),
|
||||
));
|
||||
}
|
||||
if let Some(id) = self.select_focus_id() {
|
||||
commands.push(Command::Iced(widget::button::focus(id).into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::SelectLast => {
|
||||
if let Some(ref items) = self.items_opt {
|
||||
if let Some(last_pos) = items.iter().filter_map(|item| item.pos_opt.get()).max()
|
||||
{
|
||||
if self.select_position(last_pos.0, last_pos.1, mod_shift) {
|
||||
if let Some(offset) = self.select_focus_scroll() {
|
||||
commands.push(Command::Iced(
|
||||
scrollable::scroll_to(self.scrollable_id.clone(), offset)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if let Some(id) = self.select_focus_id() {
|
||||
commands.push(Command::Iced(widget::button::focus(id).into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::SetOpenWith(mime, id) => {
|
||||
commands.push(Command::SetOpenWith(mime, id));
|
||||
}
|
||||
Message::SetSort(heading_option, dir) => {
|
||||
if !matches!(self.location, Location::Search(..)) {
|
||||
self.sort_name = heading_option;
|
||||
|
|
@ -2865,7 +2912,7 @@ impl Tab {
|
|||
Message::Drop(Some((to, mut from))) => {
|
||||
self.dnd_hovered = None;
|
||||
match to {
|
||||
Location::Path(to) => {
|
||||
Location::Desktop(to, ..) | Location::Path(to) => {
|
||||
if let Ok(entries) = fs::read_dir(&to) {
|
||||
for i in entries.into_iter().filter_map(|e| e.ok()) {
|
||||
let i = i.path();
|
||||
|
|
@ -3581,8 +3628,7 @@ impl Tab {
|
|||
pub fn empty_view(&self, has_hidden: bool) -> Element<Message> {
|
||||
let cosmic_theme::Spacing { space_xxs, .. } = theme::active().cosmic().spacing;
|
||||
|
||||
//TODO: left clicking on an empty folder does not clear context menu
|
||||
widget::column::with_children(vec![widget::container(
|
||||
mouse_area::MouseArea::new(widget::column::with_children(vec![widget::container(
|
||||
widget::column::with_children(match self.mode {
|
||||
Mode::App | Mode::Dialog(_) => vec![
|
||||
widget::icon::from_name("folder-symbolic")
|
||||
|
|
@ -3604,7 +3650,8 @@ impl Tab {
|
|||
.spacing(space_xxs),
|
||||
)
|
||||
.center(Length::Fill)
|
||||
.into()])
|
||||
.into()]))
|
||||
.on_press(|_| Message::Click(None))
|
||||
.into()
|
||||
}
|
||||
|
||||
|
|
@ -4285,9 +4332,9 @@ impl Tab {
|
|||
.drag_content(move || {
|
||||
ClipboardCopy::new(crate::clipboard::ClipboardKind::Copy, &files)
|
||||
})
|
||||
.drag_icon(move || {
|
||||
.drag_icon(move |v| {
|
||||
let state: tree::State = Widget::<Message, _, _>::state(&drag_list);
|
||||
(Element::from(drag_list.clone()).map(|_m| ()), state)
|
||||
(Element::from(drag_list.clone()).map(|_m| ()), state, v)
|
||||
})
|
||||
}
|
||||
_ => item_view,
|
||||
|
|
@ -4402,7 +4449,7 @@ impl Tab {
|
|||
dnd_dest.into()
|
||||
}
|
||||
|
||||
pub fn view<'a>(&'a self, key_binds: &'a HashMap<KeyBind, Action>) -> Element<Message> {
|
||||
pub fn view<'a>(&'a self, key_binds: &'a HashMap<KeyBind, Action>) -> Element<'a, Message> {
|
||||
widget::responsive(|size| self.view_responsive(key_binds, size)).into()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,9 +144,7 @@ impl ThumbnailerCache {
|
|||
}
|
||||
|
||||
pub fn get(&self, key: &Mime) -> Vec<Thumbnailer> {
|
||||
self.cache
|
||||
.get(&key)
|
||||
.map_or_else(|| Vec::new(), |x| x.clone())
|
||||
self.cache.get(key).map_or_else(Vec::new, |x| x.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue