X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=src%2FJsRender%2FPlainFile.vala;h=69872879e17045d7ebda6b9aedebf6db5d9aed7b;hb=HEAD;hp=ad41f8dfa9818b6b2efbc5fd55492c3159c692db;hpb=7fc74a9cd41f24f708672eada69a3149d6d3d865;p=app.Builder.js diff --git a/src/JsRender/PlainFile.vala b/src/JsRender/PlainFile.vala index ad41f8dfa..69872879e 100644 --- a/src/JsRender/PlainFile.vala +++ b/src/JsRender/PlainFile.vala @@ -24,11 +24,30 @@ namespace JsRender { base( project, path); this.xtype = "PlainFile"; + // 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"; + this.loaded = true; + + } + + this.language = ""; + // fixme... - this.language = "vala"; + - this.contents = ""; + this.contents = ""; // super?!?! this.id = "file-plain-%d".printf(plid++); @@ -56,27 +75,29 @@ namespace JsRender { }, */ - public override void removeFiles() { - if (FileUtils.test(this.path, FileTest.EXISTS)) { - GLib.FileUtils.remove(this.path); - } - + public override void removeFiles() { + if (FileUtils.test(this.path, FileTest.EXISTS)) { + GLib.FileUtils.remove(this.path); } - - public override void loadItems() throws GLib.Error // : function(cb, sync) == original was async. - { - - GLib.FileUtils.get_contents(this.path, out this.contents); - - } - + + } + + public override void loadItems() throws GLib.Error // : function(cb, sync) == original was async. + { + if (this.loaded) { + return; + } + GLib.FileUtils.get_contents(this.path, out this.contents); + this.loaded = true; + } + public override string toSourcePreview() { return ""; } - public override string setSource(string str) { + public override void setSource(string str) { this.contents = str; } public override string toSource() @@ -86,9 +107,23 @@ namespace JsRender { } - + public override string toSourceCode() + { + return this.contents; + + + + } 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.