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
@@ -33,17 +33,23 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
3333 // Layout
3434 this . _orientation = orientation ;
3535 this . menuManager = new PopupMenu . PopupMenuManager ( this ) ;
36+ this . menu = new Applet . AppletPopupMenu ( this , orientation ) ;
37+ this . menuManager . addMenu ( this . menu ) ;
3638
3739 // Lists
3840 this . notifications = [ ] ; // The list of notifications, in order from oldest to newest.
3941
4042 // Events
41- Main . messageTray . connect ( 'notify-applet-update' , Lang . bind ( this , this . _notification_added ) ) ;
42- this . panelEditModeHandler = global . settings . connect ( 'changed::' + PANEL_EDIT_MODE_KEY , Lang . bind ( this , this . _on_panel_edit_mode_changed ) ) ;
43+ this . signals = new SignalManager . SignalManager ( null ) ;
44+ this . signals . connect ( Main . messageTray , 'notify-applet-update' , this . _notification_added . bind ( this ) ) ;
45+ this . signals . connect ( global . settings , 'changed::' + PANEL_EDIT_MODE_KEY , this . _on_panel_edit_mode_changed . bind ( this ) ) ;
46+ this . signals . connect ( this . menu , 'menu-animated-closed' , this . _onMenuClosed . bind ( this ) ) ;
4347
4448 // States
4549 this . _blinking = false ;
4650 this . _blink_toggle = false ;
51+
52+ this . _display ( ) ;
4753 }
4854
4955 _setKeybinding ( ) {
@@ -55,19 +61,24 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
5561 Main . keybindingManager . removeXletHotKey ( this , "notification-open" ) ;
5662 Main . keybindingManager . removeXletHotKey ( this , "notification-clear" ) ;
5763 global . settings . disconnect ( this . panelEditModeHandler ) ;
64+
65+ this . destroy ( ) ;
5866 }
5967
6068 _openMenu ( ) {
6169 this . _update_timestamp ( ) ;
6270
63- this . _notificationbin . remove_all_children ( ) ;
6471 this . notifications . forEach ( notification => {
6572 global . reparentActor ( notification . actor , this . _notificationbin ) ;
6673 } ) ;
6774
6875 this . menu . toggle ( ) ;
6976 }
7077
78+ _onMenuClosed ( ) {
79+ this . _notificationbin . remove_all_children ( ) ;
80+ }
81+
7182 _display ( ) {
7283 // Always start the applet empty, void of any notifications.
7384 this . set_applet_icon_symbolic_name ( "empty-notif" ) ;
@@ -76,7 +87,6 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
7687 // Setup the notification container.
7788 this . _maincontainer = new St . BoxLayout ( { name : 'traycontainer' , vertical : true } ) ;
7889 this . _notificationbin = new St . BoxLayout ( { vertical :true } ) ;
79- this . button_label_box = new St . BoxLayout ( ) ;
8090
8191 // Setup the tray icon.
8292 this . menu_label = new PopupMenu . PopupMenuItem ( stringify ( this . notifications . length ) ) ;
@@ -87,42 +97,50 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
8797 this . clear_separator = new PopupMenu . PopupSeparatorMenuItem ( ) ;
8898
8999 this . clear_action = new PopupMenu . PopupMenuItem ( _ ( "Clear notifications" ) ) ;
90- this . clear_action . connect ( 'activate' , Lang . bind ( this , this . _clear_all ) ) ;
100+ this . clear_action . connect ( 'activate' , this . _clear_all . bind ( this ) ) ;
91101 this . clear_action . actor . hide ( ) ;
92102
93- if ( this . _orientation == St . Side . BOTTOM ) {
94- this . menu . addMenuItem ( this . menu_label ) ;
95- this . menu . addActor ( this . _maincontainer ) ;
96- this . menu . addMenuItem ( this . clear_separator ) ;
97- this . menu . addMenuItem ( this . clear_action ) ;
98- } else {
99- this . menu . addMenuItem ( this . clear_action ) ;
100- this . menu . addMenuItem ( this . clear_separator ) ;
101- this . menu . addMenuItem ( this . menu_label ) ;
102- this . menu . addActor ( this . _maincontainer ) ;
103- }
104-
103+ this . menu . addMenuItem ( this . clear_action ) ;
104+ this . menu . addMenuItem ( this . clear_separator ) ;
105+ this . menu . addMenuItem ( this . menu_label ) ;
106+ this . menu . addActor ( this . _maincontainer ) ;
107+
105108 this . scrollview = new St . ScrollView ( { x_fill : true , y_fill : true , y_align : St . Align . START , style_class : "vfade" } ) ;
106109 this . _maincontainer . add ( this . scrollview ) ;
107110 this . scrollview . add_actor ( this . _notificationbin ) ;
108111 this . scrollview . set_policy ( St . PolicyType . NEVER , St . PolicyType . AUTOMATIC ) ;
109112 this . scrollview . set_clip_to_allocation ( true ) ;
110113
111114 let vscroll = this . scrollview . get_vscroll_bar ( ) ;
112- vscroll . connect ( 'scroll-start' , Lang . bind ( this , function ( ) {
113- this . menu . passEvents = true ;
114- } ) ) ;
115- vscroll . connect ( 'scroll-stop' , Lang . bind ( this , function ( ) {
116- this . menu . passEvents = false ;
117- } ) ) ;
115+ vscroll . connect ( 'scroll-start' , ( ) => this . menu . passEvents = true ) ;
116+ vscroll . connect ( 'scroll-stop' , ( ) => this . menu . passEvents = false ) ;
118117
119118 // Alternative tray icons.
120119 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' } ) ;
121120 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' } ) ;
122121
123122 this . _on_panel_edit_mode_changed ( ) ;
124123
125- this . menu . addSettingsAction ( _ ( "Notification Settings" ) , 'notifications' ) ;
124+ this . settingsMenuItem = this . menu . addSettingsAction ( _ ( "Notification Settings" ) , 'notifications' ) ;
125+ }
126+
127+ _arrangeDisplay ( ) {
128+ // Remove menu actors so we can put them back in a different order according to orientation.
129+ this . menu . box . remove_all_children ( ) ;
130+
131+ if ( this . _orientation == St . Side . BOTTOM ) {
132+ this . menu . addActor ( this . menu_label . actor ) ;
133+ this . menu . addActor ( this . _maincontainer ) ;
134+ this . menu . addActor ( this . clear_separator . actor ) ;
135+ this . menu . addActor ( this . clear_action . actor ) ;
136+ } else {
137+ this . menu . addActor ( this . clear_action . actor ) ;
138+ this . menu . addActor ( this . clear_separator . actor ) ;
139+ this . menu . addActor ( this . menu_label . actor ) ;
140+ this . menu . addActor ( this . _maincontainer ) ;
141+ }
142+
143+ this . menu . addActor ( this . settingsMenuItem . actor ) ;
126144 }
127145
128146 _notification_added ( mtray , notification ) { // Notification event handler.
@@ -164,7 +182,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
164182
165183 update_list ( ) {
166184 try {
167- let count = this . notifications . length ;
185+ const count = this . notifications . length ;
168186 if ( count > 0 ) { // There are notifications.
169187 this . actor . show ( ) ;
170188 this . clear_action . actor . show ( ) ;
@@ -272,12 +290,7 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
272290 on_orientation_changed ( orientation ) {
273291 this . _orientation = orientation ;
274292
275- if ( this . menu ) {
276- this . menu . destroy ( ) ;
277- }
278- this . menu = new Applet . AppletPopupMenu ( this , orientation ) ;
279- this . menuManager . addMenu ( this . menu ) ;
280- this . _display ( ) ;
293+ this . _arrangeDisplay ( ) ;
281294 }
282295
283296 on_applet_clicked ( event ) {
@@ -308,7 +321,14 @@ class CinnamonNotificationsApplet extends Applet.TextIconApplet {
308321 this . _applet_icon_box . child = this . _alt_crit_icon ;
309322 }
310323 this . _blink_toggle = ! this . _blink_toggle ;
311- Mainloop . timeout_add_seconds ( 1 , Lang . bind ( this , this . critical_blink ) ) ;
324+ Mainloop . timeout_add_seconds ( 1 , this . critical_blink . bind ( this ) ) ;
325+ }
326+
327+ destroy ( ) {
328+ this . signals . disconnectAllSignals ( ) ;
329+ this . _crit_icon . destroy ( ) ;
330+ this . _alt_crit_icon . destroy ( ) ;
331+ this . menu . destroy ( ) ;
312332 }
313333}
314334
0 commit comments