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