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