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