chore: clippy

This commit is contained in:
Vukašin Vojinović 2026-01-24 17:03:31 +01:00
parent 339e4c104e
commit 1e25e7dd69
11 changed files with 938 additions and 981 deletions

View file

@ -1230,12 +1230,12 @@ impl App {
};
for item in items {
if item.selected {
if let Some(path) = item.path_opt() {
if op_sel.selected.contains(path) || op_sel.ignored.contains(path) {
if let Some(path) = item.path_opt()
&& (op_sel.selected.contains(path) || op_sel.ignored.contains(path))
{
// Ignore if path in selected or ignored paths
continue;
}
}
// Return if there is a previous selection not matching
return Task::none();
@ -1891,13 +1891,13 @@ impl App {
children.push(item.preview_view(Some(&self.mime_app_cache), military_time));
}
PreviewKind::Location(location) => {
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
if let Some(items) = tab.items_opt() {
if let Some(tab) = self.tab_model.data::<Tab>(entity)
&& let Some(items) = tab.items_opt()
{
for item in items {
if item.location_opt.as_ref() == Some(location) {
children.push(
item.preview_view(Some(&self.mime_app_cache), military_time),
);
children
.push(item.preview_view(Some(&self.mime_app_cache), military_time));
// Only show one property view to avoid issues like hangs when generating
// preview images on thousands of files
break;
@ -1905,10 +1905,10 @@ impl App {
}
}
}
}
PreviewKind::Selected => {
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
if let Some(items) = tab.items_opt() {
if let Some(tab) = self.tab_model.data::<Tab>(entity)
&& let Some(items) = tab.items_opt()
{
let preview_opt = {
let mut selected = items.iter().filter(|item| item.selected);
@ -1916,9 +1916,9 @@ impl App {
// At least two selected items
(Some(_), Some(_)) => Some(tab.multi_preview_view()),
// Exactly one selected item
(Some(item), None) => Some(
item.preview_view(Some(&self.mime_app_cache), military_time),
),
(Some(item), None) => {
Some(item.preview_view(Some(&self.mime_app_cache), military_time))
}
// No selected items
_ => None,
}
@ -1928,13 +1928,10 @@ impl App {
children.push(preview);
}
if children.is_empty() {
if let Some(item) = &tab.parent_item_opt {
children.push(
item.preview_view(Some(&self.mime_app_cache), military_time),
);
}
}
if children.is_empty()
&& let Some(item) = &tab.parent_item_opt
{
children.push(item.preview_view(Some(&self.mime_app_cache), military_time));
}
}
}
@ -2062,14 +2059,14 @@ impl App {
.map(|favorite| {
if let Favorite::Path(path) = favorite {
for (from, to) in path_changes.iter().map(|(f, t)| (f.as_ref(), t.as_ref())) {
if path.starts_with(from) {
if let Ok(relative) = path.strip_prefix(from) {
if path.starts_with(from)
&& let Ok(relative) = path.strip_prefix(from)
{
favorites_changed = true;
return Favorite::from_path(to.join(relative));
}
}
}
}
favorite.clone()
})
.collect();
@ -2235,9 +2232,10 @@ impl Application for App {
let mut commands = vec![app.update_config()];
for location in flags.locations {
if let Some(path) = location.path_opt() {
if path.is_file() {
if let Some(parent) = path.parent() {
if let Some(path) = location.path_opt()
&& path.is_file()
&& let Some(parent) = path.parent()
{
commands.push(app.open_tab(
Location::Path(parent.to_path_buf()),
true,
@ -2245,8 +2243,6 @@ impl Application for App {
));
continue;
}
}
}
commands.push(app.open_tab(location, true, None));
}
for location in flags.uris {
@ -2405,15 +2401,14 @@ impl Application for App {
// TODO do we need to choose the correct mounter?
self.mounter_items.keys().copied().next()
})
&& let Some(mounter) = MOUNTERS.get(&key)
{
if let Some(mounter) = MOUNTERS.get(&key) {
return mounter.network_drive(uri.clone()).map(move |()| {
cosmic::Action::App(Message::NetworkDriveOpenEntityAfterMount {
entity,
})
});
}
}
log::warn!(
"failed to open favorite, path does not exist: {}",
@ -2468,13 +2463,13 @@ 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) {
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()
}
@ -2505,12 +2500,12 @@ impl Application for App {
}
// Close gallery mode if open
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if tab.gallery {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
&& tab.gallery
{
tab.gallery = false;
return Task::none();
}
}
// Close menus and context panes in order per message
// Why: It'd be weird to close everything all at once
@ -2635,8 +2630,9 @@ impl Application for App {
}
Message::Compress(entity_opt) => {
let paths: Box<[_]> = self.selected_paths(entity_opt).collect();
if let Some(current_path) = paths.first() {
if let Some(destination) = current_path.parent().zip(current_path.file_stem()) {
if let Some(current_path) = paths.first()
&& let Some(destination) = current_path.parent().zip(current_path.file_stem())
{
let to = destination.0.to_path_buf();
let name = destination.1.to_str().unwrap_or_default().to_string();
let archive_type = ArchiveType::default();
@ -2652,7 +2648,6 @@ impl Application for App {
);
}
}
}
Message::Config(config) => {
if config != self.config {
log::info!("update config");
@ -2664,11 +2659,11 @@ impl Application for App {
}
}
Message::Copy(entity_opt) => {
if let Some(entity) = entity_opt {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if let Some(entity) = entity_opt
&& let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
{
tab.refresh_cut(&[]);
}
}
let paths = self.selected_paths(entity_opt);
let contents = ClipboardCopy::new(ClipboardKind::Copy, paths);
return clipboard::write_data(contents);
@ -2975,15 +2970,15 @@ impl Application for App {
DialogResult::Cancel => {}
DialogResult::Open(selected_paths) => {
let mut archive_paths = None;
if let Some(file_dialog) = &self.file_dialog_opt {
if let Some(window) = self.windows.remove(&file_dialog.window_id()) {
if let WindowKind::FileDialog(paths) = window.kind {
if let Some(file_dialog) = &self.file_dialog_opt
&& let Some(window) = self.windows.remove(&file_dialog.window_id())
&& let WindowKind::FileDialog(paths) = window.kind
{
archive_paths = paths;
}
}
}
if let Some(archive_paths) = archive_paths {
if !selected_paths.is_empty() {
if let Some(archive_paths) = archive_paths
&& !selected_paths.is_empty()
{
self.file_dialog_opt = None;
return self.operation(Operation::Extract {
paths: archive_paths,
@ -2993,7 +2988,6 @@ impl Application for App {
}
}
}
}
self.file_dialog_opt = None;
}
Message::FileDialogMessage(dialog_message) => {
@ -3020,12 +3014,11 @@ impl Application for App {
&& !modifiers.control()
&& !modifiers.alt()
&& matches!(key, Key::Character(_))
&& let Some(text) = text
{
if let Some(text) = text {
match self.config.type_to_search {
TypeToSearch::Recursive => {
let mut term =
self.search_get().unwrap_or_default().to_string();
let mut term = self.search_get().unwrap_or_default().to_string();
term.push_str(&text);
return self.search_set_active(Some(term));
}
@ -3042,8 +3035,7 @@ impl Application for App {
tab.edit_location =
Some(location.with_uri(uri_string).into());
} else if let Some(path) = location.path_opt() {
let mut path_string =
path.to_string_lossy().into_owned();
let mut path_string = path.to_string_lossy().into_owned();
path_string.push_str(&text);
tab.edit_location =
Some(location.with_path(path_string.into()).into());
@ -3052,11 +3044,11 @@ impl Application for App {
}
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 {
if let Some(last_key) = self.type_select_last_key
&& 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());
@ -3076,7 +3068,6 @@ impl Application for App {
}
}
}
}
Message::MaybeExit => {
if self.core.main_window_id().is_none() && self.pending_operations.is_empty() {
// Exit if window is closed and there are no pending operations
@ -3106,24 +3097,25 @@ 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() {
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() {
if path == old_path && item.is_mounted() {
if let Some(path) = item.path()
&& path == old_path
&& item.is_mounted()
{
still_mounted = true;
break;
}
}
}
if !still_mounted {
unmounted.push(old_path);
}
}
}
}
}
// Go back to home in any tabs that were unmounted
let mut commands = Vec::new();
@ -3254,8 +3246,9 @@ impl Application for App {
}
Message::NewItem(entity_opt, dir) => {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if let Some(path) = tab.location.path_opt() {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
&& let Some(path) = tab.location.path_opt()
{
return Task::batch([
self.dialog_pages.push_back(DialogPage::NewItem {
parent: path.clone(),
@ -3266,7 +3259,6 @@ impl Application for App {
]);
}
}
}
#[cfg(feature = "notify")]
Message::Notification(notification) => {
self.notification_opt = Some(notification);
@ -3277,8 +3269,9 @@ impl Application for App {
let mut needs_reload = Vec::new();
let entities: Box<[_]> = self.tab_model.iter().collect();
for entity in entities {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if let Some(path) = tab.location.path_opt() {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
&& let Some(path) = tab.location.path_opt()
{
let mut contains_change = false;
for event in &events {
for event_path in &event.paths {
@ -3330,7 +3323,6 @@ impl Application for App {
}
}
}
}
let commands = needs_reload
.into_iter()
@ -3351,22 +3343,23 @@ impl Application for App {
if let Some(terminal) = self.mime_app_cache.terminal() {
let mut paths = Box::from([]);
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if let Some(path) = tab.location.path_opt() {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
&& let Some(path) = tab.location.path_opt()
{
if let Some(items) = tab.items_opt() {
paths =
items
paths = items
.iter()
.filter_map(|item| {
.filter_map(
|item| {
if item.selected { item.path_opt() } else { None }
})
},
)
.collect();
}
if paths.is_empty() {
paths = Box::from([path]);
}
}
}
for path in paths {
if let Some(mut command) = terminal
.command::<&str>(&[])
@ -3454,8 +3447,9 @@ impl Application for App {
},
Message::OpenWithDialog(entity_opt) => {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
if let Some(items) = tab.items_opt() {
if let Some(tab) = self.tab_model.data::<Tab>(entity)
&& let Some(items) = tab.items_opt()
{
for item in items {
if !item.selected {
continue;
@ -3480,7 +3474,6 @@ impl Application for App {
}
}
}
}
Message::OpenWithSelection(index) => {
if let Some(DialogPage::OpenWith { selected, .. }) = self.dialog_pages.front_mut() {
*selected = index;
@ -3488,21 +3481,20 @@ impl Application for App {
}
Message::Paste(entity_opt) => {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if let Some(path) = tab.location.path_opt() {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
&& let Some(path) = tab.location.path_opt()
{
let to = path.clone();
return clipboard::read_data::<ClipboardPaste>().map(move |contents_opt| {
match contents_opt {
Some(contents) => cosmic::action::app(Message::PasteContents(
to.clone(),
contents,
)),
Some(contents) => {
cosmic::action::app(Message::PasteContents(to.clone(), contents))
}
None => cosmic::action::none(),
}
});
}
}
}
Message::PasteContents(to, mut contents) => {
contents.paths.retain(|p| *p != to);
if !contents.paths.is_empty() {
@ -3733,8 +3725,9 @@ impl Application for App {
}
Message::Rename(entity_opt) => {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if let Some(items) = tab.items_opt() {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
&& let Some(items) = tab.items_opt()
{
let selected: Box<[_]> = items
.iter()
.filter_map(|item| {
@ -3767,7 +3760,6 @@ impl Application for App {
}
}
}
}
Message::ReplaceResult(replace_result) => {
if let Some((dialog_page, task)) = self.dialog_pages.pop_front() {
match dialog_page {
@ -3787,8 +3779,9 @@ impl Application for App {
Message::RestoreFromTrash(entity_opt) => {
let mut trash_items = Vec::new();
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
if let Some(items) = tab.items_opt() {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity)
&& let Some(items) = tab.items_opt()
{
for item in items {
if item.selected {
if let ItemMetadata::Trash { entry, .. } = &item.metadata {
@ -3799,7 +3792,6 @@ impl Application for App {
}
}
}
}
if !trash_items.is_empty() {
return self.operation(Operation::Restore { items: trash_items });
}
@ -3840,14 +3832,14 @@ impl Application for App {
// Close old context menu
let active = self.tab_model.active();
if let Some(tab) = self.tab_model.data_mut::<Tab>(active) {
if tab.context_menu.is_some() {
if let Some(tab) = self.tab_model.data_mut::<Tab>(active)
&& tab.context_menu.is_some()
{
tasks.push(self.update(Message::TabMessage(
Some(active),
tab::Message::ContextMenu(None, None),
)));
}
}
// Activate new tab
self.tab_model.activate(entity);
@ -4042,12 +4034,12 @@ impl Application for App {
// Destroy previous popup
let mut window_ids = Vec::new();
for (window_id, window) in &self.windows {
if let WindowKind::ContextMenu(e, _) = &window.kind {
if *e == entity {
if let WindowKind::ContextMenu(e, _) = &window.kind
&& *e == entity
{
window_ids.push(*window_id);
}
}
}
for window_id in window_ids {
commands.push(self.update(Message::Surface(
cosmic::surface::action::destroy_popup(window_id),
@ -4453,14 +4445,14 @@ impl Application for App {
}
}
Message::NavBarClose(entity) => {
if let Some(data) = self.nav_model.data::<MounterData>(entity) {
if let Some(mounter) = MOUNTERS.get(&data.0) {
if let Some(data) = self.nav_model.data::<MounterData>(entity)
&& let Some(mounter) = MOUNTERS.get(&data.0)
{
return mounter
.unmount(data.1.clone())
.map(|()| cosmic::action::none());
}
}
}
Message::NavBarContext(entity) => {
self.nav_bar_context_id = entity;
@ -4755,8 +4747,8 @@ impl Application for App {
if let Some(p) = paths.next() {
{
for (k, mounter_items) in &self.mounter_items {
if let Some(mounter) = MOUNTERS.get(k) {
if let Some(item) = mounter_items
if let Some(mounter) = MOUNTERS.get(k)
&& let Some(item) = mounter_items
.iter()
.find(|&item| item.path().is_some_and(|path| path == p))
{
@ -4769,7 +4761,6 @@ impl Application for App {
}
}
}
}
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
Message::Focused(id) => {
if let Some(w) = self.windows.get(&id) {
@ -4786,8 +4777,8 @@ impl Application for App {
}
Message::SaveSortNames => {
self.must_save_sort_names = false;
if let Some(state_handler) = self.state_handler.as_ref() {
if let Err(err) = state_handler
if let Some(state_handler) = self.state_handler.as_ref()
&& let Err(err) = state_handler
.set::<&FxOrderMap<String, (HeadingOptions, bool)>>(
"sort_names",
&self.state.sort_names,
@ -4796,7 +4787,6 @@ impl Application for App {
log::warn!("Failed to save sort names: {err:?}");
}
}
}
Message::NetworkDriveOpenEntityAfterMount { entity } => {
return self.on_nav_select(entity);
}
@ -4890,14 +4880,14 @@ impl Application for App {
fn dialog(&self) -> Option<Element<'_, Message>> {
//TODO: should gallery view just be a dialog?
let entity = self.tab_model.active();
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
if tab.gallery {
if let Some(tab) = self.tab_model.data::<Tab>(entity)
&& tab.gallery
{
return Some(
tab.gallery_view()
.map(move |x| Message::TabMessage(Some(entity), x)),
);
}
}
let dialog_page = self.dialog_pages.front()?;
let cosmic_theme::Spacing {
@ -5778,8 +5768,9 @@ impl Application for App {
let mut tab_column = widget::column::with_capacity(4);
if self.core.is_condensed() {
if let Some(term) = self.search_get() {
if self.core.is_condensed()
&& let Some(term) = self.search_get()
{
tab_column = tab_column.push(
widget::container(
widget::text_input::search_input("", term)
@ -5791,7 +5782,6 @@ impl Application for App {
.padding(space_xxs),
);
}
}
if self.tab_model.len() > 1 {
tab_column = tab_column.push(
@ -6088,16 +6078,16 @@ impl Application for App {
let should_rescan =
events.iter().any(|event| !event.kind.is_access());
if should_rescan {
if let Err(e) = futures::executor::block_on(async {
if should_rescan
&& let Err(e) = futures::executor::block_on(async {
output.send(Message::RescanTrash).await
}) {
})
{
log::warn!(
"trash needs to be rescanned but sending message failed: {e:?}"
);
}
}
}
Err(e) => {
log::warn!("failed to watch trash bin for changes: {e:?}");
}
@ -6173,8 +6163,7 @@ impl Application for App {
|| kind.is_modify()
|| kind.is_remove()
|| kind.is_other()
}) {
if let Err(e) = futures::executor::block_on(async {
}) && let Err(e) = futures::executor::block_on(async {
output.send(Message::RescanRecents).await
}) {
log::warn!(
@ -6182,7 +6171,6 @@ impl Application for App {
);
}
}
}
Err(e) => {
log::warn!("failed to watch recents file for changes: {e:?}")
}
@ -6297,17 +6285,16 @@ impl Application for App {
let mut selected_previews = Vec::new();
match self.mode {
Mode::App => {
if self.core.window.show_context {
if let ContextPage::Preview(entity_opt, PreviewKind::Selected) =
if self.core.window.show_context
&& let ContextPage::Preview(entity_opt, PreviewKind::Selected) =
self.context_page
{
selected_previews
.push(Some(entity_opt.unwrap_or_else(|| self.tab_model.active())));
}
}
}
Mode::Desktop => {
for window_kind in self.windows.iter().map(|(_, window)| &window.kind) {
for window_kind in self.windows.values().map(|window| &window.kind) {
if let WindowKind::Preview(entity_opt, _) = window_kind {
selected_previews
.push(Some(entity_opt.unwrap_or_else(|| self.tab_model.active())));
@ -6322,8 +6309,7 @@ impl Application for App {
tab.subscription(
selected_previews
.iter()
.find(|preview| preview.as_ref() == Some(entity).as_ref())
.is_some(),
.any(|preview| preview.as_ref() == Some(entity).as_ref()),
)
.with(entity)
.map(|(entity, tab_msg)| Message::TabMessage(Some(entity), tab_msg)),

View file

@ -179,12 +179,12 @@ impl<T: AsRef<str>> From<T> for DialogLabel {
});
}
if let Some(span) = spans.last_mut() {
if underline == span.underline {
if let Some(span) = spans.last_mut()
&& underline == span.underline
{
span.text.push(c);
continue;
}
}
spans.push(DialogLabelSpan {
text: String::from(c),
@ -718,14 +718,14 @@ impl App {
children.push(preview);
}
if children.is_empty() {
if let Some(item) = &self.tab.parent_item_opt {
if children.is_empty()
&& let Some(item) = &self.tab.parent_item_opt
{
children.push(item.preview_view(None, military_time));
}
}
}
}
}
widget::column::with_children(children).into()
}
@ -1279,13 +1279,13 @@ 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) {
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,11 +1322,11 @@ 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 {
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,23 +1419,23 @@ 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) {
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
if !modifiers.logo()
&& !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();
@ -1456,11 +1456,11 @@ impl Application for App {
}
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 {
if let Some(last_key) = self.type_select_last_key
&& 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());
@ -1477,7 +1477,6 @@ impl Application for App {
}
}
}
}
Message::ModifiersChanged(modifiers) => {
self.modifiers = modifiers;
}
@ -1486,24 +1485,25 @@ 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() {
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() {
if path == old_path && item.is_mounted() {
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));
}
}
}
}
}
// Go back to home in any tabs that were unmounted
let mut commands = Vec::new();
@ -1601,8 +1601,9 @@ 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() {
if item.selected
&& let Some(path) = item.path_opt()
{
paths.push(path.clone());
let _ = update_recently_used(
path,
@ -1613,7 +1614,6 @@ impl Application for App {
}
}
}
}
// Ensure selection is allowed
//TODO: improve tab logic so this doesn't block the open button so often
@ -1640,13 +1640,13 @@ 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 {
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 => {
self.context_page = ContextPage::Preview(None, PreviewKind::Selected);
return self.with_dialog_config(|config| {
@ -1654,15 +1654,15 @@ 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() {
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),
));
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 {
@ -1674,8 +1674,6 @@ impl Application for App {
return window::close(self.flags.window_id);
}
}
}
}
Message::ScrollTab(scroll_speed) => {
return self.update(Message::TabMessage(tab::Message::ScrollTab(
f32::from(scroll_speed) / 10.0,
@ -1703,17 +1701,15 @@ 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() {
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();
for tab_command in tab_commands {
@ -1840,8 +1836,9 @@ 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) {
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();
@ -1868,7 +1865,6 @@ impl Application for App {
|| parsed_globs.iter().any(|glob| glob.matches(&item.name))
});
}
}
// Select based on filename
if let DialogKind::SaveFile { filename } = &self.flags.kind {
@ -1944,8 +1940,9 @@ impl Application for App {
let mut col = widget::column::with_capacity(2);
if self.core.is_condensed() {
if let Some(term) = self.search_get() {
if self.core.is_condensed()
&& let Some(term) = self.search_get()
{
col = col.push(
widget::container(
widget::text_input::search_input("", term)
@ -1957,7 +1954,6 @@ impl Application for App {
.padding(space_xxs),
);
}
}
col = col.push(
self.tab

View file

@ -392,8 +392,9 @@ impl LargeImageManager {
generation: u64,
) -> bool {
// Check if this decode is still current (not superseded by a newer one)
if let Some(&current_gen) = self.decode_generations.get(&path) {
if generation != current_gen {
if let Some(&current_gen) = self.decode_generations.get(&path)
&& generation != current_gen
{
log::info!(
"Discarding outdated decode for {} (generation {} != current {})",
path.display(),
@ -402,7 +403,6 @@ impl LargeImageManager {
);
return false;
}
}
log::info!(
"Storing decoded image for {} (generation {})",
@ -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()

View file

@ -62,13 +62,13 @@ 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) {
if let Some(lang) = cleaned_locale.split('-').next()
&& let Ok(locale) = Locale::try_from_str(lang)
{
return locale;
}
}
}
}
log::warn!("No valid locale found in environment, using fallback");
Locale::try_from_str("en-US").expect("Failed to parse fallback locale 'en-US'")
});

View file

@ -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) {

View file

@ -23,13 +23,12 @@ 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 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(()));

View file

@ -246,9 +246,10 @@ 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 {
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);
@ -258,8 +259,6 @@ impl State {
Size::new(max_x - min_x, max_y - min_y),
));
}
}
}
None
}
@ -527,13 +526,13 @@ 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 {
if let Some(message) = widget.on_resize.as_ref()
&& viewport_changed
{
shell.publish(message(*viewport));
}
}
state.viewport = Some(*viewport);
@ -664,11 +663,12 @@ 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;
@ -685,93 +685,91 @@ fn update<Message: Clone>(
}
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)));
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)));
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)));
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)));
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)));
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)));
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)));
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) {
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)) {
shell.publish(message(drag_rect.intersection(&layout_bounds).map(

View file

@ -957,11 +957,11 @@ 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() {
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());
op_sel.selected.push(new_dir.clone());

View file

@ -138,11 +138,11 @@ impl Context {
}),
is_cleanup: false,
};
if matches!(method, Method::Move { .. }) {
if let Some(cleanup_op) = op.move_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());
}

View file

@ -934,8 +934,9 @@ 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 {
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
@ -974,7 +975,6 @@ pub fn scan_path(tab_path: &PathBuf, sizes: IconSizes) -> Vec<Item> {
}
}
}
}
if !remote_scannable {
match fs::read_dir(tab_path) {
@ -1410,13 +1410,13 @@ impl EditLocation {
self.selected = Some(selected);
// Automatically resolve if there is only one completion
if completions.len() == 1 {
if let Some(resolved) = self.resolve() {
if completions.len() == 1
&& let Some(resolved) = self.resolve()
{
self.location = resolved;
self.selected = None;
}
}
}
} else {
self.selected = None;
}
@ -2033,11 +2033,11 @@ 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) {
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,17 +2076,16 @@ 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() {
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,14 +2272,14 @@ 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() {
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,12 +2444,12 @@ impl Item {
}
}
if let Some(path) = self.path_opt() {
if let Ok(img) = image::image_dimensions(path) {
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() {
@ -2637,13 +2636,12 @@ 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() {
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.
tokio::task::yield_now().await;
@ -2768,12 +2766,12 @@ 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) {
if let Some(location) = &item.location_opt
&& selected.contains(location)
{
item.selected = true;
}
}
}
self.items_opt = Some(items);
}
@ -2790,14 +2788,13 @@ 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;
}
}
}
}
}
pub fn selected_locations(&self) -> Vec<Location> {
if let Some(ref items) = self.items_opt {
@ -2883,15 +2880,15 @@ 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) {
if let Some(path) = item.path_opt()
&& paths.contains(path)
{
item.selected = true;
self.select_focus = Some(i);
}
}
}
}
}
fn select_position(&mut self, row: usize, col: usize, mod_shift: bool) -> bool {
let mut start = (row, col);
@ -3087,11 +3084,11 @@ impl Tab {
return Vec::new();
};
if let Some((w, h)) = original_dims {
if !should_use_tiling(*w, *h) {
if let Some((w, h)) = original_dims
&& !should_use_tiling(*w, *h)
{
return Vec::new();
}
}
let Some(path) = item.path_opt() else {
return Vec::new();
@ -3391,8 +3388,7 @@ 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 {
if show_hidden_changed && let Location::Search(path, term, ..) = &self.location {
cd = Some(Location::Search(
path.clone(),
term.clone(),
@ -3400,7 +3396,6 @@ impl Tab {
Instant::now(),
));
}
}
// Unhighlight all items when config changes
if let Some(ref mut items) = self.items_opt {
for item in items.iter_mut() {
@ -3420,14 +3415,15 @@ 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 {
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;
}
}
}
}
Message::LocationContextMenuPoint(point_opt) => {
self.context_menu = None;
self.location_context_menu_point = point_opt;
@ -3512,13 +3508,13 @@ impl Tab {
}
}
Message::EditLocationComplete(selected) => {
if let Some(mut edit_location) = self.edit_location.take() {
if !matches!(edit_location.location, Location::Network(..)) {
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 => {
commands.push(Command::Iced(
widget::text_input::focus(self.edit_location_id.clone()).into(),
@ -3532,11 +3528,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);
}
@ -3634,21 +3630,21 @@ impl Tab {
}
}
Message::GoNext => {
if let Some(history_i) = self.history_i.checked_add(1) {
if let Some(location) = self.history.get(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) {
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 => {
if let Some(edit_location) = &mut self.edit_location {
edit_location.select(true);
@ -3825,12 +3821,12 @@ 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() {
if let Location::Path(ref path) = self.location
&& let Some(parent) = path.parent()
{
cd = Some(Location::Path(parent.to_owned()));
}
}
}
Message::Open(path_opt) => {
match path_opt {
Some(path) => {
@ -3870,27 +3866,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 {
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();
@ -3935,8 +3929,8 @@ 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
@ -3944,7 +3938,6 @@ impl Tab {
item.selected = Some(i) == click_i_opt;
}
}
}
//TODO: hack for clearing selecting when right clicking empty space
self.last_right_click = click_i_opt;
}
@ -3990,13 +3983,13 @@ 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() {
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);
}
@ -4099,14 +4092,13 @@ 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 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 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(),
scrollable::scroll_to(self.scrollable_id.clone(), offset).into(),
));
}
if let Some(id) = self.select_focus_id() {
@ -4114,8 +4106,6 @@ impl Tab {
}
}
}
}
}
Message::SetOpenWith(mime, id) => {
commands.push(Command::SetOpenWith(mime, id));
}
@ -4136,15 +4126,15 @@ impl Tab {
}
}
Message::TabComplete(path, completions) => {
if let Some(edit_location) = &mut self.edit_location {
if edit_location.location.path_opt() == Some(&path) {
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) => {
if let Some(ref mut items) = self.items_opt {
let location = Location::Path(path);
@ -4276,11 +4266,11 @@ 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) {
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() {
if item.location_opt.as_ref() == Some(&location) {
@ -4317,14 +4307,13 @@ 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() {
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()) {
if selected_paths.is_none() {
@ -4531,9 +4520,10 @@ 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) {
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
@ -4599,8 +4589,7 @@ impl Tab {
widget::image(image_handle).into()
};
element_opt =
Some(widget::container(content).center(Length::Fill).into());
element_opt = Some(widget::container(content).center(Length::Fill).into());
}
ItemThumbnail::Svg(handle) => {
element_opt = Some(
@ -4612,21 +4601,15 @@ impl Tab {
}
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,
)),
),
)
widget::container(widget::text_editor(text).padding(space_xxs).class(
cosmic::theme::iced::TextEditor::Custom(Box::new(text_editor_class)),
))
.center(Length::Fill)
.into(),
);
}
}
}
}
}
let mut column = widget::column::with_capacity(2);
column = column.push(widget::Space::with_height(Length::Fixed(space_m.into())));
@ -4862,8 +4845,9 @@ 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() {
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() {
@ -4888,7 +4872,6 @@ impl Tab {
.max_width(size.width - 140.0),
);
}
}
row = row.push(popover);
let mut column = widget::column::with_capacity(4).padding([0, space_s]);
column = column.push(row);
@ -5913,14 +5896,14 @@ 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);
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);
if let Some(location_view) = location_view_opt {
@ -5939,8 +5922,9 @@ impl Tab {
}
match &self.location {
Location::Trash => {
if let Some(items) = self.items_opt() {
if !items.is_empty() {
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(),
@ -5955,7 +5939,6 @@ impl Tab {
);
}
}
}
Location::Network(uri, _display_name, _path) if uri == "network:///" => {
tab_column = tab_column.push(
widget::layer_container(widget::row::with_children([
@ -6250,11 +6233,11 @@ 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() {
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
if let Some(path) = item.path_opt().cloned() {

View file

@ -66,11 +66,11 @@ 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) {
) && 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.
if self.is_thumbnail_valid(&self.thumbnail_path) {