c54a9b21e4c59d95a288aca16192aa9f2ed24f2d
[roobuilder] / 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             aconstruct( project, path);
25             this.xtype = "PlainFile";
26             this.content_type = "text/plain";
27             
28             // if the file does not exist...
29             if (GLib.FileUtils.test(path, GLib.FileTest.EXISTS)) {
30                         var f = File.new_for_path (path) ;
31                         try {
32                                     var info = f.query_info ("standard::*", 0);
33                                     var ct = info.get_content_type();
34                                 this.content_type = ct;
35                         } catch (GLib.Error e) {}
36                        
37             } else {
38                         this.content_type = "text/plain"; // hopefully..
39 //                      var ar = path.split(".");
40   //                    var ext = ar[ar.length -1]; // hopefully not fail...
41                         
42   //                    switch(ext) { 
43         //                      case "vala";
44                         this.loaded = true;
45                         
46             
47             }
48        
49             this.language = "";
50              
51             // fixme...
52
53             
54             this.contents = "";
55             
56             // super?!?!
57             this.id = "file-plain-%d".printf(plid++);
58             //console.dump(this);
59             // various loader methods..
60
61             // Class = list of arguments ... and which property to use as a value.
62        
63
64             
65             
66         }
67           
68
69         /*
70         setNSID : function(id)
71         {
72             
73             this.items[0]['*class'] = id;
74             
75             
76         },
77         getType: function() {
78             return 'Gtk';
79         },
80         */
81
82         public   override void   removeFiles() {
83                 if (FileUtils.test(this.path, FileTest.EXISTS)) {
84                         GLib.FileUtils.remove(this.path);
85                 }
86                  
87         }
88     
89         public   override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
90         {
91                         if (this.loaded) {
92                                 return;
93                         }
94                 GLib.FileUtils.get_contents(this.path, out this.contents);
95                 this.loaded = true;
96         }
97      
98         
99                 
100         public override string toSourcePreview()
101         {
102                          return "";
103                 }
104                 public override void setSource(string str) {
105                         this.contents = str;
106                 }
107         public override string toSource()
108         {
109                         return this.contents;
110             
111              
112             
113         }
114                  public override string toSourceCode()
115         {
116                         return this.contents;
117             
118              
119             
120         }
121         public override void save() {
122                 if (!this.loaded) {
123                         print("Ignoring Save  - as file was never loaded?\n");
124                         return;
125                 }
126                 try { 
127                     this.writeFile(this.path, this.contents);
128             } catch (GLib.Error e) {
129                     // error ???
130                 }
131             
132         }
133             // ignore these calls.
134         public override void saveHTML ( string html ) {}
135             
136                     
137         /** 
138          *  saveJS
139          * 
140          * save as a javascript file.
141          * why is this not save...???
142          * 
143          */ 
144          
145    
146         
147         public override void  findTransStrings(Node? node )
148                 {
149                         // not yet..
150                 }
151         
152         public override string toGlade() 
153                 {
154                         return "Roo files do not convert to glade";
155                 }
156             public override string targetName()
157             {
158                 return this.path;
159         }
160
161                 
162
163         }
164 }
165
166
167