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