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.XObject
20 gitlive = imports.gitlive;
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.position_menu , 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                             gitlive.monitor.stop();
77                            // this.el.label  = status ? 'Resume' : 'Pause';
78                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
79                             
80                         }
81                     }
82                 },
83                 
84                 {
85                     init : function() {
86                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PLAY);
87                         XObject.prototype.init.call(this);
88                     },
89                     label: 'Resume Commits',
90                     always_show_image : true,
91                     accel_group : null,
92                     id : 'resume',
93                     //label: 'Pause',
94                     pack:  'append',
95                     listeners : {
96                         activate : function () {
97                             this.parent.parent.paused = false;
98                             gitlive.monitor.start();
99                             //var status = this.el.label == 'Pause' ? 1 : 0
100                            // this.el.label  = status ? 'Resume' : 'Pause';
101                             this.parent.parent.el.set_from_stock(   Gtk.STOCK_MEDIA_PLAY);
102                             
103                         }
104                     }
105                 },
106                 
107                 {
108                     init : function() {
109                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
110                         XObject.prototype.init.call(this);
111                     },
112                     label: 'Pull (Refresh) All',
113                     always_show_image : true,
114                     accel_group : null,
115                     //label: 'Pause',
116                     pack:  'append',
117                     listeners : {
118                         activate : function () {
119                             gitlive.monitor.stop();
120                             
121                             
122                             
123                             gitlive.monitor.start();
124                             
125                         }
126                     }
127                 },
128                 {
129                     init : function() {
130                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
131                         XObject.prototype.init.call(this);
132                     },
133                     label: 'Manage Clones',
134                     always_show_image : true,
135                     accel_group : null,
136                     
137                     //label: 'Pause',
138                     pack:  'append',
139                     listeners : {
140                         activate : function () {
141                              
142                             
143                         }
144                     }
145                 },
146                 
147                 
148                 
149             
150                 {
151                     init : function() {
152                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT);
153                         XObject.prototype.init.call(this);
154                     },
155                     label: 'About GitLive',
156                     pack:  'append',
157                     listeners : {
158                         activate : function () {
159                             var msg = new Gtk.MessageDialog({message_type:
160                                 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - auto commits and pushes everything in ~/gitlive"});
161                             msg.run();
162                             msg.destroy();
163                         }
164                     }
165                 },
166                 
167                 {
168                     init : function() {
169                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT);
170                         XObject.prototype.init.call(this);
171                     },
172                     label: 'Quit',
173                     pack:  'append',
174                     listeners : {
175                         activate : function () {
176                             Seed.quit();
177                         }
178                     }
179                 }
180                 
181                 
182             ]
183         }
184     ]
185     
186 });
187
188