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 ;
@@ -11,6 +10,7 @@ const NotificationDestroyedReason = imports.ui.messageTray.NotificationDestroyed
1110const Settings = imports . ui . settings ;
1211const Gettext = imports . gettext . domain ( "cinnamon-applets" ) ;
1312const Util = imports . misc . util ;
13+ const SignalManager = imports . misc . signalManager ;
1414
1515const PANEL_EDIT_MODE_KEY = "panel-edit-mode" ;
1616
@@ -32,40 +32,51 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
3232 // Layout
3333 this . _orientation = orientation ;
3434 this . menuManager = new PopupMenu . PopupMenuManager ( this ) ;
35+ this . menu = new Applet . AppletPopupMenu ( this , orientation ) ;
36+ this . menuManager . addMenu ( this . menu ) ;
3537
3638 // Lists
3739 this . notifications = [ ] ; // The list of notifications, in order from oldest to newest.
3840
3941 // Events
40- Main . messageTray . connect ( 'notify-applet-update' , Lang . bind ( this , this . _notification_added ) ) ;
41- global . settings . connect ( 'changed::' + PANEL_EDIT_MODE_KEY , Lang . bind ( this , this . _on_panel_edit_mode_changed ) ) ;
42+ this . signals = new SignalManager . SignalManager ( null ) ;
43+ this . signals . connect ( Main . messageTray , 'notify-applet-update' , this . _notification_added . bind ( this ) ) ;
44+ this . signals . connect ( global . settings , 'changed::' + PANEL_EDIT_MODE_KEY , this . _on_panel_edit_mode_changed . bind ( this ) ) ;
45+ this . signals . connect ( this . menu , 'menu-animated-closed' , this . _onMenuClosed . bind ( this ) ) ;
4246
4347 // States
4448 this . _blinking = false ;
4549 this . _blink_toggle = false ;
50+
51+ this . _display ( ) ;
4652 }
4753
4854 _setKeybinding ( ) {
49- Main . keybindingManager . addHotKey ( "notification-open-" + this . instance_id , this . keyOpen , Lang . bind ( this , this . _openMenu ) ) ;
50- Main . keybindingManager . addHotKey ( "notification-clear-" + this . instance_id , this . keyClear , Lang . bind ( this , this . _clear_all ) ) ;
55+ Main . keybindingManager . addHotKey ( "notification-open-" + this . instance_id , this . keyOpen , this . _openMenu . bind ( this ) ) ;
56+ Main . keybindingManager . addHotKey ( "notification-clear-" + this . instance_id , this . keyClear , this . _clear_all . bind ( this ) ) ;
5157 }
5258
5359 on_applet_removed_from_panel ( ) {
5460 Main . keybindingManager . removeHotKey ( "notification-open-" + this . instance_id ) ;
5561 Main . keybindingManager . removeHotKey ( "notification-clear-" + this . instance_id ) ;
62+
63+ this . destroy ( ) ;
5664 }
5765
5866 _openMenu ( ) {
5967 this . _update_timestamp ( ) ;
6068
61- this . _notificationbin . remove_all_children ( ) ;
6269 this . notifications . forEach ( notification => {
6370 global . reparentActor ( notification . actor , this . _notificationbin ) ;
6471 } ) ;
6572
6673 this . menu . toggle ( ) ;
6774 }
6875
76+ _onMenuClosed ( ) {
77+ this . _notificationbin . remove_all_children ( ) ;
78+ }
79+
6980 _display ( ) {
7081 // Always start the applet empty, void of any notifications.
7182 this . set_applet_icon_symbolic_name ( "empty-notif" ) ;
@@ -74,7 +85,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
7485 // Setup the notification container.
7586 this . _maincontainer = new St . BoxLayout ( { name : 'traycontainer' , vertical : true } ) ;
7687 this . _notificationbin = new St . BoxLayout ( { vertical :true } ) ;
77- this . button_label_box = new St . BoxLayout ( ) ;
7888
7989 // Setup the tray icon.
8090 this . menu_label = new PopupMenu . PopupMenuItem ( stringify ( this . notifications . length ) ) ;
@@ -85,42 +95,50 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
8595 this . clear_separator = new PopupMenu . PopupSeparatorMenuItem ( ) ;
8696
8797 this . clear_action = new PopupMenu . PopupMenuItem ( _ ( "Clear notifications" ) ) ;
88- this . clear_action . connect ( 'activate' , Lang . bind ( this , this . _clear_all ) ) ;
98+ this . clear_action . connect ( 'activate' , this . _clear_all . bind ( this ) ) ;
8999 this . clear_action . actor . hide ( ) ;
90100
91- if ( this . _orientation == St . Side . BOTTOM ) {
92- this . menu . addMenuItem ( this . menu_label ) ;
93- this . menu . addActor ( this . _maincontainer ) ;
94- this . menu . addMenuItem ( this . clear_separator ) ;
95- this . menu . addMenuItem ( this . clear_action ) ;
96- } else {
97- this . menu . addMenuItem ( this . clear_action ) ;
98- this . menu . addMenuItem ( this . clear_separator ) ;
99- this . menu . addMenuItem ( this . menu_label ) ;
100- this . menu . addActor ( this . _maincontainer ) ;
101- }
102-
101+ this . menu . addMenuItem ( this . clear_action ) ;
102+ this . menu . addMenuItem ( this . clear_separator ) ;
103+ this . menu . addMenuItem ( this . menu_label ) ;
104+ this . menu . addActor ( this . _maincontainer ) ;
105+
103106 this . scrollview = new St . ScrollView ( { x_fill : true , y_fill : true , y_align : St . Align . START , style_class : "vfade" } ) ;
104107 this . _maincontainer . add ( this . scrollview ) ;
105108 this . scrollview . add_actor ( this . _notificationbin ) ;
106109 this . scrollview . set_policy ( St . PolicyType . NEVER , St . PolicyType . AUTOMATIC ) ;
107110 this . scrollview . set_clip_to_allocation ( true ) ;
108111
109112 let vscroll = this . scrollview . get_vscroll_bar ( ) ;
110- vscroll . connect ( 'scroll-start' , Lang . bind ( this , function ( ) {
111- this . menu . passEvents = true ;
112- } ) ) ;
113- vscroll . connect ( 'scroll-stop' , Lang . bind ( this , function ( ) {
114- this . menu . passEvents = false ;
115- } ) ) ;
113+ vscroll . connect ( 'scroll-start' , ( ) => this . menu . passEvents = true ) ;
114+ vscroll . connect ( 'scroll-stop' , ( ) => this . menu . passEvents = false ) ;
116115
117116 // Alternative tray icons.
118117 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' } ) ;
119118 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' } ) ;
120119
121120 this . _on_panel_edit_mode_changed ( ) ;
122121
123- this . menu . addSettingsAction ( _ ( "Notification Settings" ) , 'notifications' ) ;
122+ this . settingsMenuItem = this . menu . addSettingsAction ( _ ( "Notification Settings" ) , 'notifications' ) ;
123+ }
124+
125+ _arrangeDisplay ( ) {
126+ // Remove menu actors so we can put them back in a different order according to orientation.
127+ this . menu . box . remove_all_children ( ) ;
128+
129+ if ( this . _orientation == St . Side . BOTTOM ) {
130+ this . menu . addActor ( this . menu_label . actor ) ;
131+ this . menu . addActor ( this . _maincontainer ) ;
132+ this . menu . addActor ( this . clear_separator . actor ) ;
133+ this . menu . addActor ( this . clear_action . actor ) ;
134+ } else {
135+ this . menu . addActor ( this . clear_action . actor ) ;
136+ this . menu . addActor ( this . clear_separator . actor ) ;
137+ this . menu . addActor ( this . menu_label . actor ) ;
138+ this . menu . addActor ( this . _maincontainer ) ;
139+ }
140+
141+ this . menu . addActor ( this . settingsMenuItem . actor ) ;
124142 }
125143
126144 _notification_added ( mtray , notification ) { // Notification event handler.
@@ -162,7 +180,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
162180
163181 update_list ( ) {
164182 try {
165- let count = this . notifications . length ;
183+ const count = this . notifications . length ;
166184 if ( count > 0 ) { // There are notifications.
167185 this . actor . show ( ) ;
168186 this . clear_action . actor . show ( ) ;
@@ -250,12 +268,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
250268 on_orientation_changed ( orientation ) {
251269 this . _orientation = orientation ;
252270
253- if ( this . menu ) {
254- this . menu . destroy ( ) ;
255- }
256- this . menu = new Applet . AppletPopupMenu ( this , orientation ) ;
257- this . menuManager . addMenu ( this . menu ) ;
258- this . _display ( ) ;
271+ this . _arrangeDisplay ( ) ;
259272 }
260273
261274 on_applet_clicked ( event ) {
@@ -286,7 +299,14 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
286299 this . _applet_icon_box . child = this . _alt_crit_icon ;
287300 }
288301 this . _blink_toggle = ! this . _blink_toggle ;
289- Mainloop . timeout_add_seconds ( 1 , Lang . bind ( this , this . critical_blink ) ) ;
302+ Mainloop . timeout_add_seconds ( 1 , this . critical_blink . bind ( this ) ) ;
303+ }
304+
305+ destroy ( ) {
306+ this . signals . disconnectAllSignals ( ) ;
307+ this . _crit_icon . destroy ( ) ;
308+ this . _alt_crit_icon . destroy ( ) ;
309+ this . menu . destroy ( ) ;
290310 }
291311}
292312
0 commit comments