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     paused : false, // on!
26     xtype : Gtk.StatusIcon,
27     stock : Gtk.STOCK_MEDIA_PLAY,
28     tooltip_text : 'GitLive',
29     listeners : {
30         //'popup-menu' : function( w, event, event_time) {
31         'activate' : function( w, event, event_time) {
32             print(Array.prototype.slice.call(arguments).join(','));
33             
34             menu = this.get('menu');
35             
36             menu.el.show_all();
37             
38             this.get(!this.paused ? 'resume' : 'pause' ).el.hide();
39             
40             menu.el.popup(null, null,Gtk.StatusIcon , this.el , 1, Gtk.get_current_event_time());
41             menu.el.popup(null, null,null, null, 1, Gtk.get_current_event_time());
42             
43             return;
44             
45             var g = { };
46             var a = new Gdk.Rectangle();
47             //  needs direction=inout setting in gir to work (in bugzilla @present)
48             this.el.get_geometry(g,a,null);
49              
50             // should check to see if @ top or bottom I guess..
51             menu.el.get_toplevel().move(a.x, a.y +a.height);
52              
53         }
54     },
55     items : [
56        {
57             xtype: Gtk.Menu,
58             id : 'menu',
59             pack: false,
60             items : [
61                 {
62                     init : function() {
63                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PAUSE);
64                         XObject.prototype.init.call(this);
65                     },
66                     label: 'Pause Commits',
67                    
68                     always_show_image : true,
69                     accel_group : null,
70                     id : 'pause',
71                     //label: 'Pause',
72                     pack:  'append',
73                     listeners : {
74                         activate : function () {
75                             this.parent.parent.paused = true;
76                            // this.el.label  = status ? 'Resume' : 'Pause';
77                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
78                             
79                         }
80                     }
81                 },
82                 
83                 {
84                     init : function() {
85                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PLAY);
86                         XObject.prototype.init.call(this);
87                     },
88                     label: 'Resume Commits',
89                     always_show_image : true,
90                     accel_group : null,
91                     id : 'resume',
92                     //label: 'Pause',
93                     pack:  'append',
94                     listeners : {
95                         activate : function () {
96                             this.parent.parent.paused = false;
97                             //var status = this.el.label == 'Pause' ? 1 : 0
98                            // this.el.label  = status ? 'Resume' : 'Pause';
99                             this.parent.parent.el.set_from_stock(   Gtk.STOCK_MEDIA_PLAY);
100                             
101                         }
102                     }
103                 },
104                 
105                 {
106                     init : function() {
107                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
108                         XObject.prototype.init.call(this);
109                     },
110                     label: 'Pull (Refresh) All',
111                     always_show_image : true,
112                     accel_group : null,
113                     //label: 'Pause',
114                     pack:  'append',
115                     listeners : {
116                         activate : function () {
117                              
118                             
119                         }
120                     }
121                 },
122                 {
123                     init : function() {
124                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
125                         XObject.prototype.init.call(this);
126                     },
127                     label: 'Manage Clones',
128                     always_show_image : true,
129                     accel_group : null,
130                     
131                     //label: 'Pause',
132                     pack:  'append',
133                     listeners : {
134                         activate : function () {
135                              
136                             
137                         }
138                     }
139                 },
140                 
141                 
142                 
143             
144                 {
145                     init : function() {
146                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT);
147                         XObject.prototype.init.call(this);
148                     },
149                     label: 'About GitLive',
150                     pack:  'append',
151                     listeners : {
152                         activate : function () {
153                             var msg = new Gtk.MessageDialog({message_type:
154                                 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - auto commits and pushes everything in ~/gitlive"});
155                             msg.run();
156                             msg.destroy();
157                         }
158                     }
159                 },
160                 
161                 {
162                     init : function() {
163                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT);
164                         XObject.prototype.init.call(this);
165                     },
166                     label: 'Quit',
167                     pack:  'append',
168                     listeners : {
169                         activate : function () {
170                             Seed.quit();
171                         }
172                     }
173                 }
174                 
175                 
176             ]
177         }
178     ]
179     
180 });
181
182