4 public static Palete factory(xtype)
6 if (this.cache == null) {
7 this.cache = new Gee.HashMap<string,Palate>();
14 public class Palete : Object
17 static Gee.HashMap<string,Palate>? cache = null;
27 //map : false, // array of mappings left: [] , right : []
29 //items : false, // the tree of nodes.
34 string guessName(JsRender.Node ar) // turns the object into full name.
39 // eg. xns: Roo, xtype: XXX -> Roo.xxx
40 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
44 return ar['|xns'] +'.' + ar['xtype'];
49 * gather a list of potentional objects that can be added..
52 gatherList: function (existing) {
53 existing = existing || [];
54 // existing.push('*top'); // always have top
56 console.log("GATHER LIST? " + this.map.length);
59 function addRight(right) {
60 right.forEach(function(r) {
61 if (ret.indexOf(r) > -1) {
68 this.map.forEach(function(m) {
70 m.left.forEach( function(left) {
73 var l = left.replace(/:.*$/, '');
74 // print("chk:" + l + " in " + existing.join(','));
75 if (existing.indexOf(l) > -1) {
78 //return true; // no more needed..
92 getDropList : function(rval)
96 this.map.forEach( function(m) {
97 if (m.right.indexOf(rval) > -1) {
98 m.left.forEach(function(l) {
99 if (ret.indexOf(l) > -1) {
107 console.log("DROP LIST:");
116 findType : function (data, prop, value)
118 if (prop[0] == '|') {
121 return typeof(value);
125 findOptions : function(ename)
127 switch(ename.toLowerCase()) {
129 return [ 'true', 'false' ];
130 // everything else does not have options.
138 console.log("OOPS: = unknown type: " + ename);
142 confirmCanAdd: function(parent, child) {
143 // confirms that one obj can be added to another.
144 // returns true, for items, or list of properties that can hold it..
148 getDefaultPack: function(pname, cname) {
151 saveTemplate: function(name, data)
153 var gn = this.guessName(JSON.parse(data));
154 // store it in user's directory..
155 var appdir = GLib.get_home_dir() + '/.Builder';
157 if (!File.isDirectory(appdir+ '/' + gn)) {
158 File.mkdir(appdir+ '/' + gn);
160 File.write(appdir+ '/' + gn + '/' + name + '.json', data);
164 * list templates - in home directory (and app dir in future...)
165 * @param {String} name - eg. Gtk.Window..
166 * @return {Array} list of templates available..
168 listTemplates : function(name)
172 if (typeof(gn) != 'string') {
173 gn = this.guessName(gn);
177 var dir= GLib.get_home_dir() + '/.Builder/' + gn;
178 if (!File.isDirectory(dir)) {
182 File.list(dir).forEach(function(n) {
183 if (!n.match(/\.json$/)) {
188 path : dir + '/' + n,
189 name: n.replace(/\.json$/,'')
195 loadTemplate : function(path)
197 return JSON.parse(File.read(path));