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                         this.code_editor.show(file, null, "", "");
445                 } else {
446                 
447                         this.switchState (State.PREVIEW); 
448                         // this triggers loadItems..
449                         this.left_tree.model.loadFile(file);
450
451                 }
452         
453         
454                 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
455                 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
456         
457                 if (file.project.xtype == "Roo" ) { 
458                         ctr.foreach( (w) => { ctr.remove(w); });
459                         ctr_p.foreach( (w) => { ctr_p.remove(w); });
460                         ctr.add(this.window_rooview.el);
461                         ctr_p.add(this.projectsettings.el);
462                         if (file.xtype != "PlainFile") {       
463                                 this.window_rooview.loadFile(file);
464                                 this.window_rooview.el.show_all();
465                         }
466                         this.projectsettings.el.show_all();            
467                         
468
469                 } else {
470                         ctr.foreach( (w) => { ctr.remove(w); });
471                         ctr_p.foreach( (w) => { ctr_p.remove(w); });            
472                         ctr.add(this.window_gladeview.el);
473                         ctr_p.add(this.vala_projectsettings.el);
474                         if (file.xtype != "PlainFile") {    
475                                 this.window_gladeview.loadFile(file);
476                                 this.window_gladeview.el.show_all();
477                         }
478                         this.vala_projectsettings.el.show_all();
479                 }
480                 print("OPEN : " + file.name);
481                 if (file.xtype != "PlainFile") {    
482                         this.win.editpane.el.set_position(this.win.editpane.el.max_position);
483                 }
484                 this.win.setTitle(file.project.name + " : " + file.name);
485                          
486
487         }
488          
489         
490         // ---------  webkit view
491         public void webkitViewInit()
492         {
493                 this.window_rooview  =new Xcls_WindowRooView();
494                 this.window_rooview.ref();
495                 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
496                 this.window_rooview.el.show_all();
497
498                 var stage = this.win.rooview.el.get_stage();
499                 stage.set_background_color(  Clutter.Color.from_string("#000"));
500         }
501
502         // ------ Gtk  - view
503
504         public void gtkViewInit()
505         {
506                 this.window_gladeview  =new Xcls_GtkView();
507                 this.window_gladeview.ref();
508                 this.window_gladeview.main_window = this.win;
509         }
510         
511         public void easingSaveAll()
512         {
513                 this.win.addpropsview.el.save_easing_state();
514                 this.win.codeeditview.el.save_easing_state();
515                 this.win.objectview.el.save_easing_state();
516                 this.win.projecteditview.el.save_easing_state();
517                 this.win.rooview.el.save_easing_state();
518                 this.clutterfiles.el.save_easing_state();
519                  
520         }
521         public void easingRestoreAll()
522         {
523                 this.win.addpropsview.el.restore_easing_state();
524                 this.win.codeeditview.el.restore_easing_state();
525                 this.win.objectview.el.restore_easing_state();
526                 this.win.projecteditview.el.restore_easing_state();
527                 this.win.rooview.el.restore_easing_state();
528                 this.clutterfiles.el.restore_easing_state();
529                 
530         }
531         public void switchState(State new_state)
532         {
533                 
534                 // if the new state and the old state are the same..
535                 
536                 if (new_state == this.state) {
537                         return;
538                 }
539                 
540                 // save the easing state of everything..
541                 this.easingSaveAll();
542                 
543                 switch (this.state) {
544
545                         case State.PREVIEW:
546                                 if (this.left_tree.getActiveFile() != null) {
547                                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
548                                                  this.window_rooview.createThumb();
549                                          } else {
550                                                   this.window_gladeview.createThumb();
551                                           }
552                                 }
553                                 // normally we are going from preview to another state.
554                                 // and different windows hide the preview in differnt ways..
555                                 
556                                 break;
557                         
558                    case State.LISTENER:
559                    case State.PROP:
560                                 
561                                 this.win.addpropsview.el.set_scale(0.0f,0.0f);
562                                  break;
563                                 
564                         case State.CODE:
565                                 this.code_editor.saveContents();
566                           
567                                 this.win.codeeditview.el.set_scale(0.0f,0.0f);
568                                 break;
569                                 
570                         case State.CODEONLY:
571                                 // going from codeonly..
572                                 this.win.leftpane.el.show();
573                                 // enable re-calc of canvas..
574                             while (Gtk.events_pending()) { 
575                                         Gtk.main_iteration();
576                                 }
577                                 //this.code_editor.saveContents(); << not yet...
578                                  
579                                 this.win.rooview.el.show(); 
580                                 this.win.codeeditview.el.set_scale(0.0f,0.0f);
581                                  
582                                 break;
583
584                          case State.OBJECT:
585                            
586                                 this.win.objectview.el.set_scale(0.0f,0.0f);
587                                  break;
588
589                    case State.PROJECT:
590                                 if (this.win.project.xtype == "Gtk") {
591                                         this.vala_projectsettings.save();
592                                 } 
593                                 
594                                 this.win.projecteditview.el.set_scale(0.0f,0.0f);
595                                  break;
596
597                   case State.FILES: // goes to preview or codeonly...
598                                 // hide files...
599                                 
600                                 if (new_state == State.CODEONLY) {
601                                         this.win.rooview.el.hide();
602                                 } else {
603                                         this.win.rooview.el.show();
604                                 }
605                                 
606                                 this.win.rooview.el.set_easing_duration(1000);
607                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
608                                 this.win.rooview.el.set_scale(1.0f,1.0f);
609                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
610                                 this.win.rooview.el.set_opacity(0xff);
611                                 
612                                 
613                            
614                                 this.clutterfiles.el.set_easing_duration(1000);
615                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
616                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
617                                 this.clutterfiles.el.set_opacity(0);
618  
619                                 //this.clutterfiles.el.hide();
620                                  
621
622                                 break;
623
624                                 
625                 }
626            
627                 var oldstate  =this.state;
628                 this.state = new_state;
629                 
630                 
631                                 
632                 this.buttonsShowHide();
633                 
634                 
635                 switch (this.state) {
636                         
637                         case State.PREVIEW:  // this is the default state when working...
638                                  this.win.editpane.el.show(); // holder for tree and properties..
639                                  
640                          
641                                  this.left_projects.el.hide(); 
642                                  if (oldstate != State.FILES) {
643                                         // it's handled above..
644                                         print ("changing state to preview from NOT files..");
645                                          
646  
647                                         this.win.rooview.el.set_scale(1.0f,1.0f);
648                                  }
649                            
650                                 break;
651
652
653                         case State.LISTENER:
654                 // same as prop?
655                         case State.PROP:
656                                 var ae =      this.left_tree.getActiveElement();
657                                 if (ae == null) {
658                                         this.state = oldstate;
659                                         this.buttonsShowHide();
660                                         this.resizeCanvasElements();
661                                         this.easingRestoreAll();
662                                         return;
663                                 }
664                                 this.add_props.el.show_all();
665                                 this.add_props.show(
666                                         Palete.factory(this.win.project.xtype), 
667                                         this.state == State.LISTENER ? "signals" : "props",
668                                         ae.fqn()
669                                 );
670  
671                                         
672  
673                                 
674                                 // -- FIXME? this needs to be State aware?
675                  
676                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
677                                   
678                                 this.win.addpropsview.el.set_scale(1.0f,1.0f);
679                                 break;
680                    
681                         case State.OBJECT:
682                                  var n = this.left_tree.getActiveElement();
683
684                                 if (this.file == null) {
685                                         this.state =oldstate;
686                                         this.buttonsShowHide();
687                                         this.resizeCanvasElements();
688                                         this.easingRestoreAll();
689                                         return;
690                                 }
691                                 
692                                 if (n == null && this.file.tree != null) {
693                                         this.state = oldstate;
694                                         this.buttonsShowHide();
695                                         this.resizeCanvasElements();
696                                         this.easingRestoreAll();
697                                         return;
698                                 }
699
700                                 this.rightpalete.el.show_all();
701                                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
702
703                                 
704                           
705                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
706                                 this.win.objectview.el.set_scale(1.0f,1.0f);
707                                  
708                                 break;
709                    
710                    
711                         case State.CODE:
712                                 this.win.codeeditview.el.show();
713                                 this.code_editor.el.show_all();
714                                 // caller needs to call editor - show....
715                                 this.win.codeeditview.el.set_scale(1.0f,1.0f);
716                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
717
718                                 break;
719
720                         case State.CODEONLY:
721                                 // going to codeonly..
722                                 this.win.codeeditview.el.show();
723                                 // recalc canvas...
724                                 while (Gtk.events_pending()) { 
725                                         Gtk.main_iteration();
726                                 }
727                                 
728                                 this.win.leftpane.el.hide();
729                                 this.win.codeeditview.el.show();
730                                 //while (Gtk.events_pending()) { 
731                                 //      Gtk.main_iteration();
732                                 //}
733                                 
734                                 
735                                 this.code_editor.el.show_all();
736                             
737                                 this.win.codeeditview.el.set_scale(1.0f,1.0f);
738                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
739                                 break;
740
741                    case State.PROJECT:
742
743                            if (this.win.project.xtype == "Roo") {
744                                         this.projectsettings.el.show_all();
745                                         this.projectsettings.show(this.win.project);
746                                 } else {
747                                         this.vala_projectsettings.el.show_all();
748                                         this.vala_projectsettings.show((Project.Gtk)this.win.project);
749                                 }
750
751                                 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
752                                 
753                                 this.win.projecteditview.el.set_scale(1.0f,1.0f);
754                                 
755                            
756                                 break;
757                                 
758                    case State.FILES:  // can only get here from PREVIEW (or code-only) state.. in theory..
759                                 
760    
761                                 this.win.editpane.el.hide(); // holder for tree and properties..
762                                 
763                                 this.left_projects.el.show(); 
764                                 
765                                 // rotate the preview to hidden...
766                                 this.win.rooview.el.set_easing_duration(1000);
767                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
768                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
769                                 this.win.rooview.el.set_opacity(0);
770                          
771                                 
772                                 
773          
774                                 if (this.win.project != null) {
775                                         this.left_projects.selectProject(this.win.project);
776                                 }
777                          
778                                 
779                                 this.clutterfiles.el.show();
780                                  
781                                 this.clutterfiles.el.set_easing_duration(1000);
782                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
783                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
784                                 this.clutterfiles.el.set_opacity(0xff);
785                                 
786                                  
787                                 
788                                 break;
789
790
791                 }
792                 this.resizeCanvasElements();
793                 this.easingRestoreAll();
794                 
795                 // run the animation.. - then load files...
796                 
797                         
798         }
799         
800         public int redraw_count = 0;
801         public void resizeCanvas() // called by window resize .. delays redraw
802         {
803                 var rc = this.redraw_count;        
804                 this.redraw_count = 2;
805                 if (rc == 0) {
806                         GLib.Timeout.add(100,  ()  =>{
807                                  return this.resizeCanvasQueue();
808                         });
809                 }
810         }
811         public bool  resizeCanvasQueue()
812         {
813                 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);        
814
815                 if (this.redraw_count < 1) {
816                         return false; // should not really happen...
817                 }
818
819
820                 this.redraw_count--;
821
822                 if (this.redraw_count > 0) {
823                         return true; // do it again in 1 second...
824                 }
825                 // got down to 0 or -1....
826                 this.redraw_count = 0;
827                 this.resizeCanvasElements();
828                 return false;
829
830         }
831         public void resizeCanvasElements()
832         {
833                 Gtk.Allocation alloc;
834                 this.win.clutterembed.el.get_allocation(out alloc);
835
836            // print("WindowState.resizeCanvasElements\n");
837                 if (!this.children_loaded || this.win.clutterembed == null) {
838                         print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
839                         return; 
840                 }
841                 
842                 var avail = alloc.width < 50.0f ? 0 :  alloc.width - 50.0f;
843                 var palsize = avail < 300.0f ? avail : 300.0f;
844                    
845  
846                 // -------- code edit min 600
847                 
848                 var codesize = avail < 800.0f ? avail : 800.0f;
849                 
850                 
851                 //print("set code size %f\n", codesize);
852
853                         
854                 
855                 switch ( this.state) {
856                         case State.PREVIEW:
857                                  
858                                 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
859                                 break;
860         
861                         case State.FILES: 
862                                 this.clutterfiles.set_size(alloc.width-50, alloc.height);
863                                 break;
864
865                         case State.PROJECT:
866                  
867                                 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
868                 
869                            // this.win.rooview.el.save_easing_state();
870                                 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
871                                  
872                                 this.win.rooview.el.set_scale(0.5f, 0.5f);
873                                 //this.win.rooview.el.restore_easing_state();
874                                 break;
875
876                         case State.CODE: 
877                                 this.win.codeeditview.el.set_size(codesize, alloc.height);
878                                 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
879                                 //this.win.rooview.el.save_easing_state();
880                                  
881                                 this.win.rooview.el.set_scale(scale,scale);
882                            // this.win.rooview.el.restore_easing_state();
883                                 break;
884                                 
885                         case State.CODEONLY: 
886                                 this.win.codeeditview.el.set_size(codesize, alloc.height);
887                                 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
888                                 //this.win.rooview.el.save_easing_state();
889                                 this.win.rooview.el.hide(); 
890                                 this.win.rooview.el.set_scale(scale,scale);
891                            // this.win.rooview.el.restore_easing_state();
892                                 break;  
893                         case State.PROP:
894                         case State.LISTENER:
895                                  this.win.addpropsview.el.set_size(palsize, alloc.height);
896                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
897                                 this.win.rooview.el.set_scale(scale,scale);
898                                 break;
899                                 
900                         case State.OBJECT:  
901                                 this.win.objectview.el.set_size(palsize, alloc.height);    
902                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
903                                 //this.win.rooview.el.save_easing_state();
904                                 this.win.rooview.el.set_scale(scale,scale);
905                            // this.win.rooview.el.restore_easing_state();
906                                 break;
907                 }
908         }
909
910         // -- buttons show hide.....
911
912         public void buttonsShowHide()
913         {
914                 // basically hide everything, then show the relivant..
915
916                  this.win.backbutton.el.hide();
917         
918                 this.win.projectbutton.el.hide(); // show file nav...
919                 this.win.editfilebutton.el.hide();
920                 this.win.projecteditbutton.el.hide();
921                  
922                 
923                 this.win.objectshowbutton.el.hide(); // add objects
924                 this.win.addpropbutton.el.hide();  
925                 this.win.addlistenerbutton.el.hide(); 
926
927         
928         
929                 this.win.addprojectbutton.el.hide();
930                 this.win.addfilebutton.el.hide();
931                 this.win.delprojectbutton.el.hide();
932                   
933                 
934                 switch (this.state) {
935                         
936                         case State.PREVIEW:  // this is the default state when working...
937                            
938                                 this.win.projectbutton.el.show(); // show file nav...
939                                 this.win.editfilebutton.el.show();
940                                 this.win.projecteditbutton.el.show();
941                                  
942                                 
943                                 this.win.objectshowbutton.el.show(); // add objects
944                                 this.win.addpropbutton.el.show();  
945                                 this.win.addlistenerbutton.el.show(); 
946                                 break;
947                         
948                         case State.CODEONLY: 
949                                 this.win.projectbutton.el.show();
950                                 break;
951                    
952                         case State.CODE: 
953                         case State.PROP:
954                         case State.LISTENER:
955                         case State.OBJECT:
956                                 
957                                 this.win.backbutton.el.show();
958                                 this.win.objectshowbutton.el.show(); // add objects
959                                 this.win.addpropbutton.el.show();  
960                                 this.win.addlistenerbutton.el.show(); 
961                                 break;
962                         
963                         case State.PROJECT: 
964                                 // anything else?
965                                 this.win.backbutton.el.show();
966                                 break;
967                         
968         
969                         case State.FILES:
970                                 if (this.left_projects.getSelectedProject() != null ) {
971                                         if (this.left_tree.getActiveFile() != null) {
972                                                 this.win.backbutton.el.show();
973                                         }
974                                         this.win.addfilebutton.el.show();
975                                 }
976                                          
977                                 this.win.addprojectbutton.el.show();
978                                 this.win.delprojectbutton.el.show();
979                                 
980                                 break;
981                 }
982                 
983                 
984
985         }
986         
987         
988         public void valaCompiled(Json.Object obj)
989                 {
990                         // vala has finished compiling...
991                         print("vala compiled");
992                         
993                         var buf = this.code_editor.buffer;
994                         buf.check_running = false;
995                                       
996                         if (obj.has_member("ERR-TOTAL")) {
997                                  this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
998                         } else {
999                                  this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1000                         }    
1001                         
1002                         if (obj.has_member("WARN-TOTAL")) {
1003
1004                                  this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1005                         } else {
1006                                  this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1007                                  
1008                         }
1009                         if (obj.has_member("DEPR-TOTAL")) {
1010                                 
1011                                  this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"),  (int) obj.get_int_member("DEPR-TOTAL"));
1012                                  
1013                         } else {
1014                                 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1015                         }
1016                         
1017                         buf.highlightErrorsJson("ERR", obj);
1018                         buf.highlightErrorsJson("WARN", obj);
1019                         buf.highlightErrorsJson("DEPR", obj);
1020                         
1021                         var gbuf =   this.window_gladeview.sourceview;
1022                         gbuf.highlightErrorsJson("ERR", obj);
1023                         gbuf.highlightErrorsJson("WARN", obj);
1024                         gbuf.highlightErrorsJson("DEPR", obj);                  
1025                         
1026                         this.last_compile_result = obj;
1027                         
1028                         
1029                 }
1030         
1031 }
1032
1033