Skip to content

Commit

Permalink
Move the reload to a separate signal
Browse files Browse the repository at this point in the history
  • Loading branch information
matzipan committed Dec 7, 2023
1 parent 1571b4e commit dc6bca3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
22 changes: 13 additions & 9 deletions app/src/models/folder_conversations_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ use gtk::prelude::*;
use glib::subclass::prelude::*;
use gtk::subclass::prelude::*;

use gtk::glib::subclass::Signal;

use std::cell::RefCell;
use std::rc::Rc;

use once_cell::sync::Lazy;

use crate::models;
use crate::services;

pub mod model {
use super::*;
use row_data::ConversationRowData;
mod imp {

use super::*;

#[derive(Debug)]
Expand All @@ -41,7 +46,12 @@ pub mod model {
}
}
}
impl ObjectImpl for FolderModel {}
impl ObjectImpl for FolderModel {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| vec![Signal::builder("folder-loaded").build()]);
SIGNALS.as_ref()
}
}
impl ListModelImpl for FolderModel {
fn item_type(&self) -> glib::Type {
ConversationRowData::static_type()
Expand Down Expand Up @@ -103,15 +113,9 @@ pub mod model {

self_.currently_loaded_folder.replace(Some(folder));

let previous_count = self_.n_items();

let new_summaries = self.load_summaries();

self_.summaries.replace(new_summaries);

let new_count = self_.n_items();
self_.summaries.replace(self.load_summaries());

self.items_changed(0, previous_count, new_count);
self_.obj().emit_by_name::<()>("folder-loaded", &[]);
}

pub fn handle_new_messages_for_folder(&self, folder: &models::Folder) {
Expand Down
13 changes: 11 additions & 2 deletions app/src/ui/window/dynamic_list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ mod imp {
}

pub fn set_conversations_list_model(&self, conversations_list_model: FolderModel) {
let obj = self.obj().clone();
let first_item_clone = self.first_item.clone();
let last_item_clone = self.last_item.clone();
let vertical_adjustment_clone = self.vertical_adjustment.clone();

conversations_list_model.connect_items_changed(move |_, _, _, _| {
let obj = self.obj().clone();

conversations_list_model.connect_local("folder-loaded", false, move |_| {
// Currently there is no ability to refresh folder contents while they are
// loaded, so I'm hijacking this to signify loading a new folder. Will have to
// change in the future.
Expand All @@ -128,6 +129,14 @@ mod imp {
*last_item_clone.borrow_mut() = 0;

obj.queue_allocate();

None
});

let obj = self.obj().clone();

conversations_list_model.connect_items_changed(move |_, _, _, _| {
obj.queue_allocate();
});

*self.conversations_list_model.borrow_mut() = Some(conversations_list_model);
Expand Down

0 comments on commit dc6bca3

Please sign in to comment.