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