StatusIcon.js
[gitlive] / StatusIcon.js
1 //<script type="text/javascript">
2
3
4 /**
5  * Status icon and menu for component of gitlive.
6  * 
7  * Implements XObject - however we want to control initialization.
8  * 
9  * 
10  * 
11  * Currently only does a few things
12  * a) Quit
13  * 
14  * b) Pause!??!
15  */
16  
17 Gtk      = imports.gi.Gtk;
18  
19 XObject = imports['XObject.js'].XObject
20
21
22  
23 StatusIcon  = new XObject({
24     
25     xtype : Gtk.StatusIcon,
26     stock : Gtk.STOCK_MEDIA_PLAY,
27     tooltip_text : 'GitLive',
28     listeners : {
29         'popup-menu' : function( w, event, event_time) {
30             print(Array.prototype.slice.call(arguments).join(','));
31             
32             menu = this.get('menu');
33             
34             menu.el.show_all();
35             
36             this.get(this.status ?  'pause' : 'resume').el.hide();
37             
38             menu.el.popup(null, null, Gtk.StatusIcon.position_menu, 
39              event, event_time, this.el)
40             
41             //menu.el.popup(null, null , null, null,  event, event_time);
42         }
43     },
44     items : [
45        {
46             xtype: Gtk.Menu,
47             xid : 'menu',
48             pack: false,
49             items : [
50                 {
51                     xtype: Gtk.ImageMenuItem.from_stock,
52                     stock: Gtk.STOCK_MEDIA_PAUSE,
53                    
54                     always_show_image : true,
55                     accel_group : null,
56                     xid : 'pause',
57                     //label: 'Pause',
58                     pack:  'append',
59                     listeners : {
60                         activate : function () {
61                             this.parent.parent.status = 1;
62                            // this.el.label  = status ? 'Resume' : 'Pause';
63                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
64                             
65                         }
66                     }
67                 },
68                 
69                {
70                     xtype: Gtk.ImageMenuItem.from_stock,
71                     stock: Gtk.STOCK_MEDIA_PLAY,
72                     always_show_image : true,
73                     accel_group : null,
74                     xid : 'resume',
75                     //label: 'Pause',
76                     pack:  'append',
77                     listeners : {
78                         activate : function () {
79                             this.parent.parent.status = 0;
80                             //var status = this.el.label == 'Pause' ? 1 : 0
81                            // this.el.label  = status ? 'Resume' : 'Pause';
82                             this.parent.parent.el.set_from_stock(   Gtk.STOCK_MEDIA_PLAY);
83                             
84                         }
85                     }
86                 },
87             
88                 {
89                     xtype: Gtk.MenuItem,
90                     label: 'About',
91                     pack:  'append',
92                     listeners : {
93                         activate : function () {
94                             var msg = new Gtk.MessageDialog({message_type:
95                                 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - auto commits and pushes everything in ~/gitlive"});
96                             msg.run();
97                             msg.destroy();
98                         }
99                     }
100                 },
101                 
102                 {
103                     xtype: Gtk.MenuItem,
104                     label: 'Close',
105                     pack:  'append',
106                     listeners : {
107                         activate : function () {
108                             Seed.quit();
109                         }
110                     }
111                 }
112                 
113                 
114             ]
115         }
116     ]
117     
118 });
119
120