From dddfc8a673c4efe1c2400f0006e50fe0dc6674fd Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Mon, 20 Jan 2025 02:48:55 -0500 Subject: [PATCH] chore(clippy): config, dialog, menu Fixes Clippy lints for: * src/config.rs * src/dialog.rs * src/menu.rs --- src/config.rs | 2 +- src/dialog.rs | 70 +++++++++++++++++++++++---------------------------- src/menu.rs | 20 +++++++-------- 3 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/config.rs b/src/config.rs index 36153da..50dfcba 100644 --- a/src/config.rs +++ b/src/config.rs @@ -68,7 +68,7 @@ impl Favorite { Self::Videos, ] { if let Some(favorite_path) = favorite.path_opt() { - if &favorite_path == &path { + if favorite_path == path { return favorite.clone(); } } diff --git a/src/dialog.rs b/src/dialog.rs index a5a792a..586a0c0 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -157,13 +157,15 @@ impl Dialog { let (config_handler, config) = Config::load(); - let mut settings = window::Settings::default(); - settings.decorations = false; - settings.exit_on_close_request = false; - settings.min_size = Some(Size::new(360.0, 180.0)); - settings.resizable = true; - settings.size = Size::new(1024.0, 640.0); - settings.transparent = true; + let mut settings = window::Settings { + decorations: false, + exit_on_close_request: false, + min_size: Some(Size::new(360.0, 180.0)), + resizable: true, + size: Size::new(1024.0, 640.0), + transparent: true, + ..Default::default() + }; #[cfg(target_os = "linux")] { @@ -296,6 +298,7 @@ struct Flags { kind: DialogKind, path_opt: Option, window_id: window::Id, + #[expect(dead_code)] config_handler: Option, config: Config, } @@ -324,6 +327,7 @@ enum Message { SearchActivate, SearchClear, SearchInput(String), + #[allow(clippy::enum_variant_names)] TabMessage(tab::Message), TabRescan(Location, Option, Vec), TabView(tab::View), @@ -598,7 +602,7 @@ impl App { .data(Location::Recents) }); - for (_favorite_i, favorite) in self.flags.config.favorites.iter().enumerate() { + for favorite in self.flags.config.favorites.iter() { if let Some(path) = favorite.path_opt() { let name = if matches!(favorite, Favorite::Home) { fl!("home") @@ -974,11 +978,8 @@ impl Application for App { ContextPage::Preview(..) => self.core.window.show_context, _ => false, }; - elements.push( - menu::dialog_menu(&self.tab, &self.key_binds, show_details) - .map(Message::from) - .into(), - ); + elements + .push(menu::dialog_menu(&self.tab, &self.key_binds, show_details).map(Message::from)); elements } @@ -1027,7 +1028,7 @@ impl Application for App { return self.update(message); } - if let Some(data) = self.nav_model.data::(entity).clone() { + if let Some(data) = self.nav_model.data::(entity) { if let Some(mounter) = MOUNTERS.get(&data.0) { return mounter.mount(data.1.clone()).map(|_| message::none()); } @@ -1169,11 +1170,9 @@ impl Application for App { let mut still_mounted = false; for item in mounter_items.iter() { if let Some(path) = item.path() { - if path == old_path { - if item.is_mounted() { - still_mounted = true; - break; - } + if path == old_path && item.is_mounted() { + still_mounted = true; + break; } } } @@ -1221,7 +1220,7 @@ impl Application for App { let mut contains_change = false; for event in events.iter() { for event_path in event.paths.iter() { - if event_path.starts_with(&path) { + if event_path.starts_with(path) { match event.kind { notify::EventKind::Modify( notify::event::ModifyKind::Metadata(_), @@ -1235,14 +1234,14 @@ impl Application for App { for item in items.iter_mut() { if item.path_opt() == Some(event_path) { //TODO: reload more, like mime types? - match fs::metadata(&event_path) { + match fs::metadata(event_path) { Ok(new_metadata) => { - match &mut item.metadata { - ItemMetadata::Path { - metadata, - .. - } => *metadata = new_metadata, - _ => {} + if let ItemMetadata::Path { + metadata, + .. + } = &mut item.metadata + { + *metadata = new_metadata; } } Err(err) => { @@ -1322,12 +1321,9 @@ impl Application for App { // If we are in directory mode, return the current directory if self.flags.kind.is_dir() { - match &self.tab.location { - Location::Path(tab_path) => { - self.result_opt = Some(DialogResult::Open(vec![tab_path.clone()])); - return window::close(self.flags.window_id); - } - _ => {} + if let Location::Path(tab_path) = &self.tab.location { + self.result_opt = Some(DialogResult::Open(vec![tab_path.clone()])); + return window::close(self.flags.window_id); } } } @@ -1344,7 +1340,7 @@ impl Application for App { if let DialogKind::SaveFile { filename } = &self.flags.kind { if !filename.is_empty() { if let Some(tab_path) = self.tab.location.path_opt() { - let path = tab_path.join(&filename); + let path = tab_path.join(filename); if path.is_dir() { // cd to directory let message = Message::TabMessage(tab::Message::Location( @@ -1592,11 +1588,7 @@ impl Application for App { } } - col = col.push( - self.tab - .view(&self.key_binds) - .map(move |message| Message::TabMessage(message)), - ); + col = col.push(self.tab.view(&self.key_binds).map(Message::TabMessage)); col.into() } diff --git a/src/menu.rs b/src/menu.rs index abd602a..219a463 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -89,7 +89,7 @@ pub fn context_menu<'a>( let mut selected_trash_only = false; let mut selected_desktop_entry = None; let mut selected_types: Vec = vec![]; - tab.items_opt().map(|items| { + if let Some(items) = tab.items_opt() { for item in items.iter() { if item.selected { selected += 1; @@ -110,7 +110,7 @@ pub fn context_menu<'a>( selected_types.push(item.mime.clone()); } } - }); + }; selected_types.sort_unstable(); selected_types.dedup(); selected_trash_only = selected_trash_only && selected == 1; @@ -342,7 +342,7 @@ pub fn context_menu<'a>( .into() } -pub fn dialog_menu<'a>( +pub fn dialog_menu( tab: &Tab, key_binds: &HashMap, show_details: bool, @@ -359,15 +359,13 @@ pub fn dialog_menu<'a>( let in_trash = tab.location == Location::Trash; let mut selected_gallery = 0; - tab.items_opt().map(|items| { + if let Some(items) = tab.items_opt() { for item in items.iter() { - if item.selected { - if item.can_gallery() { - selected_gallery += 1; - } + if item.selected && item.can_gallery() { + selected_gallery += 1; } } - }); + }; MenuBar::new(vec![ menu::Tree::with_children( @@ -504,7 +502,7 @@ pub fn menu_bar<'a>( let mut selected_dir = 0; let mut selected = 0; let mut selected_gallery = 0; - tab_opt.and_then(|tab| tab.items_opt()).map(|items| { + if let Some(items) = tab_opt.and_then(|tab| tab.items_opt()) { for item in items.iter() { if item.selected { selected += 1; @@ -516,7 +514,7 @@ pub fn menu_bar<'a>( } } } - }); + }; MenuBar::new(vec![ menu::Tree::with_children(