calendarMessageList: Remove sections map and use clutter children
Now that the calendar message list and the message sections are actors, there's no need to keep track of the sections in a different Map as we can just use the native clutter functions to manage the children and access to their properties. Also cleanup the signal connection/disconnection. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:
parent
9bb12f6f87
commit
3838220961
@ -1083,8 +1083,7 @@ class CalendarMessageList extends St.Widget {
|
|||||||
can_focus: true });
|
can_focus: true });
|
||||||
this._clearButton.set_x_align(Clutter.ActorAlign.END);
|
this._clearButton.set_x_align(Clutter.ActorAlign.END);
|
||||||
this._clearButton.connect('clicked', () => {
|
this._clearButton.connect('clicked', () => {
|
||||||
let sections = [...this._sections.keys()];
|
this._sectionList.get_children().forEach(s => s.clear());
|
||||||
sections.forEach(s => s.clear());
|
|
||||||
});
|
});
|
||||||
box.add_actor(this._clearButton);
|
box.add_actor(this._clearButton);
|
||||||
|
|
||||||
@ -1096,8 +1095,9 @@ class CalendarMessageList extends St.Widget {
|
|||||||
vertical: true,
|
vertical: true,
|
||||||
y_expand: true,
|
y_expand: true,
|
||||||
y_align: Clutter.ActorAlign.START });
|
y_align: Clutter.ActorAlign.START });
|
||||||
|
this._sectionList.connect('actor-added', this._sync.bind(this));
|
||||||
|
this._sectionList.connect('actor-removed', this._sync.bind(this));
|
||||||
this._scrollView.add_actor(this._sectionList);
|
this._scrollView.add_actor(this._sectionList);
|
||||||
this._sections = new Map();
|
|
||||||
|
|
||||||
this._mediaSection = new Mpris.MediaSection();
|
this._mediaSection = new Mpris.MediaSection();
|
||||||
this._addSection(this._mediaSection);
|
this._addSection(this._mediaSection);
|
||||||
@ -1112,46 +1112,26 @@ class CalendarMessageList extends St.Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_addSection(section) {
|
_addSection(section) {
|
||||||
let obj = {
|
let connectionsIds = [];
|
||||||
destroyId: 0,
|
|
||||||
visibleId: 0,
|
|
||||||
emptyNotifyId: 0,
|
|
||||||
canClearNotifyId: 0,
|
|
||||||
messageFocusedId: 0
|
|
||||||
};
|
|
||||||
obj.destroyId = section.connect('destroy', () => {
|
|
||||||
this._removeSection(section);
|
|
||||||
});
|
|
||||||
obj.visibleId = section.connect('notify::visible', this._sync.bind(this));
|
|
||||||
obj.emptyNotifyId = section.connect('notify::empty', this._sync.bind(this));
|
|
||||||
obj.canClearNotifyId = section.connect('notify::can-clear', this._sync.bind(this));
|
|
||||||
obj.messageFocusedId = section.connect('message-focused',
|
|
||||||
this._onMessageFocused.bind(this));
|
|
||||||
|
|
||||||
this._sections.set(section, obj);
|
for (let prop of ['visible', 'empty', 'can-clear']) {
|
||||||
this._sectionList.add_actor(section);
|
connectionsIds.push(
|
||||||
this._sync();
|
section.connect(`notify::${prop}`, this._sync.bind(this)));
|
||||||
}
|
}
|
||||||
|
connectionsIds.push(section.connect('message-focused', (_s, messageActor) => {
|
||||||
_removeSection(section) {
|
|
||||||
let obj = this._sections.get(section);
|
|
||||||
section.disconnect(obj.destroyId);
|
|
||||||
section.disconnect(obj.visibleId);
|
|
||||||
section.disconnect(obj.emptyNotifyId);
|
|
||||||
section.disconnect(obj.canClearNotifyId);
|
|
||||||
section.disconnect(obj.messageFocusedId);
|
|
||||||
|
|
||||||
this._sections.delete(section);
|
|
||||||
this._sectionList.remove_actor(section);
|
|
||||||
this._sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
_onMessageFocused(_section, messageActor) {
|
|
||||||
Util.ensureActorVisibleInScrollView(this._scrollView, messageActor);
|
Util.ensureActorVisibleInScrollView(this._scrollView, messageActor);
|
||||||
|
}));
|
||||||
|
|
||||||
|
connectionsIds.push(section.connect('destroy', (section) => {
|
||||||
|
connectionsIds.forEach(id => section.disconnect(id));
|
||||||
|
this._sectionList.remove_actor(section);
|
||||||
|
}));
|
||||||
|
|
||||||
|
this._sectionList.add_actor(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
_sync() {
|
_sync() {
|
||||||
let sections = [...this._sections.keys()];
|
let sections = this._sectionList.get_children();
|
||||||
let visible = sections.some(s => s.allowed);
|
let visible = sections.some(s => s.allowed);
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
if (!visible)
|
if (!visible)
|
||||||
@ -1169,8 +1149,7 @@ class CalendarMessageList extends St.Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDate(date) {
|
setDate(date) {
|
||||||
for (let section of this._sections.keys())
|
this._sectionList.get_children().forEach(s => s.setDate(date));
|
||||||
section.setDate(date);
|
|
||||||
this._placeholder.setDate(date);
|
this._placeholder.setDate(date);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user