resources/RooUsage.txt
[app.Builder.js] / src / Builder4 / WindowLeftProjects.vala
1 static Xcls_WindowLeftProjects  _WindowLeftProjects;
2
3 public class Xcls_WindowLeftProjects : Object
4 {
5     public Gtk.Box el;
6     private Xcls_WindowLeftProjects  _this;
7
8     public static Xcls_WindowLeftProjects singleton()
9     {
10         if (_WindowLeftProjects == null) {
11             _WindowLeftProjects= new Xcls_WindowLeftProjects();
12         }
13         return _WindowLeftProjects;
14     }
15     public Xcls_view view;
16     public Xcls_model model;
17     public Xcls_namecol namecol;
18
19         // my vars (def)
20     public signal void project_selected (Project.Project project);
21     public bool is_loaded;
22     public bool is_loading;
23     public signal void show_new_project ();
24
25     // ctor
26     public Xcls_WindowLeftProjects()
27     {
28         _this = this;
29         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
30
31         // my vars (dec)
32         this.is_loaded = false;
33         this.is_loading = false;
34
35         // set gobject values
36         this.el.homogeneous = false;
37         var child_0 = new Xcls_ScrolledWindow2( _this );
38         child_0.ref();
39         this.el.pack_end (  child_0.el , true,true,0 );
40
41         //listeners
42         this.el.show.connect( ( ) => {
43             this.load();
44         });
45     }
46
47     // user defined functions
48     public  void load () {
49          // clear list...
50         
51          if (_this.is_loaded) {
52              return;
53          }
54          _this.is_loading = true;
55             
56          _this.is_loaded = true;
57          
58          Project.Project.loadAll();
59          var projects = Project.Project.allProjectsByName();
60          
61          Gtk.TreeIter iter;
62          var m = this.model.el;
63          m.clear();
64               
65          for (var i = 0; i < projects.size; i++) {
66             m.append(out iter);
67             m.set(iter,   0,projects.get(i).name );
68             
69             var o =  GLib.Value(typeof(Object));
70             o.set_object((Object)projects.get(i));
71                        
72             m.set_value(iter, 1, o);
73          
74          }
75          m.set_sort_column_id(0, Gtk.SortType.ASCENDING);
76          _this.is_loading = false;     
77     }
78     public  Project.Project? getSelectedProject () {    
79         Gtk.TreeIter iter;
80         Gtk.TreeModel mod;
81                 
82         var s = this.view.el.get_selection();
83         if (!s.get_selected(out mod, out iter)) {
84             return null;
85         }
86         
87         GLib.Value gval;
88     
89         mod.get_value(iter, 1 , out gval);
90         var project = (Project.Project)gval.get_object();
91         
92         return project;
93     }
94     public  void selectProject (Project.Project project) {
95         
96         var sel = _this.view.el.get_selection();
97         
98         sel.unselect_all();
99         
100         var found = false;
101         _this.model.el.foreach((mod, path, iter) => {
102             GLib.Value val;
103         
104             mod.get_value(iter, 1, out val);
105             if ( ( (Project.Project)val.get_object()).fn != project.fn) {
106                 print("SKIP %s != %s\n", ((Project.Project)val.get_object()).name , project.name);
107                 return false;//continue
108             }
109             sel.select_iter(iter);
110             this.project_selected(project);
111             found = true;
112             return true;
113             
114         
115         });
116          if (!found) {
117             print("tried to select %s, could not find it", project.name);
118         }
119     }
120     public class Xcls_ScrolledWindow2 : Object
121     {
122         public Gtk.ScrolledWindow el;
123         private Xcls_WindowLeftProjects  _this;
124
125
126             // my vars (def)
127
128         // ctor
129         public Xcls_ScrolledWindow2(Xcls_WindowLeftProjects _owner )
130         {
131             _this = _owner;
132             this.el = new Gtk.ScrolledWindow( null, null );
133
134             // my vars (dec)
135
136             // set gobject values
137             this.el.shadow_type = Gtk.ShadowType.IN;
138             var child_0 = new Xcls_view( _this );
139             child_0.ref();
140             this.el.add (  child_0.el  );
141
142             // init method
143
144             this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
145         }
146
147         // user defined functions
148     }
149     public class Xcls_view : Object
150     {
151         public Gtk.TreeView el;
152         private Xcls_WindowLeftProjects  _this;
153
154
155             // my vars (def)
156
157         // ctor
158         public Xcls_view(Xcls_WindowLeftProjects _owner )
159         {
160             _this = _owner;
161             _this.view = this;
162             this.el = new Gtk.TreeView();
163
164             // my vars (dec)
165
166             // set gobject values
167             this.el.enable_tree_lines = true;
168             this.el.headers_visible = true;
169             var child_0 = new Xcls_model( _this );
170             child_0.ref();
171             this.el.set_model (  child_0.el  );
172             var child_1 = new Xcls_TreeViewColumn5( _this );
173             child_1.ref();
174             this.el.append_column (  child_1.el  );
175
176             // init method
177
178             var description = new Pango.FontDescription();
179                  description.set_size(8000);
180                 this.el.override_font(description);     
181                                 
182                 var selection = this.el.get_selection();
183                 selection.set_mode( Gtk.SelectionMode.SINGLE);
184
185             //listeners
186             this.el.cursor_changed.connect( () => {
187                 if (_this.is_loading) {
188                     return;
189                 }
190                 
191                 Gtk.TreeIter iter;
192                 Gtk.TreeModel mod;
193                         
194                 var s = this.el.get_selection();
195                 if (!s.get_selected(out mod, out iter)) {
196                     return;
197                 }
198                 
199                 GLib.Value gval;
200             
201                 mod.get_value(iter, 1 , out gval);
202                 var project = (Project.Project)gval.get_object();
203                 
204                 _this.project_selected(project);
205                 
206             });
207         }
208
209         // user defined functions
210     }
211     public class Xcls_model : Object
212     {
213         public Gtk.ListStore el;
214         private Xcls_WindowLeftProjects  _this;
215
216
217             // my vars (def)
218
219         // ctor
220         public Xcls_model(Xcls_WindowLeftProjects _owner )
221         {
222             _this = _owner;
223             _this.model = this;
224             this.el = new Gtk.ListStore( 2, typeof(string), typeof(Object) );
225
226             // my vars (dec)
227
228             // set gobject values
229
230             // init method
231
232             {
233                this.el.set_sort_func(0, (mod,a,b) => {
234                    GLib.Value ga, gb;
235                    mod.get_value(a,0, out ga);
236                    mod.get_value(b,0, out gb);
237                     
238                     if ((string)ga == (string)gb) {
239                         return 0;
240                     }
241                     return (string)ga > (string)gb ? 1 : -1;
242                }); 
243             
244             
245             }
246         }
247
248         // user defined functions
249     }
250
251     public class Xcls_TreeViewColumn5 : Object
252     {
253         public Gtk.TreeViewColumn el;
254         private Xcls_WindowLeftProjects  _this;
255
256
257             // my vars (def)
258
259         // ctor
260         public Xcls_TreeViewColumn5(Xcls_WindowLeftProjects _owner )
261         {
262             _this = _owner;
263             this.el = new Gtk.TreeViewColumn();
264
265             // my vars (dec)
266
267             // set gobject values
268             this.el.title = "Projects";
269             var child_0 = new Xcls_namecol( _this );
270             child_0.ref();
271             this.el.pack_start (  child_0.el , true );
272
273             // init method
274
275             this.el.add_attribute(_this.namecol.el , "markup", 0  );
276         }
277
278         // user defined functions
279     }
280     public class Xcls_namecol : Object
281     {
282         public Gtk.CellRendererText el;
283         private Xcls_WindowLeftProjects  _this;
284
285
286             // my vars (def)
287
288         // ctor
289         public Xcls_namecol(Xcls_WindowLeftProjects _owner )
290         {
291             _this = _owner;
292             _this.namecol = this;
293             this.el = new Gtk.CellRendererText();
294
295             // my vars (dec)
296
297             // set gobject values
298         }
299
300         // user defined functions
301     }
302
303
304
305
306 }