4 public errordomain Error {
11 public class Usage : Object
13 public GLib.List<string> left;
14 public GLib.List<string> right;
15 public Usage(GLib.List<string> ileft, GLib.List<string> iright)
17 this.left = ileft.copy();
18 this.right= iright.copy();
24 static Gee.HashMap<string,Palete>? cache = null;
26 public static Palete factory(string xtype)
29 cache = new Gee.HashMap<string,Palete>();
31 if (cache.get(xtype) != null) {
32 return cache.get(xtype);
36 cache.set(xtype, new Gtk());
39 // cache.set(xtype, new Roo());
42 throw new Error.INVALID_TYPE("invalid argument to Palete factory");
44 return cache.get(xtype);
48 public abstract class Palete : Object
54 public GLib.List<Usage> map;
62 //map : false, // array of mappings left: [] , right : []
64 //items : false, // the tree of nodes.
69 string guessName(JsRender.Node ar) throws Error // turns the object into full name.
71 throw new Error.NEED_IMPLEMENTING("xxx. guessName needs implimenting");
77 * gather a list of potentional objects that can be added..
81 gatherList: function (existing) {
82 existing = existing || [];
83 // existing.push('*top'); // always have top
85 console.log("GATHER LIST? " + this.map.length);
88 function addRight(right) {
89 right.forEach(function(r) {
90 if (ret.indexOf(r) > -1) {
97 this.map.forEach(function(m) {
99 m.left.forEach( function(left) {
102 var l = left.replace(/:.*$/, '');
103 // print("chk:" + l + " in " + existing.join(','));
104 if (existing.indexOf(l) > -1) {
107 //return true; // no more needed..
114 // console.dump(ret);
121 public string[] getDropList(string rval)
123 // should be a bit more than this..
124 // -> it should look for all elements that inherit
126 var rt = new GLib.List<string>();
127 for (var i = 0; i < this.map.length(); i++) {
128 var m = this.map.nth_data(i);
130 if (m.right.index(rval) > -1) {
131 print("found RIGHT, adding left\n");
133 for(var ii =0; ii < m.left.length(); ii++) {
134 var l = m.left.nth_data(ii);
136 if (rt.index(l) > -1) {
139 print("ADD " + string.joinv(", ", ret) + "\n");
146 //console.log("DROP LIST:");
155 findType : function (data, prop, value)
157 if (prop[0] == '|') {
160 return typeof(value);
164 findOptions : function(ename)
166 switch(ename.toLowerCase()) {
168 return [ 'true', 'false' ];
169 // everything else does not have options.
177 console.log("OOPS: = unknown type: " + ename);
181 confirmCanAdd: function(parent, child) {
182 // confirms that one obj can be added to another.
183 // returns true, for items, or list of properties that can hold it..
187 getDefaultPack: function(pname, cname) {
191 public void saveTemplate (string name, JsRender.Node data)
195 // store it in user's directory..
196 var appdir = GLib.Environment.get_home_dir() + "/.Builder";
199 if (!GLib.FileUtils.test(appdir+ "/" + gn, GLib.FileTest.IS_DIR)) {
200 GLib.File.new_for_path (appdir+ "/" + gn).make_directory ();
203 GLib.FileUtils.set_contents(appdir+ "/" + gn + "/" + name + ".json", data.toJsonString());
208 * list templates - in home directory (and app dir in future...)
209 * @param {String} name - eg. Gtk.Window..
210 * @return {Array} list of templates available..
213 public GLib.List<string> listTemplates (JsRender.Node node)
218 var ret = new GLib.List<string>();
219 var dir= GLib.Environment.get_home_dir() + "/.Builder/" + gn;
220 if (!GLib.FileUtils.test(dir, GLib.FileTest.IS_DIR)) {
227 var f = File.new_for_path(dir);
229 var file_enum = f.enumerate_children(GLib.FileAttribute.STANDARD_DISPLAY_NAME, GLib.FileQueryInfoFlags.NONE, null);
232 while ((next_file = file_enum.next_file(null)) != null) {
233 var n = next_file.get_display_name();
234 if (!Regex.match_simple ("\\.json$", n)) {
237 ret.append( dir + "/" + n);
243 public JsRender.Node? loadTemplate(string path)
246 var pa = new Json.Parser();
247 pa.load_from_file(path);
248 var node = pa.get_root();
250 if (node.get_node_type () != Json.NodeType.OBJECT) {
253 var obj = node.get_object ();
255 var ret = new JsRender.Node();
256 ret.loadFromJson(obj);
260 public abstract void fillPack(JsRender.Node node,JsRender.Node parent);