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