h-gtk: Further refactor of the ShowStack.

This commit is contained in:
Jordan Petridis 2018-04-21 08:01:34 +03:00
parent 6406c3af13
commit e560cce879
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 11 additions and 20 deletions

View File

@ -1,6 +1,5 @@
use gtk; use gtk;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::Cast;
use failure::Error; use failure::Error;
@ -20,7 +19,7 @@ use std::sync::Arc;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ShowStack { pub struct ShowStack {
stack: gtk::Stack, stack: gtk::Stack,
podcasts: ShowsPopulated, podcasts: Rc<ShowsPopulated>,
show: Rc<ShowWidget>, show: Rc<ShowWidget>,
empty: EmptyView, empty: EmptyView,
sender: Sender<Action>, sender: Sender<Action>,
@ -55,26 +54,18 @@ impl ShowStack {
// self.update_podcasts(); // self.update_podcasts();
// } // }
pub fn update_podcasts(&self) -> Result<(), Error> { pub fn update_podcasts(&mut self) -> Result<(), Error> {
let vis = self.stack let vis = self.stack
.get_visible_child_name() .get_visible_child_name()
.ok_or_else(|| format_err!("Failed to get visible child name."))?; .ok_or_else(|| format_err!("Failed to get visible child name."))?;
let old = self.stack let old = &self.podcasts.container.clone();
.get_child_by_name("podcasts") debug!("Name: {:?}", WidgetExt::get_name(old));
.ok_or_else(|| format_err!("Faild to get \"podcasts\" child from the stack."))?
.downcast::<gtk::Box>()
.map_err(|_| format_err!("Failed to downcast stack child to a Box."))?;
debug!("Name: {:?}", WidgetExt::get_name(&old));
let pop = ShowsPopulated::new(self.sender.clone())?; let pop = ShowsPopulated::new(self.sender.clone())?;
// Copy the vertical scrollbar adjustment from the old view into the new one. self.podcasts = pop;
// scrolled_window self.stack.remove(old);
// .get_vadjustment() self.stack.add_named(&self.podcasts.container, "podcasts");
// .map(|x| pop.set_vadjustment(&x));
self.stack.remove(&old);
self.stack.add_named(&pop.container, "podcasts");
if !dbqueries::is_podcasts_populated()? { if !dbqueries::is_podcasts_populated()? {
self.stack.set_visible_child_name("empty"); self.stack.set_visible_child_name("empty");
@ -108,10 +99,9 @@ impl ShowStack {
WidgetExt::get_name(&new.container) WidgetExt::get_name(&new.container)
); );
let root = new.container.clone();
self.show = new; self.show = new;
self.stack.remove(&old); self.stack.remove(&old);
self.stack.add_named(&root, "widget"); self.stack.add_named(&self.show.container, "widget");
Ok(()) Ok(())
} }

View File

@ -8,6 +8,7 @@ use hammond_data::Podcast;
use app::Action; use app::Action;
use utils::{get_ignored_shows, lazy_load, set_image_from_path}; use utils::{get_ignored_shows, lazy_load, set_image_from_path};
use std::rc::Rc;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::sync::Arc; use std::sync::Arc;
@ -36,8 +37,8 @@ impl Default for ShowsPopulated {
impl ShowsPopulated { impl ShowsPopulated {
#[inline] #[inline]
pub fn new(sender: Sender<Action>) -> Result<ShowsPopulated, Error> { pub fn new(sender: Sender<Action>) -> Result<Rc<ShowsPopulated>, Error> {
let pop = ShowsPopulated::default(); let pop = Rc::new(ShowsPopulated::default());
pop.init(sender)?; pop.init(sender)?;
Ok(pop) Ok(pop)
} }