1 //<script type="text/javascript">
5 * Status icon and menu for component of gitlive.
7 * Implements XObject - however we want to control initialization.
11 * Currently only does a few things
17 var Gtk = imports.gi.Gtk;
18 var Gdk = imports.gi.Gdk;
19 var Gio = imports.gi.Gio;
20 var GLib = imports.gi.GLib;
21 var Notify = imports.gi.Notify;
23 var Git = imports.Git;
24 var XObject = imports.XObject.XObject;
26 //var gitlive = imports.gitlive;
29 var StatusIcon = new XObject({
31 paused : false, // on!
32 xtype : Gtk.StatusIcon,
34 stock : Gtk.STOCK_MEDIA_PLAY,
35 tooltip_text : 'GitLive',
37 XObject.prototype.init.call(this);
38 this.el.set_name('gitlive');
41 //'popup-menu' : function( w, event, event_time) {
42 'activate' : function( w, event, event_time) {
43 print(Array.prototype.slice.call(arguments).join(','));
45 menu = this.get('menu');
49 this.get(!this.paused ? 'resume' : 'pause' ).el.hide();
51 menu.el.popup(null, null,Gtk.StatusIcon.position_menu , this.el , 1, Gtk.get_current_event_time());
52 //menu.el.popup(null, null,null, null, 1, Gtk.get_current_event_time());
57 var a = new Gdk.Rectangle();
58 // needs direction=inout setting in gir to work (in bugzilla @present)
59 this.el.get_geometry(g,a,null);
61 // should check to see if @ top or bottom I guess..
62 menu.el.get_toplevel().move(a.x, a.y +a.height);
74 this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PAUSE);
75 XObject.prototype.init.call(this);
77 label: 'Pause Commits',
79 always_show_image : true,
85 activate : function () {
86 this.parent.parent.paused = true;
87 imports.gitlive.monitor.stop();
88 // this.el.label = status ? 'Resume' : 'Pause';
89 this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
97 this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PLAY);
98 XObject.prototype.init.call(this);
100 label: 'Resume Commits',
101 always_show_image : true,
107 activate : function () {
108 this.parent.parent.paused = false;
109 imports.gitlive.monitor.start();
110 //var status = this.el.label == 'Pause' ? 1 : 0
111 // this.el.label = status ? 'Resume' : 'Pause';
112 this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PLAY);
120 this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
121 XObject.prototype.init.call(this);
123 label: 'Pull (Refresh) All',
124 always_show_image : true,
129 activate : function () {
130 imports.gitlive.monitor.stop();
132 var f = Gio.file_new_for_path(imports.gitlive.gitlive);
133 var file_enum = f.enumerate_children(
134 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, Gio.FileQueryInfoFlags.NONE, null);
136 var next_file = null;
138 while ((next_file = file_enum.next_file(null)) != null) {
140 var fn = imports.gitlive.gitlive + '/' + next_file.get_display_name();
141 if (! GLib.file_test(fn + '/.git', GLib.FileTest.IS_DIR)) {
146 var res = Git.run(fn, 'pull' );
147 if (res.result * 1 == 0) {
149 var notification = new Notify.Notification({
150 summary: "Updated " + fn,
153 notification.set_timeout(1000);
157 imports.gitlive.errorDialog(res.stderr);
158 // should also update modules ideally.
163 file_enum.close(null);
166 imports.gitlive.monitor.start();
173 this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
174 XObject.prototype.init.call(this);
176 label: 'Manage Clones',
177 always_show_image : true,
183 activate : function () {
195 this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT);
196 XObject.prototype.init.call(this);
198 label: 'About GitLive',
201 activate : function () {
202 var msg = new Gtk.AboutDialog({
203 program_name : "Git Live",
205 website: 'http://git.akbkhome.com',
206 website_label: 'AK BK Consulting (git repo)',
209 msg.set_authors([ "Alan Knowles <alan@akbkhome.com>" ]);
218 this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT);
219 XObject.prototype.init.call(this);
224 activate : function () {