Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh/reload tab view & search, fix(#146). #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delay value was a totally arbitrary decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in a 60Hz display you need at least 16.6 ms , so you will see at least one frame and more that one in higher refresh rate displays assuming the execution of the rescan of the view contents is instantaneous.


#[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![]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially, I set an "empty" value for the given tab and register a delayed callback that will either rescan or search again. Maybe something better could be done here.

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