4 public errordomain Error {
10 static Gee.HashMap<string,Palete>? cache = null;
12 public static Palete factory(string xtype)
15 cache = new Gee.HashMap<string,Palete>();
17 if (this.cache.get(xtype) != null) {
18 return this.cache.get(xtype);
22 this.cache.set(xtype, new Gtk());
25 this.cache.set(xtype, new Roo());
28 throw Error.INVALID_TYPE("invalid argument to Palete factory");
30 return this.cache.get(xtype);
34 public class Palete : Object
46 //map : false, // array of mappings left: [] , right : []
48 //items : false, // the tree of nodes.
53 string guessName(JsRender.Node ar) throws Error // turns the object into full name.
55 throw new Error.NEED_IMPLEMENTING("xxx. guessName needs implimenting");
61 * gather a list of potentional objects that can be added..
65 gatherList: function (existing) {
66 existing = existing || [];
67 // existing.push('*top'); // always have top
69 console.log("GATHER LIST? " + this.map.length);
72 function addRight(right) {
73 right.forEach(function(r) {
74 if (ret.indexOf(r) > -1) {
81 this.map.forEach(function(m) {
83 m.left.forEach( function(left) {
86 var l = left.replace(/:.*$/, '');
87 // print("chk:" + l + " in " + existing.join(','));
88 if (existing.indexOf(l) > -1) {
91 //return true; // no more needed..
105 getDropList : function(rval)
109 this.map.forEach( function(m) {
110 if (m.right.indexOf(rval) > -1) {
111 m.left.forEach(function(l) {
112 if (ret.indexOf(l) > -1) {
120 console.log("DROP LIST:");
129 findType : function (data, prop, value)
131 if (prop[0] == '|') {
134 return typeof(value);
138 findOptions : function(ename)
140 switch(ename.toLowerCase()) {
142 return [ 'true', 'false' ];
143 // everything else does not have options.
151 console.log("OOPS: = unknown type: " + ename);
155 confirmCanAdd: function(parent, child) {
156 // confirms that one obj can be added to another.
157 // returns true, for items, or list of properties that can hold it..
161 getDefaultPack: function(pname, cname) {
164 saveTemplate: function(name, data)
166 var gn = this.guessName(JSON.parse(data));
167 // store it in user's directory..
168 var appdir = GLib.get_home_dir() + '/.Builder';
170 if (!File.isDirectory(appdir+ '/' + gn)) {
171 File.mkdir(appdir+ '/' + gn);
173 File.write(appdir+ '/' + gn + '/' + name + '.json', data);
177 * list templates - in home directory (and app dir in future...)
178 * @param {String} name - eg. Gtk.Window..
179 * @return {Array} list of templates available..
181 listTemplates : function(name)
185 if (typeof(gn) != 'string') {
186 gn = this.guessName(gn);
190 var dir= GLib.get_home_dir() + '/.Builder/' + gn;
191 if (!File.isDirectory(dir)) {
195 File.list(dir).forEach(function(n) {
196 if (!n.match(/\.json$/)) {
201 path : dir + '/' + n,
202 name: n.replace(/\.json$/,'')
208 loadTemplate : function(path)
210 return JSON.parse(File.read(path));