From 6801d0b1d1e0c13a20d7e6872f2c1fadcf1bf213 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 7 Dec 2017 10:51:16 +0200 Subject: [PATCH] Move replace_*view functions inot Content methods. --- hammond-gtk/src/content.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs index dc8e0d0..be858f0 100644 --- a/hammond-gtk/src/content.rs +++ b/hammond-gtk/src/content.rs @@ -35,6 +35,24 @@ impl Content { podcasts, } } + + fn replace_widget(&mut self, pdw: PodcastWidget) { + let old = self.stack.get_child_by_name("widget").unwrap(); + self.stack.remove(&old); + + self.widget = pdw; + self.stack.add_named(&self.widget.container, "widget"); + old.destroy(); + } + + fn replace_podcasts(&mut self, pop: PopulatedView) { + let old = self.stack.get_child_by_name("podcasts").unwrap(); + self.stack.remove(&old); + + self.podcasts = pop; + self.stack.add_named(&self.podcasts.container, "podcasts"); + old.destroy(); + } } trait UpdateView { @@ -102,14 +120,8 @@ impl PodcastsView { impl UpdateView for PodcastsView { fn update(&mut self) { - let old = self.content.stack.get_child_by_name("podcasts").unwrap(); - - self.content.podcasts = PopulatedView::new_initialized(&self.content.stack); - - self.content.stack.remove(&old); - self.content.stack.add_named(&self.content.podcasts.container, "podcasts"); - - old.destroy(); + let pop = PopulatedView::new_initialized(&self.content.stack); + self.content.replace_podcasts(pop) } } @@ -135,11 +147,8 @@ impl UpdateView for WidgetsView { let id = WidgetExt::get_name(&old).unwrap(); let pd = dbqueries::get_podcast_from_id(id.parse::().unwrap()).unwrap(); - self.content.widget = PodcastWidget::new_initialized(&self.content.stack, &pd);; - self.content.stack.remove(&old); - self.content.stack.add_named(&self.content.widget.container, "widget"); - - old.destroy(); + let pdw = PodcastWidget::new_initialized(&self.content.stack, &pd);; + self.content.replace_widget(pdw); } }