tweak the providers page a bit

This commit is contained in:
Bilal Elmoussaoui 2022-01-05 12:50:30 +01:00
parent dde4c3790d
commit 93088f47d8
5 changed files with 107 additions and 112 deletions

View file

@ -44,31 +44,3 @@
font-weight: 500;
font-feature-settings: "tnum" 1;
}
listview.content.small > row {
margin: 0px;
border-radius: 0px;
border-left-width: 0px;
border-right-width: 0px;
}
listview.content.small > row:first-child {
border-top-width: 0px;
}
listview.content.small > row:last-child {
border-bottom-width: 0px;
}
listview > row:first-child {
margin-top: 12px;
}
listview > row:last-child {
margin-bottom: 12px;
}
listview > row {
margin-left: 12px;
margin-right: 12px;
}

View file

@ -33,7 +33,7 @@
<property name="hexpand">True</property>
<child>
<object class="GtkHeaderBar">
<property name="show-title-buttons">False</property>
<property name="show-title-buttons">True</property>
<property name="title-widget">
<object class="GtkLabel" id="title">
<property name="wrap">True</property>
@ -44,11 +44,16 @@
</object>
</property>
<child type="start">
<object class="GtkButton" id="back_btn">
<property name="receives-default">True</property>
<property name="action-name">providers.back</property>
<property name="icon-name">go-previous-symbolic</property>
<property name="tooltip-text" translatable="yes">Go Back</property>
<object class="GtkRevealer" id="revealer">
<property name="transition-type">crossfade</property>
<child>
<object class="GtkButton">
<property name="receives-default">True</property>
<property name="action-name">providers.back</property>
<property name="icon-name">go-previous-symbolic</property>
<property name="tooltip-text" translatable="yes">Go Back</property>
</object>
</child>
</object>
</child>
<child type="end">

View file

@ -7,16 +7,20 @@
<property name="default-height">760</property>
<child>
<object class="AdwLeaflet" id="deck">
<property name="can-unfold">False</property>
<property name="can-unfold">True</property>
<property name="can-navigate-back">True</property>
<child>
<object class="AdwLeafletPage">
<property name="name">providers</property>
<property name="child">
<object class="GtkBox">
<property name="width-request">240</property>
<property name="orientation">vertical</property>
<child>
<object class="AdwHeaderBar">
<binding name="show-end-title-buttons">
<lookup name="folded">deck</lookup>
</binding>
<child type="start">
<object class="GtkButton">
<property name="receives-default">True</property>
@ -43,13 +47,7 @@
<object class="GtkStackPage">
<property name="name">search</property>
<property name="child">
<object class="AdwClamp">
<property name="tightening-threshold">300</property>
<property name="maximum-size">400</property>
<property name="child">
<object class="GtkSearchEntry" id="search_entry"/>
</property>
</object>
<object class="GtkSearchEntry" id="search_entry"/>
</property>
</object>
</child>
@ -68,52 +66,76 @@
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<object class="GtkStack" id="stack">
<property name="transition-type">crossfade</property>
<child>
<object class="GtkStack" id="stack">
<property name="transition-type">crossfade</property>
<child>
<object class="GtkStackPage">
<property name="name">results</property>
<property name="child">
<object class="GtkScrolledWindow">
<property name="min-content-width">340</property>
<property name="min-content-height">400</property>
<object class="GtkStackPage">
<property name="name">results</property>
<property name="child">
<object class="GtkScrolledWindow">
<child>
<object class="AdwClamp">
<child>
<object class="AdwClampScrollable">
<property name="vexpand">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkListView" id="providers_list">
<property name="vexpand">true</property>
<property name="single-click-activate">True</property>
<style>
<class name="boxed-list" />
</style>
</object>
</child>
<object class="GtkListBox" id="providers_list">
<property name="vexpand">true</property>
<property name="width-request">240</property>
<property name="activate-on-single-click">True</property>
<property name="selection-mode">browse</property>
<style>
<class name="navigation-sidebar"/>
</style>
</object>
</child>
</object>
</property>
</child>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">no-results</property>
<property name="child">
<object class="AdwStatusPage">
<property name="vexpand">True</property>
<property name="title" translatable="yes">No Results</property>
<property name="description" translatable="yes">No providers matching the query were found.</property>
<property name="icon-name">system-search-symbolic</property>
</object>
</property>
</object>
</child>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">no-results</property>
<property name="child">
<object class="AdwStatusPage">
<property name="vexpand">True</property>
<property name="title" translatable="yes">No Results</property>
<property name="description" translatable="yes">No providers matching the query were found.</property>
<property name="icon-name">system-search-symbolic</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="AdwLeafletPage">
<property name="navigatable">False</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkWindowHandle" id="header_separator">
<child>
<object class="GtkSeparator">
<property name="orientation">vertical</property>
<style>
<class name="sidebar"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparator">
<property name="orientation">vertical</property>
<property name="vexpand">True</property>
<style>
<class name="sidebar"/>
</style>
</object>
</child>
</object>

