src/Builder4/WindowState.vala
[app.Builder.js] / src / Builder4 / WindowState.vala
1 /**
2  * as state management is a bit too complicated inside the builder
3  * it's better to seperate this into this class
4  * 
5  * This class has references to all the Class instances that make up the window..
6  * 
7  */
8 public class WindowState : Object 
9 {
10         public Xcls_MainWindow win;
11
12         public enum State {
13                 NONE,
14                 PREVIEW,
15                 OBJECT,
16                 PROP,
17                 LISTENER,
18                 CODE,
19                 CODEONLY,
20                 FILES,
21                 PROJECT // project settings..
22         }
23
24         public State state = State.NONE;
25
26         public bool children_loaded = false;
27
28         
29         
30         public Project.Project project;
31         public JsRender.JsRender file;
32         
33         
34         
35         public Xcls_WindowLeftTree  left_tree;
36         public Xcls_WindowAddProp   add_props;
37         public Xcls_LeftProps       left_props;
38         public Xcls_ProjectSettings projectsettings;
39         public ValaProjectSettings  vala_projectsettings;
40         public Xcls_RightPalete     rightpalete;
41         public Editor               code_editor;    
42         public Xcls_WindowRooView   window_rooview;
43         public Xcls_GtkView         window_gladeview;
44         
45         public Xcls_ClutterFiles     clutterfiles;
46
47         public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized.. 
48         
49         public DialogTemplateSelect template_select; 
50         
51         public Xcls_PopoverFileDetails file_details;
52         
53         
54         // dialogs??
55         public Xcls_DialogPluginWebkit webkit_plugin;
56         
57         
58         public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
59         public Json.Object last_compile_result;
60         
61         // ctor 
62         public WindowState(Xcls_MainWindow win)
63         {
64                 this.win = win;
65                 // initialize
66
67                 // left elements..
68                 this.leftTreeInit();
69                 this.propsListInit();
70
71                 // on clutter space...
72                 this.projectEditInit();
73                 this.codeEditInit();
74                 this.projectListInit();
75                 this.fileViewInit();
76
77                 // adding stuff
78                 this.objectAddInit();
79                 this.propsAddInit();
80
81
82                 // previews...
83                 this.gtkViewInit();
84                 this.webkitViewInit();
85
86                 // dialogs
87
88                 this.fileDetailsInit();
89
90                 this.webkit_plugin = new Xcls_DialogPluginWebkit();
91                 this.template_select = new DialogTemplateSelect();
92                 this.children_loaded = true;
93                 
94                 this.left_tree.node_selected.connect((sel) => {
95                         this.window_gladeview.sourceview.nodeSelected(sel);
96                 });
97                 this.valasource = new Palete.ValaSource();
98                 this.valasource.compiled.connect(this.valaCompiled);
99                 
100                 
101         }
102
103
104         // left tree
105
106         public void leftTreeInit()
107         {
108          
109                 this.left_tree = new Xcls_WindowLeftTree();
110                 this.left_tree.ref();
111                 this.left_tree.main_window = this.win;
112         
113                 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
114                 this.left_tree.el.show_all();
115                    
116                 this.left_tree.before_node_change.connect(() => {
117                         return this.leftTreeBeforeChange();
118
119                 });
120
121                 this.left_tree.node_selected.connect((sel) => {
122                         this.leftTreeNodeSelected(sel);
123                 });
124          
125                 this.left_tree.changed.connect(() => {
126                         
127                         this.file.save();
128                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
129                                    this.window_rooview.requestRedraw();
130                         } else {
131                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
132                         }
133                          
134                 });
135                  
136         }
137
138         public bool leftTreeBeforeChange()
139         {
140                 if (this.state != State.CODE) {
141                         this.left_props.finish_editing();
142                         return true;
143                 }
144                 if (!this.code_editor.saveContents()) {
145                         return false;
146                 }
147                 return false;
148         }
149         
150         public void leftTreeNodeSelected(JsRender.Node? sel)
151         {
152
153                 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
154
155                 if (sel == null) {
156                         this.left_props.el.hide();
157                 } 
158                 this.left_props.el.show();
159                 this.left_props.load(this.left_tree.getActiveFile(), sel);
160                 switch (this.state) {
161                         
162                         case State.OBJECT: 
163                                   
164                                  if (sel == null) {
165                                         this.rightpalete.clear();
166                                         break;
167                                 }
168                                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
169                                 break;
170                                  
171                 
172                    case State.PROP:
173                                 if (sel == null) {
174                                         this.add_props.clear();
175                                         break;
176                                 }
177                                 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
178                                 break;
179
180                         case State.LISTENER:
181                            
182                                 if (sel == null) {
183                                         this.add_props.clear();
184                                         break;
185                                 }
186                                 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
187                                 break;
188                                 
189                         case State.CODE:
190                                  this.switchState(State.PREVIEW);
191                          
192                                 break;
193                            
194                                                         
195                 }
196                  
197
198         }
199
200
201
202
203         public void propsListInit()
204         {
205         
206                 this.left_props =new Xcls_LeftProps();
207                 this.left_props.ref();
208                 this.left_props.main_window = this.win;
209                 this.win.props.el.pack_start(this.left_props.el,true, true,0);
210                 this.left_props.el.show_all();
211         
212                 this.left_props.show_editor.connect( (file, node, type,  key) => {
213                         this.switchState(State.CODE);
214                         this.code_editor.show(
215                                 file,
216                                 node,
217                                 type,
218                                 key
219                         );
220                         
221                         
222                 });
223
224    
225                 this.left_props.stop_editor.connect( () => {
226                         if (this.state != State.CODE) {
227                                 return true;
228                         }
229         
230                         var ret =  this.code_editor.saveContents();
231                         if (!ret) {
232                                 return false;
233                         }
234                         this.switchState(State.PREVIEW);
235                         return ret;
236                 });
237         
238                 this.left_props.changed.connect(() => {
239                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
240                                    this.window_rooview.requestRedraw();
241                         } else {
242                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
243                         }
244                         this.left_tree.model.updateSelected();
245                         this.file.save();
246                         if (this.file.xtype=="Gtk") {
247                                 this.valasource.checkFileSpawn(this.file);
248                         }
249                 });
250         
251
252
253         }
254
255         //-------------  projects edit
256
257         public void projectEditInit()
258         {
259                 this.projectsettings  =new Xcls_ProjectSettings();
260                 this.projectsettings.ref();  /// really?
261         
262                 this.vala_projectsettings  =new ValaProjectSettings();
263                 this.vala_projectsettings.ref();
264                 this.vala_projectsettings.window = this.win;
265         
266                 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
267                 //this.projectsettings.el.show_all();
268
269                 var stage = this.win.projecteditview.el.get_stage();
270                 stage.set_background_color(  Clutter.Color.from_string("#000"));
271         
272                 this.projectsettings.buttonPressed.connect((btn) => {
273                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
274                                 if (btn == "save") {
275                                         this.window_rooview.view.renderJS(true);
276                                 }
277                                 if (btn == "apply") {
278                                         this.window_rooview.view.renderJS(true);
279                                         return;
280                                 }
281                         } else {
282                                 // do nothing for gtk..
283                         }
284                         if (btn == "save" || btn == "apply") {
285                                 this.win.project.save();
286                  
287                         }
288                         this.switchState (State.PREVIEW); 
289                          
290                  });
291
292         }
293         // ----------- object adding
294         public void objectAddInit()
295         {
296
297                 this.rightpalete  = new Xcls_RightPalete();
298                 this.rightpalete.ref();  /// really?
299                 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
300                 //this.projectsettings.el.show_all();
301
302                 var stage = this.win.objectview.el.get_stage();
303                 stage.set_background_color(  Clutter.Color.from_string("#000"));
304                    
305         }
306         
307         // -----------  properties adding list...
308         // listener uses the properties 
309         public void propsAddInit()
310         {
311         // Add properties
312                 this.add_props  = new Xcls_WindowAddProp();
313                 this.add_props.ref();  /// really?
314                 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
315                 //this.projectsettings.el.show_all();
316
317                 var  stage = this.win.addpropsview.el.get_stage();
318                 stage.set_background_color(  Clutter.Color.from_string("#000"));
319
320
321                 this.add_props.select.connect( (key,type,skel, etype) => {
322                         this.left_props.addProp(etype, key, skel, type);
323                 });
324
325         }
326         public void propsAddShow()
327         {
328
329         }
330         public void propsAddHide()
331         {
332         
333         }
334
335
336
337         
338         // ----------- Add / Edit listener
339         // listener uses the properties 
340         //public void listenerInit()     { }
341         public void listenerShow()
342         {
343
344         }
345         public void listenerHide()
346         {
347         
348         }
349
350         // -------------- codeEditor
351
352         public void codeEditInit()
353         {
354                 this.code_editor  = new  Editor();
355                 //this.code_editor.ref();  /// really?
356                 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
357                 
358                 this.code_editor.window = this.win;
359                 //this.projectsettings.el.show_all();
360
361                 var stage = this.win.codeeditview.el.get_stage();
362                 stage.set_background_color(  Clutter.Color.from_string("#000"));
363                 // editor.save...
364
365                 this.code_editor.save.connect( () => {
366                         this.file.save();
367                         this.left_tree.model.updateSelected();
368                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
369                                    this.window_rooview.requestRedraw();
370                         } else {
371                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
372                         }
373                          // we do not need to call spawn... - as it's already called by the editor?
374                          
375                 });
376                 
377         }
378
379         // ----------- list of projects on left
380         public void  projectListInit() 
381         {
382
383                 this.left_projects = new Xcls_WindowLeftProjects();
384                  this.left_projects.ref();
385                  this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
386                  this.left_projects.el.show_all();
387                  this.left_projects.project_selected.connect((proj) => {
388                         this.buttonsShowHide();
389                         proj.scanDirs();
390                         this.clutterfiles.loadProject(proj);
391                 
392                  });
393
394         }
395         // ----------- file view
396
397         public void fileViewInit()
398         {
399                 var stage = this.win.rooview.el.get_stage(); // seems odd... 
400                 this.clutterfiles = new Xcls_ClutterFiles();
401                 this.clutterfiles.ref();
402                 stage.add_child(this.clutterfiles.el);
403                 this.clutterfiles.el.show();
404
405
406                 this.clutterfiles.open.connect((file) => { 
407                         this.fileViewOpen(file);
408                 });
409                 this.clutterfiles.el.transitions_completed.connect(() => {
410                         if (this.state == State.FILES) {
411                                 this.win.rooview.el.hide();
412                         } else {
413                                 this.clutterfiles.el.hide();
414                         }
415                         
416                         
417                 });
418
419         }
420  
421         public void fileDetailsInit()
422         {
423                 this.file_details = new Xcls_PopoverFileDetails();
424                 this.file_details.mainwindow = this.win;
425                 // force it modal to the main window..
426                 
427                 this.file_details.success.connect((project,file) =>
428                 {
429                         this.fileViewOpen(file);
430                 });
431
432         }
433         
434         public void fileViewOpen(JsRender.JsRender file)
435         {
436                 this.win.project = file.project;
437                 this.project = project;
438                 this.file = file;
439                 
440                 
441                 if (file.xtype == "PlainFile") {
442                         this.switchState (State.CODEONLY); 
443                         file.loadItems();
444                 } else {
445                 
446                         this.switchState (State.PREVIEW); 
447                         this.left_tree.model.loadFile(file);
448
449                 }
450         
451         
452                 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
453                 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
454         
455                 if (file.project.xtype == "Roo" ) { 
456                         ctr.foreach( (w) => { ctr.remove(w); });
457                         ctr_p.foreach( (w) => { ctr_p.remove(w); });
458                         ctr.add(this.window_rooview.el);
459                         ctr_p.add(this.projectsettings.el);
460                         if (file.xtype != "PlainFile") {       
461                                 this.window_rooview.loadFile(file);
462                                 this.window_rooview.el.show_all();
463                         }
464                         this.projectsettings.el.show_all();            
465                         
466
467                 } else {
468                         ctr.foreach( (w) => { ctr.remove(w); });
469                         ctr_p.foreach( (w) => { ctr_p.remove(w); });            
470                         ctr.add(this.window_gladeview.el);
471                         ctr_p.add(this.vala_projectsettings.el);
472                         if (file.xtype != "PlainFile") {    
473                                 this.window_gladeview.loadFile(file);
474                                 this.window_gladeview.el.show_all();
475                         }
476                         this.vala_projectsettings.el.show_all();
477                 }
478                 print("OPEN : " + file.name);
479                 if (file.xtype != "PlainFile") {    
480                         this.win.editpane.el.set_position(this.win.editpane.el.max_position);
481                 }
482                 this.win.setTitle(file.project.name + " : " + file.name);
483                          
484
485         }
486          
487         
488         // ---------  webkit view
489         public void webkitViewInit()
490         {
491                 this.window_rooview  =new Xcls_WindowRooView();
492                 this.window_rooview.ref();
493                 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
494                 this.window_rooview.el.show_all();
495
496                 var stage = this.win.rooview.el.get_stage();
497                 stage.set_background_color(  Clutter.Color.from_string("#000"));
498         }
499
500         // ------ Gtk  - view
501
502         public void gtkViewInit()
503         {
504                 this.window_gladeview  =new Xcls_GtkView();
505                 this.window_gladeview.ref();
506                 this.window_gladeview.main_window = this.win;
507         }
508         
509         public void easingSaveAll()
510         {
511                 this.win.addpropsview.el.save_easing_state();
512                 this.win.codeeditview.el.save_easing_state();
513                 this.win.objectview.el.save_easing_state();
514                 this.win.projecteditview.el.save_easing_state();
515                 this.win.rooview.el.save_easing_state();
516                 this.clutterfiles.el.save_easing_state();
517                  
518         }
519         public void easingRestoreAll()
520         {
521                 this.win.addpropsview.el.restore_easing_state();
522                 this.win.codeeditview.el.restore_easing_state();
523                 this.win.objectview.el.restore_easing_state();
524                 this.win.projecteditview.el.restore_easing_state();
525                 this.win.rooview.el.restore_easing_state();
526                 this.clutterfiles.el.restore_easing_state();
527                 
528         }
529         public void switchState(State new_state)
530         {
531                 
532                 // if the new state and the old state are the same..
533                 
534                 if (new_state == this.state) {
535                         return;
536                 }
537                 
538                 // save the easing state of everything..
539                 this.easingSaveAll();
540                 
541                 switch (this.state) {
542
543                         case State.PREVIEW:
544                                 if (this.left_tree.getActiveFile() != null) {
545                                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
546                                                  this.window_rooview.createThumb();
547                                          } else {
548                                                   this.window_gladeview.createThumb();
549                                           }
550                                 }
551                                 // normally we are going from preview to another state.
552                                 // and different windows hide the preview in differnt ways..
553                                 
554                                 break;
555                         
556                    case State.LISTENER:
557                    case State.PROP:
558                                 
559                                 this.win.addpropsview.el.set_scale(0.0f,0.0f);
560                                  break;
561                                 
562                         case State.CODE:
563                                 this.code_editor.saveContents();
564                           
565                                 this.win.codeeditview.el.set_scale(0.0f,0.0f);
566                                 break;
567                                 
568                         case State.CODEONLY:
569                                 // going from codeonly..
570                                 this.win.leftpane.el.show();
571                                 // enable re-calc of canvas..
572                             while (Gtk.events_pending()) { 
573                                         Gtk.main_iteration();
574                                 }
575                                 //this.code_editor.saveContents(); << not yet...
576                                  
577                                 this.win.rooview.el.show(); 
578                                 this.win.codeeditview.el.set_scale(0.0f,0.0f);
579                                  
580                                 break;
581
582                          case State.OBJECT:
583                            
584                                 this.win.objectview.el.set_scale(0.0f,0.0f);
585                                  break;
586
587                    case State.PROJECT:
588                                 if (this.win.project.xtype == "Gtk") {
589                                         this.vala_projectsettings.save();
590                                 } 
591                                 
592                                 this.win.projecteditview.el.set_scale(0.0f,0.0f);
593                                  break;
594
595                   case State.FILES: // goes to preview or codeonly...
596                                 // hide files...
597                                 
598                                 if (new_state == State.CODEONLY) {
599                                         this.win.rooview.el.hide();
600                                 } else {
601                                         this.win.rooview.el.show();
602                                 }
603                                 
604                                 this.win.rooview.el.set_easing_duration(1000);
605                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
606                                 this.win.rooview.el.set_scale(1.0f,1.0f);
607                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
608                                 this.win.rooview.el.set_opacity(0xff);
609                                 
610                                 
611                            
612                                 this.clutterfiles.el.set_easing_duration(1000);
613                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
614                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
615                                 this.clutterfiles.el.set_opacity(0);
616  
617                                 //this.clutterfiles.el.hide();
618                                  
619
620                                 break;
621
622                                 
623                 }
624            
625                 var oldstate  =this.state;
626                 this.state = new_state;
627                 
628                 
629                                 
630                 this.buttonsShowHide();
631                 
632                 
633                 switch (this.state) {
634                         
635                         case State.PREVIEW:  // this is the default state when working...
636                                  this.win.editpane.el.show(); // holder for tree and properties..
637                                  
638                          
639                                  this.left_projects.el.hide(); 
640                                  if (oldstate != State.FILES) {
641                                         // it's handled above..
642                                         print ("changing state to preview from NOT files..");
643                                          
644  
645                                         this.win.rooview.el.set_scale(1.0f,1.0f);
646                                  }
647                            
648                                 break;
649
650
651                         case State.LISTENER:
652                 // same as prop?
653                         case State.PROP:
654                                 var ae =      this.left_tree.getActiveElement();
655                                 if (ae == null) {
656                                         this.state = oldstate;
657                                         this.buttonsShowHide();
658                                         this.resizeCanvasElements();
659                                         this.easingRestoreAll();
660                                         return;
661                                 }
662                                 this.add_props.el.show_all();
663                                 this.add_props.show(
664                                         Palete.factory(this.win.project.xtype), 
665                                         this.state == State.LISTENER ? "signals" : "props",
666                                         ae.fqn()
667                                 );
668  
669                                         
670  
671                                 
672                                 // -- FIXME? this needs to be State aware?
673                  
674                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
675                                   
676                                 this.win.addpropsview.el.set_scale(1.0f,1.0f);
677                                 break;
678                    
679                         case State.OBJECT:
680                                  var n = this.left_tree.getActiveElement();
681
682                                 if (this.file == null) {
683                                         this.state =oldstate;
684                                         this.buttonsShowHide();
685                                         this.resizeCanvasElements();
686                                         this.easingRestoreAll();
687                                         return;
688                                 }
689                                 
690                                 if (n == null && this.file.tree != null) {
691                                         this.state = oldstate;
692                                         this.buttonsShowHide();
693                                         this.resizeCanvasElements();
694                                         this.easingRestoreAll();
695                                         return;
696                                 }
697
698                                 this.rightpalete.el.show_all();
699                                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
700
701                                 
702                           
703                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
704                                 this.win.objectview.el.set_scale(1.0f,1.0f);
705                                  
706                                 break;
707                    
708                    
709                         case State.CODE:
710                                 this.win.codeeditview.el.show();
711                                 this.code_editor.el.show_all();
712                                 // caller needs to call editor - show....
713                                 this.win.codeeditview.el.set_scale(1.0f,1.0f);
714                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
715
716                                 break;
717
718                         case State.CODEONLY:
719                                 // going to codeonly..
720                                 this.win.codeeditview.el.show();
721                                 // recalc canvas...
722                                 while (Gtk.events_pending()) { 
723                                         Gtk.main_iteration();
724                                 }
725                                 
726                                 this.win.leftpane.el.hide();
727                                 this.win.codeeditview.el.show();
728                                 //while (Gtk.events_pending()) { 
729                                 //      Gtk.main_iteration();
730                                 //}
731                                 
732                                 
733                                 this.code_editor.el.show_all();
734                             
735                                 this.win.codeeditview.el.set_scale(1.0f,1.0f);
736                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
737                                 break;
738
739                    case State.PROJECT:
740
741                            if (this.win.project.xtype == "Roo") {
742                                         this.projectsettings.el.show_all();
743                                         this.projectsettings.show(this.win.project);
744                                 } else {
745                                         this.vala_projectsettings.el.show_all();
746                                         this.vala_projectsettings.show((Project.Gtk)this.win.project);
747                                 }
748
749                                 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
750                                 
751                                 this.win.projecteditview.el.set_scale(1.0f,1.0f);
752                                 
753                            
754                                 break;
755                                 
756                    case State.FILES:  // can only get here from PREVIEW (or code-only) state.. in theory..
757                                 
758    
759                                 this.win.editpane.el.hide(); // holder for tree and properties..
760                                 
761                                 this.left_projects.el.show(); 
762                                 
763                                 // rotate the preview to hidden...
764                                 this.win.rooview.el.set_easing_duration(1000);
765                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
766                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
767                                 this.win.rooview.el.set_opacity(0);
768                          
769                                 
770                                 
771          
772                                 if (this.win.project != null) {
773                                         this.left_projects.selectProject(this.win.project);
774                                 }
775                          
776                                 
777                                 this.clutterfiles.el.show();
778                                  
779                                 this.clutterfiles.el.set_easing_duration(1000);
780                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
781                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
782                                 this.clutterfiles.el.set_opacity(0xff);
783                                 
784                                  
785                                 
786                                 break;
787
788
789                 }
790                 this.resizeCanvasElements();
791                 this.easingRestoreAll();
792                 
793                 // run the animation.. - then load files...
794                 
795                         
796         }
797         
798         public int redraw_count = 0;
799         public void resizeCanvas() // called by window resize .. delays redraw
800         {
801                 var rc = this.redraw_count;        
802                 this.redraw_count = 2;
803                 if (rc == 0) {
804                         GLib.Timeout.add(100,  ()  =>{
805                                  return this.resizeCanvasQueue();
806                         });
807                 }
808         }
809         public bool  resizeCanvasQueue()
810         {
811                 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);        
812
813                 if (this.redraw_count < 1) {
814                         return false; // should not really happen...
815                 }
816
817
818                 this.redraw_count--;
819
820                 if (this.redraw_count > 0) {
821                         return true; // do it again in 1 second...
822                 }
823                 // got down to 0 or -1....
824                 this.redraw_count = 0;
825                 this.resizeCanvasElements();
826                 return false;
827
828         }
829         public void resizeCanvasElements()
830         {
831                 Gtk.Allocation alloc;
832                 this.win.clutterembed.el.get_allocation(out alloc);
833
834            // print("WindowState.resizeCanvasElements\n");
835                 if (!this.children_loaded || this.win.clutterembed == null) {
836                         print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
837                         return; 
838                 }
839                 
840                 var avail = alloc.width < 50.0f ? 0 :  alloc.width - 50.0f;
841                 var palsize = avail < 300.0f ? avail : 300.0f;
842                    
843  
844                 // -------- code edit min 600
845                 
846                 var codesize = avail < 800.0f ? avail : 800.0f;
847                 
848                 
849                 //print("set code size %f\n", codesize);
850
851                         
852                 
853                 switch ( this.state) {
854                         case State.PREVIEW:
855                                  
856                                 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
857                                 break;
858         
859                         case State.FILES: 
860                                 this.clutterfiles.set_size(alloc.width-50, alloc.height);
861                                 break;
862
863                         case State.PROJECT:
864                  
865                                 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
866                 
867                            // this.win.rooview.el.save_easing_state();
868                                 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
869                                  
870                                 this.win.rooview.el.set_scale(0.5f, 0.5f);
871                                 //this.win.rooview.el.restore_easing_state();
872                                 break;
873
874                         case State.CODE: 
875                                 this.win.codeeditview.el.set_size(codesize, alloc.height);
876                                 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
877                                 //this.win.rooview.el.save_easing_state();
878                                  
879                                 this.win.rooview.el.set_scale(scale,scale);
880                            // this.win.rooview.el.restore_easing_state();
881                                 break;
882                                 
883                         case State.CODEONLY: 
884                                 this.win.codeeditview.el.set_size(codesize, alloc.height);
885                                 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
886                                 //this.win.rooview.el.save_easing_state();
887                                 this.win.rooview.el.hide(); 
888                                 this.win.rooview.el.set_scale(scale,scale);
889                            // this.win.rooview.el.restore_easing_state();
890                                 break;  
891                         case State.PROP:
892                         case State.LISTENER:
893                                  this.win.addpropsview.el.set_size(palsize, alloc.height);
894                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
895                                 this.win.rooview.el.set_scale(scale,scale);
896                                 break;
897                                 
898                         case State.OBJECT:  
899                                 this.win.objectview.el.set_size(palsize, alloc.height);    
900                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
901                                 //this.win.rooview.el.save_easing_state();
902                                 this.win.rooview.el.set_scale(scale,scale);
903                            // this.win.rooview.el.restore_easing_state();
904                                 break;
905                 }
906         }
907
908         // -- buttons show hide.....
909
910         public void buttonsShowHide()
911         {
912                 // basically hide everything, then show the relivant..
913
914                  this.win.backbutton.el.hide();
915         
916                 this.win.projectbutton.el.hide(); // show file nav...
917                 this.win.editfilebutton.el.hide();
918                 this.win.projecteditbutton.el.hide();
919                  
920                 
921                 this.win.objectshowbutton.el.hide(); // add objects
922                 this.win.addpropbutton.el.hide();  
923                 this.win.addlistenerbutton.el.hide(); 
924
925         
926         
927                 this.win.addprojectbutton.el.hide();
928                 this.win.addfilebutton.el.hide();
929                 this.win.delprojectbutton.el.hide();
930                   
931                 
932                 switch (this.state) {
933                         
934                         case State.PREVIEW:  // this is the default state when working...
935                            
936                                 this.win.projectbutton.el.show(); // show file nav...
937                                 this.win.editfilebutton.el.show();
938                                 this.win.projecteditbutton.el.show();
939                                  
940                                 
941                                 this.win.objectshowbutton.el.show(); // add objects
942                                 this.win.addpropbutton.el.show();  
943                                 this.win.addlistenerbutton.el.show(); 
944                                 break;
945                         
946                         case State.CODEONLY: 
947                                 this.win.projectbutton.el.show();
948                                 break;
949                    
950                         case State.CODE: 
951                         case State.PROP:
952                         case State.LISTENER:
953                         case State.OBJECT:
954                                 
955                                 this.win.backbutton.el.show();
956                                 this.win.objectshowbutton.el.show(); // add objects
957                                 this.win.addpropbutton.el.show();  
958                                 this.win.addlistenerbutton.el.show(); 
959                                 break;
960                         
961                         case State.PROJECT: 
962                                 // anything else?
963                                 this.win.backbutton.el.show();
964                                 break;
965                         
966         
967                         case State.FILES:
968                                 if (this.left_projects.getSelectedProject() != null ) {
969                                         if (this.left_tree.getActiveFile() != null) {
970                                                 this.win.backbutton.el.show();
971                                         }
972                                         this.win.addfilebutton.el.show();
973                                 }
974                                          
975                                 this.win.addprojectbutton.el.show();
976                                 this.win.delprojectbutton.el.show();
977                                 
978                                 break;
979                 }
980                 
981                 
982
983         }
984         
985         
986         public void valaCompiled(Json.Object obj)
987                 {
988                         // vala has finished compiling...
989                         print("vala compiled");
990                         
991                         var buf = this.code_editor.buffer;
992                         buf.check_running = false;
993                                       
994                         if (obj.has_member("ERR-TOTAL")) {
995                                  this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
996                         } else {
997                                  this.win.statusbar_errors.setNotices( new Json.Object() , 0);
998                         }    
999                         
1000                         if (obj.has_member("WARN-TOTAL")) {
1001
1002                                  this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1003                         } else {
1004                                  this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1005                                  
1006                         }
1007                         if (obj.has_member("DEPR-TOTAL")) {
1008                                 
1009                                  this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"),  (int) obj.get_int_member("DEPR-TOTAL"));
1010                                  
1011                         } else {
1012                                 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1013                         }
1014                         
1015                         buf.highlightErrorsJson("ERR", obj);
1016                         buf.highlightErrorsJson("WARN", obj);
1017                         buf.highlightErrorsJson("DEPR", obj);
1018                         
1019                         var gbuf =   this.window_gladeview.sourceview;
1020                         gbuf.highlightErrorsJson("ERR", obj);
1021                         gbuf.highlightErrorsJson("WARN", obj);
1022                         gbuf.highlightErrorsJson("DEPR", obj);                  
1023                         
1024                         this.last_compile_result = obj;
1025                         
1026                         
1027                 }
1028         
1029 }
1030
1031