slidingView: Don't notify page updates emmediately
This allows to add new pages after clearing without triggering an empty state in between. This also fixes opening a new image leaving the fullscreen mode. Fixes #286
This commit is contained in:
parent
f0c374afdc
commit
476abf1612
2 changed files with 58 additions and 10 deletions
|
|
@ -293,14 +293,14 @@ impl LpImageView {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_files(&self, files: Vec<gio::File>) {
|
fn load_files(&self, files: Vec<gio::File>) {
|
||||||
let sliding_view = self.sliding_view();
|
let sliding_view = self.sliding_view().editor();
|
||||||
|
|
||||||
if let Some(first) = files.first().cloned() {
|
if let Some(first) = files.first().cloned() {
|
||||||
let model = LpFileModel::from_files(files);
|
let model = LpFileModel::from_files(files);
|
||||||
self.set_model(model);
|
self.set_model(model);
|
||||||
let page = self.new_image_page(&first);
|
let page = self.new_image_page(&first);
|
||||||
|
|
||||||
sliding_view.clear();
|
sliding_view.clear_lazy();
|
||||||
sliding_view.append(&page);
|
sliding_view.append(&page);
|
||||||
self.update_sliding_view(&first);
|
self.update_sliding_view(&first);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -421,7 +421,7 @@ impl LpImageView {
|
||||||
"Updating sliding_view neighbors for current path {}",
|
"Updating sliding_view neighbors for current path {}",
|
||||||
current_file.uri()
|
current_file.uri()
|
||||||
);
|
);
|
||||||
let sliding_view = self.sliding_view();
|
let sliding_view = self.sliding_view().editor();
|
||||||
|
|
||||||
self.imp().preserve_content.set(false);
|
self.imp().preserve_content.set(false);
|
||||||
|
|
||||||
|
|
@ -431,7 +431,7 @@ impl LpImageView {
|
||||||
// remove old pages
|
// remove old pages
|
||||||
for (uri, page) in &existing {
|
for (uri, page) in &existing {
|
||||||
if !target.contains_key(uri) {
|
if !target.contains_key(uri) {
|
||||||
sliding_view.remove(page);
|
sliding_view.remove_lazy(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,14 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LpSlidingView {
|
impl LpSlidingView {
|
||||||
|
/// Returns a struct that allows lazy updates
|
||||||
|
///
|
||||||
|
/// Lazy updates don't apply their notifications directly but only when the
|
||||||
|
/// editor struct is dropped.
|
||||||
|
pub fn editor(&self) -> SlidingViewEditor {
|
||||||
|
SlidingViewEditor::new(self.clone())
|
||||||
|
}
|
||||||
|
|
||||||
/// Add page to the end
|
/// Add page to the end
|
||||||
pub fn append(&self, page: &LpImagePage) {
|
pub fn append(&self, page: &LpImagePage) {
|
||||||
self.insert(page, self.n_pages());
|
self.insert(page, self.n_pages());
|
||||||
|
|
@ -323,7 +331,7 @@ impl LpSlidingView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the page
|
/// Removes the page
|
||||||
pub fn remove(&self, page: &LpImagePage) {
|
fn remove(&self, page: &LpImagePage, lazy: bool) {
|
||||||
let current_index = self.current_index();
|
let current_index = self.current_index();
|
||||||
|
|
||||||
if let Some(index) = self.index_of(page) {
|
if let Some(index) = self.index_of(page) {
|
||||||
|
|
@ -334,8 +342,8 @@ impl LpSlidingView {
|
||||||
|
|
||||||
self.shift_position(current_index);
|
self.shift_position(current_index);
|
||||||
|
|
||||||
if self.is_empty() {
|
if self.is_empty() && !lazy {
|
||||||
self.clear();
|
self.clear(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::error!("Trying to remove non-existent page.");
|
log::error!("Trying to remove non-existent page.");
|
||||||
|
|
@ -351,7 +359,7 @@ impl LpSlidingView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes all pages
|
/// Removes all pages
|
||||||
pub fn clear(&self) {
|
fn clear(&self, lazy: bool) {
|
||||||
self.scroll_animation().pause();
|
self.scroll_animation().pause();
|
||||||
|
|
||||||
for page in self.imp().pages.borrow().iter() {
|
for page in self.imp().pages.borrow().iter() {
|
||||||
|
|
@ -362,8 +370,10 @@ impl LpSlidingView {
|
||||||
self.set_position(0.);
|
self.set_position(0.);
|
||||||
self.imp().position_shift.set(0.);
|
self.imp().position_shift.set(0.);
|
||||||
|
|
||||||
|
if !lazy {
|
||||||
self.set_current_page(None);
|
self.set_current_page(None);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Gives all pages with hash access via their path
|
/// Gives all pages with hash access via their path
|
||||||
pub fn pages(&self) -> IndexMap<glib::GString, LpImagePage> {
|
pub fn pages(&self) -> IndexMap<glib::GString, LpImagePage> {
|
||||||
|
|
@ -415,7 +425,7 @@ impl LpSlidingView {
|
||||||
} else if let Some(prev_page) = self.prev_page() {
|
} else if let Some(prev_page) = self.prev_page() {
|
||||||
self.scroll_to(&prev_page);
|
self.scroll_to(&prev_page);
|
||||||
} else if let Some(current_page) = self.current_page() {
|
} else if let Some(current_page) = self.current_page() {
|
||||||
self.remove(¤t_page);
|
self.remove(¤t_page, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -509,3 +519,41 @@ impl LpSlidingView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// See [`LpSlidingView::editor`](LpSlidingView::editor)
|
||||||
|
pub struct SlidingViewEditor {
|
||||||
|
sliding_view: LpSlidingView,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SlidingViewEditor {
|
||||||
|
fn new(sliding_view: LpSlidingView) -> Self {
|
||||||
|
Self { sliding_view }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the page giving notifications later
|
||||||
|
pub fn remove_lazy(&self, page: &LpImagePage) {
|
||||||
|
self.remove(page, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes all pages giving notifications later
|
||||||
|
pub fn clear_lazy(&self) {
|
||||||
|
self.clear(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for SlidingViewEditor {
|
||||||
|
type Target = LpSlidingView;
|
||||||
|
|
||||||
|
fn deref(&self) -> &LpSlidingView {
|
||||||
|
&self.sliding_view
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for SlidingViewEditor {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
// Trigger everything that hasn't been done by lazy updates
|
||||||
|
if self.is_empty() {
|
||||||
|
self.clear(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue