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) {
167 public void saveTemplate (string name, JsRender.Node data)
171 // store it in user's directory..
172 var appdir = GLib.Environment.get_home_dir() + "/.Builder";
175 if (!GLib.FileUtils.test(appdir+ "/" + gn, GLib.FileTest.IS_DIR)) {
176 GLib.File.new_for_path (appdir+ "/" + gn).make_directory ();
179 GLib.FileUtils.set_contents(appdir+ "/" + gn + "/" + name + ".json", data.toJsonString());
184 * list templates - in home directory (and app dir in future...)
185 * @param {String} name - eg. Gtk.Window..
186 * @return {Array} list of templates available..
189 public GLib.List<string> listTemplates (JsRender.Node node)
194 var ret = new GLib.List<string>();
195 var dir= GLib.Environment.get_home_dir() + "/.Builder/" + gn;
196 if (!GLib.FileUtils.test(dir, GLib.FileTest.IS_DIR)) {
203 var f = File.new_for_path(dir);
205 var file_enum = f.enumerate_children(GLib.FileAttribute.STANDARD_DISPLAY_NAME, GLib.FileQueryInfoFlags.NONE, null);
208 while ((next_file = file_enum.next_file(null)) != null) {
209 var n = next_file.get_display_name();
210 if (!Regex.match_simple ("\\.json$", n)) {
213 ret.append( dir + "/" + n);
219 public JsRender.Node? loadTemplate(string path)
222 var pa = new Json.Parser();
223 pa.load_from_file(path);
224 var node = pa.get_root();
226 if (node.get_node_type () != Json.NodeType.OBJECT) {
229 var obj = node.get_object ();
231 var ret = new JsRender.Node();
232 ret.loadFromJson(obj);