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