View file

@ -23,7 +23,7 @@ mod imp {
pub actions: gio::SimpleActionGroup,
pub filter_model: gtk::FilterListModel,
#[template_child]
pub providers_list: TemplateChild<gtk::ListView>,
pub providers_list: TemplateChild<gtk::ListBox>,
#[template_child]
pub deck: TemplateChild<adw::Leaflet>,
#[template_child]
@ -122,39 +122,27 @@ impl ProvidersDialog {
}
}));
let factory = gtk::SignalListItemFactory::new();
factory.connect_setup(|_, list_item| {
let row = ProviderActionRow::new();
list_item.set_child(Some(&row));
});
factory.connect_bind(|_, list_item| {
let row = list_item
.child()
.unwrap()
.downcast::<ProviderActionRow>()
.unwrap();
let item = list_item.item().unwrap();
let provider = item.downcast::<Provider>().unwrap();
row.set_provider(provider);
});
imp.providers_list.set_factory(Some(&factory));
let sorter = ProviderSorter::default();
let sort_model = gtk::SortListModel::new(Some(&imp.filter_model), Some(&sorter));
let selection_model = gtk::NoSelection::new(Some(&sort_model));
imp.providers_list.set_model(Some(&selection_model));
imp.providers_list
.connect_activate(clone!(@weak self as dialog => move |listview, pos| {
let model = listview.model().unwrap();
let provider = model
.item(pos)
.unwrap()
.downcast::<Provider>()
.unwrap();
.bind_model(Some(&selection_model), move |obj| {
let provider = obj.clone().downcast::<Provider>().unwrap();
let row = ProviderActionRow::new();
row.set_provider(provider);
row.upcast::<gtk::Widget>()
});
imp.providers_list.connect_row_activated(
clone!(@weak self as dialog => move |_list, row| {
let row = row.downcast_ref::<ProviderActionRow>().unwrap();
let provider = row.provider();
dialog.edit_provider(provider);
}));
}),
);
imp.page.connect_local(
"created",
@ -192,6 +180,11 @@ impl ProvidersDialog {
let deck_page = imp.deck.append(&imp.page);
deck_page.set_name(Some("provider"));
self.set_view(View::List);
imp.deck
.bind_property("folded", &*imp.page.imp().revealer, "reveal-child")
.flags(glib::BindingFlags::SYNC_CREATE)
.build();
}
fn setup_actions(&self) {
@ -280,7 +273,7 @@ mod row {
impl ObjectSubclass for ProviderActionRow {
const NAME: &'static str = "ProviderActionRow";
type Type = super::ProviderActionRow;
type ParentType = adw::Bin;
type ParentType = gtk::ListBoxRow;
fn new() -> Self {
let actions = gio::SimpleActionGroup::new();
@ -338,11 +331,11 @@ mod row {
}
}
impl WidgetImpl for ProviderActionRow {}
impl BinImpl for ProviderActionRow {}
impl ListBoxRowImpl for ProviderActionRow {}
}
glib::wrapper! {
pub struct ProviderActionRow(ObjectSubclass<imp::ProviderActionRow>) @extends gtk::Widget, adw::Bin;
pub struct ProviderActionRow(ObjectSubclass<imp::ProviderActionRow>) @extends gtk::Widget, gtk::ListBoxRow;
}
impl ProviderActionRow {
@ -371,7 +364,7 @@ mod row {
self.imp().title_label.set_text(&provider.name());
}
pub fn provider(&self) -> Option<Provider> {
pub fn provider(&self) -> Provider {
self.property("provider")
}
}

View file

@ -21,6 +21,8 @@ mod imp {
pub methods_model: adw::EnumListModel,
pub algorithms_model: adw::EnumListModel,
#[template_child]
pub revealer: TemplateChild<gtk::Revealer>,
#[template_child]
pub error_revealer: TemplateChild<ErrorRevealer>,
#[template_child]
pub image: TemplateChild<ProviderImage>,
@ -69,6 +71,7 @@ mod imp {
Self {
actions: gio::SimpleActionGroup::new(),
image: TemplateChild::default(),
revealer: TemplateChild::default(),
error_revealer: TemplateChild::default(),
name_entry: TemplateChild::default(),
period_spinbutton: TemplateChild::default(),