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