c296599d5547f6c81d788e72659a00e39f58e3ec
[roobuilder] / 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                 CODE,
16                 CODEONLY  
17           
18         }  
19
20         public State state = State.NONE;
21
22         public bool children_loaded = false;
23  
24         public Project.Project project;
25         public JsRender.JsRender file;
26           
27         public Xcls_WindowLeftTree  left_tree;
28         public Xcls_PopoverAddProp   add_props;
29         public Xcls_LeftProps       left_props;
30         public Xcls_RooProjectSettings roo_projectsettings_pop;
31         public ValaProjectSettingsPopover  vala_projectsettings_pop; 
32         public Xcls_PopoverAddObject     rightpalete;
33         //public Xcls_PopoverEditor               code_editor_popover;
34         public Editor                                    code_editor_tab; 
35         public Xcls_WindowRooView   window_rooview;
36         public Xcls_GtkView         window_gladeview;
37         public Xcls_PopoverFiles popover_files;
38         
39         //public Xcls_ClutterFiles     clutterfiles;
40         //public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized.. 
41          
42         public DialogTemplateSelect template_select; 
43         
44         public Xcls_PopoverFileDetails file_details;
45         public Xcls_ValaCompileResults compile_results;
46         
47         // dialogs??
48         public Xcls_DialogPluginWebkit webkit_plugin;
49         
50         
51         //public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
52         public Json.Object last_compile_result;
53         
54         // ctor 
55         public WindowState(Xcls_MainWindow win)
56         {
57                 this.win = win;
58                 // initialize
59
60                 // left elements..
61                 this.leftTreeInit();
62                 this.propsListInit();
63
64                 // on clutter space...
65                 this.projectEditInit();
66                 this.codeEditInit();
67                 //this.codePopoverEditInit();
68                 //this.projectListInit();
69                 //this.fileViewInit();
70
71                 // adding stuff
72                 this.objectAddInit();
73                 this.propsAddInit();
74
75
76                 // previews...
77                 this.gtkViewInit();
78                 this.webkitViewInit();
79
80                 // dialogs
81
82                 this.fileDetailsInit();
83
84                 this.webkit_plugin = new Xcls_DialogPluginWebkit();
85                 this.template_select = new DialogTemplateSelect();
86                 this.children_loaded = true;
87                 
88                 
89                  
90                 BuilderApplication.valasource.compiled.connect(this.showCompileResult); 
91                 
92                 this.compile_results = new  Xcls_ValaCompileResults(); // the poup dialogs with results in.
93                 this.compile_results.window = this.win;
94                 BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
95                 
96                 this.win.statusbar_compilestatus_label.el.hide();
97                 this.win.statusbar_run.el.hide();
98                 this.win.search_results.el.hide();
99                 
100                 this.popover_files = new Xcls_PopoverFiles();
101                 this.popover_files.setMainWindow(this.win);
102         }
103
104
105         // left tree
106
107         public void leftTreeInit()
108         {
109          
110                 this.left_tree = new Xcls_WindowLeftTree();
111                 this.left_tree.ref();
112                 this.left_tree.main_window = this.win;
113         
114                 this.win.leftpane.el.remove(this.win.editpane.el);
115         //this.win.tree.el.remove(this.left_tree.el);
116         this.win.leftpane.el.add(this.left_tree.el);
117             
118         
119                 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
120                 this.left_tree.el.show_all();
121                    
122                 this.left_tree.before_node_change.connect(() => {
123                         // if the node change is caused by the editor (code preview)
124                         if (this.left_tree.view.lastEventSource == "editor") {
125                                 return true;
126                         }
127                         return this.leftTreeBeforeChange();
128
129                 });
130                 // node selected -- only by clicking?
131                 this.left_tree.node_selected.connect((sel, source) => {
132                         if (source == "editor") {
133                                 return;
134                         }
135                         if (this.file.xtype == "Roo") { 
136                                 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
137                         } else {
138                                 this.window_gladeview.sourceview.nodeSelected(sel);
139                         }
140                 });
141                 
142                 this.left_tree.node_selected.connect((sel, source) => {
143                         this.leftTreeNodeSelected(sel, source);
144                 });
145          
146                 this.left_tree.changed.connect(() => {
147                         GLib.debug("LEFT TREE: Changed fired\n");
148                         this.file.save();
149                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
150                                    this.window_rooview.requestRedraw();
151                         } else {
152                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
153                         }
154                          
155                 });
156                  
157         }
158
159         public bool leftTreeBeforeChange()
160         {
161                 // in theory code editor has to hide before tree change occurs.
162                 //if (this.state != State.CODE) {
163                         this.left_props.finish_editing();
164                         
165                         if (this.state == State.CODE) {
166                                 this.code_editor_tab.saveContents();
167                                 this.switchState(State.PREVIEW);
168                         }
169                         
170                         return true;
171                 //}
172
173                 //if (!this.code_editor.saveContents()) {
174                 //      return false;
175                 //}
176                 //return false;
177         }
178         
179         int tree_width = 300;
180         int props_width = 300;
181         
182         public void leftTreeNodeSelected(JsRender.Node? sel, string source)
183         {
184                 
185                 // do we really want to flip paletes if differnt nodes are selected
186                 // showing palete should be deliberate thing..
187                  
188          
189                 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
190
191                 this.add_props.hide(); // always hide add node/add listener if we change node.
192                 this.rightpalete.hide();
193                 
194                 this.left_props.load(this.left_tree.getActiveFile(), sel);
195                 
196                 var outerpane = this.win.mainpane.el;
197                 var innerpane = this.win.editpane.el;
198                 
199                  if (this.win.editpane.el.parent != null && sel != null) {
200                         // select another node... no change to show hide/resize
201                         return;
202                 }
203                                  
204                 if (sel == null) {
205                     // remove win.editpane from leftpane
206                     // remove lefttree from from win.tree 
207                     // add win.tree to leftpane
208                     if (this.win.editpane.el.parent != null) {
209                         this.props_width =  outerpane.get_position() - innerpane.get_position();
210                         this.tree_width = innerpane.get_position();
211                         GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
212                         
213                         this.win.leftpane.el.remove(this.win.editpane.el);
214                         this.win.tree.el.remove(this.left_tree.el);
215                         this.win.leftpane.el.add(this.left_tree.el);
216                 }
217                     
218                 
219                         //GLib.debug("Hide Properties");
220                         outerpane.show_all(); // make sure it's visiable..
221                         this.left_props.el.hide();
222                         GLib.debug("set position: %d", this.tree_width);
223                         outerpane.set_position(this.tree_width);
224                         //outerpane.set_position(int.max(250,innerpane.get_position()));
225                         //this.left_props.el.width_request =  this.left_props.el.get_allocated_width();
226                         return;
227                 }
228                 
229                 // at this point we are showing the outer only,
230                 
231                 
232                 
233                 
234                 this.tree_width = outerpane.get_position();
235                 
236                 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
237                       
238                 // remove this.ldeftree from this.win.leftpane
239                 this.win.leftpane.el.remove(this.left_tree.el);
240                 this.win.tree.el.add(this.left_tree.el);
241                 this.win.leftpane.el.add(this.win.editpane.el);
242                 
243                 
244                 
245                 
246                 GLib.debug("left props is %s",  this.left_props.el.visible ? "shown" : "hidden");
247                 // at start (hidden) - outer  = 400 inner = 399
248                 // expanded out -> outer = 686, inner = 399 
249                 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
250                 this.left_props.el.show_all();
251                 //if (!this.left_props.el.visible) {
252                  
253                         GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
254                         outerpane.set_position(this.tree_width + this.props_width);
255                         innerpane.set_position(this.tree_width);
256                         /* var cw = outerpane.el.get_position();
257                         var rw = int.min(this.left_props.el.width_request, 150);
258                         print("outerpos : %d, innerpos : %d", cw + rw, cw);
259                         
260                         innerpane.set_position(cw); */
261                         this.left_props.el.show();
262                 
263                 //}
264                 
265                  
266                 
267                 
268                 
269
270                 
271                 
272                 // if either of these are active.. then we should update them??
273                 
274                 
275                 
276    /**
277    
278    make outerpane = {current width of left pane} + width of props
279    make innerpane = {current width of left pane}
280    
281    
282    
283    
284    
285    var outerpane = _this.main_window.leftpane.el;
286    var pane = _this.main_window.editpane.el;
287    
288   
289    
290     var try_size = (i * 25) + 60; // est. 20px per line + 40px header
291     GLib.Timeout.add_seconds(1, () => { 
292                 // max 80%...
293                 pane.set_position( 
294                      ((try_size * 1.0f) /  (pane.max_position * 1.0f))  > 0.8f  ? 
295                     (int) (pane.max_position * 0.2f) :
296                     pane.max_position-try_size);
297             return GLib.Source.REMOVE;
298         });
299         */
300                 
301                 
302                 /*
303                 switch (this.state) {
304                  
305                         case State.CODE:
306                                  this.switchState(State.PREVIEW);
307                          
308                                 break;
309                            
310                                                         
311                 }
312                 */
313  
314                  
315
316         }
317
318
319
320
321         public void propsListInit()
322         {
323         
324                 this.left_props =new Xcls_LeftProps();
325                 this.left_props.ref();
326                 this.left_props.main_window = this.win;
327                 this.win.props.el.pack_start(this.left_props.el,true, true,0);
328                 this.left_props.el.show_all();
329         
330                 this.left_props.show_editor.connect( (file, node, prop) => {
331                         this.switchState(State.CODE);
332                         
333                         
334                         this.code_editor_tab.show(
335                                 file,
336                                 node,
337                                 prop
338                         );
339                         
340                         
341                         
342                 });
343
344                 // not sure if this is needed - as closing the popvoer should save it.
345                 this.left_props.stop_editor.connect( () => {
346                         var ret =  this.code_editor_tab.saveContents();
347                         if (!ret) {
348                                 return false;
349                         }
350                         this.switchState(State.PREVIEW);
351                          
352                         return ret;
353                 });
354         
355                 this.left_props.changed.connect(() => {
356                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
357                                    this.window_rooview.requestRedraw();
358                         } else {
359                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
360                         }
361                         this.left_tree.model.updateSelected();
362                         this.file.save();
363                         if (this.file.xtype=="Gtk") {
364                                 BuilderApplication.valasource.checkFileSpawn(this.file);
365                         }
366                 });
367          
368
369         }
370
371         //-------------  projects edit
372
373         public void projectEditInit()
374         {
375                 this.roo_projectsettings_pop  =new Xcls_RooProjectSettings();
376                 this.roo_projectsettings_pop.ref();  /// really?
377         
378                 this.vala_projectsettings_pop  =new  ValaProjectSettingsPopover();
379                 this.vala_projectsettings_pop.ref();
380                 this.vala_projectsettings_pop.window = this.win;
381         
382                 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
383  
384  
385                 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
386                         // in theory active file can only be rooo...
387                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
388                                 if (btn == "save") {
389                                         this.window_rooview.view.renderJS(true);
390                                         this.roo_projectsettings_pop.el.hide();
391                                 }
392                                 if (btn == "apply") {
393                                         this.window_rooview.view.renderJS(true);
394                                         return;
395                                 }
396                         } else {
397                                 // do nothing for gtk..
398                         }
399                         if (btn == "save" || btn == "apply") {
400                                 this.win.project.save();
401                  
402                         }
403                         //this.switchState (State.PREVIEW); 
404                          
405                  });
406
407         }
408         
409         public void projectPopoverShow(Gtk.Widget btn, Project.Project? pr) 
410         { 
411                 if (pr == null) {
412                     pr = this.project;
413             }
414           
415             /*
416         var active_file = this.left_tree.getActiveFile() ;
417         if (active_file != null) {
418             xtype = active_file.xtype;
419         } else {
420         
421                 return; // no active project
422             // we might be on the file brower..
423             //pr = this.left_projects.getSelectedProject();        
424             //if (pr != null) {
425             //    xtype = pr.xtype;
426             //}
427         } 
428         */
429         if (pr.xtype == "") {
430             return;
431         }
432         if (pr.xtype  == "Roo" ) {
433                         this.roo_projectsettings_pop.show(btn,pr);
434                         return;
435                 }
436
437                 // gtk..
438                 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
439         
440         }
441         
442         
443         // ----------- object adding
444         public void objectAddInit()
445         {
446
447                 this.rightpalete  = new Xcls_PopoverAddObject();
448                 this.rightpalete.mainwindow = this.win;
449                 this.rightpalete.ref();  /// really?
450                 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
451  
452
453                 var stage = this.win.objectview.el.get_stage();
454                 stage.set_background_color(  Clutter.Color.from_string("#000"));
455                  */
456         }
457         
458         // -----------  properties adding list...
459         // listener uses the properties 
460         public void propsAddInit()
461         {
462         // Add properties
463                 this.add_props  = new Xcls_PopoverAddProp();
464                 this.add_props.mainwindow = this.win;
465                 this.add_props.ref();  /// really?
466                 // don't need to add it..
467                 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
468  
469
470                 //var  stage = this.win.addpropsview.el.get_stage();
471                 //stage.set_background_color(  Clutter.Color.from_string("#000"));
472
473
474                 this.add_props.select.connect( (prop) => {
475                          
476                         this.left_props.addProp(prop);
477                 });
478
479         }
480         public void propsAddShow()
481         {
482
483         }
484         public void propsAddHide()
485         {
486         
487         }
488
489  
490         // ----------- Add / Edit listener
491         // listener uses the properties 
492         //public void listenerInit()     { }
493         public void listenerShow()
494         {
495
496         }
497         public void listenerHide()
498         {
499         
500         }
501
502         // -------------- codeEditor
503
504         public void codeEditInit()
505         {
506                 this.code_editor_tab  = new  Editor();
507                 //this.code_editor.ref();  /// really?
508                 this.win.codeeditviewbox.el.add(this.code_editor_tab.el);
509                 
510                 this.win.codeeditviewbox.el.hide();
511                 this.code_editor_tab.window = this.win;
512  
513                 // editor.save...
514
515                 this.code_editor_tab.save.connect( () => {
516                         this.file.save();
517                         this.left_tree.model.updateSelected();
518                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
519                                    this.window_rooview.requestRedraw();
520                         } else {
521                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
522                         }
523                          // we do not need to call spawn... - as it's already called by the editor?
524                          
525                 });
526                 
527         }
528         /*
529         public void codePopoverEditInit()
530         {
531                 this.code_editor_popover  = new  Xcls_PopoverEditor();
532                 //this.code_editor.ref();  /// really?
533                  
534                 this.code_editor_popover.setMainWindow( this.win);
535   
536                 this.code_editor_popover.editor.save.connect( () => {
537                         this.file.save();
538                         this.left_tree.model.updateSelected();
539                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
540                                    this.window_rooview.requestRedraw();
541                         } else {
542                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
543                         }
544                          // we do not need to call spawn... - as it's already called by the editor?
545                          
546                 });
547                 
548         }
549         */
550         // ----------- list of projects on left
551         /*
552         public void  projectListInit() 
553         {
554
555                 this.left_projects = new Xcls_WindowLeftProjects();
556                  this.left_projects.ref();
557                  this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
558                  this.left_projects.el.show_all();
559                  this.left_projects.project_selected.connect((proj) => {
560                         this.buttonsShowHide();
561                         proj.scanDirs();
562                         this.clutterfiles.loadProject(proj);
563                 
564                  });
565
566         }
567         */
568         
569         
570         // ----------- file view
571         public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
572         {
573                 this.popover_files.show(btn, project, new_window);
574         
575         }
576         
577         
578  
579         public void fileDetailsInit()
580         {
581                 this.file_details = new Xcls_PopoverFileDetails();
582                 this.file_details.mainwindow = this.win;
583                 // force it modal to the main window..
584                 
585                 this.file_details.success.connect((project,file) =>
586                 {
587                         this.fileViewOpen(file, this.file_details.new_window,  -1);
588                 });
589
590         }
591         
592         
593         public void gotoLine(int line)
594         {
595         
596                 if (file.xtype == "PlainFile") {
597                     this.switchState (State.CODEONLY); 
598                         if (line> -1) {
599                                 this.code_editor_tab.scroll_to_line(line);
600                         }
601                 } else {
602                 
603                         this.switchState (State.PREVIEW); 
604                          
605                         if (file.project.xtype == "Gtk" && line> -1 ) {
606                                 // fixme - show the editing tab.
607                                 this.window_gladeview.scroll_to_line(line);
608                         } 
609                         // fixme - what about Roo?
610
611                 }
612         
613         }
614         
615         public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
616         {
617                 var existing = BuilderApplication.getWindow(file);
618                 
619                 if (existing != null) {
620                         existing.el.present();
621                         existing.windowstate.gotoLine(line);
622                         return;
623                 }
624                 
625                 if (new_window) {
626                         BuilderApplication.newWindow(file, line);
627                         return;
628                 }
629                 
630                 
631                 this.win.project = file.project;
632                 this.project = file.project;
633                 this.file = file;
634                 BuilderApplication.updateWindows();
635                 
636                 if (file.xtype == "PlainFile") {
637                         this.win.codeeditviewbox.el.show();
638                         this.switchState (State.CODEONLY); 
639                         file.loadItems();
640                         this.code_editor_tab.show(file, null, null);
641                          
642                 } else {
643                 
644                         this.switchState (State.PREVIEW); 
645                         // this triggers loadItems..
646                         this.left_tree.model.loadFile(file);
647                          
648
649                 }
650                 this.gotoLine(line);
651         
652                 var ctr= this.win.rooviewbox.el;
653  
654         
655                 if (file.project.xtype == "Roo" ) { 
656                     // removes all the childe elemnts from rooviewbox
657                 
658                         ctr.foreach( (w) => { ctr.remove(w); });
659  
660                         ctr.add(this.window_rooview.el);
661  
662                         if (file.xtype != "PlainFile") {       
663  
664                                 this.window_rooview.loadFile(file);
665                                 this.window_rooview.el.show_all();
666                         }
667  
668                         
669
670                 } else {
671                         ctr.foreach( (w) => { ctr.remove(w); });
672
673                         ctr.add(this.window_gladeview.el);
674  
675                         if (file.xtype != "PlainFile") {    
676                                 
677                                 this.window_gladeview.loadFile(file);
678                                 this.window_gladeview.el.show_all();
679                         }
680  
681                 }
682                 print("OPEN : " + file.name);
683                 if (file.xtype != "PlainFile") { 
684                         // hide the file editor.
685                    this.win.codeeditviewbox.el.hide();
686                         //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
687                 }
688                 this.win.setTitle(file.project.name + " : " + file.name);
689                          
690
691         }
692  
693  
694          /*
695         public void fileViewOpenPlain(string fname)
696         {
697                 
698                 this.switchState (State.CODEONLY); 
699                 this.code_editor.showPlainFile(fname);
700         }
701  */
702          
703         // ---------  webkit view
704         public void webkitViewInit()
705         {
706                 this.window_rooview  =new Xcls_WindowRooView();
707                 this.window_rooview.main_window = this.win;
708                 this.window_rooview.ref();
709                 this.win.rooviewbox.el.add(this.window_rooview.el);
710                 
711                 this.window_rooview.el.show_all();
712                 this.win.rooviewbox.el.hide();
713         
714         }
715
716         // ------ Gtk  - view
717
718         public void gtkViewInit()
719         {
720
721                 
722                 
723                 this.window_gladeview  =new Xcls_GtkView( );
724                 this.window_gladeview.ref();
725                 this.window_gladeview.main_window = this.win;
726  
727         }
728         
729
730         
731         
732         public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
733         {
734                 var ae =  this.left_tree.getActiveElement();
735                 if (ae == null) {
736                                 return;
737                 }
738                 this.rightpalete.hide(); 
739                 
740                 this.add_props.el.show_all(); 
741                 this.add_props.show(
742                         this.win.project.palete, //Palete.factory(this.win.project.xtype), 
743                          sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
744                         ae.fqn(),
745                         btn
746                         
747                 );
748         }
749         
750         public void showAddObject(Gtk.Widget btn)
751         {
752          
753                  var n = this.left_tree.getActiveElement();
754                 this.add_props.hide();
755                 this.rightpalete.el.show_all();
756                 this.rightpalete.show(
757                         this.left_tree.getActiveFile().palete(), 
758                         n == null ? "*top" : n.fqn(),
759                         btn
760                 );
761         }
762          
763                  
764         
765         public void switchState(State new_state)
766         {
767                 
768                 // if the new state and the old state are the same..
769                 
770                 if (new_state == this.state) {
771                         return;
772                 }
773                 
774                 // anything to do beforehand?
775                 
776                 switch (this.state) {
777                          
778                  
779                         
780                         case State.PREVIEW:
781                                 // stop editing the editor tab.
782                                 // always save before calling switch state to preview?
783                                 
784                                 this.code_editor_tab.reset();
785                                  
786                                 if (this.left_tree.getActiveFile() != null) {
787                                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
788                                                  this.window_rooview.createThumb();
789                                          } else {
790                                                   this.window_gladeview.createThumb();
791                                           }
792                                 }
793                                 // normally we are going from preview to another state.
794                                 // and different windows hide the preview in differnt ways..
795                                 
796                                 break;
797                                 
798          }
799                          
800                 this.state = new_state;
801                 this.buttonsShowHide();
802                 
803                 switch (this.state) {
804
805                         case State.PREVIEW:  // this is the default state when working...
806                                 this.win.leftpane.el.show();
807                                 this.win.editpane.el.show(); // holder for tree and properties..
808                             this.win.rooviewbox.el.show();
809                                 this.win.codeeditviewbox.el.hide();
810                                 break;
811
812                         case State.CODE:
813                                 this.win.leftpane.el.show();
814                                 this.win.editpane.el.show();
815                                 this.win.rooviewbox.el.hide();
816                                 this.win.codeeditviewbox.el.show();
817                                 this.code_editor_tab.el.show_all();
818                                 break;
819
820                         case State.CODEONLY:
821                                 this.win.leftpane.el.hide();
822                                 this.win.codeeditviewbox.el.show();
823                                 this.win.rooviewbox.el.hide();
824                                 this.code_editor_tab.el.show_all();
825                                 break;
826
827                         case State.NONE:
828                                 break;
829
830                 }
831
832         }
833   
834
835         // -- buttons show hide.....
836
837         public void buttonsShowHide()
838         {
839                 // basically hide everything, then show the relivant..
840
841                 // top bar btns
842                 //this.win.openbtn.el.hide();
843                 //this.win.openbackbtn.el.hide();
844                 
845                 //this.win.backbutton.el.hide();
846                 
847
848                  
849          
850         
851         
852                 this.win.search_entry.el.hide();
853                 this.win.search_results.el.hide();
854                 switch (this.state) {
855                         
856                         case State.PREVIEW:  // this is the default state when working...
857                            
858                                  
859                                  
860                                 
861                                  
862                                 this.win.search_entry.el.show();
863                                 
864                         //      this.win.openbtn.el.show();
865                                 
866                                 break;
867                         
868                         case State.CODEONLY: 
869                         //      this.win.openbtn.el.show();
870                                 this.win.search_entry.el.show();
871                                 break;
872                  
873                          
874                  /*
875                         case State.FILES:
876                                 if (this.left_projects.getSelectedProject() != null ) {
877                                         if (this.left_tree.getActiveFile() != null) {
878                                          
879                                                 this.win.openbackbtn.el.show();
880                                         }
881                                         this.win.addfilebutton.el.show();
882                                         this.win.search_entry.el.show();
883                                         this.win.projecteditbutton.el.show(); 
884                                 } 
885                                 
886                                          
887                                 this.win.addprojectbutton.el.show();
888                                 this.win.delprojectbutton.el.show();
889                                 
890                                 
891                                 
892                                 
893                                 break;
894                                 */
895                 }
896                 
897                 
898
899         }
900         
901         
902         public void showCompileResult(Json.Object obj)
903                 {
904                         // vala has finished compiling...
905  
906                         // stop the spinner...
907                         GLib.debug("vala compiled Built Project: %s    Window Project %s",
908                                 
909                         BuilderApplication.valasource.file == null ? "No file?" : (
910                         
911                                 BuilderApplication.valasource.file.project == null  ? "No Project" : BuilderApplication.valasource.file.project.fn
912                         ),
913                         this.project != null ? this.project.fn : "No Project?"
914                         );
915                                 
916                         
917                         
918                         if (this.project != null && 
919                         BuilderApplication.valasource.file != null &&   
920                         BuilderApplication.valasource.file.project != null &&                           
921                             this.project.fn != BuilderApplication.valasource.file.project.fn) {
922                                 GLib.debug("skip update - not our project");
923                                 return;
924                         }
925                         
926                         var generator = new Json.Generator ();
927                         var n  = new Json.Node(Json.NodeType.OBJECT);
928                         n.init_object(obj);
929                         generator.set_root (n);
930                         print("result :%s", generator.to_data (null));
931                         
932                         
933                         var buf = this.code_editor_tab.buffer;
934                         buf.check_running = false;
935                         var has_errors = false;
936                                       
937                         if (obj.has_member("ERR-TOTAL")) {
938                                 if (obj.get_int_member("ERR-TOTAL")> 0) {
939                                         has_errors = true;
940                                 }
941                                  this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
942                         } else {
943                                  this.win.statusbar_errors.setNotices( new Json.Object() , 0);
944                         }    
945                         
946                         if (obj.has_member("WARN-TOTAL")) {
947
948                                  this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
949                         } else {
950                                  this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
951                                  
952                         }
953                         if (obj.has_member("DEPR-TOTAL")) {
954                                 
955                                  this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"),  (int) obj.get_int_member("DEPR-TOTAL"));
956                                  
957                         } else {
958                                 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
959                         }
960                         //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
961                         if ( this.state == State.CODEONLY) {
962                                 buf.highlightErrorsJson("ERR", obj); 
963                                 buf.highlightErrorsJson("WARN", obj);
964                                 buf.highlightErrorsJson("DEPR", obj);
965                         }
966                         
967                         this.win.statusbar_compilestatus_label.el.hide();
968                         this.win.statusbar_run.el.hide();
969                         if (!has_errors) { 
970                                 this.win.statusbar_compilestatus_label.el.show();
971                                 this.win.statusbar_run.el.show();
972                         }
973                         if (this.file.xtype == "Gtk") {
974                                 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
975                                 var gbuf =   this.window_gladeview.sourceview;
976                                 gbuf.highlightErrorsJson("ERR", obj);
977                                 gbuf.highlightErrorsJson("WARN", obj);
978                                 gbuf.highlightErrorsJson("DEPR", obj);                  
979                                 
980                                 if (!has_errors) {
981                                         this.win.statusbar_run.el.show();
982                                 }
983                         
984                    }
985                    
986                    if (this.file.xtype == "Roo") {
987                                 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
988                                 var gbuf =   this.window_rooview.sourceview;
989                                 gbuf.highlightErrorsJson("ERR", obj);
990                                 gbuf.highlightErrorsJson("WARN", obj);
991                                 gbuf.highlightErrorsJson("DEPR", obj);                  
992                         
993                    }
994                     
995                         this.last_compile_result = obj;
996                         
997                         
998                 }
999         
1000 }
1001
1002