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             var cts = ct.split("/");
31             this.language = "plain-text";
32             
33             if (ct.length > 1 && cts.length > 1) { 
34                     
35                     this.language = cts[1];
36                     
37                     this.language = (new Regex("^x-")).replace( this.language, this.language.length, 0, "");
38                     print("got language %s\n", this.language);
39                     
40             }
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            
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             this.writeFile(this.path, this.contents);
106             
107         }
108             // ignore these calls.
109         public override void saveHTML ( string html ) {}
110             
111                     
112         /** 
113          *  saveJS
114          * 
115          * save as a javascript file.
116          * why is this not save...???
117          * 
118          */ 
119          
120    
121         string getHelpUrl(string cls)
122         {
123             return ""; 
124         }
125         public override void  findTransStrings(Node? node )
126                 {
127                         // not yet..
128                 }
129         
130         
131           
132
133                 
134
135         }
136 }
137
138
139