4 public errordomain Error {
12 static Gee.HashMap<string,Palete>? cache = null;
14 public static Palete factory(string xtype)
17 cache = new Gee.HashMap<string,Palete>();
19 if (cache.get(xtype) != null) {
20 return cache.get(xtype);
24 cache.set(xtype, new Gtk());
27 // cache.set(xtype, new Roo());
30 throw new Error.INVALID_TYPE("invalid argument to Palete factory");
32 return cache.get(xtype);
36 public class Palete : Object
48 //map : false, // array of mappings left: [] , right : []
50 //items : false, // the tree of nodes.
55 string guessName(JsRender.Node ar) throws Error // turns the object into full name.
57 throw new Error.NEED_IMPLEMENTING("xxx. guessName needs implimenting");
63 * gather a list of potentional objects that can be added..
67 gatherList: function (existing) {
68 existing = existing || [];
69 // existing.push('*top'); // always have top
71 console.log("GATHER LIST? " + this.map.length);
74 function addRight(right) {
75 right.forEach(function(r) {
76 if (ret.indexOf(r) > -1) {
83 this.map.forEach(function(m) {
85 m.left.forEach( function(left) {
88 var l = left.replace(/:.*$/, '');
89 // print("chk:" + l + " in " + existing.join(','));
90 if (existing.indexOf(l) > -1) {
93 //return true; // no more needed..
100 // console.dump(ret);
107 getDropList : function(rval)
111 this.map.forEach( function(m) {
112 if (m.right.indexOf(rval) > -1) {
113 m.left.forEach(function(l) {
114 if (ret.indexOf(l) > -1) {
122 console.log("DROP LIST:");
131 findType : function (data, prop, value)
133 if (prop[0] == '|') {
136 return typeof(value);
140 findOptions : function(ename)
142 switch(ename.toLowerCase()) {
144 return [ 'true', 'false' ];
145 // everything else does not have options.
153 console.log("OOPS: = unknown type: " + ename);
157 confirmCanAdd: function(parent, child) {
158 // confirms that one obj can be added to another.
159 // returns true, for items, or list of properties that can hold it..
163 getDefaultPack: function(pname, cname) {
166 saveTemplate: function(name, data)
168 var gn = this.guessName(JSON.parse(data));
169 // store it in user's directory..
170 var appdir = GLib.get_home_dir() + '/.Builder';
172 if (!File.isDirectory(appdir+ '/' + gn)) {
173 File.mkdir(appdir+ '/' + gn);
175 File.write(appdir+ '/' + gn + '/' + name + '.json', data);
179 * list templates - in home directory (and app dir in future...)
180 * @param {String} name - eg. Gtk.Window..
181 * @return {Array} list of templates available..
183 listTemplates : function(name)
187 if (typeof(gn) != 'string') {
188 gn = this.guessName(gn);
192 var dir= GLib.get_home_dir() + '/.Builder/' + gn;
193 if (!File.isDirectory(dir)) {
197 File.list(dir).forEach(function(n) {
198 if (!n.match(/\.json$/)) {
203 path : dir + '/' + n,
204 name: n.replace(/\.json$/,'')
210 loadTemplate : function(path)
212 return JSON.parse(File.read(path));