Merge branch 'master' into master
This commit is contained in:
commit
eb1218a0db
26 changed files with 2278 additions and 1660 deletions
794
src/app.rs
794
src/app.rs
File diff suppressed because it is too large
Load diff
109
src/archive.rs
109
src/archive.rs
|
|
@ -1,15 +1,15 @@
|
|||
use std::{
|
||||
collections::VecDeque,
|
||||
fs,
|
||||
io::{self, Read, Write},
|
||||
path::Path,
|
||||
};
|
||||
use zip::result::ZipError;
|
||||
|
||||
use crate::{
|
||||
mime_icon::mime_for_path,
|
||||
operation::{Controller, OpReader, OperationError, OperationErrorType},
|
||||
operation::{Controller, OpReader, OperationError, OperationErrorType, sync_to_disk},
|
||||
};
|
||||
use cosmic::iced::futures;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fs,
|
||||
io::{self, Read, Write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use zip::result::ZipError;
|
||||
|
||||
pub const SUPPORTED_ARCHIVE_TYPES: &[&str] = &[
|
||||
"application/gzip",
|
||||
|
|
@ -113,27 +113,36 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
|
|||
use std::{ffi::OsString, fs};
|
||||
use zip::result::ZipError;
|
||||
|
||||
fn make_writable_dir_all<T: AsRef<Path>>(outpath: T) -> Result<(), ZipError> {
|
||||
fs::create_dir_all(outpath.as_ref())?;
|
||||
fn make_writable_dir_all<T: AsRef<Path>>(
|
||||
outpath: T,
|
||||
target_dirs: &mut HashSet<PathBuf>,
|
||||
) -> Result<(), ZipError> {
|
||||
let path = outpath.as_ref();
|
||||
if !path.exists() {
|
||||
fs::create_dir_all(path)?;
|
||||
}
|
||||
if !target_dirs.contains(path) {
|
||||
target_dirs.insert(path.to_path_buf());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
// Dirs must be writable until all normal files are extracted
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
std::fs::set_permissions(
|
||||
outpath.as_ref(),
|
||||
std::fs::Permissions::from_mode(
|
||||
0o700 | std::fs::metadata(outpath.as_ref())?.permissions().mode(),
|
||||
),
|
||||
fs::set_permissions(
|
||||
path,
|
||||
fs::Permissions::from_mode(0o700 | fs::metadata(path)?.permissions().mode()),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
let mut files_by_unix_mode = Vec::new();
|
||||
let mut buffer = vec![0; 4 * 1024 * 1024];
|
||||
let total_files = archive.len();
|
||||
let mut pending_directory_creates = VecDeque::new();
|
||||
let mut written_files = Vec::with_capacity(total_files);
|
||||
let mut target_dirs = HashSet::new();
|
||||
#[cfg(unix)]
|
||||
let mut files_by_unix_mode = Vec::with_capacity(total_files);
|
||||
|
||||
for i in 0..total_files {
|
||||
futures::executor::block_on(async {
|
||||
|
|
@ -143,7 +152,7 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
|
|||
.map_err(|s| io::Error::other(OperationError::from_state(s, &controller)))
|
||||
})?;
|
||||
|
||||
controller.set_progress((i as f32) / total_files as f32);
|
||||
controller.set_progress(i as f32 / total_files as f32);
|
||||
|
||||
let mut file = match password {
|
||||
None => archive.by_index(i),
|
||||
|
|
@ -156,26 +165,22 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
|
|||
let outpath = directory.as_ref().join(filepath);
|
||||
|
||||
if file.is_dir() {
|
||||
pending_directory_creates.push_back(outpath.clone());
|
||||
make_writable_dir_all(&outpath, &mut target_dirs)?;
|
||||
|
||||
#[cfg(unix)]
|
||||
if let Some(mode) = file.unix_mode() {
|
||||
files_by_unix_mode.push((outpath, mode));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let symlink_target = if file.is_symlink() && (cfg!(unix) || cfg!(windows)) {
|
||||
|
||||
if let Some(parent) = outpath.parent() {
|
||||
make_writable_dir_all(parent, &mut target_dirs)?;
|
||||
}
|
||||
|
||||
if file.is_symlink() && (cfg!(unix) || cfg!(windows)) {
|
||||
let mut target = Vec::with_capacity(file.size() as usize);
|
||||
file.read_to_end(&mut target)?;
|
||||
Some(target)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
drop(file);
|
||||
if let Some(target) = symlink_target {
|
||||
// create all pending dirs
|
||||
while let Some(pending_dir) = pending_directory_creates.pop_front() {
|
||||
make_writable_dir_all(pending_dir)?;
|
||||
}
|
||||
|
||||
if let Some(p) = outpath.parent() {
|
||||
make_writable_dir_all(p)?;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
|
|
@ -205,21 +210,10 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
|
|||
std::os::windows::fs::symlink_file(target_path, outpath.as_path())?;
|
||||
}
|
||||
}
|
||||
|
||||
written_files.push(outpath);
|
||||
continue;
|
||||
}
|
||||
let mut file = match password {
|
||||
None => archive.by_index(i),
|
||||
Some(pwd) => archive.by_index_decrypt(i, pwd.as_bytes()),
|
||||
}?;
|
||||
|
||||
// create all pending dirs
|
||||
while let Some(pending_dir) = pending_directory_creates.pop_front() {
|
||||
make_writable_dir_all(pending_dir)?;
|
||||
}
|
||||
|
||||
if let Some(p) = outpath.parent() {
|
||||
make_writable_dir_all(p)?;
|
||||
}
|
||||
|
||||
let total = file.size();
|
||||
let mut outfile = fs::File::create(&outpath)?;
|
||||
|
|
@ -245,13 +239,14 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
|
|||
controller.set_progress(total_progress);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for real permissions, which we'll set in a second pass
|
||||
#[cfg(unix)]
|
||||
{
|
||||
// Check for real permissions, which we'll set in a second pass
|
||||
if let Some(mode) = file.unix_mode() {
|
||||
files_by_unix_mode.push((outpath.clone(), mode));
|
||||
}
|
||||
if let Some(mode) = file.unix_mode() {
|
||||
files_by_unix_mode.push((outpath.clone(), mode));
|
||||
}
|
||||
|
||||
written_files.push(outpath);
|
||||
}
|
||||
#[cfg(unix)]
|
||||
{
|
||||
|
|
@ -260,11 +255,15 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
|
|||
|
||||
if files_by_unix_mode.len() > 1 {
|
||||
// Ensure we update children's permissions before making a parent unwritable
|
||||
files_by_unix_mode.sort_by_key(|(path, _)| Reverse(path.clone()));
|
||||
files_by_unix_mode.sort_by_key(|(path, _)| Reverse(path.components().count()));
|
||||
}
|
||||
for (path, mode) in files_by_unix_mode {
|
||||
fs::set_permissions(&path, fs::Permissions::from_mode(mode))?;
|
||||
}
|
||||
}
|
||||
|
||||
// Flush files to disk
|
||||
futures::executor::block_on(async { sync_to_disk(written_files, target_dirs).await });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
296
src/dialog.rs
296
src/dialog.rs
|
|
@ -179,11 +179,11 @@ impl<T: AsRef<str>> From<T> for DialogLabel {
|
|||
});
|
||||
}
|
||||
|
||||
if let Some(span) = spans.last_mut() {
|
||||
if underline == span.underline {
|
||||
span.text.push(c);
|
||||
continue;
|
||||
}
|
||||
if let Some(span) = spans.last_mut()
|
||||
&& underline == span.underline
|
||||
{
|
||||
span.text.push(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
spans.push(DialogLabelSpan {
|
||||
|
|
@ -718,10 +718,10 @@ impl App {
|
|||
children.push(preview);
|
||||
}
|
||||
|
||||
if children.is_empty() {
|
||||
if let Some(item) = &self.tab.parent_item_opt {
|
||||
children.push(item.preview_view(None, military_time));
|
||||
}
|
||||
if children.is_empty()
|
||||
&& let Some(item) = &self.tab.parent_item_opt
|
||||
{
|
||||
children.push(item.preview_view(None, military_time));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1279,12 +1279,12 @@ impl Application for App {
|
|||
return self.update(message);
|
||||
}
|
||||
|
||||
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(|()| cosmic::action::none());
|
||||
}
|
||||
if let Some(data) = self.nav_model.data::<MounterData>(entity)
|
||||
&& let Some(mounter) = MOUNTERS.get(&data.0)
|
||||
{
|
||||
return mounter
|
||||
.mount(data.1.clone())
|
||||
.map(|()| cosmic::action::none());
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -1322,10 +1322,10 @@ impl Application for App {
|
|||
|
||||
// Close the dialog if the focused widget is the dialog's main text input instead of
|
||||
// unfocussing the widget.
|
||||
if let operation::Outcome::Some(focused) = operation::focusable::find_focused().finish() {
|
||||
if self.dialog_text_input == focused {
|
||||
return self.update(Message::Cancel);
|
||||
}
|
||||
if let operation::Outcome::Some(focused) = operation::focusable::find_focused().finish()
|
||||
&& self.dialog_text_input == focused
|
||||
{
|
||||
return self.update(Message::Cancel);
|
||||
}
|
||||
|
||||
self.update(Message::Cancel)
|
||||
|
|
@ -1419,14 +1419,14 @@ impl Application for App {
|
|||
}
|
||||
|
||||
// Check key binds from accept label
|
||||
if let Some(key_bind) = &self.accept_label.key_bind_opt {
|
||||
if key_bind.matches(modifiers, &key) {
|
||||
return self.update(if self.flags.kind.save() {
|
||||
Message::Save(false)
|
||||
} else {
|
||||
Message::Open
|
||||
});
|
||||
}
|
||||
if let Some(key_bind) = &self.accept_label.key_bind_opt
|
||||
&& key_bind.matches(modifiers, &key)
|
||||
{
|
||||
return self.update(if self.flags.kind.save() {
|
||||
Message::Save(false)
|
||||
} else {
|
||||
Message::Open
|
||||
});
|
||||
}
|
||||
|
||||
// Uncaptured keys with only shift modifiers go to the search or location box
|
||||
|
|
@ -1434,45 +1434,44 @@ impl Application for App {
|
|||
&& !modifiers.control()
|
||||
&& !modifiers.alt()
|
||||
&& matches!(key, Key::Character(_))
|
||||
&& let Some(text) = text
|
||||
{
|
||||
if let Some(text) = text {
|
||||
match self.flags.config.type_to_search {
|
||||
TypeToSearch::Recursive => {
|
||||
let mut term = self.search_get().unwrap_or_default().to_string();
|
||||
term.push_str(&text);
|
||||
return self.search_set(Some(term));
|
||||
match self.flags.config.type_to_search {
|
||||
TypeToSearch::Recursive => {
|
||||
let mut term = self.search_get().unwrap_or_default().to_string();
|
||||
term.push_str(&text);
|
||||
return self.search_set(Some(term));
|
||||
}
|
||||
TypeToSearch::EnterPath => {
|
||||
let location = (self.tab.edit_location)
|
||||
.as_ref()
|
||||
.map_or_else(|| &self.tab.location, |x| &x.location);
|
||||
// Try to add text to end of location
|
||||
if let Some(path) = location.path_opt() {
|
||||
let mut path_string = path.to_string_lossy().to_string();
|
||||
path_string.push_str(&text);
|
||||
self.tab.edit_location =
|
||||
Some(location.with_path(PathBuf::from(path_string)).into());
|
||||
}
|
||||
TypeToSearch::EnterPath => {
|
||||
let location = (self.tab.edit_location)
|
||||
.as_ref()
|
||||
.map_or_else(|| &self.tab.location, |x| &x.location);
|
||||
// Try to add text to end of location
|
||||
if let Some(path) = location.path_opt() {
|
||||
let mut path_string = path.to_string_lossy().to_string();
|
||||
path_string.push_str(&text);
|
||||
self.tab.edit_location =
|
||||
Some(location.with_path(PathBuf::from(path_string)).into());
|
||||
}
|
||||
}
|
||||
TypeToSearch::SelectByPrefix => {
|
||||
// Reset buffer if timeout elapsed
|
||||
if let Some(last_key) = self.type_select_last_key
|
||||
&& last_key.elapsed() >= tab::TYPE_SELECT_TIMEOUT
|
||||
{
|
||||
self.type_select_prefix.clear();
|
||||
}
|
||||
TypeToSearch::SelectByPrefix => {
|
||||
// Reset buffer if timeout elapsed
|
||||
if let Some(last_key) = self.type_select_last_key {
|
||||
if last_key.elapsed() >= tab::TYPE_SELECT_TIMEOUT {
|
||||
self.type_select_prefix.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Accumulate character and select
|
||||
self.type_select_prefix.push_str(&text.to_lowercase());
|
||||
self.type_select_last_key = Some(Instant::now());
|
||||
// Accumulate character and select
|
||||
self.type_select_prefix.push_str(&text.to_lowercase());
|
||||
self.type_select_last_key = Some(Instant::now());
|
||||
|
||||
self.tab.select_by_prefix(&self.type_select_prefix);
|
||||
if let Some(offset) = self.tab.select_focus_scroll() {
|
||||
return scrollable::scroll_to(
|
||||
self.tab.scrollable_id.clone(),
|
||||
offset,
|
||||
);
|
||||
}
|
||||
self.tab.select_by_prefix(&self.type_select_prefix);
|
||||
if let Some(offset) = self.tab.select_focus_scroll() {
|
||||
return scrollable::scroll_to(
|
||||
self.tab.scrollable_id.clone(),
|
||||
offset,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1486,21 +1485,22 @@ impl Application for App {
|
|||
let mut unmounted = Vec::new();
|
||||
if let Some(old_items) = self.mounter_items.get(&mounter_key) {
|
||||
for old_item in old_items {
|
||||
if let Some(old_path) = old_item.path() {
|
||||
if old_item.is_mounted() {
|
||||
let mut still_mounted = false;
|
||||
for item in &mounter_items {
|
||||
if let Some(path) = item.path() {
|
||||
if path == old_path && item.is_mounted() {
|
||||
still_mounted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if !still_mounted {
|
||||
unmounted.push(Location::Path(old_path));
|
||||
if let Some(old_path) = old_item.path()
|
||||
&& old_item.is_mounted()
|
||||
{
|
||||
let mut still_mounted = false;
|
||||
for item in &mounter_items {
|
||||
if let Some(path) = item.path()
|
||||
&& path == old_path
|
||||
&& item.is_mounted()
|
||||
{
|
||||
still_mounted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !still_mounted {
|
||||
unmounted.push(Location::Path(old_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1601,16 +1601,16 @@ impl Application for App {
|
|||
let mut paths = Vec::new();
|
||||
if let Some(items) = self.tab.items_opt() {
|
||||
for item in items {
|
||||
if item.selected {
|
||||
if let Some(path) = item.path_opt() {
|
||||
paths.push(path.clone());
|
||||
let _ = update_recently_used(
|
||||
path,
|
||||
Self::APP_ID.to_string(),
|
||||
"cosmic-files".to_string(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
if item.selected
|
||||
&& let Some(path) = item.path_opt()
|
||||
{
|
||||
paths.push(path.clone());
|
||||
let _ = update_recently_used(
|
||||
path,
|
||||
Self::APP_ID.to_string(),
|
||||
"cosmic-files".to_string(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1640,11 +1640,11 @@ impl Application for App {
|
|||
}
|
||||
|
||||
// If we are in directory mode, return the current directory
|
||||
if self.flags.kind.is_dir() {
|
||||
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);
|
||||
}
|
||||
if self.flags.kind.is_dir()
|
||||
&& 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);
|
||||
}
|
||||
}
|
||||
Message::Preview => {
|
||||
|
|
@ -1654,26 +1654,24 @@ impl Application for App {
|
|||
});
|
||||
}
|
||||
Message::Save(replace) => {
|
||||
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);
|
||||
if path.is_dir() {
|
||||
// cd to directory
|
||||
let message = Message::TabMessage(tab::Message::Location(
|
||||
Location::Path(path),
|
||||
));
|
||||
return self.update(message);
|
||||
} else if !replace && path.exists() {
|
||||
self.dialog_pages.push_back(DialogPage::Replace {
|
||||
filename: filename.clone(),
|
||||
});
|
||||
return widget::button::focus(REPLACE_BUTTON_ID.clone());
|
||||
}
|
||||
self.result_opt = Some(DialogResult::Open(vec![path]));
|
||||
return window::close(self.flags.window_id);
|
||||
}
|
||||
if let DialogKind::SaveFile { filename } = &self.flags.kind
|
||||
&& !filename.is_empty()
|
||||
&& let Some(tab_path) = self.tab.location.path_opt()
|
||||
{
|
||||
let path = tab_path.join(filename);
|
||||
if path.is_dir() {
|
||||
// cd to directory
|
||||
let message =
|
||||
Message::TabMessage(tab::Message::Location(Location::Path(path)));
|
||||
return self.update(message);
|
||||
} else if !replace && path.exists() {
|
||||
self.dialog_pages.push_back(DialogPage::Replace {
|
||||
filename: filename.clone(),
|
||||
});
|
||||
return widget::button::focus(REPLACE_BUTTON_ID.clone());
|
||||
}
|
||||
self.result_opt = Some(DialogResult::Open(vec![path]));
|
||||
return window::close(self.flags.window_id);
|
||||
}
|
||||
}
|
||||
Message::ScrollTab(scroll_speed) => {
|
||||
|
|
@ -1703,16 +1701,14 @@ impl Application for App {
|
|||
let tab_commands = self.tab.update(tab_message, self.modifiers);
|
||||
|
||||
// Update filename box when anything is selected
|
||||
if let DialogKind::SaveFile { filename } = &mut self.flags.kind {
|
||||
if let Some(click_i) = click_i_opt {
|
||||
if let Some(items) = self.tab.items_opt() {
|
||||
if let Some(item) = items.get(click_i) {
|
||||
if item.selected && !item.metadata.is_dir() {
|
||||
filename.clone_from(&item.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let DialogKind::SaveFile { filename } = &mut self.flags.kind
|
||||
&& let Some(click_i) = click_i_opt
|
||||
&& let Some(items) = self.tab.items_opt()
|
||||
&& let Some(item) = items.get(click_i)
|
||||
&& item.selected
|
||||
&& !item.metadata.is_dir()
|
||||
{
|
||||
filename.clone_from(&item.name);
|
||||
}
|
||||
|
||||
let mut commands = Vec::new();
|
||||
|
|
@ -1840,34 +1836,34 @@ impl Application for App {
|
|||
Message::TabRescan(location, parent_item_opt, mut items, selection_paths) => {
|
||||
if location == self.tab.location {
|
||||
// Filter
|
||||
if let Some(filter_i) = self.filter_selected {
|
||||
if let Some(filter) = self.filters.get(filter_i) {
|
||||
// Parse globs (Mime implements PartialEq with &str, so no need to parse)
|
||||
let mut parsed_globs = Vec::new();
|
||||
let mut mimes = Vec::new();
|
||||
for pattern in &filter.patterns {
|
||||
match pattern {
|
||||
DialogFilterPattern::Glob(value) => {
|
||||
match glob::Pattern::new(value) {
|
||||
Ok(glob) => parsed_globs.push(glob),
|
||||
Err(err) => {
|
||||
log::warn!("failed to parse glob {value:?}: {err}");
|
||||
}
|
||||
if let Some(filter_i) = self.filter_selected
|
||||
&& let Some(filter) = self.filters.get(filter_i)
|
||||
{
|
||||
// Parse globs (Mime implements PartialEq with &str, so no need to parse)
|
||||
let mut parsed_globs = Vec::new();
|
||||
let mut mimes = Vec::new();
|
||||
for pattern in &filter.patterns {
|
||||
match pattern {
|
||||
DialogFilterPattern::Glob(value) => {
|
||||
match glob::Pattern::new(value) {
|
||||
Ok(glob) => parsed_globs.push(glob),
|
||||
Err(err) => {
|
||||
log::warn!("failed to parse glob {value:?}: {err}");
|
||||
}
|
||||
}
|
||||
DialogFilterPattern::Mime(value) => mimes.push(value.as_str()),
|
||||
}
|
||||
DialogFilterPattern::Mime(value) => mimes.push(value.as_str()),
|
||||
}
|
||||
}
|
||||
|
||||
items.retain(|item| {
|
||||
// Directories are always shown
|
||||
item.metadata.is_dir()
|
||||
items.retain(|item| {
|
||||
// Directories are always shown
|
||||
item.metadata.is_dir()
|
||||
// Check for mime type match (first because it is faster)
|
||||
|| mimes.iter().copied().any(|mime| mime == item.mime)
|
||||
// Check for glob match (last because it is slower)
|
||||
|| parsed_globs.iter().any(|glob| glob.matches(&item.name))
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Select based on filename
|
||||
|
|
@ -1944,19 +1940,19 @@ impl Application for App {
|
|||
|
||||
let mut col = widget::column::with_capacity(2);
|
||||
|
||||
if self.core.is_condensed() {
|
||||
if let Some(term) = self.search_get() {
|
||||
col = col.push(
|
||||
widget::container(
|
||||
widget::text_input::search_input("", term)
|
||||
.width(Length::Fill)
|
||||
.id(self.search_id.clone())
|
||||
.on_clear(Message::SearchClear)
|
||||
.on_input(Message::SearchInput),
|
||||
)
|
||||
.padding(space_xxs),
|
||||
);
|
||||
}
|
||||
if self.core.is_condensed()
|
||||
&& let Some(term) = self.search_get()
|
||||
{
|
||||
col = col.push(
|
||||
widget::container(
|
||||
widget::text_input::search_input("", term)
|
||||
.width(Length::Fill)
|
||||
.id(self.search_id.clone())
|
||||
.on_clear(Message::SearchClear)
|
||||
.on_input(Message::SearchInput),
|
||||
)
|
||||
.padding(space_xxs),
|
||||
);
|
||||
}
|
||||
|
||||
col = col.push(
|
||||
|
|
|
|||
|
|
@ -392,16 +392,16 @@ impl LargeImageManager {
|
|||
generation: u64,
|
||||
) -> bool {
|
||||
// Check if this decode is still current (not superseded by a newer one)
|
||||
if let Some(¤t_gen) = self.decode_generations.get(&path) {
|
||||
if generation != current_gen {
|
||||
log::info!(
|
||||
"Discarding outdated decode for {} (generation {} != current {})",
|
||||
path.display(),
|
||||
generation,
|
||||
current_gen
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if let Some(¤t_gen) = self.decode_generations.get(&path)
|
||||
&& generation != current_gen
|
||||
{
|
||||
log::info!(
|
||||
"Discarding outdated decode for {} (generation {} != current {})",
|
||||
path.display(),
|
||||
generation,
|
||||
current_gen
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
log::info!(
|
||||
|
|
@ -556,7 +556,7 @@ impl LargeImageManager {
|
|||
|
||||
/// Check if sufficient memory is available, clearing cache if needed.
|
||||
/// Returns true if memory is available, false otherwise.
|
||||
fn ensure_memory_available(&mut self, path: &PathBuf, width: u32, height: u32) -> bool {
|
||||
fn ensure_memory_available(&mut self, path: &Path, width: u32, height: u32) -> bool {
|
||||
let (has_memory, error_opt) = check_memory_available(width, height);
|
||||
|
||||
if has_memory {
|
||||
|
|
@ -565,7 +565,7 @@ impl LargeImageManager {
|
|||
|
||||
if self.cache_is_empty() {
|
||||
if let Some(error_msg) = error_opt {
|
||||
self.store_error(path.clone(), error_msg);
|
||||
self.store_error(path.to_path_buf(), error_msg);
|
||||
log::warn!(
|
||||
"Cannot load {}: insufficient memory and cache is empty",
|
||||
path.display()
|
||||
|
|
@ -588,7 +588,7 @@ impl LargeImageManager {
|
|||
}
|
||||
|
||||
if let Some(error_msg) = error_opt_after {
|
||||
self.store_error(path.clone(), error_msg);
|
||||
self.store_error(path.to_path_buf(), error_msg);
|
||||
log::warn!(
|
||||
"Cannot load {}: insufficient memory even after cache clear",
|
||||
path.display()
|
||||
|
|
|
|||
|
|
@ -62,10 +62,10 @@ pub static LOCALE: LazyLock<Locale> = LazyLock::new(|| {
|
|||
}
|
||||
|
||||
// Try language-only fallback (e.g., "en" from "en-US")
|
||||
if let Some(lang) = cleaned_locale.split('-').next() {
|
||||
if let Ok(locale) = Locale::try_from_str(lang) {
|
||||
return locale;
|
||||
}
|
||||
if let Some(lang) = cleaned_locale.split('-').next()
|
||||
&& let Ok(locale) = Locale::try_from_str(lang)
|
||||
{
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ impl MimeAppCache {
|
|||
for (mime, filenames) in list.removed_associations.iter() {
|
||||
for filename in filenames {
|
||||
log::trace!("remove {mime}={filename}");
|
||||
if let Some(apps) = self.cache.get_mut(&mime) {
|
||||
if let Some(apps) = self.cache.get_mut(mime) {
|
||||
apps.retain(|x| !filename_eq(&x.path, filename));
|
||||
}
|
||||
}
|
||||
|
|
@ -319,7 +319,7 @@ impl MimeAppCache {
|
|||
for (mime, filenames) in list.default_apps.iter() {
|
||||
for filename in filenames {
|
||||
log::trace!("default {mime}={filename}");
|
||||
if let Some(apps) = self.cache.get_mut(&mime) {
|
||||
if let Some(apps) = self.cache.get_mut(mime) {
|
||||
let mut found = false;
|
||||
for app in apps.iter_mut() {
|
||||
if filename_eq(&app.path, filename) {
|
||||
|
|
|
|||
|
|
@ -23,12 +23,11 @@ fn resolve_uri(uri: &str) -> (String, gio::File) {
|
|||
TARGET_URI_ATTRIBUTE,
|
||||
gio::FileQueryInfoFlags::NONE,
|
||||
gio::Cancellable::NONE,
|
||||
) {
|
||||
if let Some(resolved_uri) = file_info.attribute_as_string(TARGET_URI_ATTRIBUTE) {
|
||||
let resolved_uri = String::from(resolved_uri);
|
||||
let file = gio::File::for_uri(&resolved_uri);
|
||||
return (resolved_uri, file);
|
||||
}
|
||||
) && let Some(resolved_uri) = file_info.attribute_as_string(TARGET_URI_ATTRIBUTE)
|
||||
{
|
||||
let resolved_uri = String::from(resolved_uri);
|
||||
let file = gio::File::for_uri(&resolved_uri);
|
||||
return (resolved_uri, file);
|
||||
}
|
||||
|
||||
(uri.to_string(), file)
|
||||
|
|
@ -60,7 +59,7 @@ fn items(monitor: &gio::VolumeMonitor, sizes: IconSizes) -> MounterItems {
|
|||
gio::Cancellable::NONE,
|
||||
)
|
||||
.ok()
|
||||
.and_then(|info| Some(info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE)))
|
||||
.map(|info| info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE))
|
||||
.unwrap_or(true); // Default to remote if query fails
|
||||
|
||||
MounterItem::Gvfs(Item {
|
||||
|
|
@ -457,9 +456,9 @@ impl Gvfs {
|
|||
log::info!("mount {name}: result {res:?}");
|
||||
// Update the mounter_item with mount information after successful mount
|
||||
let mut updated_item = mounter_item.clone();
|
||||
if res.is_ok() {
|
||||
if let MounterItem::Gvfs(ref mut item) = updated_item {
|
||||
if let Some(mount) = volume_for_callback.get_mount() {
|
||||
if res.is_ok()
|
||||
&& let MounterItem::Gvfs(ref mut item) = updated_item
|
||||
&& let Some(mount) = volume_for_callback.get_mount() {
|
||||
let root = MountExt::root(&mount);
|
||||
item.path_opt = root.path();
|
||||
item.is_mounted = true;
|
||||
|
|
@ -469,14 +468,9 @@ impl Gvfs {
|
|||
gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE,
|
||||
gio::Cancellable::NONE,
|
||||
)
|
||||
.ok()
|
||||
.and_then(|info| {
|
||||
Some(info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE))
|
||||
})
|
||||
.ok().map(|info| info.boolean(gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE))
|
||||
.unwrap_or(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
event_tx.send(Event::MountResult(updated_item, match res {
|
||||
Ok(()) => {
|
||||
_ = complete_tx.send(Ok(()));
|
||||
|
|
|
|||
|
|
@ -246,19 +246,18 @@ struct State {
|
|||
|
||||
impl State {
|
||||
fn drag_rect(&self, cursor: mouse::Cursor) -> Option<Rectangle> {
|
||||
if let Some(drag_source) = self.drag_initiated {
|
||||
if let Some(position) = cursor.position().or(self.last_virtual_position) {
|
||||
if position.distance(drag_source) > 1.0 {
|
||||
let min_x = drag_source.x.min(position.x);
|
||||
let max_x = drag_source.x.max(position.x);
|
||||
let min_y = drag_source.y.min(position.y);
|
||||
let max_y = drag_source.y.max(position.y);
|
||||
return Some(Rectangle::new(
|
||||
Point::new(min_x, min_y),
|
||||
Size::new(max_x - min_x, max_y - min_y),
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(drag_source) = self.drag_initiated
|
||||
&& let Some(position) = cursor.position().or(self.last_virtual_position)
|
||||
&& position.distance(drag_source) > 1.0
|
||||
{
|
||||
let min_x = drag_source.x.min(position.x);
|
||||
let max_x = drag_source.x.max(position.x);
|
||||
let min_y = drag_source.y.min(position.y);
|
||||
let max_y = drag_source.y.max(position.y);
|
||||
return Some(Rectangle::new(
|
||||
Point::new(min_x, min_y),
|
||||
Size::new(max_x - min_x, max_y - min_y),
|
||||
));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
@ -527,12 +526,12 @@ fn update<Message: Clone>(
|
|||
let offset = layout.virtual_offset();
|
||||
let layout_bounds = layout.bounds();
|
||||
|
||||
let viewport_changed = state.viewport.map_or(true, |v| v != *viewport);
|
||||
let viewport_changed = state.viewport != Some(*viewport);
|
||||
|
||||
if let Some(message) = widget.on_resize.as_ref() {
|
||||
if viewport_changed {
|
||||
shell.publish(message(*viewport));
|
||||
}
|
||||
if let Some(message) = widget.on_resize.as_ref()
|
||||
&& viewport_changed
|
||||
{
|
||||
shell.publish(message(*viewport));
|
||||
}
|
||||
|
||||
state.viewport = Some(*viewport);
|
||||
|
|
@ -664,113 +663,112 @@ fn update<Message: Clone>(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_right_press.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_right_press.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Right))
|
||||
) {
|
||||
let point_opt = if widget.on_right_press_window_position {
|
||||
cursor.position_over(layout_bounds).map(|mut p| {
|
||||
p.x -= offset.x;
|
||||
p.y -= offset.y;
|
||||
p
|
||||
})
|
||||
} else {
|
||||
cursor.position_in(layout_bounds)
|
||||
};
|
||||
shell.publish(message(point_opt));
|
||||
)
|
||||
{
|
||||
let point_opt = if widget.on_right_press_window_position {
|
||||
cursor.position_over(layout_bounds).map(|mut p| {
|
||||
p.x -= offset.x;
|
||||
p.y -= offset.y;
|
||||
p
|
||||
})
|
||||
} else {
|
||||
cursor.position_in(layout_bounds)
|
||||
};
|
||||
shell.publish(message(point_opt));
|
||||
|
||||
if widget.on_right_press_no_capture {
|
||||
return event::Status::Ignored;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
if widget.on_right_press_no_capture {
|
||||
return event::Status::Ignored;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_right_release.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_right_release.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Right))
|
||||
) {
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
)
|
||||
{
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
|
||||
return event::Status::Captured;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_middle_press.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_middle_press.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Middle))
|
||||
) {
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
)
|
||||
{
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
|
||||
return event::Status::Captured;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_middle_release.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_middle_release.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Middle))
|
||||
) {
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
)
|
||||
{
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
|
||||
return event::Status::Captured;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_back_press.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_back_press.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Back))
|
||||
) {
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
)
|
||||
{
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
|
||||
return event::Status::Captured;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_back_release.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_back_release.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Back))
|
||||
) {
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
)
|
||||
{
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
|
||||
return event::Status::Captured;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_forward_press.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_forward_press.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Forward))
|
||||
) {
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
)
|
||||
{
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
|
||||
return event::Status::Captured;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some(message) = widget.on_forward_release.as_ref() {
|
||||
if matches!(
|
||||
if let Some(message) = widget.on_forward_release.as_ref()
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Forward))
|
||||
) {
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
)
|
||||
{
|
||||
shell.publish(message(cursor.position_in(layout_bounds)));
|
||||
|
||||
return event::Status::Captured;
|
||||
}
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
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) {
|
||||
shell.publish(message);
|
||||
return event::Status::Captured;
|
||||
}
|
||||
}
|
||||
if let Some(on_scroll) = widget.on_scroll.as_ref()
|
||||
&& let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event
|
||||
&& let Some(message) = on_scroll(*delta)
|
||||
{
|
||||
shell.publish(message);
|
||||
return event::Status::Captured;
|
||||
}
|
||||
|
||||
if let Some((message, drag_rect)) = widget.on_drag.as_ref().zip(state.drag_rect(cursor)) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
spawn_detached::spawn_detached,
|
||||
tab,
|
||||
};
|
||||
use cosmic::iced::futures::{SinkExt, channel::mpsc::Sender};
|
||||
use cosmic::iced::futures::{self, SinkExt, StreamExt, channel::mpsc::Sender, stream};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fmt::Formatter,
|
||||
|
|
@ -196,6 +196,31 @@ async fn copy_or_move(
|
|||
.map_err(wrap_compio_spawn_error)?
|
||||
}
|
||||
|
||||
pub async fn sync_to_disk(
|
||||
written_files: Vec<PathBuf>,
|
||||
target_dirs: std::collections::HashSet<PathBuf>,
|
||||
) {
|
||||
// Sync files to disk
|
||||
stream::iter(written_files.into_iter().map(|path| async move {
|
||||
if let Ok(file) = compio::fs::OpenOptions::new().write(true).open(&path).await {
|
||||
let _ = file.sync_all().await;
|
||||
}
|
||||
}))
|
||||
.buffer_unordered(32)
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
|
||||
// Sync directories to disk
|
||||
stream::iter(target_dirs.into_iter().map(|path| async move {
|
||||
if let Ok(dir) = compio::fs::OpenOptions::new().read(true).open(&path).await {
|
||||
let _ = dir.sync_all().await;
|
||||
}
|
||||
}))
|
||||
.buffer_unordered(16)
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
}
|
||||
|
||||
fn copy_unique_path(from: &Path, to: &Path) -> PathBuf {
|
||||
// List of compound extensions to check
|
||||
const COMPOUND_EXTENSIONS: &[&str] = &[
|
||||
|
|
@ -934,10 +959,10 @@ impl Operation {
|
|||
let dir_name = get_directory_name(file_name);
|
||||
let mut new_dir = to.join(dir_name);
|
||||
|
||||
if new_dir.exists() {
|
||||
if let Some(new_dir_parent) = new_dir.parent() {
|
||||
new_dir = copy_unique_path(&new_dir, new_dir_parent);
|
||||
}
|
||||
if new_dir.exists()
|
||||
&& let Some(new_dir_parent) = new_dir.parent()
|
||||
{
|
||||
new_dir = copy_unique_path(&new_dir, new_dir_parent);
|
||||
}
|
||||
|
||||
op_sel.ignored.push(path.clone());
|
||||
|
|
@ -1185,7 +1210,7 @@ mod tests {
|
|||
path::PathBuf,
|
||||
};
|
||||
|
||||
use cosmic::iced::futures::{StreamExt, channel::mpsc};
|
||||
use cosmic::iced::futures::{StreamExt, channel::mpsc, future};
|
||||
use log::debug;
|
||||
use test_log::test;
|
||||
use tokio::sync;
|
||||
|
|
@ -1239,7 +1264,7 @@ mod tests {
|
|||
}
|
||||
};
|
||||
|
||||
futures::future::join(handle_messages, handle_copy).await.1
|
||||
future::join(handle_messages, handle_copy).await.1
|
||||
}
|
||||
|
||||
#[test(compio::test)]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl OpReader {
|
|||
|
||||
impl io::Read for OpReader {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
futures::executor::block_on(async {
|
||||
cosmic::iced::futures::executor::block_on(async {
|
||||
self.controller
|
||||
.check()
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::time::Instant;
|
|||
use std::{cell::Cell, error::Error, fs, ops::ControlFlow, path::PathBuf, rc::Rc};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::operation::OperationError;
|
||||
use crate::operation::{OperationError, sync_to_disk};
|
||||
|
||||
use super::{Controller, OperationSelection, ReplaceResult, copy_unique_path};
|
||||
|
||||
|
|
@ -57,6 +57,8 @@ impl Context {
|
|||
) -> Result<bool, OperationError> {
|
||||
let mut ops = Vec::new();
|
||||
let mut cleanup_ops = Vec::new();
|
||||
let mut written_files = Vec::new();
|
||||
let mut target_dirs = std::collections::HashSet::new();
|
||||
for (from_parent, to_parent) in from_to_pairs {
|
||||
self.controller
|
||||
.check()
|
||||
|
|
@ -136,10 +138,13 @@ impl Context {
|
|||
}),
|
||||
is_cleanup: false,
|
||||
};
|
||||
if matches!(method, Method::Move { .. }) {
|
||||
if let Some(cleanup_op) = op.move_cleanup_op() {
|
||||
cleanup_ops.push(cleanup_op);
|
||||
}
|
||||
if matches!(method, Method::Move { .. })
|
||||
&& let Some(cleanup_op) = op.move_cleanup_op()
|
||||
{
|
||||
cleanup_ops.push(cleanup_op);
|
||||
}
|
||||
if let Some(parent) = op.to.parent() {
|
||||
target_dirs.insert(parent.to_path_buf());
|
||||
}
|
||||
ops.push(op);
|
||||
}
|
||||
|
|
@ -177,10 +182,19 @@ impl Context {
|
|||
&self.controller,
|
||||
)
|
||||
})? {
|
||||
if matches!(
|
||||
op.kind,
|
||||
OpKind::Copy
|
||||
| OpKind::Move {
|
||||
cross_device_copy: true
|
||||
}
|
||||
) {
|
||||
written_files.push(op.to.clone());
|
||||
}
|
||||
// The from path is ignored in the operation selection if it is a top level item
|
||||
if self.op_sel.ignored.contains(&op.from) {
|
||||
// So add the to path to the selection
|
||||
self.op_sel.selected.push(op.to.clone());
|
||||
self.op_sel.selected.push(op.to);
|
||||
}
|
||||
} else {
|
||||
// Cancelled
|
||||
|
|
@ -188,6 +202,9 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
// Flush files to disk
|
||||
sync_to_disk(written_files, target_dirs).await;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +322,7 @@ impl Op {
|
|||
}
|
||||
}
|
||||
|
||||
let (from_file, metadata, mut to_file) = futures::try_join!(
|
||||
let (from_file, metadata, mut to_file) = cosmic::iced::futures::try_join!(
|
||||
async {
|
||||
compio::fs::OpenOptions::new()
|
||||
.read(true)
|
||||
|
|
@ -411,8 +428,6 @@ impl Op {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
to_file.sync_all().await?;
|
||||
}
|
||||
OpKind::Move { cross_device_copy } => {
|
||||
// Remove `to` if overwriting and it is an existing file
|
||||
|
|
|
|||
659
src/tab.rs
659
src/tab.rs
|
|
@ -1,5 +1,8 @@
|
|||
use chrono::{Datelike, Timelike, Utc};
|
||||
use cosmic::{
|
||||
Apply, Element, cosmic_theme, font,
|
||||
Apply, Element, cosmic_theme,
|
||||
desktop::fde::{DesktopEntry, get_languages_from_env},
|
||||
font,
|
||||
iced::{
|
||||
Alignment,
|
||||
Border,
|
||||
|
|
@ -37,8 +40,6 @@ use cosmic::{
|
|||
menu::{action::MenuAction, key_bind::KeyBind},
|
||||
},
|
||||
};
|
||||
|
||||
use chrono::{Datelike, Timelike, Utc};
|
||||
use i18n_embed::LanguageLoader;
|
||||
use icu::{
|
||||
datetime::{
|
||||
|
|
@ -615,7 +616,8 @@ pub fn fs_kind(_metadata: &Metadata) -> FsKind {
|
|||
}
|
||||
|
||||
fn get_desktop_file_display_name(path: &Path) -> Option<String> {
|
||||
let entry = match freedesktop_entry_parser::parse_entry(path) {
|
||||
let locales = get_languages_from_env();
|
||||
let entry = match DesktopEntry::from_path(path, Some(&locales)) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
log::warn!("failed to parse {}: {}", path.display(), err);
|
||||
|
|
@ -623,14 +625,11 @@ fn get_desktop_file_display_name(path: &Path) -> Option<String> {
|
|||
}
|
||||
};
|
||||
|
||||
entry
|
||||
.section("Desktop Entry")
|
||||
.attr("Name")
|
||||
.map(str::to_string)
|
||||
entry.name(&locales).map(|s| s.into_owned())
|
||||
}
|
||||
|
||||
fn get_desktop_file_icon(path: &Path) -> Option<String> {
|
||||
let entry = match freedesktop_entry_parser::parse_entry(path) {
|
||||
let entry = match DesktopEntry::from_path::<&str>(path, None) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
log::warn!("failed to parse {}: {}", path.display(), err);
|
||||
|
|
@ -638,10 +637,7 @@ fn get_desktop_file_icon(path: &Path) -> Option<String> {
|
|||
}
|
||||
};
|
||||
|
||||
entry
|
||||
.section("Desktop Entry")
|
||||
.attr("Icon")
|
||||
.map(str::to_string)
|
||||
entry.icon().map(str::to_string)
|
||||
}
|
||||
|
||||
/// Creates an icon handle from a desktop file's Icon field value.
|
||||
|
|
@ -656,17 +652,17 @@ fn desktop_icon_handle(icon: &str, size: u16) -> widget::icon::Handle {
|
|||
}
|
||||
|
||||
pub fn parse_desktop_file(path: &Path) -> (Option<String>, Option<String>) {
|
||||
let entry = match freedesktop_entry_parser::parse_entry(path) {
|
||||
let locales = get_languages_from_env();
|
||||
let entry = match DesktopEntry::from_path(path, Some(&locales)) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
log::warn!("failed to parse {}: {}", path.display(), err);
|
||||
return (None, None);
|
||||
}
|
||||
};
|
||||
let section = entry.section("Desktop Entry");
|
||||
(
|
||||
section.attr("Name").map(str::to_string),
|
||||
section.attr("Icon").map(str::to_string),
|
||||
entry.name(&locales).map(|s| s.into_owned()),
|
||||
entry.icon().map(str::to_string),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -934,43 +930,43 @@ pub fn scan_path(tab_path: &PathBuf, sizes: IconSizes) -> Vec<Item> {
|
|||
|
||||
#[cfg(feature = "gvfs")]
|
||||
{
|
||||
if let Ok(path_meta) = fs::metadata(tab_path) {
|
||||
if fs_kind(&path_meta) == FsKind::Gvfs {
|
||||
let file = gio::File::for_path(tab_path);
|
||||
if let Ok(path_meta) = fs::metadata(tab_path)
|
||||
&& fs_kind(&path_meta) == FsKind::Gvfs
|
||||
{
|
||||
let file = gio::File::for_path(tab_path);
|
||||
|
||||
// gio crate expects a comma delimited string
|
||||
let attr_string = [
|
||||
gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.as_str(),
|
||||
gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE.as_str(),
|
||||
gio::FILE_ATTRIBUTE_TIME_MODIFIED.as_str(),
|
||||
gio::FILE_ATTRIBUTE_STANDARD_SIZE.as_str(),
|
||||
gio::FILE_ATTRIBUTE_STANDARD_TYPE.as_str(),
|
||||
gio::FILE_ATTRIBUTE_STANDARD_NAME.as_str(),
|
||||
]
|
||||
.join(",");
|
||||
// gio crate expects a comma delimited string
|
||||
let attr_string = [
|
||||
gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.as_str(),
|
||||
gio::FILE_ATTRIBUTE_FILESYSTEM_REMOTE.as_str(),
|
||||
gio::FILE_ATTRIBUTE_TIME_MODIFIED.as_str(),
|
||||
gio::FILE_ATTRIBUTE_STANDARD_SIZE.as_str(),
|
||||
gio::FILE_ATTRIBUTE_STANDARD_TYPE.as_str(),
|
||||
gio::FILE_ATTRIBUTE_STANDARD_NAME.as_str(),
|
||||
]
|
||||
.join(",");
|
||||
|
||||
match gio::prelude::FileExt::enumerate_children(
|
||||
&file,
|
||||
attr_string.as_str(),
|
||||
gio::FileQueryInfoFlags::NONE,
|
||||
gio::Cancellable::NONE,
|
||||
) {
|
||||
Ok(res) => {
|
||||
remote_scannable = true;
|
||||
items = res
|
||||
.filter_map(|file| {
|
||||
let file = file.ok()?;
|
||||
Some(item_from_gvfs_info(tab_path.join(file.name()), file, sizes))
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!(
|
||||
"could not enumerate {} via gio: {}",
|
||||
tab_path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
match gio::prelude::FileExt::enumerate_children(
|
||||
&file,
|
||||
attr_string.as_str(),
|
||||
gio::FileQueryInfoFlags::NONE,
|
||||
gio::Cancellable::NONE,
|
||||
) {
|
||||
Ok(res) => {
|
||||
remote_scannable = true;
|
||||
items = res
|
||||
.filter_map(|file| {
|
||||
let file = file.ok()?;
|
||||
Some(item_from_gvfs_info(tab_path.join(file.name()), file, sizes))
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!(
|
||||
"could not enumerate {} via gio: {}",
|
||||
tab_path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1410,11 +1406,11 @@ impl EditLocation {
|
|||
self.selected = Some(selected);
|
||||
|
||||
// Automatically resolve if there is only one completion
|
||||
if completions.len() == 1 {
|
||||
if let Some(resolved) = self.resolve() {
|
||||
self.location = resolved;
|
||||
self.selected = None;
|
||||
}
|
||||
if completions.len() == 1
|
||||
&& let Some(resolved) = self.resolve()
|
||||
{
|
||||
self.location = resolved;
|
||||
self.selected = None;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -2033,10 +2029,10 @@ impl ItemThumbnail {
|
|||
if let Some((item_thumbnail, temp_file)) =
|
||||
Self::generate_thumbnail_external(path, &mime, thumbnail_size, thumbnail_dir)
|
||||
{
|
||||
if let Ok(cache) = thumbnail_cacher {
|
||||
if let Err(err) = cache.update_with_temp_file(temp_file) {
|
||||
log::warn!("failed to update cache for {}: {}", path.display(), err);
|
||||
}
|
||||
if let Ok(cache) = thumbnail_cacher
|
||||
&& let Err(err) = cache.update_with_temp_file(temp_file)
|
||||
{
|
||||
log::warn!("failed to update cache for {}: {}", path.display(), err);
|
||||
}
|
||||
return item_thumbnail;
|
||||
}
|
||||
|
|
@ -2076,16 +2072,15 @@ impl ItemThumbnail {
|
|||
// If we weren't able to create a thumbnail, but we should have
|
||||
// been able to, create a fail marker so that it isn't tried the
|
||||
// next time.
|
||||
if let Ok(cacher) = thumbnail_cacher {
|
||||
if tried_supported_file {
|
||||
if let Err(err) = cacher.create_fail_marker() {
|
||||
log::warn!(
|
||||
"failed to create thumbnail fail marker for {}: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Ok(cacher) = thumbnail_cacher
|
||||
&& tried_supported_file
|
||||
&& let Err(err) = cacher.create_fail_marker()
|
||||
{
|
||||
log::warn!(
|
||||
"failed to create thumbnail fail marker for {}: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
|
||||
Self::NotImage
|
||||
|
|
@ -2273,13 +2268,13 @@ impl Item {
|
|||
widget::button::icon(widget::icon::from_name("go-next-symbolic"))
|
||||
.on_press(Message::ItemRight),
|
||||
);
|
||||
if self.can_gallery() {
|
||||
if let Some(_path) = self.path_opt() {
|
||||
row = row.push(
|
||||
widget::button::icon(widget::icon::from_name("view-fullscreen-symbolic"))
|
||||
.on_press(Message::Gallery(true)),
|
||||
);
|
||||
}
|
||||
if self.can_gallery()
|
||||
&& let Some(_path) = self.path_opt()
|
||||
{
|
||||
row = row.push(
|
||||
widget::button::icon(widget::icon::from_name("view-fullscreen-symbolic"))
|
||||
.on_press(Message::Gallery(true)),
|
||||
);
|
||||
}
|
||||
row.into()
|
||||
}
|
||||
|
|
@ -2445,18 +2440,20 @@ impl Item {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(path) = self.path_opt() {
|
||||
if let Ok(img) = image::image_dimensions(path) {
|
||||
let (width, height) = img;
|
||||
details = details.push(widget::text::body(format!("{width}x{height}")));
|
||||
}
|
||||
if let Some(path) = self.path_opt()
|
||||
&& let Ok(img) = image::image_dimensions(path)
|
||||
{
|
||||
let (width, height) = img;
|
||||
details = details.push(widget::text::body(format!("{width}x{height}")));
|
||||
}
|
||||
column = column.push(details);
|
||||
|
||||
if let Some(path) = self.path_opt() {
|
||||
column = column.push(
|
||||
widget::button::standard(fl!("open")).on_press(Message::Open(Some(path.clone()))),
|
||||
);
|
||||
if self.selected {
|
||||
column = column.push(
|
||||
widget::button::standard(fl!("open")).on_press(Message::Open(Some(path.clone()))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !settings.is_empty() {
|
||||
|
|
@ -2635,12 +2632,11 @@ async fn calculate_dir_size(path: &Path, controller: Controller) -> Result<u64,
|
|||
.map_err(|s| OperationError::from_state(s, &controller))?;
|
||||
|
||||
//TODO: report more errors?
|
||||
if let Ok(entry) = entry_res {
|
||||
if let Ok(metadata) = entry.metadata() {
|
||||
if metadata.is_file() {
|
||||
total += metadata.len();
|
||||
}
|
||||
}
|
||||
if let Ok(entry) = entry_res
|
||||
&& let Ok(metadata) = entry.metadata()
|
||||
&& metadata.is_file()
|
||||
{
|
||||
total += metadata.len();
|
||||
}
|
||||
|
||||
// Yield in case this process takes a while.
|
||||
|
|
@ -2766,10 +2762,10 @@ impl Tab {
|
|||
let selected = self.selected_locations();
|
||||
for item in &mut items {
|
||||
item.selected = false;
|
||||
if let Some(location) = &item.location_opt {
|
||||
if selected.contains(location) {
|
||||
item.selected = true;
|
||||
}
|
||||
if let Some(location) = &item.location_opt
|
||||
&& selected.contains(location)
|
||||
{
|
||||
item.selected = true;
|
||||
}
|
||||
}
|
||||
self.items_opt = Some(items);
|
||||
|
|
@ -2788,10 +2784,9 @@ impl Tab {
|
|||
for item in items.iter_mut() {
|
||||
item.cut = false;
|
||||
if let Some(location_path) = item.location_opt.as_ref().and_then(Location::path_opt)
|
||||
&& locations.contains(location_path)
|
||||
{
|
||||
if locations.contains(location_path) {
|
||||
item.cut = true;
|
||||
}
|
||||
item.cut = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2881,11 +2876,11 @@ impl Tab {
|
|||
if let Some(ref mut items) = self.items_opt {
|
||||
for (i, item) in items.iter_mut().enumerate() {
|
||||
item.selected = false;
|
||||
if let Some(path) = item.path_opt() {
|
||||
if paths.contains(path) {
|
||||
item.selected = true;
|
||||
self.select_focus = Some(i);
|
||||
}
|
||||
if let Some(path) = item.path_opt()
|
||||
&& paths.contains(path)
|
||||
{
|
||||
item.selected = true;
|
||||
self.select_focus = Some(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3085,10 +3080,10 @@ impl Tab {
|
|||
return Vec::new();
|
||||
};
|
||||
|
||||
if let Some((w, h)) = original_dims {
|
||||
if !should_use_tiling(*w, *h) {
|
||||
return Vec::new();
|
||||
}
|
||||
if let Some((w, h)) = original_dims
|
||||
&& !should_use_tiling(*w, *h)
|
||||
{
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let Some(path) = item.path_opt() else {
|
||||
|
|
@ -3389,15 +3384,13 @@ impl Tab {
|
|||
self.date_time_formatter = date_time_formatter(self.config.military_time);
|
||||
self.time_formatter = time_formatter(self.config.military_time);
|
||||
}
|
||||
if show_hidden_changed {
|
||||
if let Location::Search(path, term, ..) = &self.location {
|
||||
cd = Some(Location::Search(
|
||||
path.clone(),
|
||||
term.clone(),
|
||||
self.config.show_hidden,
|
||||
Instant::now(),
|
||||
));
|
||||
}
|
||||
if show_hidden_changed && let Location::Search(path, term, ..) = &self.location {
|
||||
cd = Some(Location::Search(
|
||||
path.clone(),
|
||||
term.clone(),
|
||||
self.config.show_hidden,
|
||||
Instant::now(),
|
||||
));
|
||||
}
|
||||
// Unhighlight all items when config changes
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
|
|
@ -3418,11 +3411,12 @@ impl Tab {
|
|||
self.location_context_menu_index = None;
|
||||
|
||||
//TODO: hack for clearing selecting when right clicking empty space
|
||||
if self.context_menu.is_some() && self.last_right_click.take().is_none() {
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
for item in items.iter_mut() {
|
||||
item.selected = false;
|
||||
}
|
||||
if self.context_menu.is_some()
|
||||
&& self.last_right_click.take().is_none()
|
||||
&& let Some(ref mut items) = self.items_opt
|
||||
{
|
||||
for item in items.iter_mut() {
|
||||
item.selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3510,11 +3504,11 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
Message::EditLocationComplete(selected) => {
|
||||
if let Some(mut edit_location) = self.edit_location.take() {
|
||||
if !matches!(edit_location.location, Location::Network(..)) {
|
||||
edit_location.selected = Some(selected);
|
||||
cd = edit_location.resolve();
|
||||
}
|
||||
if let Some(mut edit_location) = self.edit_location.take()
|
||||
&& !matches!(edit_location.location, Location::Network(..))
|
||||
{
|
||||
edit_location.selected = Some(selected);
|
||||
cd = edit_location.resolve();
|
||||
}
|
||||
}
|
||||
Message::EditLocationEnable => {
|
||||
|
|
@ -3530,11 +3524,11 @@ impl Tab {
|
|||
&& edit_location
|
||||
.completions
|
||||
.as_ref()
|
||||
.map_or(false, |completions| !completions.is_empty())
|
||||
.is_some_and(|completions| !completions.is_empty())
|
||||
&& edit_location
|
||||
.location
|
||||
.path_opt()
|
||||
.map_or(false, |path| !path.exists())
|
||||
.is_some_and(|path| !path.exists())
|
||||
{
|
||||
edit_location.selected = Some(0);
|
||||
}
|
||||
|
|
@ -3632,19 +3626,19 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
Message::GoNext => {
|
||||
if let Some(history_i) = self.history_i.checked_add(1) {
|
||||
if let Some(location) = self.history.get(history_i) {
|
||||
cd = Some(location.clone());
|
||||
history_i_opt = Some(history_i);
|
||||
}
|
||||
if let Some(history_i) = self.history_i.checked_add(1)
|
||||
&& let Some(location) = self.history.get(history_i)
|
||||
{
|
||||
cd = Some(location.clone());
|
||||
history_i_opt = Some(history_i);
|
||||
}
|
||||
}
|
||||
Message::GoPrevious => {
|
||||
if let Some(history_i) = self.history_i.checked_sub(1) {
|
||||
if let Some(location) = self.history.get(history_i) {
|
||||
cd = Some(location.clone());
|
||||
history_i_opt = Some(history_i);
|
||||
}
|
||||
if let Some(history_i) = self.history_i.checked_sub(1)
|
||||
&& let Some(location) = self.history.get(history_i)
|
||||
{
|
||||
cd = Some(location.clone());
|
||||
history_i_opt = Some(history_i);
|
||||
}
|
||||
}
|
||||
Message::ItemDown => {
|
||||
|
|
@ -3823,10 +3817,10 @@ impl Tab {
|
|||
Message::LocationUp => {
|
||||
// Sets location to the path's parent
|
||||
// Does nothing if path is root or location is Trash
|
||||
if let Location::Path(ref path) = self.location {
|
||||
if let Some(parent) = path.parent() {
|
||||
cd = Some(Location::Path(parent.to_owned()));
|
||||
}
|
||||
if let Location::Path(ref path) = self.location
|
||||
&& let Some(parent) = path.parent()
|
||||
{
|
||||
cd = Some(Location::Path(parent.to_owned()));
|
||||
}
|
||||
}
|
||||
Message::Open(path_opt) => {
|
||||
|
|
@ -3868,27 +3862,25 @@ impl Tab {
|
|||
match mode {
|
||||
Mode::App => {
|
||||
if is_only_one_selected {
|
||||
return ResolveResult::Cd(location.clone());
|
||||
ResolveResult::Cd(location.clone())
|
||||
} else {
|
||||
return ResolveResult::OpenInTab(path_opt.cloned());
|
||||
ResolveResult::OpenInTab(path_opt.cloned())
|
||||
}
|
||||
}
|
||||
Mode::Desktop => {
|
||||
return match location {
|
||||
Location::Trash => ResolveResult::OpenTrash,
|
||||
_ => ResolveResult::Open(path_opt.cloned()),
|
||||
};
|
||||
}
|
||||
Mode::Desktop => match location {
|
||||
Location::Trash => ResolveResult::OpenTrash,
|
||||
_ => ResolveResult::Open(path_opt.cloned()),
|
||||
},
|
||||
Mode::Dialog(_) => {
|
||||
if is_only_one_selected {
|
||||
return ResolveResult::Cd(location.clone());
|
||||
ResolveResult::Cd(location.clone())
|
||||
} else {
|
||||
return ResolveResult::Skip;
|
||||
ResolveResult::Skip
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ResolveResult::Open(path_opt.cloned());
|
||||
ResolveResult::Open(path_opt.cloned())
|
||||
}
|
||||
}
|
||||
let mut open_files = Vec::new();
|
||||
|
|
@ -3933,14 +3925,13 @@ impl Tab {
|
|||
if mod_ctrl || mod_shift {
|
||||
self.update(Message::Click(click_i_opt), modifiers);
|
||||
}
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
if !click_i_opt
|
||||
if let Some(ref mut items) = self.items_opt
|
||||
&& !click_i_opt
|
||||
.is_some_and(|click_i| items.get(click_i).is_some_and(|x| x.selected))
|
||||
{
|
||||
// If item not selected, clear selection on other items
|
||||
for (i, item) in items.iter_mut().enumerate() {
|
||||
item.selected = Some(i) == click_i_opt;
|
||||
}
|
||||
{
|
||||
// If item not selected, clear selection on other items
|
||||
for (i, item) in items.iter_mut().enumerate() {
|
||||
item.selected = Some(i) == click_i_opt;
|
||||
}
|
||||
}
|
||||
//TODO: hack for clearing selecting when right clicking empty space
|
||||
|
|
@ -3988,12 +3979,12 @@ impl Tab {
|
|||
}
|
||||
Message::Resize(viewport) => {
|
||||
// Scroll to ensure focused item still in view
|
||||
if self.viewport_opt.map(|v| v.size()) != Some(viewport.size()) {
|
||||
if let Some(offset) = self.select_focus_scroll() {
|
||||
commands.push(Command::Iced(
|
||||
scrollable::scroll_to(self.scrollable_id.clone(), offset).into(),
|
||||
));
|
||||
}
|
||||
if self.viewport_opt.map(|v| v.size()) != Some(viewport.size())
|
||||
&& let Some(offset) = self.select_focus_scroll()
|
||||
{
|
||||
commands.push(Command::Iced(
|
||||
scrollable::scroll_to(self.scrollable_id.clone(), offset).into(),
|
||||
));
|
||||
}
|
||||
|
||||
self.viewport_opt = Some(viewport);
|
||||
|
|
@ -4097,20 +4088,17 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
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()));
|
||||
}
|
||||
}
|
||||
if let Some(ref items) = self.items_opt
|
||||
&& let Some(last_pos) = items.iter().filter_map(|item| item.pos_opt.get()).max()
|
||||
&& 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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4134,13 +4122,13 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
Message::TabComplete(path, completions) => {
|
||||
if let Some(edit_location) = &mut self.edit_location {
|
||||
if edit_location.location.path_opt() == Some(&path) {
|
||||
edit_location.completions = Some(completions);
|
||||
commands.push(Command::Iced(
|
||||
widget::text_input::focus(self.edit_location_id.clone()).into(),
|
||||
));
|
||||
}
|
||||
if let Some(edit_location) = &mut self.edit_location
|
||||
&& edit_location.location.path_opt() == Some(&path)
|
||||
{
|
||||
edit_location.completions = Some(completions);
|
||||
commands.push(Command::Iced(
|
||||
widget::text_input::focus(self.edit_location_id.clone()).into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
Message::Thumbnail(path, thumbnail) => {
|
||||
|
|
@ -4274,10 +4262,10 @@ impl Tab {
|
|||
}
|
||||
Message::DirectorySize(path, dir_size) => {
|
||||
let location = Location::Path(path);
|
||||
if let Some(ref mut item) = self.parent_item_opt {
|
||||
if item.location_opt.as_ref() == Some(&location) {
|
||||
item.dir_size.clone_from(&dir_size);
|
||||
}
|
||||
if let Some(ref mut item) = self.parent_item_opt
|
||||
&& item.location_opt.as_ref() == Some(&location)
|
||||
{
|
||||
item.dir_size.clone_from(&dir_size);
|
||||
}
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
for item in items.iter_mut() {
|
||||
|
|
@ -4315,13 +4303,12 @@ impl Tab {
|
|||
} else {
|
||||
// Select parent if location is not directory
|
||||
let mut selected_paths = None;
|
||||
if let Some(path) = location.path_opt() {
|
||||
if !path.is_dir() {
|
||||
if let Some(parent) = path.parent() {
|
||||
selected_paths = Some(vec![path.clone()]);
|
||||
location = location.with_path(parent.to_path_buf());
|
||||
}
|
||||
}
|
||||
if let Some(path) = location.path_opt()
|
||||
&& !path.is_dir()
|
||||
&& let Some(parent) = path.parent()
|
||||
{
|
||||
selected_paths = Some(vec![path.clone()]);
|
||||
location = location.with_path(parent.to_path_buf());
|
||||
}
|
||||
if location != self.location || selected_paths.is_some() {
|
||||
if location.path_opt().is_none_or(|path| path.is_dir()) {
|
||||
|
|
@ -4529,99 +4516,93 @@ impl Tab {
|
|||
//TODO: display error messages when image not found?
|
||||
let mut name_opt = None;
|
||||
let mut element_opt: Option<Element<Message>> = None;
|
||||
if let Some(index) = self.select_focus {
|
||||
if let Some(items) = &self.items_opt {
|
||||
if let Some(item) = items.get(index) {
|
||||
name_opt = Some(widget::text::heading(&item.display_name));
|
||||
match item
|
||||
.thumbnail_opt
|
||||
.as_ref()
|
||||
.unwrap_or(&ItemThumbnail::NotImage)
|
||||
{
|
||||
ItemThumbnail::NotImage => {}
|
||||
ItemThumbnail::Image(handle, original_dims) => {
|
||||
// Determine which image to show based on async decode state
|
||||
let mut is_loading = false;
|
||||
let mut error_msg_opt = None;
|
||||
let image_handle = if let Some(path) = item.path_opt() {
|
||||
if let Some(error_msg) = self.large_image_manager.get_error(path) {
|
||||
error_msg_opt = Some(error_msg.clone());
|
||||
handle.clone()
|
||||
} else if self.large_image_manager.is_decoding(path) {
|
||||
// Currently decoding (initial or re-decode) --> show cached/thumbnail with loading indicator
|
||||
is_loading = true;
|
||||
// Use decoded handle if available (re-decode), otherwise thumbnail (initial decode)
|
||||
self.large_image_manager
|
||||
.get_decoded(path)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| handle.clone())
|
||||
} else if let Some(decoded_handle) =
|
||||
self.large_image_manager.get_decoded(path)
|
||||
{
|
||||
// Decoded and not currently decoding --> use it
|
||||
decoded_handle.clone()
|
||||
} else if let Some((w, h)) = original_dims {
|
||||
// Check if image needs tiling
|
||||
if should_use_tiling(*w, *h) {
|
||||
// Large image --> show thumbnail only
|
||||
handle.clone()
|
||||
} else {
|
||||
// Normal-sized image --> load full resolution directly
|
||||
widget::image::Handle::from_path(path)
|
||||
}
|
||||
} else {
|
||||
// No dimensions available --> show thumbnail
|
||||
handle.clone()
|
||||
}
|
||||
} else {
|
||||
if let Some(index) = self.select_focus
|
||||
&& let Some(items) = &self.items_opt
|
||||
&& let Some(item) = items.get(index)
|
||||
{
|
||||
name_opt = Some(widget::text::heading(&item.display_name));
|
||||
match item
|
||||
.thumbnail_opt
|
||||
.as_ref()
|
||||
.unwrap_or(&ItemThumbnail::NotImage)
|
||||
{
|
||||
ItemThumbnail::NotImage => {}
|
||||
ItemThumbnail::Image(handle, original_dims) => {
|
||||
// Determine which image to show based on async decode state
|
||||
let mut is_loading = false;
|
||||
let mut error_msg_opt = None;
|
||||
let image_handle = if let Some(path) = item.path_opt() {
|
||||
if let Some(error_msg) = self.large_image_manager.get_error(path) {
|
||||
error_msg_opt = Some(error_msg.clone());
|
||||
handle.clone()
|
||||
} else if self.large_image_manager.is_decoding(path) {
|
||||
// Currently decoding (initial or re-decode) --> show cached/thumbnail with loading indicator
|
||||
is_loading = true;
|
||||
// Use decoded handle if available (re-decode), otherwise thumbnail (initial decode)
|
||||
self.large_image_manager
|
||||
.get_decoded(path)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| handle.clone())
|
||||
} else if let Some(decoded_handle) =
|
||||
self.large_image_manager.get_decoded(path)
|
||||
{
|
||||
// Decoded and not currently decoding --> use it
|
||||
decoded_handle.clone()
|
||||
} else if let Some((w, h)) = original_dims {
|
||||
// Check if image needs tiling
|
||||
if should_use_tiling(*w, *h) {
|
||||
// Large image --> show thumbnail only
|
||||
handle.clone()
|
||||
};
|
||||
} else {
|
||||
// Normal-sized image --> load full resolution directly
|
||||
widget::image::Handle::from_path(path)
|
||||
}
|
||||
} else {
|
||||
// No dimensions available --> show thumbnail
|
||||
handle.clone()
|
||||
}
|
||||
} else {
|
||||
handle.clone()
|
||||
};
|
||||
|
||||
let content: cosmic::Element<'_, Message> =
|
||||
if let Some(error_msg) = error_msg_opt {
|
||||
widget::column()
|
||||
.push(widget::image(image_handle))
|
||||
.push(widget::text(format!("⚠ {}", error_msg)).size(13))
|
||||
.padding(space_xs)
|
||||
.align_x(cosmic::iced::Alignment::Center)
|
||||
.into()
|
||||
} else if is_loading {
|
||||
widget::column()
|
||||
.push(widget::image(image_handle))
|
||||
.push(widget::text("Loading higher resolution...").size(14))
|
||||
.padding(space_xs)
|
||||
.align_x(cosmic::iced::Alignment::Center)
|
||||
.into()
|
||||
} else {
|
||||
//TODO: use widget::image::viewer, when its zoom can be reset
|
||||
widget::image(image_handle).into()
|
||||
};
|
||||
let content: cosmic::Element<'_, Message> =
|
||||
if let Some(error_msg) = error_msg_opt {
|
||||
widget::column()
|
||||
.push(widget::image(image_handle))
|
||||
.push(widget::text(format!("⚠ {}", error_msg)).size(13))
|
||||
.padding(space_xs)
|
||||
.align_x(cosmic::iced::Alignment::Center)
|
||||
.into()
|
||||
} else if is_loading {
|
||||
widget::column()
|
||||
.push(widget::image(image_handle))
|
||||
.push(widget::text("Loading higher resolution...").size(14))
|
||||
.padding(space_xs)
|
||||
.align_x(cosmic::iced::Alignment::Center)
|
||||
.into()
|
||||
} else {
|
||||
//TODO: use widget::image::viewer, when its zoom can be reset
|
||||
widget::image(image_handle).into()
|
||||
};
|
||||
|
||||
element_opt =
|
||||
Some(widget::container(content).center(Length::Fill).into());
|
||||
}
|
||||
ItemThumbnail::Svg(handle) => {
|
||||
element_opt = Some(
|
||||
widget::svg(handle.clone())
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
ItemThumbnail::Text(text) => {
|
||||
element_opt = Some(
|
||||
widget::container(
|
||||
widget::text_editor(text).padding(space_xxs).class(
|
||||
cosmic::theme::iced::TextEditor::Custom(Box::new(
|
||||
text_editor_class,
|
||||
)),
|
||||
),
|
||||
)
|
||||
.center(Length::Fill)
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
element_opt = Some(widget::container(content).center(Length::Fill).into());
|
||||
}
|
||||
ItemThumbnail::Svg(handle) => {
|
||||
element_opt = Some(
|
||||
widget::svg(handle.clone())
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
ItemThumbnail::Text(text) => {
|
||||
element_opt = Some(
|
||||
widget::container(widget::text_editor(text).padding(space_xxs).class(
|
||||
cosmic::theme::iced::TextEditor::Custom(Box::new(text_editor_class)),
|
||||
))
|
||||
.center(Length::Fill)
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4860,32 +4841,32 @@ impl Tab {
|
|||
);
|
||||
let mut popover =
|
||||
widget::popover(text_input).position(widget::popover::Position::Bottom);
|
||||
if let Some(completions) = &edit_location.completions {
|
||||
if !completions.is_empty() {
|
||||
let mut column =
|
||||
widget::column::with_capacity(completions.len()).padding(space_xxs);
|
||||
for (i, (name, _path)) in completions.iter().enumerate() {
|
||||
let selected = edit_location.selected == Some(i);
|
||||
column = column.push(
|
||||
widget::button::custom(widget::text::body(name))
|
||||
//TODO: match to design
|
||||
.class(if selected {
|
||||
theme::Button::Standard
|
||||
} else {
|
||||
theme::Button::HeaderBar
|
||||
})
|
||||
.on_press(Message::EditLocationComplete(i))
|
||||
.padding(space_xxs)
|
||||
.width(Length::Fill),
|
||||
);
|
||||
}
|
||||
popover = popover.popup(
|
||||
widget::container(column)
|
||||
.class(theme::Container::Dropdown)
|
||||
//TODO: This is a hack to get the popover to be the right width
|
||||
.max_width(size.width - 140.0),
|
||||
if let Some(completions) = &edit_location.completions
|
||||
&& !completions.is_empty()
|
||||
{
|
||||
let mut column =
|
||||
widget::column::with_capacity(completions.len()).padding(space_xxs);
|
||||
for (i, (name, _path)) in completions.iter().enumerate() {
|
||||
let selected = edit_location.selected == Some(i);
|
||||
column = column.push(
|
||||
widget::button::custom(widget::text::body(name))
|
||||
//TODO: match to design
|
||||
.class(if selected {
|
||||
theme::Button::Standard
|
||||
} else {
|
||||
theme::Button::HeaderBar
|
||||
})
|
||||
.on_press(Message::EditLocationComplete(i))
|
||||
.padding(space_xxs)
|
||||
.width(Length::Fill),
|
||||
);
|
||||
}
|
||||
popover = popover.popup(
|
||||
widget::container(column)
|
||||
.class(theme::Container::Dropdown)
|
||||
//TODO: This is a hack to get the popover to be the right width
|
||||
.max_width(size.width - 140.0),
|
||||
);
|
||||
}
|
||||
row = row.push(popover);
|
||||
let mut column = widget::column::with_capacity(4).padding([0, space_s]);
|
||||
|
|
@ -5911,13 +5892,13 @@ impl Tab {
|
|||
.wayland_on_right_press_window_position();
|
||||
|
||||
let mut popover = widget::popover(mouse_area);
|
||||
if let Some(point) = self.context_menu {
|
||||
if !cfg!(feature = "wayland") || !crate::is_wayland() {
|
||||
let context_menu = menu::context_menu(self, key_binds, &modifiers);
|
||||
popover = popover
|
||||
.popup(context_menu)
|
||||
.position(widget::popover::Position::Point(point));
|
||||
}
|
||||
if let Some(point) = self.context_menu
|
||||
&& (!cfg!(feature = "wayland") || !crate::is_wayland())
|
||||
{
|
||||
let context_menu = menu::context_menu(self, key_binds, modifiers);
|
||||
popover = popover
|
||||
.popup(context_menu)
|
||||
.position(widget::popover::Position::Point(point));
|
||||
}
|
||||
|
||||
let mut tab_column = widget::column::with_capacity(3);
|
||||
|
|
@ -5937,21 +5918,21 @@ impl Tab {
|
|||
}
|
||||
match &self.location {
|
||||
Location::Trash => {
|
||||
if let Some(items) = self.items_opt() {
|
||||
if !items.is_empty() {
|
||||
tab_column = tab_column.push(
|
||||
widget::layer_container(widget::row::with_children([
|
||||
widget::horizontal_space().into(),
|
||||
widget::button::standard(fl!("empty-trash"))
|
||||
.on_press(Message::EmptyTrash)
|
||||
.into(),
|
||||
]))
|
||||
.padding([space_xxs, space_xs])
|
||||
.layer(cosmic_theme::Layer::Primary)
|
||||
.apply(widget::container)
|
||||
.padding([0, 0, 7, 0]),
|
||||
);
|
||||
}
|
||||
if let Some(items) = self.items_opt()
|
||||
&& !items.is_empty()
|
||||
{
|
||||
tab_column = tab_column.push(
|
||||
widget::layer_container(widget::row::with_children([
|
||||
widget::horizontal_space().into(),
|
||||
widget::button::standard(fl!("empty-trash"))
|
||||
.on_press(Message::EmptyTrash)
|
||||
.into(),
|
||||
]))
|
||||
.padding([space_xxs, space_xs])
|
||||
.layer(cosmic_theme::Layer::Primary)
|
||||
.apply(widget::container)
|
||||
.padding([0, 0, 7, 0]),
|
||||
);
|
||||
}
|
||||
}
|
||||
Location::Network(uri, _display_name, _path) if uri == "network:///" => {
|
||||
|
|
@ -6248,10 +6229,10 @@ impl Tab {
|
|||
let mut selected_items: Vec<&Item> =
|
||||
items.iter().filter(|item| item.selected).collect();
|
||||
|
||||
if selected_items.is_empty() {
|
||||
if let Some(p) = self.parent_item_opt.as_ref() {
|
||||
selected_items.push(p)
|
||||
}
|
||||
if selected_items.is_empty()
|
||||
&& let Some(p) = self.parent_item_opt.as_ref()
|
||||
{
|
||||
selected_items.push(p)
|
||||
}
|
||||
for item in selected_items {
|
||||
// Item must have a path
|
||||
|
|
|
|||
|
|
@ -66,10 +66,10 @@ impl ThumbnailCacher {
|
|||
if let (Some(cache_base_dir), Ok(metadata)) = (
|
||||
THUMBNAIL_CACHE_BASE_DIR.as_ref(),
|
||||
std::fs::metadata(&self.file_path),
|
||||
) {
|
||||
if metadata.is_file() && self.file_path.starts_with(cache_base_dir) {
|
||||
return CachedThumbnail::Valid((self.file_path.clone(), None));
|
||||
}
|
||||
) && metadata.is_file()
|
||||
&& self.file_path.starts_with(cache_base_dir)
|
||||
{
|
||||
return CachedThumbnail::Valid((self.file_path.clone(), None));
|
||||
}
|
||||
|
||||
// Use cached thumbnail if it is valid.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::desktop::fde::GenericEntry;
|
||||
use mime_guess::Mime;
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::{
|
||||
|
|
@ -115,7 +116,7 @@ impl ThumbnailerCache {
|
|||
|
||||
//TODO: handle directory specific behavior
|
||||
for path in thumbnailer_paths {
|
||||
let entry = match freedesktop_entry_parser::parse_entry(&path) {
|
||||
let entry = match GenericEntry::from_path(&path) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
log::warn!("failed to parse {}: {}", path.display(), err);
|
||||
|
|
@ -124,12 +125,18 @@ impl ThumbnailerCache {
|
|||
};
|
||||
|
||||
//TODO: use TryExec?
|
||||
let section = entry.section("Thumbnailer Entry");
|
||||
let Some(exec) = section.attr("Exec") else {
|
||||
let Some(section) = entry.group("Thumbnailer Entry") else {
|
||||
log::warn!(
|
||||
"missing Thumbnailer Entry section for thumbnailer {}",
|
||||
path.display()
|
||||
);
|
||||
continue;
|
||||
};
|
||||
let Some(exec) = section.entry("Exec") else {
|
||||
log::warn!("missing Exec attribute for thumbnailer {}", path.display());
|
||||
continue;
|
||||
};
|
||||
let Some(mime_types) = section.attr("MimeType") else {
|
||||
let Some(mime_types) = section.entry("MimeType") else {
|
||||
log::warn!(
|
||||
"missing MimeType attribute for thumbnailer {}",
|
||||
path.display()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue