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, null, event, event_time);
39             var g = { };
40             this.el.get_geometry(g);
41             print(g);
42             
43             menu.el.set_uposition(g.area.x,g.area.y);
44             
45             
46             //menu.el.popup(null, null , null, null,  event, event_time);
47         }
48     },
49     items : [
50        {
51             xtype: Gtk.Menu,
52             xid : 'menu',
53             pack: false,
54             items : [
55                 {
56                     xtype: Gtk.ImageMenuItem.from_stock,
57                     stock: Gtk.STOCK_MEDIA_PAUSE,
58                    
59                     always_show_image : true,
60                     accel_group : null,
61                     xid : 'pause',
62                     //label: 'Pause',
63                     pack:  'append',
64                     listeners : {
65                         activate : function () {
66                             this.parent.parent.status = 1;
67                            // this.el.label  = status ? 'Resume' : 'Pause';
68                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
69                             
70                         }
71                     }
72                 },
73                 
74                {
75                     xtype: Gtk.ImageMenuItem.from_stock,
76                     stock: Gtk.STOCK_MEDIA_PLAY,
77                     always_show_image : true,
78                     accel_group : null,
79                     xid : 'resume',
80                     //label: 'Pause',
81                     pack:  'append',
82                     listeners : {
83                         activate : function () {
84                             this.parent.parent.status = 0;
85                             //var status = this.el.label == 'Pause' ? 1 : 0
86                            // this.el.label  = status ? 'Resume' : 'Pause';
87                             this.parent.parent.el.set_from_stock(   Gtk.STOCK_MEDIA_PLAY);
88                             
89                         }
90                     }
91                 },
92             
93                 {
94                     xtype: Gtk.MenuItem,
95                     label: 'About',
96                     pack:  'append',
97                     listeners : {
98                         activate : function () {
99                             var msg = new Gtk.MessageDialog({message_type:
100                                 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - auto commits and pushes everything in ~/gitlive"});
101                             msg.run();
102                             msg.destroy();
103                         }
104                     }
105                 },
106                 
107                 {
108                     xtype: Gtk.MenuItem,
109                     label: 'Close',
110                     pack:  'append',
111                     listeners : {
112                         activate : function () {
113                             Seed.quit();
114                         }
115                     }
116                 }
117                 
118                 
119             ]
120         }
121     ]
122     
123 });
124
125