src/Builder4/WindowState.vala
[app.Builder.js] / src / Builder4 / WindowState.vala
index f00b51d..bb2c15b 100644 (file)
@@ -16,14 +16,21 @@ public class WindowState : Object
                PROP,
                LISTENER,
                CODE,
+               CODEONLY,
                FILES,
-               PROJECT // project settings..
+               PROJECT, // project settings..
+               FILEPROJECT // project when in file mode
        }
 
        public State state = State.NONE;
 
        public bool children_loaded = false;
 
+        
+       public Project.Project project;
+       public JsRender.JsRender file;
+       
+       
        
        public Xcls_WindowLeftTree  left_tree;
        public Xcls_WindowAddProp   add_props;
@@ -44,6 +51,8 @@ public class WindowState : Object
        public Xcls_PopoverFileDetails file_details;
        
        
+       public Xcls_ValaCompileResults compile_results;
+       
        // dialogs??
        public Xcls_DialogPluginWebkit webkit_plugin;
        
@@ -85,12 +94,22 @@ public class WindowState : Object
                this.children_loaded = true;
                
                this.left_tree.node_selected.connect((sel) => {
-                       this.window_gladeview.sourceview.nodeSelected(sel);
+                       if (this.file.xtype == "Roo") { 
+                               this.window_rooview.sourceview.nodeSelected(sel);                       
+                       } else {
+                               this.window_gladeview.sourceview.nodeSelected(sel);
+                       }
                });
                this.valasource = new Palete.ValaSource();
                this.valasource.compiled.connect(this.valaCompiled);
                
+               this.compile_results = new  Xcls_ValaCompileResults();
+               this.compile_results.window = this.win;
+               this.valasource.compile_output.connect(this.compile_results.addLine);
                
+               this.win.statusbar_compilestatus_label.el.hide();
+               this.win.statusbar_run.el.hide();
+               this.win.search_results.el.hide();
        }
 
 
@@ -117,7 +136,7 @@ public class WindowState : Object
         
                this.left_tree.changed.connect(() => {
                        
-                       this.left_tree.model.file.save();
+                       this.file.save();
                        if (this.left_tree.getActiveFile().xtype == "Roo" ) {
                                   this.window_rooview.requestRedraw();
                        } else {
@@ -235,9 +254,9 @@ public class WindowState : Object
                                  this.window_gladeview.loadFile(this.left_tree.getActiveFile());
                        }
                        this.left_tree.model.updateSelected();
-                       this.left_tree.model.file.save();
-                       if (this.left_tree.model.file.xtype=="Gtk") {
-                               this.valasource.checkFileSpawn(this.left_tree.model.file);
+                       this.file.save();
+                       if (this.file.xtype=="Gtk") {
+                               this.valasource.checkFileSpawn(this.file);
                        }
                });
        
@@ -356,8 +375,13 @@ public class WindowState : Object
                // editor.save...
 
                this.code_editor.save.connect( () => {
-                        this.left_tree.model.file.save();
-                        this.left_tree.model.updateSelected();
+                       this.file.save();
+                       this.left_tree.model.updateSelected();
+                       if (this.left_tree.getActiveFile().xtype == "Roo" ) {
+                                  this.window_rooview.requestRedraw();
+                       } else {
+                                 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
+                       }
                         // we do not need to call spawn... - as it's already called by the editor?
                         
                });
@@ -388,7 +412,7 @@ public class WindowState : Object
                this.clutterfiles = new Xcls_ClutterFiles();
                this.clutterfiles.ref();
                stage.add_child(this.clutterfiles.el);
-               this.clutterfiles.el.show_all();
+               this.clutterfiles.el.show();
 
 
                this.clutterfiles.open.connect((file) => { 
@@ -419,46 +443,73 @@ public class WindowState : Object
 
        }
        
-       public void fileViewOpen(JsRender.JsRender file)
+       public void fileViewOpen(JsRender.JsRender file, int line = -1)
        {
                this.win.project = file.project;
-               this.switchState (State.PREVIEW); 
+               this.project = file.project;
+               this.file = file;
+               
+               
+               if (file.xtype == "PlainFile") {
+                       this.switchState (State.CODEONLY); 
+                       file.loadItems();
+                       this.code_editor.show(file, null, "", "");
+                       if (line> -1) {
+                               this.code_editor.scroll_to_line(line);
+                       }
+               } else {
+               
+                       this.switchState (State.PREVIEW); 
+                       // this triggers loadItems..
+                       this.left_tree.model.loadFile(file);
+                       if (file.project.xtype == "Gtk" && line> -1 ) {
+                               this.window_gladeview.scroll_to_line(line);
+                       }
+
+               }
        
-               this.left_tree.model.loadFile(file);
        
                var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
                var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
        
-               if (file.xtype == "Roo" ) { 
+               if (file.project.xtype == "Roo" ) { 
                        ctr.foreach( (w) => { ctr.remove(w); });
                        ctr_p.foreach( (w) => { ctr_p.remove(w); });
                        ctr.add(this.window_rooview.el);
-                       ctr_p.add(this.projectsettings.el);            
-                       this.window_rooview.loadFile(file);
-                       this.window_rooview.el.show_all();
+                       ctr_p.add(this.projectsettings.el);
+                       if (file.xtype != "PlainFile") {       
+                               this.window_rooview.loadFile(file);
+                               this.window_rooview.el.show_all();
+                       }
                        this.projectsettings.el.show_all();            
+                       
 
                } else {
                        ctr.foreach( (w) => { ctr.remove(w); });
                        ctr_p.foreach( (w) => { ctr_p.remove(w); });            
                        ctr.add(this.window_gladeview.el);
                        ctr_p.add(this.vala_projectsettings.el);
-                       this.window_gladeview.loadFile(file);
-                       this.window_gladeview.el.show_all();
+                       if (file.xtype != "PlainFile") {    
+                               this.window_gladeview.loadFile(file);
+                               this.window_gladeview.el.show_all();
+                       }
                        this.vala_projectsettings.el.show_all();
                }
                print("OPEN : " + file.name);
-               this.win.editpane.el.set_position(this.win.editpane.el.max_position);
-               this.win.setTitle(file.project.name + " : " +file.name);
-                        
-
+               if (file.xtype != "PlainFile") {    
+                       this.win.editpane.el.set_position(this.win.editpane.el.max_position);
                }
+               this.win.setTitle(file.project.name + " : " + file.name);
+                        
 
+       }
+        
        
        // ---------  webkit view
        public void webkitViewInit()
        {
                this.window_rooview  =new Xcls_WindowRooView();
+               this.window_rooview.main_window = this.win;
                this.window_rooview.ref();
                ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
                this.window_rooview.el.show_all();
@@ -499,6 +550,12 @@ public class WindowState : Object
        public void switchState(State new_state)
        {
                
+               // if the new state and the old state are the same..
+               
+               if (new_state == this.state) {
+                       return;
+               }
+               
                // save the easing state of everything..
                this.easingSaveAll();
                
@@ -524,20 +581,32 @@ public class WindowState : Object
                                 break;
                                
                        case State.CODE:
-
-
                                this.code_editor.saveContents();
                          
                                this.win.codeeditview.el.set_scale(0.0f,0.0f);
-                                break;
-
+                               break;
+                               
+                       case State.CODEONLY:
+                               // going from codeonly..
+                               this.win.leftpane.el.show();
+                               // enable re-calc of canvas..
+                           while (Gtk.events_pending()) { 
+                                       Gtk.main_iteration();
+                               }
+                               //this.code_editor.saveContents(); << not yet...
+                                
+                               this.win.rooview.el.show(); 
+                               this.win.codeeditview.el.set_scale(0.0f,0.0f);
+                                
+                               break;
 
                         case State.OBJECT:
                           
                                this.win.objectview.el.set_scale(0.0f,0.0f);
                                 break;
 
-                  case State.PROJECT:
+                       case State.FILEPROJECT:
+                       case State.PROJECT:
                                if (this.win.project.xtype == "Gtk") {
                                        this.vala_projectsettings.save();
                                } 
@@ -545,19 +614,24 @@ public class WindowState : Object
                                this.win.projecteditview.el.set_scale(0.0f,0.0f);
                                 break;
 
-                 case State.FILES:
+                 case State.FILES: // goes to preview or codeonly...
                                // hide files...
                                
-                               this.win.rooview.el.show_all();
+                               if (new_state == State.CODEONLY) {
+                                       this.win.rooview.el.hide();
+                               } else {
+                                       this.win.rooview.el.show();
+                               }
+                               
                                this.win.rooview.el.set_easing_duration(1000);
                                this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
                                this.win.rooview.el.set_scale(1.0f,1.0f);
                                this.win.rooview.el.set_pivot_point(0.5f,0.5f);
                                this.win.rooview.el.set_opacity(0xff);
-                          
+                               
                                
                           
-                                this.clutterfiles.el.set_easing_duration(1000);
+                               this.clutterfiles.el.set_easing_duration(1000);
                                this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
                                this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
                                this.clutterfiles.el.set_opacity(0);
@@ -622,12 +696,12 @@ public class WindowState : Object
                                this.win.rooview.el.set_pivot_point(1.0f,0.5f);
                                  
                                this.win.addpropsview.el.set_scale(1.0f,1.0f);
-                                break;
+                               break;
                   
                        case State.OBJECT:
                                 var n = this.left_tree.getActiveElement();
 
-                               if (this.left_tree.model.file == null) {
+                               if (this.file == null) {
                                        this.state =oldstate;
                                        this.buttonsShowHide();
                                        this.resizeCanvasElements();
@@ -635,7 +709,7 @@ public class WindowState : Object
                                        return;
                                }
                                
-                               if (n == null && this.left_tree.model.file.tree != null) {
+                               if (n == null && this.file.tree != null) {
                                        this.state = oldstate;
                                        this.buttonsShowHide();
                                        this.resizeCanvasElements();
@@ -648,68 +722,103 @@ public class WindowState : Object
 
                                
                          
-                       
+                               this.win.rooview.el.set_pivot_point(1.0f,0.5f);
                                this.win.objectview.el.set_scale(1.0f,1.0f);
                                 
                                break;
                   
                   
                        case State.CODE:
-
+                               this.win.codeeditview.el.show();
                                this.code_editor.el.show_all();
-                               
                                // caller needs to call editor - show....
-                                 
-                                this.win.codeeditview.el.set_scale(1.0f,1.0f);
-                                break;
+                               this.win.codeeditview.el.set_scale(1.0f,1.0f);
+                               this.win.rooview.el.set_pivot_point(1.0f,0.5f);
+
+                               break;
+
+                       case State.CODEONLY:
+                               // going to codeonly..
+                               this.win.codeeditview.el.show();
+                               // recalc canvas...
+                               //while (Gtk.events_pending()) { 
+                               //      Gtk.main_iteration();
+                               //}
+                               
+                               this.win.leftpane.el.hide();
+                               this.win.codeeditview.el.show();
+                               //while (Gtk.events_pending()) { 
+                               //      Gtk.main_iteration();
+                               //}
+                               
+                               
+                               this.code_editor.el.show_all();
+                           
+                               this.win.codeeditview.el.set_scale(1.0f,1.0f);
+                               this.win.rooview.el.set_pivot_point(1.0f,0.5f);
+                               break;
 
 
 
-                  case State.PROJECT:
 
-                          if (this.win.project.xtype == "Roo") {
+                       case State.PROJECT:
+                               this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
+                               
+                               if (this.win.project.xtype == "Roo") {
                                        this.projectsettings.el.show_all();
                                        this.projectsettings.show(this.win.project);
                                } else {
                                        this.vala_projectsettings.el.show_all();
                                        this.vala_projectsettings.show((Project.Gtk)this.win.project);
                                }
-
-                               this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
-                               
                                this.win.projecteditview.el.set_scale(1.0f,1.0f);
+                                
+                               break;
                                
-                          
+                       case State.FILEPROJECT:
+                               var pr = this.left_projects.getSelectedProject();
+                               if (pr.xtype == "Roo") {
+                                       this.projectsettings.el.show_all();
+                                       this.projectsettings.show(this.win.project);
+                               } else {
+                                       this.vala_projectsettings.el.show_all();
+                                       this.vala_projectsettings.show((Project.Gtk)this.win.project);
+                               }
+                               this.win.projecteditview.el.set_scale(1.0f,1.0f);
+                                
                                break;
                                
-                  case State.FILES:  // can only get here from PREVIEW state.. in theory..
+                  case State.FILES:  // can only get here from PREVIEW (or code-only) state.. in theory..
                                
    
                                this.win.editpane.el.hide(); // holder for tree and properties..
-                        
+                               
                                this.left_projects.el.show(); 
-                       
-                                this.win.rooview.el.set_easing_duration(1000);
+                               
+                               // rotate the preview to hidden...
+                               this.win.rooview.el.set_easing_duration(1000);
                                this.win.rooview.el.set_pivot_point(0.5f,0.5f);
                                this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
                                this.win.rooview.el.set_opacity(0);
-                               //el.set_scale(0.0f,0.0f);
-
+                        
+                               
+                               
+        
                                if (this.win.project != null) {
                                        this.left_projects.selectProject(this.win.project);
                                }
                         
                                
-                               this.clutterfiles.el.show_all();
+                               this.clutterfiles.el.show();
                                 
                                this.clutterfiles.el.set_easing_duration(1000);
                                this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
                                this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
                                this.clutterfiles.el.set_opacity(0xff);
                                
-                               
+                                
                                
                                break;
 
@@ -718,6 +827,11 @@ public class WindowState : Object
                this.resizeCanvasElements();
                this.easingRestoreAll();
                
+               // run the animation.. - then load files...
+               GLib.Timeout.add(500,  ()  =>{
+                        this.resizeCanvasElements();
+                        return false;
+               });
                        
        }
        
@@ -778,6 +892,7 @@ public class WindowState : Object
                
                switch ( this.state) {
                        case State.PREVIEW:
+                                
                                this.win.rooview.el.set_size(alloc.width-50, alloc.height);
                                break;
        
@@ -791,6 +906,7 @@ public class WindowState : Object
                
                           // this.win.rooview.el.save_easing_state();
                                //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
+                                
                                this.win.rooview.el.set_scale(0.5f, 0.5f);
                                //this.win.rooview.el.restore_easing_state();
                                break;
@@ -804,6 +920,14 @@ public class WindowState : Object
                           // this.win.rooview.el.restore_easing_state();
                                break;
                                
+                       case State.CODEONLY: 
+                               this.win.codeeditview.el.set_size(codesize, alloc.height);
+                               var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
+                               //this.win.rooview.el.save_easing_state();
+                               this.win.rooview.el.hide(); 
+                               this.win.rooview.el.set_scale(scale,scale);
+                          // this.win.rooview.el.restore_easing_state();
+                               break;  
                        case State.PROP:
                        case State.LISTENER:
                                 this.win.addpropsview.el.set_size(palsize, alloc.height);
@@ -827,9 +951,13 @@ public class WindowState : Object
        {
                // basically hide everything, then show the relivant..
 
-                this.win.backbutton.el.hide();
-       
-               this.win.projectbutton.el.hide(); // show file nav...
+               // top bar btns
+               this.win.openbtn.el.hide();
+               this.win.openbackbtn.el.hide();
+               
+               this.win.backbutton.el.hide();
+               
+
                this.win.editfilebutton.el.hide();
                this.win.projecteditbutton.el.hide();
                 
@@ -843,24 +971,42 @@ public class WindowState : Object
                this.win.addprojectbutton.el.hide();
                this.win.addfilebutton.el.hide();
                this.win.delprojectbutton.el.hide();
-                 
                
+               this.win.search_entry.el.hide();
+               this.win.search_results.el.hide();
                switch (this.state) {
                        
                        case State.PREVIEW:  // this is the default state when working...
                           
-                               this.win.projectbutton.el.show(); // show file nav...
+                               
                                this.win.editfilebutton.el.show();
                                this.win.projecteditbutton.el.show();
                                 
+                                
                                
                                this.win.objectshowbutton.el.show(); // add objects
                                this.win.addpropbutton.el.show();  
                                this.win.addlistenerbutton.el.show(); 
+                               this.win.search_entry.el.show();
+                               
+                               this.win.openbtn.el.show();
+                               
                                break;
                        
+                       case State.CODEONLY: 
+                               this.win.openbtn.el.show();
+       
+                               this.win.search_entry.el.show();
+                               break;
                   
                        case State.CODE: 
+                               this.win.search_entry.el.show();
+                               this.win.backbutton.el.show();
+                               this.win.objectshowbutton.el.show(); // add objects ?? can you do this from here?
+                               this.win.addpropbutton.el.show();  
+                               this.win.addlistenerbutton.el.show(); 
+                               break;
+                               // continue thru..
                        case State.PROP:
                        case State.LISTENER:
                        case State.OBJECT:
@@ -874,20 +1020,28 @@ public class WindowState : Object
                        case State.PROJECT: 
                                // anything else?
                                this.win.backbutton.el.show();
+                               
                                break;
                        
        
                        case State.FILES:
                                if (this.left_projects.getSelectedProject() != null ) {
                                        if (this.left_tree.getActiveFile() != null) {
-                                               this.win.backbutton.el.show();
+                                        
+                                               this.win.openbackbtn.el.show();
                                        }
                                        this.win.addfilebutton.el.show();
-                               }
+                                       this.win.search_entry.el.show();
+                                       this.win.projecteditbutton.el.show(); 
+                               } 
+                               
                                         
                                this.win.addprojectbutton.el.show();
                                this.win.delprojectbutton.el.show();
                                
+                               
+                               
+                               
                                break;
                }
                
@@ -903,8 +1057,12 @@ public class WindowState : Object
                        
                        var buf = this.code_editor.buffer;
                        buf.check_running = false;
+                       var has_errors = false;
                                      
                        if (obj.has_member("ERR-TOTAL")) {
+                               if (obj.get_int_member("ERR-TOTAL")> 0) {
+                                       has_errors = true;
+                               }
                                 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
                        } else {
                                 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
@@ -929,11 +1087,20 @@ public class WindowState : Object
                        buf.highlightErrorsJson("WARN", obj);
                        buf.highlightErrorsJson("DEPR", obj);
                        
-                       var gbuf =   this.window_gladeview.sourceview;
-                       gbuf.highlightErrorsJson("ERR", obj);
-                       gbuf.highlightErrorsJson("WARN", obj);
-                       gbuf.highlightErrorsJson("DEPR", obj);                  
+                       this.win.statusbar_compilestatus_label.el.hide();
+                       this.win.statusbar_run.el.hide();
+                       
+                       if (this.file.xtype == "Gtk") {
+                               this.win.statusbar_compilestatus_label.el.show();
+                               if (!has_errors) { 
+                                       this.win.statusbar_run.el.show();
+                               }
+                               var gbuf =   this.window_gladeview.sourceview;
+                               gbuf.highlightErrorsJson("ERR", obj);
+                               gbuf.highlightErrorsJson("WARN", obj);
+                               gbuf.highlightErrorsJson("DEPR", obj);                  
                        
+                  }
                        this.last_compile_result = obj;