src/JsRender/PlainFile.vala
[app.Builder.js] / src / JsRender / PlainFile.vala
1
2 /**
3  * 
4  *  this is the code represents a File when using the Gtk view..
5  *   
6  *  It ues NodeToGtk
7  * 
8  * 
9  */
10
11 namespace JsRender {
12
13
14  
15     int plid = 1;
16
17   
18     public  class PlainFile : JsRender
19     {
20                 string contents;
21
22         public PlainFile(Project.Project project, string path) {
23         
24             base( project, path);
25             this.xtype = "PlainFile";
26             
27             // if the file does not exist...
28             if (GLib.FileUtils.test(path, GLib.FileTest.EXISTS)) {
29                         var f = File.new_for_path (path) ;
30                         var info = f.query_info ("standard::*", 0);
31                         var ct = info.get_content_type();
32                     this.content_type = ct;
33             } else {
34                         var ar = path.split(".");
35                         var ext = ar[ar.length -1]; // hopefully not fail...
36                         
37             
38             }
39        
40             this.language = "";
41              
42             // fixme...
43
44             
45             this.contents = "";
46             
47             // super?!?!
48             this.id = "file-plain-%d".printf(plid++);
49             //console.dump(this);
50             // various loader methods..
51
52             // Class = list of arguments ... and which property to use as a value.
53        
54
55             
56             
57         }
58           
59
60         /*
61         setNSID : function(id)
62         {
63             
64             this.items[0]['*class'] = id;
65             
66             
67         },
68         getType: function() {
69             return 'Gtk';
70         },
71         */
72
73         public   override void   removeFiles() {
74                 if (FileUtils.test(this.path, FileTest.EXISTS)) {
75                         GLib.FileUtils.remove(this.path);
76                 }
77                  
78         }
79     
80         public   override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
81         {
82            
83                GLib.FileUtils.get_contents(this.path, out this.contents);
84                this.loaded = true;
85         }
86      
87         
88                 
89         public override string toSourcePreview()
90         {
91                          return "";
92                 }
93                 public override void setSource(string str) {
94                         this.contents = str;
95                 }
96         public override string toSource()
97         {
98                         return this.contents;
99             
100              
101             
102         }
103                 
104         public override void save() {
105                 if (!this.loaded) {
106                         print("Ignoring Save  - as file was never loaded?\n");
107                         return;
108                 }
109                 try { 
110                     this.writeFile(this.path, this.contents);
111             } catch (GLib.Error e) {
112                     // error ???
113                 }
114             
115         }
116             // ignore these calls.
117         public override void saveHTML ( string html ) {}
118             
119                     
120         /** 
121          *  saveJS
122          * 
123          * save as a javascript file.
124          * why is this not save...???
125          * 
126          */ 
127          
128    
129         string getHelpUrl(string cls)
130         {
131             return ""; 
132         }
133         public override void  findTransStrings(Node? node )
134                 {
135                         // not yet..
136                 }
137         
138         
139           
140
141                 
142
143         }
144 }
145
146
147