cleanup: Use inheritance for Actor classes instead of composition

Remove the `this.actor = ...` and `this.actor._delegate = this` patterns in most
of classes, by inheriting all the actor container classes.

Uses interfaces when needed for making sure that multiple classes will implement
some required methods or to avoid redefining the same code multiple times.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:
Marco Trevisan (Treviño)
2019-07-16 11:24:13 +02:00
committed by Florian Müllner
parent f67b409fc1
commit c4c5c4fd5c
58 changed files with 2000 additions and 1757 deletions

View File

@ -313,8 +313,10 @@ var DBusEventSource = class DBusEventSource {
};
Signals.addSignalMethods(DBusEventSource.prototype);
var Calendar = class Calendar {
constructor() {
var Calendar = GObject.registerClass({
Signals: { 'selected-date-changed': { param_types: [GLib.DateTime.$gtype] } }
}, class Calendar extends St.Widget {
_init() {
this._weekStart = Shell.util_get_week_start();
this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.calendar' });
@ -344,12 +346,13 @@ var Calendar = class Calendar {
this._shouldDateGrabFocus = false;
this.actor = new St.Widget({ style_class: 'calendar',
layout_manager: new Clutter.TableLayout(),
reactive: true });
super._init({
style_class: 'calendar',
layout_manager: new Clutter.TableLayout(),
reactive: true
});
this.actor.connect('scroll-event',
this._onScroll.bind(this));
this.connect('scroll-event', this._onScroll.bind(this));
this._buildHeader ();
}
@ -387,9 +390,9 @@ var Calendar = class Calendar {
}
_buildHeader() {
let layout = this.actor.layout_manager;
let layout = this.layout_manager;
let offsetCols = this._useWeekdate ? 1 : 0;
this.actor.destroy_all_children();
this.destroy_all_children();
// Top line of the calendar '<| September 2009 |>'
this._topBox = new St.BoxLayout();
@ -431,7 +434,7 @@ var Calendar = class Calendar {
can_focus: true });
label.accessible_name = iter.toLocaleFormat('%A');
let col;
if (this.actor.get_text_direction() == Clutter.TextDirection.RTL)
if (this.get_text_direction() == Clutter.TextDirection.RTL)
col = 6 - (7 + iter.getDay() - this._weekStart) % 7;
else
col = offsetCols + (7 + iter.getDay() - this._weekStart) % 7;
@ -440,7 +443,7 @@ var Calendar = class Calendar {
}
// All the children after this are days, and get removed when we update the calendar
this._firstDayIndex = this.actor.get_n_children();
this._firstDayIndex = this.get_n_children();
}
_onScroll(actor, event) {
@ -514,7 +517,7 @@ var Calendar = class Calendar {
let now = new Date();
// Remove everything but the topBox and the weekday labels
let children = this.actor.get_children();
let children = this.get_children();
for (let i = this._firstDayIndex; i < children.length; i++)
children[i].destroy();
@ -551,7 +554,7 @@ var Calendar = class Calendar {
beginDate.setTime(beginDate.getTime() - (weekPadding + daysToWeekStart) * MSECS_IN_DAY);
let layout = this.actor.layout_manager;
let layout = this.layout_manager;
let iter = new Date(beginDate);
let row = 2;
// nRows here means 6 weeks + one header + one navbar
@ -651,12 +654,12 @@ var Calendar = class Calendar {
}
});
}
};
Signals.addSignalMethods(Calendar.prototype);
});
var EventMessage = class EventMessage extends MessageList.Message {
constructor(event, date) {
super('', event.summary);
var EventMessage = GObject.registerClass(
class EventMessage extends MessageList.Message {
_init(event, date) {
super._init('', event.summary);
this._event = event;
this._date = date;
@ -666,8 +669,8 @@ var EventMessage = class EventMessage extends MessageList.Message {
this._icon = new St.Icon({ icon_name: 'x-office-calendar-symbolic' });
this.setIcon(this._icon);
this.actor.connect('style-changed', () => {
let iconVisible = this.actor.get_parent().has_style_pseudo_class('first-child');
this.connect('style-changed', () => {
let iconVisible = this.get_parent().has_style_pseudo_class('first-child');
this._icon.opacity = (iconVisible ? 255 : 0);
});
}
@ -705,12 +708,12 @@ var EventMessage = class EventMessage extends MessageList.Message {
}
return title;
}
};
});
var NotificationMessage =
var NotificationMessage = GObject.registerClass(
class NotificationMessage extends MessageList.Message {
constructor(notification) {
super(notification.title, notification.bannerBodyText);
_init(notification) {
super._init(notification.title, notification.bannerBodyText);
this.setUseBodyMarkup(notification.bannerBodyMarkup);
this.notification = notification;
@ -769,11 +772,12 @@ class NotificationMessage extends MessageList.Message {
canClose() {
return true;
}
};
});
var EventsSection = class EventsSection extends MessageList.MessageListSection {
constructor() {
super();
var EventsSection = GObject.registerClass(
class EventsSection extends MessageList.MessageListSection {
_init() {
super._init();
this._desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
this._desktopSettings.connect('changed', this._reloadEvents.bind(this));
@ -785,7 +789,7 @@ var EventsSection = class EventsSection extends MessageList.MessageListSection {
label: '',
x_align: St.Align.START,
can_focus: true });
this.actor.insert_child_below(this._title, null);
this.insert_child_below(this._title, null);
this._title.connect('clicked', this._onTitleClicked.bind(this));
this._title.connect('key-focus-in', this._onKeyFocusIn.bind(this));
@ -904,12 +908,12 @@ var EventsSection = class EventsSection extends MessageList.MessageListSection {
super._sync();
}
};
});
var NotificationSection =
var NotificationSection = GObject.registerClass(
class NotificationSection extends MessageList.MessageListSection {
constructor() {
super();
_init() {
super._init();
this._sources = new Map();
this._nUrgent = 0;
@ -919,7 +923,7 @@ class NotificationSection extends MessageList.MessageListSection {
this._sourceAdded(Main.messageTray, source);
});
this.actor.connect('notify::mapped', this._onMapped.bind(this));
this.connect('notify::mapped', this._onMapped.bind(this));
}
get allowed() {
@ -961,7 +965,7 @@ class NotificationSection extends MessageList.MessageListSection {
let updatedId = notification.connect('updated', () => {
message.setSecondaryActor(this._createTimeLabel(notification.datetime));
this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.actor.mapped);
this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.mapped);
});
let destroyId = notification.connect('destroy', () => {
notification.disconnect(destroyId);
@ -981,7 +985,7 @@ class NotificationSection extends MessageList.MessageListSection {
}
let index = isUrgent ? 0 : this._nUrgent;
this.addMessageAtIndex(message, index, this.actor.mapped);
this.addMessageAtIndex(message, index, this.mapped);
}
_onSourceDestroy(source, obj) {
@ -992,7 +996,7 @@ class NotificationSection extends MessageList.MessageListSection {
}
_onMapped() {
if (!this.actor.mapped)
if (!this.mapped)
return;
for (let message of this._messages.keys())
@ -1003,13 +1007,12 @@ class NotificationSection extends MessageList.MessageListSection {
_shouldShow() {
return !this.empty && isToday(this._date);
}
};
var Placeholder = class Placeholder {
constructor() {
this.actor = new St.BoxLayout({ style_class: 'message-list-placeholder',
vertical: true });
});
var Placeholder = GObject.registerClass(
class Placeholder extends St.BoxLayout {
_init() {
super._init({ style_class: 'message-list-placeholder', vertical: true });
this._date = new Date();
let todayFile = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/no-notifications.svg');
@ -1018,10 +1021,10 @@ var Placeholder = class Placeholder {
this._otherIcon = new Gio.FileIcon({ file: otherFile });
this._icon = new St.Icon();
this.actor.add_actor(this._icon);
this.add_actor(this._icon);
this._label = new St.Label();
this.actor.add_actor(this._label);
this.add_actor(this._label);
this._sync();
}
@ -1048,20 +1051,24 @@ var Placeholder = class Placeholder {
this._label.text = _("No Events");
}
}
};
});
var CalendarMessageList = class CalendarMessageList {
constructor() {
this.actor = new St.Widget({ style_class: 'message-list',
layout_manager: new Clutter.BinLayout(),
x_expand: true, y_expand: true });
var CalendarMessageList = GObject.registerClass(
class CalendarMessageList extends St.Widget {
_init() {
super._init({
style_class: 'message-list',
layout_manager: new Clutter.BinLayout(),
x_expand: true,
y_expand: true
});
this._placeholder = new Placeholder();
this.actor.add_actor(this._placeholder.actor);
this.add_actor(this._placeholder);
let box = new St.BoxLayout({ vertical: true,
x_expand: true, y_expand: true });
this.actor.add_actor(box);
this.add_actor(box);
this._scrollView = new St.ScrollView({ style_class: 'vfade',
overlay_scrollbars: true,
@ -1080,7 +1087,7 @@ var CalendarMessageList = class CalendarMessageList {
});
box.add_actor(this._clearButton);
this._placeholder.actor.bind_property('visible',
this._placeholder.bind_property('visible',
this._clearButton, 'visible',
GObject.BindingFlags.INVERT_BOOLEAN);
@ -1107,37 +1114,34 @@ var CalendarMessageList = class CalendarMessageList {
let obj = {
destroyId: 0,
visibleId: 0,
emptyChangedId: 0,
canClearChangedId: 0,
emptyNotifyId: 0,
canClearNotifyId: 0,
messageFocusedId: 0
};
obj.destroyId = section.actor.connect('destroy', () => {
obj.destroyId = section.connect('destroy', () => {
this._removeSection(section);
});
obj.visibleId = section.actor.connect('notify::visible',
this._sync.bind(this));
obj.emptyChangedId = section.connect('empty-changed',
this._sync.bind(this));
obj.canClearChangedId = section.connect('can-clear-changed',
this._sync.bind(this));
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);
this._sectionList.add_actor(section.actor);
this._sectionList.add_actor(section);
this._sync();
}
_removeSection(section) {
let obj = this._sections.get(section);
section.actor.disconnect(obj.destroyId);
section.actor.disconnect(obj.visibleId);
section.disconnect(obj.emptyChangedId);
section.disconnect(obj.canClearChangedId);
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.actor);
this._sectionList.remove_actor(section);
this._sync();
}
@ -1148,14 +1152,14 @@ var CalendarMessageList = class CalendarMessageList {
_sync() {
let sections = [...this._sections.keys()];
let visible = sections.some(s => s.allowed);
this.actor.visible = visible;
this.visible = visible;
if (!visible)
return;
let empty = sections.every(s => s.empty || !s.actor.visible);
this._placeholder.actor.visible = empty;
let empty = sections.every(s => s.empty || !s.visible);
this._placeholder.visible = empty;
let canClear = sections.some(s => s.canClear && s.actor.visible);
let canClear = sections.some(s => s.canClear && s.visible);
this._clearButton.reactive = canClear;
}
@ -1168,4 +1172,4 @@ var CalendarMessageList = class CalendarMessageList {
section.setDate(date);
this._placeholder.setDate(date);
}
};
});