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