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 gid = 1;
16
17   
18     public  class PlainFile : JsRender
19     {
20        
21
22         public PlainFile(Project.Project project, string path) {
23         
24             base( project, path);
25             this.xtype = "PlainFile";
26             
27             
28             // fixme...
29             this.language = "vala";
30             
31           
32             
33             // super?!?!
34             this.id = "file-plain-%d".printf(gid++);
35             //console.dump(this);
36             // various loader methods..
37
38             // Class = list of arguments ... and which property to use as a value.
39        
40
41             
42             
43         }
44           
45
46         /*
47         setNSID : function(id)
48         {
49             
50             this.items[0]['*class'] = id;
51             
52             
53         },
54         getType: function() {
55             return 'Gtk';
56         },
57         */
58
59                 public   override void   removeFiles() {
60                         if (FileUtils.test(this.pat, FileTest.EXISTS)) {
61                                 GLib.FileUtils.remove(this.pat);
62                         }
63                          
64                 }
65         
66                 public   override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
67                 {
68                    return;
69                 }
70          
71         
72                 
73         public override string toSourcePreview()
74         {
75                         return "";
76                 }
77       
78         public override string toSource()
79         {
80         
81             
82             if (this.tree == null) {
83                 return "";
84             }
85             
86             // var data = JSON.parse(JSON.stringify(this.items[0]));
87             // we should base this on the objects in the tree really..
88             string[]  inc = { "Gtk", "Gdk", "Pango", "GLib", "Gio", "GObject", 
89                 "GtkSource", "WebKit", "Vte" }; //, "GtkClutter" , "Gdl"];
90             var src = "";
91                          
92             for (var i=0; i< inc.length; i++) {
93                                 var e = inc[i];
94                 src += e+" = imports.gi." + e +";\n";
95             }
96             
97             src += "console = imports.console;\n"; // path?!!?
98             src += "XObject = imports.XObject.XObject;\n"; // path?!!?
99             
100             
101             src += this.name + "=new XObject("+ this.mungeToString("    ") + ");\n";
102             src += this.name + ".init();\n";
103             // register it in the cache
104             src += "XObject.cache['/" + this.name + "'] = " + this.name + ";\n";
105             
106             
107             return src;
108             
109             
110         }
111                 
112         public override void save() {
113             this.saveBJS();
114             // this.saveJS(); - disabled at present.. project settings will probably enable this later..
115                 
116             this.saveVala();
117         }
118             // ignore these calls.
119         public override void saveHTML ( string html ) {}
120             
121                     
122         /** 
123          *  saveJS
124          * 
125          * save as a javascript file.
126          * why is this not save...???
127          * 
128          */ 
129           
130         void saveJS()
131         {
132              
133             var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".js";
134             print("WRITE :%s\n " , fn);
135             this.writeFile(fn, this.toSource());
136             
137         }
138         
139        void  saveVala()
140         {
141                 if (this.tree == null) {
142                         return;
143                 }
144                 var fn = GLib.Path.get_dirname(this.path) + "/" + this.name + ".vala";
145                 print("WRITE :%s\n " , fn);
146                         this.writeFile(fn,  NodeToVala.mungeFile(this));
147             
148             
149         }
150                 /*
151         valaCompileCmd : function()
152         {
153             
154             var fn = '/tmp/' + this.name + '.vala';
155             print("WRITE : " + fn);
156             File.write(fn, this.toVala(true));
157             
158             
159             
160             return ["valac",
161                    "--pkg",  "gio-2.0",
162                    "--pkg" , "posix" ,
163                    "--pkg" , "gtk+-3.0",
164                    "--pkg",  "libnotify",
165                    "--pkg",  "gtksourceview-3.0",
166                    "--pkg", "libwnck-3.0",
167                    fn ,   "-o", "/tmp/" + this.name];
168             
169            
170              
171             
172         },
173         */
174         
175    
176         string getHelpUrl(string cls)
177         {
178             return "http://devel.akbkhome.com/seed/" + cls + ".html";
179         }
180         public override void  findTransStrings(Node? node )
181                 {
182                         // not yet..
183                 }
184         
185         
186           
187
188                 
189
190         }
191 }
192
193
194