4 static Gee.HashMap<string,Palate>? cache = null;
6 public static Palete factory(xtype)
8 if (this.cache == null) {
9 this.cache = new Gee.HashMap<string,Palate>();
16 public class Palete : Object
29 //map : false, // array of mappings left: [] , right : []
31 //items : false, // the tree of nodes.
36 string guessName(JsRender.Node ar) // turns the object into full name.
41 // eg. xns: Roo, xtype: XXX -> Roo.xxx
42 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
46 return ar['|xns'] +'.' + ar['xtype'];
51 * gather a list of potentional objects that can be added..
54 gatherList: function (existing) {
55 existing = existing || [];
56 // existing.push('*top'); // always have top
58 console.log("GATHER LIST? " + this.map.length);
61 function addRight(right) {
62 right.forEach(function(r) {
63 if (ret.indexOf(r) > -1) {
70 this.map.forEach(function(m) {
72 m.left.forEach( function(left) {
75 var l = left.replace(/:.*$/, '');
76 // print("chk:" + l + " in " + existing.join(','));
77 if (existing.indexOf(l) > -1) {
80 //return true; // no more needed..
94 getDropList : function(rval)
98 this.map.forEach( function(m) {
99 if (m.right.indexOf(rval) > -1) {
100 m.left.forEach(function(l) {
101 if (ret.indexOf(l) > -1) {
109 console.log("DROP LIST:");
118 findType : function (data, prop, value)
120 if (prop[0] == '|') {
123 return typeof(value);
127 findOptions : function(ename)
129 switch(ename.toLowerCase()) {
131 return [ 'true', 'false' ];
132 // everything else does not have options.
140 console.log("OOPS: = unknown type: " + ename);
144 confirmCanAdd: function(parent, child) {
145 // confirms that one obj can be added to another.
146 // returns true, for items, or list of properties that can hold it..
150 getDefaultPack: function(pname, cname) {
153 saveTemplate: function(name, data)
155 var gn = this.guessName(JSON.parse(data));
156 // store it in user's directory..
157 var appdir = GLib.get_home_dir() + '/.Builder';
159 if (!File.isDirectory(appdir+ '/' + gn)) {
160 File.mkdir(appdir+ '/' + gn);
162 File.write(appdir+ '/' + gn + '/' + name + '.json', data);
166 * list templates - in home directory (and app dir in future...)
167 * @param {String} name - eg. Gtk.Window..
168 * @return {Array} list of templates available..
170 listTemplates : function(name)
174 if (typeof(gn) != 'string') {
175 gn = this.guessName(gn);
179 var dir= GLib.get_home_dir() + '/.Builder/' + gn;
180 if (!File.isDirectory(dir)) {
184 File.list(dir).forEach(function(n) {
185 if (!n.match(/\.json$/)) {
190 path : dir + '/' + n,
191 name: n.replace(/\.json$/,'')
197 loadTemplate : function(path)
199 return JSON.parse(File.read(path));