Correctly set the date range picker when initializing the historical view
This commit is contained in:
parent
55b6327d42
commit
d70ca08db2
|
@ -65,12 +65,12 @@ impl DateRangePicker {
|
|||
*self.imp().on_search.borrow_mut() = Box::new(f);
|
||||
}
|
||||
|
||||
fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) {
|
||||
pub fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) {
|
||||
self.imp().start.set_date(start);
|
||||
self.imp().end.set_date(end);
|
||||
}
|
||||
|
||||
fn interval(&self) -> DayInterval {
|
||||
pub fn interval(&self) -> DayInterval {
|
||||
DayInterval {
|
||||
start: self.imp().start.date(),
|
||||
end: self.imp().end.date(),
|
||||
|
|
|
@ -30,6 +30,7 @@ use std::{cell::RefCell, rc::Rc};
|
|||
pub struct HistoricalViewPrivate {
|
||||
app: Rc<RefCell<Option<App>>>,
|
||||
list_view: gtk::ListView,
|
||||
date_range_picker: DateRangePicker,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -47,12 +48,15 @@ impl ObjectSubclass for HistoricalViewPrivate {
|
|||
.set_child(Some(&DaySummary::new()));
|
||||
});
|
||||
|
||||
let date_range_picker = DateRangePicker::default();
|
||||
|
||||
let s = Self {
|
||||
app: Rc::new(RefCell::new(None)),
|
||||
list_view: gtk::ListView::builder()
|
||||
.factory(&factory)
|
||||
.single_click_activate(true)
|
||||
.build(),
|
||||
date_range_picker,
|
||||
};
|
||||
|
||||
factory.connect_bind({
|
||||
|
@ -106,17 +110,11 @@ impl HistoricalView {
|
|||
|
||||
*s.imp().app.borrow_mut() = Some(app);
|
||||
|
||||
let date_range_picker = DateRangePicker::default();
|
||||
date_range_picker.connect_on_search({
|
||||
s.imp().date_range_picker.connect_on_search({
|
||||
let s = s.clone();
|
||||
move |interval| s.set_interval(interval)
|
||||
});
|
||||
|
||||
let mut model = gio::ListStore::new::<Date>();
|
||||
model.extend(interval.days().map(Date::new));
|
||||
s.imp()
|
||||
.list_view
|
||||
.set_model(Some(>k::NoSelection::new(Some(model))));
|
||||
s.set_interval(interval);
|
||||
|
||||
s.imp().list_view.connect_activate({
|
||||
let on_select_day = on_select_day.clone();
|
||||
|
@ -135,7 +133,7 @@ impl HistoricalView {
|
|||
.hscrollbar_policy(gtk::PolicyType::Never)
|
||||
.build();
|
||||
|
||||
s.append(&date_range_picker);
|
||||
s.append(&s.imp().date_range_picker);
|
||||
s.append(&scroller);
|
||||
|
||||
s
|
||||
|
@ -147,6 +145,7 @@ impl HistoricalView {
|
|||
self.imp()
|
||||
.list_view
|
||||
.set_model(Some(>k::NoSelection::new(Some(model))));
|
||||
self.imp().date_range_picker.set_interval(interval.start, interval.end);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue