Fix #8003 - undo code
[roobuilder] / src / JsRender / Gtk.vala
index df9a73e..fad040f 100644 (file)
@@ -17,10 +17,17 @@ namespace JsRender {
        public  class Gtk : JsRender
        {
           
+          
+          public Project.Gtk gproject { 
+                       get {
+                               return (Project.Gtk) this.project;
+                       }
+                       private set {}
+               }
 
            public Gtk(Project.Project project, string path) {
            
-               aconstruct( project, path);
+               base( project, path);
                this.xtype = "Gtk";
                this.language = "vala";
                
@@ -101,13 +108,17 @@ namespace JsRender {
                        var obj = node.get_object ();
                
                        this.name = obj.get_string_member("name");
-                       this.parent = obj.get_string_member("parent");
-                       this.title = obj.get_string_member("title");
                
                        if (obj.has_member("build_module")) { // should check type really..
                                this.build_module = obj.get_string_member("build_module");
                        }
+                       if (obj.has_member("gen_extended")) { // should check type really..
+                               this.gen_extended = obj.get_boolean_member("gen_extended");
+                       }
+                       
                         
+                       
                        // load items[0] ??? into tree...
                        var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
                        bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
@@ -120,14 +131,17 @@ namespace JsRender {
                        ) {
                                var ar = obj.get_array_member("items");
                                var tree_base = ar.get_object_element(0);
-                               this.tree = new Node();
-                               this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
-
+                               this.loadTree(tree_base,  int.parse(bjs_version_str));
                        }
-                       NodeToVala.mungeFile(this); // force line numbering..
+                       this.gen_extended ? 
+                               NodeToValaExtended.mungeFile(this) :
+                               NodeToValaWrapped.mungeFile(this); // force line numbering..?? should we call toSourceCode???
                        this.loaded = true;
+                       this.updateUndo();
                
                }
+               
+               
             
            
        
@@ -137,25 +151,49 @@ namespace JsRender {
                }
            public override void setSource(string str) {}
            
+           int last_source_version = -2;
+           string last_source;
            public override string toSourceCode() // no seed support currently.
            {
-                   return  NodeToVala.mungeFile(this);
+                   if (this.version == this.last_source_version) {
+                       GLib.debug("toSource - using Cache");
+                       return this.last_source;
+               }
+               GLib.debug("toSource - generating %s", this.gen_extended  ? "Extended": "Wrapped");
+               
+                   this.last_source =          this.gen_extended ? 
+                               NodeToValaExtended.mungeFile(this) :
+                               NodeToValaWrapped.mungeFile(this);
+                               
+                   this.last_source_version = this.version;
+                   
+                   
+                   
+                   return this.last_source;
+                   
            }
            
            // this is only used by dumping code...
            public override string toSource() // no seed support currently.
            {
                 
-                        return  NodeToVala.mungeFile(this);
+                        return  this.toSourceCode();
                
                
            }
        
-           public override void save() {
+           public override void save() 
+           {
                this.saveBJS();
                // this.saveJS(); - disabled at present.. project settings will probably enable this later..
        
                this.saveVala();
+
+                       
+               this.getLanguageServer().document_save.begin(this, (obj, res) => {
+                       this.getLanguageServer().document_save.end(res);
+               });
+               BuilderApplication.showSpinner("spinner", "document save send");                
            }
                // ignore these calls.
            public override void saveHTML ( string html ) {}
@@ -190,11 +228,40 @@ namespace JsRender {
                                return;
                        }
                        var fn = this.targetName();
-                       print("WRITE :%s\n " , fn);
-                       this.writeFile(fn,  NodeToVala.mungeFile(this));
+                       GLib.debug("WRITE :%s\n " , fn);
+                       try {
+                               this.writeFile(fn, this.toSourceCode());
+               } catch (GLib.Error e) {}
                
                
            }
+           
+           
+           public void updateCompileGroup(string old_target, string new_target) 
+           {
+               if (old_target == new_target) {
+                       return;
+               }
+               if (old_target != "") {
+                       if (this.gproject.compilegroups.has_key(old_target)) {
+                               var cg = this.gproject.compilegroups.get(old_target);
+                               if (cg.sources.contains(this.relpath)) {
+                                       cg.sources.remove(this.relpath);
+                                       }
+                               }
+                       }
+                if (new_target != "") {
+                       if (this.gproject.compilegroups.has_key(new_target)) {
+                               var cg = this.gproject.compilegroups.get(new_target);
+                               if (!cg.sources.contains(this.relpath)) {
+                                       cg.sources.add(this.relpath);
+                                       }
+                               }
+                       }
+           
+           
+           }
+           
                /*
            valaCompileCmd : function()
            {
@@ -219,12 +286,7 @@ namespace JsRender {
                
            },
            */
-           
-   
-           string getHelpUrl(string cls)
-           {
-               return "http://devel.akbkhome.com/seed/" + cls + ".html";
-           }
+            
            public override void  findTransStrings(Node? node )
                {
                        // not yet..
@@ -234,7 +296,10 @@ namespace JsRender {
                {
                        return  NodeToGlade.mungeFile(this);
                }
-         
+               public   override string language_id() 
+               {
+                       return "vala";
+               }