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