src/JsRender/PlainFile.vala
[app.Builder.js] / src / JsRender / PlainFile.vala
index 70ddf1d..94f86f1 100644 (file)
@@ -24,16 +24,25 @@ namespace JsRender {
             base( project, path);
             this.xtype = "PlainFile";
             
-            var f = File.new_for_path (path) ;
-            var info = f.query_info ("standard::*", 0);
-            var ct = info.get_content_type();
-            var cts = ct.split("/");
-            this.language = "plain-text";
+            // if the file does not exist...
+            if (GLib.FileUtils.test(path, GLib.FileTest.EXISTS)) {
+                       var f = File.new_for_path (path) ;
+                       var info = f.query_info ("standard::*", 0);
+                       var ct = info.get_content_type();
+                   this.content_type = ct;
+            } else {
+                       this.content_type = "text/plain"; // hopefully..
+                       var ar = path.split(".");
+                       var ext = ar[ar.length -1]; // hopefully not fail...
+                       
+                       switch(ext) { 
+                               case "vala";
+                                       
+                       
             
-            if (ct.length > 1 && cts.length > 1) { 
-                    
-                    this.language = cts[1];
             }
+       
+            this.language = "";
              
             // fixme...
 
@@ -76,8 +85,8 @@ namespace JsRender {
        public   override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
        {
           
-          GLib.FileUtils.get_contents(this.path, out this.contents);
-          
+              GLib.FileUtils.get_contents(this.path, out this.contents);
+              this.loaded = true;
        }
      
         
@@ -98,7 +107,15 @@ namespace JsRender {
         }
                
         public override void save() {
-            this.writeFile(this.path, this.contents);
+               if (!this.loaded) {
+                       print("Ignoring Save  - as file was never loaded?\n");
+                       return;
+               }
+               try { 
+                   this.writeFile(this.path, this.contents);
+            } catch (GLib.Error e) {
+                   // error ???
+               }
             
         }
            // ignore these calls.