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             var f = File.new_for_path (path) ;
28             var info = f.query_info ("standard::*", 0);
29             var ct = info.get_content_type();
30             this.content_type = ct;
31             var cts = ct.split("/");
32             this.language = "plain-text";
33             
34             if (ct.length > 1 && cts.length > 1) { 
35                     
36                     this.language = cts[1];
37                     
38                     this.language = (new Regex("^x-")).replace( this.language, this.language.length, 0, "");
39                     print("got language %s\n", this.language);
40                     
41             }
42              
43             // fixme...
44
45             
46             this.contents = "";
47             
48             // super?!?!
49             this.id = "file-plain-%d".printf(plid++);
50             //console.dump(this);
51             // various loader methods..
52
53             // Class = list of arguments ... and which property to use as a value.
54        
55
56             
57             
58         }
59           
60
61         /*
62         setNSID : function(id)
63         {
64             
65             this.items[0]['*class'] = id;
66             
67             
68         },
69         getType: function() {
70             return 'Gtk';
71         },
72         */
73
74         public   override void   removeFiles() {
75                 if (FileUtils.test(this.path, FileTest.EXISTS)) {
76                         GLib.FileUtils.remove(this.path);
77                 }
78                  
79         }
80     
81         public   override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
82         {
83            
84                GLib.FileUtils.get_contents(this.path, out this.contents);
85                this.loaded = true;
86         }
87      
88         
89                 
90         public override string toSourcePreview()
91         {
92                          return "";
93                 }
94                 public override void setSource(string str) {
95                         this.contents = str;
96                 }
97         public override string toSource()
98         {
99                         return this.contents;
100             
101              
102             
103         }
104                 
105         public override void save() {
106             this.writeFile(this.path, this.contents);
107             
108         }
109             // ignore these calls.
110         public override void saveHTML ( string html ) {}
111             
112                     
113         /** 
114          *  saveJS
115          * 
116          * save as a javascript file.
117          * why is this not save...???
118          * 
119          */ 
120          
121    
122         string getHelpUrl(string cls)
123         {
124             return ""; 
125         }
126         public override void  findTransStrings(Node? node )
127                 {
128                         // not yet..
129                 }
130         
131         
132           
133
134                 
135
136         }
137 }
138
139
140