Skip to content

Commit 4312179

Browse files
committed
Allow type to enter path to select files in dialog
1 parent 9e8fb60 commit 4312179

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/dialog.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<M: Send + 'static> Dialog<M> {
344344
self.cosmic.app.filter_selected = filter_selected;
345345
self.cosmic
346346
.app
347-
.rescan_tab()
347+
.rescan_tab(None)
348348
.map(DialogMessage)
349349
.map(move |message| cosmic::action::app(mapper(message)))
350350
}
@@ -431,7 +431,9 @@ enum Message {
431431
Surface(cosmic::surface::Action),
432432
#[allow(clippy::enum_variant_names)]
433433
TabMessage(tab::Message),
434-
TabRescan(Location, Option<tab::Item>, Vec<tab::Item>),
434+
TabRescan(Location, Option<tab::Item>, Vec<tab::Item>,
435+
Option<Vec<PathBuf>>,
436+
),
435437
TabView(tab::View),
436438
TimeConfigChange(TimeConfig),
437439
ToggleFoldersFirst,
@@ -662,7 +664,9 @@ impl App {
662664
widget::column::with_children(children).into()
663665
}
664666

665-
fn rescan_tab(&self) -> Task<Message> {
667+
fn rescan_tab(&self,
668+
selection_paths: Option<Vec<PathBuf>>,
669+
) -> Task<Message> {
666670
let location = self.tab.location.clone();
667671
let icon_sizes = self.tab.config.icon_sizes;
668672
let mounter_items = self.mounter_items.clone();
@@ -685,7 +689,7 @@ impl App {
685689
}
686690
}
687691
}
688-
cosmic::action::app(Message::TabRescan(location, parent_item_opt, items))
692+
cosmic::action::app(Message::TabRescan(location, parent_item_opt, items, selection_paths))
689693
}
690694
Err(err) => {
691695
log::warn!("failed to rescan: {}", err);
@@ -727,7 +731,7 @@ impl App {
727731
return Task::batch([
728732
self.update_title(),
729733
self.update_watcher(),
730-
self.rescan_tab(),
734+
self.rescan_tab(None),
731735
if focus_search {
732736
widget::text_input::focus(self.search_id.clone())
733737
} else {
@@ -985,7 +989,7 @@ impl Application for App {
985989
app.update_config(),
986990
app.update_title(),
987991
app.update_watcher(),
988-
app.rescan_tab(),
992+
app.rescan_tab(None),
989993
]);
990994

991995
(app, commands)
@@ -1339,7 +1343,7 @@ impl Application for App {
13391343
} else {
13401344
self.filter_selected = None;
13411345
}
1342-
return self.rescan_tab();
1346+
return self.rescan_tab(None);
13431347
}
13441348
Message::Key(modifiers, key, text) => {
13451349
for (key_bind, action) in self.key_binds.iter() {
@@ -1426,7 +1430,7 @@ impl Application for App {
14261430
if unmounted.contains(&self.tab.location) {
14271431
self.tab.change_location(&home_location, None);
14281432
commands.push(self.update_watcher());
1429-
commands.push(self.rescan_tab());
1433+
commands.push(self.rescan_tab(None));
14301434
}
14311435
}
14321436

@@ -1502,7 +1506,7 @@ impl Application for App {
15021506
}
15031507
}
15041508
if contains_change {
1505-
return self.rescan_tab();
1509+
return self.rescan_tab(None);
15061510
}
15071511
}
15081512
}
@@ -1640,8 +1644,8 @@ impl Application for App {
16401644
tab::Command::Action(action) => {
16411645
commands.push(self.update(Message::from(action.message())));
16421646
}
1643-
tab::Command::ChangeLocation(_tab_title, _tab_path, _selection_paths) => {
1644-
commands.push(Task::batch([self.update_watcher(), self.rescan_tab()]));
1647+
tab::Command::ChangeLocation(_tab_title, _tab_path, selection_paths) => {
1648+
commands.push(Task::batch([self.update_watcher(), self.rescan_tab(selection_paths)]));
16451649
}
16461650
tab::Command::ContextMenu(point_opt, parent_id) => {
16471651
#[cfg(feature = "wayland")]
@@ -1753,7 +1757,7 @@ impl Application for App {
17531757
}
17541758
return Task::batch(commands);
17551759
}
1756-
Message::TabRescan(location, parent_item_opt, mut items) => {
1760+
Message::TabRescan(location, parent_item_opt, mut items, selection_paths) => {
17571761
if location == self.tab.location {
17581762
// Filter
17591763
if let Some(filter_i) = self.filter_selected {
@@ -1826,6 +1830,14 @@ impl Application for App {
18261830
self.tab.parent_item_opt = parent_item_opt;
18271831
self.tab.set_items(items);
18281832

1833+
if let Some(mut selection_paths) = selection_paths {
1834+
if !self.flags.kind.multiple() {
1835+
selection_paths.truncate(1);
1836+
}
1837+
self.tab.select_paths(selection_paths);
1838+
}
1839+
1840+
18291841
// Reset focus on location change
18301842
if self.search_get().is_some() {
18311843
return widget::text_input::focus(self.search_id.clone());

0 commit comments

Comments
 (0)