From 4312179a4dd89f12a840a9eecb1e11e284c92ed5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 14 Oct 2025 11:16:37 -0600 Subject: [PATCH] Allow type to enter path to select files in dialog --- src/dialog.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/dialog.rs b/src/dialog.rs index 47d5348..4122749 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -344,7 +344,7 @@ impl Dialog { self.cosmic.app.filter_selected = filter_selected; self.cosmic .app - .rescan_tab() + .rescan_tab(None) .map(DialogMessage) .map(move |message| cosmic::action::app(mapper(message))) } @@ -431,7 +431,9 @@ enum Message { Surface(cosmic::surface::Action), #[allow(clippy::enum_variant_names)] TabMessage(tab::Message), - TabRescan(Location, Option, Vec), + TabRescan(Location, Option, Vec, + Option>, + ), TabView(tab::View), TimeConfigChange(TimeConfig), ToggleFoldersFirst, @@ -662,7 +664,9 @@ impl App { widget::column::with_children(children).into() } - fn rescan_tab(&self) -> Task { + fn rescan_tab(&self, + selection_paths: Option>, + ) -> Task { let location = self.tab.location.clone(); let icon_sizes = self.tab.config.icon_sizes; let mounter_items = self.mounter_items.clone(); @@ -685,7 +689,7 @@ impl App { } } } - cosmic::action::app(Message::TabRescan(location, parent_item_opt, items)) + cosmic::action::app(Message::TabRescan(location, parent_item_opt, items, selection_paths)) } Err(err) => { log::warn!("failed to rescan: {}", err); @@ -727,7 +731,7 @@ impl App { return Task::batch([ self.update_title(), self.update_watcher(), - self.rescan_tab(), + self.rescan_tab(None), if focus_search { widget::text_input::focus(self.search_id.clone()) } else { @@ -985,7 +989,7 @@ impl Application for App { app.update_config(), app.update_title(), app.update_watcher(), - app.rescan_tab(), + app.rescan_tab(None), ]); (app, commands) @@ -1339,7 +1343,7 @@ impl Application for App { } else { self.filter_selected = None; } - return self.rescan_tab(); + return self.rescan_tab(None); } Message::Key(modifiers, key, text) => { for (key_bind, action) in self.key_binds.iter() { @@ -1426,7 +1430,7 @@ impl Application for App { if unmounted.contains(&self.tab.location) { self.tab.change_location(&home_location, None); commands.push(self.update_watcher()); - commands.push(self.rescan_tab()); + commands.push(self.rescan_tab(None)); } } @@ -1502,7 +1506,7 @@ impl Application for App { } } if contains_change { - return self.rescan_tab(); + return self.rescan_tab(None); } } } @@ -1640,8 +1644,8 @@ impl Application for App { tab::Command::Action(action) => { commands.push(self.update(Message::from(action.message()))); } - tab::Command::ChangeLocation(_tab_title, _tab_path, _selection_paths) => { - commands.push(Task::batch([self.update_watcher(), self.rescan_tab()])); + tab::Command::ChangeLocation(_tab_title, _tab_path, selection_paths) => { + commands.push(Task::batch([self.update_watcher(), self.rescan_tab(selection_paths)])); } tab::Command::ContextMenu(point_opt, parent_id) => { #[cfg(feature = "wayland")] @@ -1753,7 +1757,7 @@ impl Application for App { } return Task::batch(commands); } - Message::TabRescan(location, parent_item_opt, mut items) => { + Message::TabRescan(location, parent_item_opt, mut items, selection_paths) => { if location == self.tab.location { // Filter if let Some(filter_i) = self.filter_selected { @@ -1826,6 +1830,14 @@ impl Application for App { self.tab.parent_item_opt = parent_item_opt; self.tab.set_items(items); + if let Some(mut selection_paths) = selection_paths { + if !self.flags.kind.multiple() { + selection_paths.truncate(1); + } + self.tab.select_paths(selection_paths); + } + + // Reset focus on location change if self.search_get().is_some() { return widget::text_input::focus(self.search_id.clone());