ShowsView: Use BaseView abstraction
This commit is contained in:
parent
e4dd9f5bb3
commit
7463e9d42c
@ -1,74 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.0
|
||||
|
||||
Copyright (C) 2017 - 2018
|
||||
|
||||
This file is part of Hammond.
|
||||
|
||||
Hammond is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Hammond is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Hammond. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Authors:
|
||||
Jordan Petridis
|
||||
Tobias Bernard
|
||||
|
||||
-->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<!-- interface-license-type gplv3 -->
|
||||
<!-- interface-name Hammond -->
|
||||
<!-- interface-description A podcast client for the GNOME Desktop -->
|
||||
<!-- interface-copyright 2017 - 2018 -->
|
||||
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
||||
<object class="GtkBox" id="fb_parent">
|
||||
<property name="name">fb_parent</property>
|
||||
<property name="width_request">290</property>
|
||||
<property name="height_request">420</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolled_window">
|
||||
<property name="name">scrolled_window</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkFlowBox" id="flowbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="margin_top">24</property>
|
||||
<property name="margin_bottom">24</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<property name="column_spacing">12</property>
|
||||
<property name="row_spacing">12</property>
|
||||
<property name="max_children_per_line">20</property>
|
||||
<property name="selection_mode">none</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
@ -7,7 +7,6 @@
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/empty_show.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/home_view.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/home_episode.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/shows_view.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/shows_child.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/headerbar.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/inapp_notif.ui</file>
|
||||
@ -20,4 +19,4 @@
|
||||
<file compressed="true" preprocess="xml-stripblanks">gtk/prefs.ui</file>
|
||||
<file compressed="true">gtk/style.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
</gresources>
|
||||
|
||||
@ -38,7 +38,7 @@ impl PopulatedStack {
|
||||
let show = Rc::new(ShowWidget::default());
|
||||
let container = gtk::Box::new(gtk::Orientation::Horizontal, 0);
|
||||
|
||||
stack.add_named(&populated.container, "shows");
|
||||
stack.add_named(populated.container(), "shows");
|
||||
stack.add_named(show.container(), "widget");
|
||||
container.add(&stack);
|
||||
container.show_all();
|
||||
@ -70,7 +70,7 @@ impl PopulatedStack {
|
||||
}
|
||||
|
||||
pub(crate) fn replace_shows(&mut self) -> Result<(), Error> {
|
||||
let old = &self.populated.container.clone();
|
||||
let old = &self.populated.container().clone();
|
||||
debug!("Name: {:?}", WidgetExt::get_name(old));
|
||||
|
||||
self.populated
|
||||
@ -81,7 +81,7 @@ impl PopulatedStack {
|
||||
let pop = ShowsView::new(self.sender.clone());
|
||||
self.populated = pop;
|
||||
self.stack.remove(old);
|
||||
self.stack.add_named(&self.populated.container, "shows");
|
||||
self.stack.add_named(self.populated.container(), "shows");
|
||||
|
||||
old.destroy();
|
||||
Ok(())
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{self, prelude::*, Align, SelectionMode};
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use failure::Error;
|
||||
@ -10,6 +9,7 @@ use podcasts_data::Show;
|
||||
|
||||
use app::Action;
|
||||
use utils::{self, get_ignored_shows, lazy_load, set_image_from_path};
|
||||
use widgets::BaseView;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
@ -22,23 +22,30 @@ lazy_static! {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct ShowsView {
|
||||
pub(crate) container: gtk::Box,
|
||||
scrolled_window: gtk::ScrolledWindow,
|
||||
view: BaseView,
|
||||
flowbox: gtk::FlowBox,
|
||||
}
|
||||
|
||||
impl Default for ShowsView {
|
||||
fn default() -> Self {
|
||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Podcasts/gtk/shows_view.ui");
|
||||
let container: gtk::Box = builder.get_object("fb_parent").unwrap();
|
||||
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
|
||||
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
|
||||
let view = BaseView::default();
|
||||
let flowbox = gtk::FlowBox::new();
|
||||
|
||||
ShowsView {
|
||||
container,
|
||||
scrolled_window,
|
||||
flowbox,
|
||||
}
|
||||
flowbox.show();
|
||||
flowbox.set_vexpand(true);
|
||||
flowbox.set_hexpand(true);
|
||||
flowbox.set_row_spacing(12);
|
||||
flowbox.set_can_focus(false);
|
||||
flowbox.set_margin_top(32);
|
||||
flowbox.set_margin_bottom(32);
|
||||
flowbox.set_homogeneous(true);
|
||||
flowbox.set_column_spacing(12);
|
||||
flowbox.set_valign(Align::Start);
|
||||
flowbox.set_halign(Align::Center);
|
||||
flowbox.set_selection_mode(SelectionMode::None);
|
||||
view.add(&flowbox);
|
||||
|
||||
ShowsView { view, flowbox }
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +66,14 @@ impl ShowsView {
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn container(&self) -> >k::Box {
|
||||
self.view.container()
|
||||
}
|
||||
|
||||
pub(crate) fn scrolled_window(&self) -> >k::ScrolledWindow {
|
||||
self.view.scrolled_window()
|
||||
}
|
||||
|
||||
/// Set scrolled window vertical adjustment.
|
||||
fn set_vadjustment(&self) -> Result<(), Error> {
|
||||
let guard = SHOWS_VIEW_VALIGNMENT
|
||||
@ -69,7 +84,7 @@ impl ShowsView {
|
||||
// Copy the vertical scrollbar adjustment from the old view into the new one.
|
||||
let res = fragile
|
||||
.try_get()
|
||||
.map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x))
|
||||
.map(|x| utils::smooth_scroll_to(self.scrolled_window(), &x))
|
||||
.map_err(From::from);
|
||||
|
||||
debug_assert!(res.is_ok());
|
||||
@ -83,7 +98,7 @@ impl ShowsView {
|
||||
pub(crate) fn save_alignment(&self) -> Result<(), Error> {
|
||||
if let Ok(mut guard) = SHOWS_VIEW_VALIGNMENT.lock() {
|
||||
let adj = self
|
||||
.scrolled_window
|
||||
.scrolled_window()
|
||||
.get_vadjustment()
|
||||
.ok_or_else(|| format_err!("Could not get the adjustment"))?;
|
||||
*guard = Some(Fragile::new(adj));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user