11const Applet = imports . ui . applet ;
2- const Lang = imports . lang ;
32const Main = imports . ui . main ;
43const Gtk = imports . gi . Gtk ;
54const Gio = imports . gi . Gio ;
@@ -12,6 +11,7 @@ const NotificationDestroyedReason = imports.ui.messageTray.NotificationDestroyed
1211const Settings = imports . ui . settings ;
1312const Gettext = imports . gettext . domain ( "cinnamon-applets" ) ;
1413const Util = imports . misc . util ;
14+ const SignalManager = imports . misc . signalManager ;
1515
1616const PANEL_EDIT_MODE_KEY = "panel-edit-mode" ;
1717
@@ -34,17 +34,23 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
3434 // Layout
3535 this . _orientation = orientation ;
3636 this . menuManager = new PopupMenu . PopupMenuManager ( this ) ;
37+ this . menu = new Applet . AppletPopupMenu ( this , orientation ) ;
38+ this . menuManager . addMenu ( this . menu ) ;
3739
3840 // Lists
3941 this . notifications = [ ] ; // The list of notifications, in order from oldest to newest.
4042
4143 // Events
42- Main . messageTray . connect ( 'notify-applet-update' , Lang . bind ( this , this . _notification_added ) ) ;
43- this . panelEditModeHandler = global . settings . connect ( 'changed::' + PANEL_EDIT_MODE_KEY , Lang . bind ( this , this . _on_panel_edit_mode_changed ) ) ;
44+ this . signals = new SignalManager . SignalManager ( null ) ;
45+ this . signals . connect ( Main . messageTray , 'notify-applet-update' , this . _notification_added . bind ( this ) ) ;
46+ this . signals . connect ( global . settings , 'changed::' + PANEL_EDIT_MODE_KEY , this . _on_panel_edit_mode_changed . bind ( this ) ) ;
47+ this . signals . connect ( this . menu , 'menu-animated-closed' , this . _onMenuClosed . bind ( this ) ) ;
4448
4549 // States
4650 this . _blinking = false ;
4751 this . _blink_toggle = false ;
52+
53+ this . _display ( ) ;
4854 }
4955
5056 _setKeybinding ( ) {
@@ -55,7 +61,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
5561 on_applet_removed_from_panel ( ) {
5662 Main . keybindingManager . removeXletHotKey ( this , "notification-open" ) ;
5763 Main . keybindingManager . removeXletHotKey ( this , "notification-clear" ) ;
58- global . settings . disconnect ( this . panelEditModeHandler ) ;
5964
6065 MessageTray . extensionsHandlingNotifications -- ;
6166 if ( MessageTray . extensionsHandlingNotifications === 0 ) {
@@ -68,14 +73,17 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
6873 _openMenu ( ) {
6974 this . _update_timestamp ( ) ;
7075
71- this . _notificationbin . remove_all_children ( ) ;
7276 this . notifications . forEach ( notification => {
7377 global . reparentActor ( notification . actor , this . _notificationbin ) ;
7478 } ) ;
7579
7680 this . menu . toggle ( ) ;
7781 }
7882
83+ _onMenuClosed ( ) {
84+ this . _notificationbin . remove_all_children ( ) ;
85+ }
86+
7987 _display ( ) {
8088 // Always start the applet empty, void of any notifications.
8189 this . set_applet_icon_symbolic_name ( "empty-notif" ) ;
@@ -84,7 +92,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
8492 // Setup the notification container.
8593 this . _maincontainer = new St . BoxLayout ( { name : 'traycontainer' , vertical : true } ) ;
8694 this . _notificationbin = new St . BoxLayout ( { vertical :true } ) ;
87- this . button_label_box = new St . BoxLayout ( ) ;
8895
8996 // Setup the tray icon.
9097 this . menu_label = new PopupMenu . PopupMenuItem ( stringify ( this . notifications . length ) ) ;
@@ -95,42 +102,50 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
95102 this . clear_separator = new PopupMenu . PopupSeparatorMenuItem ( ) ;
96103
97104 this . clear_action = new PopupMenu . PopupMenuItem ( _ ( "Clear notifications" ) ) ;
98- this . clear_action . connect ( 'activate' , Lang . bind ( this , this . _clear_all ) ) ;
105+ this . clear_action . connect ( 'activate' , this . _clear_all . bind ( this ) ) ;
99106 this . clear_action . actor . hide ( ) ;
100107
101- if ( this . _orientation == St . Side . BOTTOM ) {
102- this . menu . addMenuItem ( this . menu_label ) ;
103- this . menu . addActor ( this . _maincontainer ) ;
104- this . menu . addMenuItem ( this . clear_separator ) ;
105- this . menu . addMenuItem ( this . clear_action ) ;
106- } else {
107- this . menu . addMenuItem ( this . clear_action ) ;
108- this . menu . addMenuItem ( this . clear_separator ) ;
109- this . menu . addMenuItem ( this . menu_label ) ;
110- this . menu . addActor ( this . _maincontainer ) ;
111- }
112-
108+ this . menu . addMenuItem ( this . clear_action ) ;
109+ this . menu . addMenuItem ( this . clear_separator ) ;
110+ this . menu . addMenuItem ( this . menu_label ) ;
111+ this . menu . addActor ( this . _maincontainer ) ;
112+
113113 this . scrollview = new St . ScrollView ( { x_fill : true , y_fill : true , y_align : St . Align . START , style_class : "vfade" } ) ;
114114 this . _maincontainer . add ( this . scrollview ) ;
115115 this . scrollview . add_actor ( this . _notificationbin ) ;
116116 this . scrollview . set_policy ( St . PolicyType . NEVER , St . PolicyType . AUTOMATIC ) ;
117117 this . scrollview . set_clip_to_allocation ( true ) ;
118118
119119 let vscroll = this . scrollview . get_vscroll_bar ( ) ;
120- vscroll . connect ( 'scroll-start' , Lang . bind ( this , function ( ) {
121- this . menu . passEvents = true ;
122- } ) ) ;
123- vscroll . connect ( 'scroll-stop' , Lang . bind ( this , function ( ) {
124- this . menu . passEvents = false ;
125- } ) ) ;
120+ vscroll . connect ( 'scroll-start' , ( ) => this . menu . passEvents = true ) ;
121+ vscroll . connect ( 'scroll-stop' , ( ) => this . menu . passEvents = false ) ;
126122
127123 // Alternative tray icons.
128124 this . _crit_icon = new St . Icon ( { icon_name : 'critical-notif' , icon_type : St . IconType . SYMBOLIC , reactive : true , track_hover : true , style_class : 'system-status-icon' } ) ;
129125 this . _alt_crit_icon = new St . Icon ( { icon_name : 'alt-critical-notif' , icon_type : St . IconType . SYMBOLIC , reactive : true , track_hover : true , style_class : 'system-status-icon' } ) ;
130126
131127 this . _on_panel_edit_mode_changed ( ) ;
132128
133- this . menu . addSettingsAction ( _ ( "Notification Settings" ) , 'notifications' ) ;
129+ this . settingsMenuItem = this . menu . addSettingsAction ( _ ( "Notification Settings" ) , 'notifications' ) ;
130+ }
131+
132+ _arrangeDisplay ( ) {
133+ // Remove menu actors so we can put them back in a different order according to orientation.
134+ this . menu . box . remove_all_children ( ) ;
135+
136+ if ( this . _orientation == St . Side . BOTTOM ) {
137+ this . menu . addActor ( this . menu_label . actor ) ;
138+ this . menu . addActor ( this . _maincontainer ) ;
139+ this . menu . addActor ( this . clear_separator . actor ) ;
140+ this . menu . addActor ( this . clear_action . actor ) ;
141+ } else {
142+ this . menu . addActor ( this . clear_action . actor ) ;
143+ this . menu . addActor ( this . clear_separator . actor ) ;
144+ this . menu . addActor ( this . menu_label . actor ) ;
145+ this . menu . addActor ( this . _maincontainer ) ;
146+ }
147+
148+ this . menu . addActor ( this . settingsMenuItem . actor ) ;
134149 }
135150
136151 _notification_added ( mtray , notification ) { // Notification event handler.
@@ -172,7 +187,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
172187
173188 update_list ( ) {
174189 try {
175- let count = this . notifications . length ;
190+ const count = this . notifications . length ;
176191 if ( count > 0 ) { // There are notifications.
177192 this . actor . show ( ) ;
178193 this . clear_action . actor . show ( ) ;
@@ -281,12 +296,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
281296 on_orientation_changed ( orientation ) {
282297 this . _orientation = orientation ;
283298
284- if ( this . menu ) {
285- this . menu . destroy ( ) ;
286- }
287- this . menu = new Applet . AppletPopupMenu ( this , orientation ) ;
288- this . menuManager . addMenu ( this . menu ) ;
289- this . _display ( ) ;
299+ this . _arrangeDisplay ( ) ;
290300 }
291301
292302 on_applet_clicked ( event ) {
@@ -317,7 +327,14 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
317327 this . _applet_icon_box . child = this . _alt_crit_icon ;
318328 }
319329 this . _blink_toggle = ! this . _blink_toggle ;
320- Mainloop . timeout_add_seconds ( 1 , Lang . bind ( this , this . critical_blink ) ) ;
330+ Mainloop . timeout_add_seconds ( 1 , this . critical_blink . bind ( this ) ) ;
331+ }
332+
333+ destroy ( ) {
334+ this . signals . disconnectAllSignals ( ) ;
335+ this . _crit_icon . destroy ( ) ;
336+ this . _alt_crit_icon . destroy ( ) ;
337+ this . menu . destroy ( ) ;
321338 }
322339}
323340
0 commit comments