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