Skip to content

Commit

Permalink
feat: Refresh/reload tab view & search fix(pop-os#146).
Browse files Browse the repository at this point in the history
  • Loading branch information
l-const committed Sep 12, 2024
1 parent f417309 commit 9c1913a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions i18n/en/cosmic_files.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cosmic-files = COSMIC Files
empty-folder = Empty folder
empty-folder-hidden = Empty folder (has hidden items)
no-results = No results found
refresh-loading = Loading...
filesystem = Filesystem
home = Home
notification-in-progress = File operations are in progress.
Expand Down
32 changes: 32 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ use crate::{
tab::{self, HeadingOptions, ItemMetadata, Location, Tab, HOVER_DURATION},
};

static REFRESH_VIEW_DELAY_MS: u64 = 20;

#[derive(Clone, Debug)]
pub enum Mode {
App,
Expand Down Expand Up @@ -111,6 +113,7 @@ pub enum Action {
OpenWith,
Paste,
Properties,
Refresh,
Rename,
RestoreFromTrash,
SearchActivate,
Expand Down Expand Up @@ -163,6 +166,7 @@ impl Action {
Action::OpenWith => Message::ToggleContextPage(ContextPage::OpenWith),
Action::Paste => Message::Paste(entity_opt),
Action::Properties => Message::ToggleContextPage(ContextPage::Properties(None)),
Action::Refresh => Message::Refresh(entity_opt),
Action::Rename => Message::Rename(entity_opt),
Action::RestoreFromTrash => Message::RestoreFromTrash(entity_opt),
Action::SearchActivate => Message::SearchActivate,
Expand Down Expand Up @@ -272,6 +276,9 @@ pub enum Message {
PendingComplete(u64),
PendingError(u64, String),
PendingProgress(u64, f32),
Refresh(Option<Entity>),
RefreshDelayStart(Entity, Location),
RefreshDelayComplete(Entity, Location),
RescanTrash,
Rename(Option<Entity>),
ReplaceResult(ReplaceResult),
Expand Down Expand Up @@ -1849,6 +1856,28 @@ impl Application for App {
}
return self.update_notification();
}
Message::Refresh(entity_opt) => {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
let location = tab.location.clone();
tab.set_items(vec![]);
tab.refresh_active = true;
return cosmic::command::message(Message::RefreshDelayStart(entity, location));
}
return Command::none();
}
Message::RefreshDelayComplete(entity, location) => {
if self.search_input.is_empty() {
return self.rescan_tab(entity, location, None);
} else {
return self.search();
}
}
Message::RefreshDelayStart(entity, location) => {
return Command::perform(tokio::time::sleep(tokio::time::Duration::from_millis(REFRESH_VIEW_DELAY_MS)), move |_| {
cosmic::app::Message::App(Message::RefreshDelayComplete(entity, location))
});
}
Message::RescanTrash => {
// Update trash icon if empty/full
let maybe_entity = self.nav_model.iter().find(|&entity| {
Expand Down Expand Up @@ -2207,6 +2236,9 @@ impl Application for App {
if let Some(selection_path) = selection_path {
tab.select_path(selection_path);
}
if tab.refresh_active {
tab.refresh_active = false;
}
}
}
_ => (),
Expand Down
2 changes: 2 additions & 0 deletions src/key_bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
bind!([Ctrl], Key::Character("v".into()), Paste);
bind!([], Key::Named(Named::Space), Properties);
bind!([], Key::Named(Named::F2), Rename);
bind!([], Key::Named(Named::F5), Refresh);
bind!([Ctrl], Key::Character("r".into()), Refresh);
bind!([Ctrl], Key::Character("f".into()), SearchActivate);
bind!([Ctrl], Key::Character("a".into()), SelectAll);
bind!([Ctrl], Key::Character(",".into()), Settings);
Expand Down
7 changes: 6 additions & 1 deletion src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,12 +1171,14 @@ pub struct Tab {
pub config: TabConfig,
pub(crate) items_opt: Option<Vec<Item>>,
pub dnd_hovered: Option<(Location, Instant)>,
pub(crate) refresh_active: bool,
scrollable_id: widget::Id,
select_focus: Option<usize>,
select_range: Option<(usize, usize)>,
cached_selected: RefCell<Option<bool>>,
clicked: Option<usize>,
selected_clicked: bool,

}

fn folder_name<P: AsRef<Path>>(path: P) -> (String, bool) {
Expand Down Expand Up @@ -1216,6 +1218,7 @@ impl Tab {
history,
config,
items_opt: None,
refresh_active: false,
scrollable_id: widget::Id::unique(),
select_focus: None,
select_range: None,
Expand Down Expand Up @@ -2608,7 +2611,9 @@ impl Tab {
.size(64)
.icon()
.into(),
widget::text(if has_hidden {
widget::text(if self.refresh_active {
fl!("refresh-loading")
} else if has_hidden {
fl!("empty-folder-hidden")
} else if matches!(self.location, Location::Search(_, _)) {
fl!("no-results")
Expand Down

0 comments on commit 9c1913a

Please sign in to comment.