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 4, 2024
1 parent b968bc0 commit 9d5b291
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ use crate::{
tab::{self, HeadingOptions, ItemMetadata, Location, Tab, HOVER_DURATION},
};

static REFRESH_VIEW_DELAY_MS: u64 = 20;

#[derive(Clone, Debug)]
pub struct Flags {
pub config_handler: Option<cosmic_config::Config>,
Expand Down Expand Up @@ -90,6 +92,7 @@ pub enum Action {
OpenWith,
Paste,
Properties,
Refresh,
Rename,
RestoreFromTrash,
SearchActivate,
Expand Down Expand Up @@ -139,6 +142,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 @@ -243,6 +247,9 @@ pub enum Message {
PendingComplete(u64),
PendingError(u64, String),
PendingProgress(u64, f32),
Refresh(Option<Entity>),
RefreshStart(Entity, Location),
RefreshComplete(Entity, Location),
RescanTrash,
Rename(Option<Entity>),
ReplaceResult(ReplaceResult),
Expand Down Expand Up @@ -1717,6 +1724,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![]);
return cosmic::command::message(Message::RefreshStart(entity, location));
}
return Command::none();
}
Message::RefreshComplete(entity, location) => {
if self.search_input.is_empty() {
return self.rescan_tab(entity, location, None);
} else {
return self.search();
}
}

Message::RefreshStart(entity, location) => {
return Command::perform(tokio::time::sleep(tokio::time::Duration::from_millis(REFRESH_VIEW_DELAY_MS)), move |_| {
cosmic::app::Message::App(Message::RefreshComplete(entity, location))
});
}
Message::RescanTrash => {
// Update trash icon if empty/full
let maybe_entity = self.nav_model.iter().find(|&entity| {
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

0 comments on commit 9d5b291

Please sign in to comment.