1 //<Script type="text/javascript">
3 console = imports.console;
4 XObject = imports.XObject.XObject;
6 GLib = imports.gi.GLib;
7 File = imports.File.File;
10 Base = XObject.define(
13 XObject.extend(this, cfg);
14 // various loader methods..
21 map : false, // array of mappings left: [] , right : []
23 items : false, // the tree of nodes.
26 guessName : function(ar) // turns the object into full name.
28 // eg. xns: Roo, xtype: XXX -> Roo.xxx
29 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
33 return ar['|xns'] +'.' + ar['xtype'];
38 * gather a list of potentional objects that can be added..
41 gatherList: function (existing) {
42 existing = existing || [];
43 // existing.push('*top'); // always have top
45 console.log("GATHER LIST? " + this.map.length);
48 function addRight(right) {
49 right.forEach(function(r) {
50 if (ret.indexOf(r) > -1) {
57 this.map.forEach(function(m) {
59 m.left.forEach( function(left) {
62 var l = left.replace(/:.*$/, '');
63 // print("chk:" + l + " in " + existing.join(','));
64 if (existing.indexOf(l) > -1) {
67 //return true; // no more needed..
81 getDropList : function(rval)
85 this.map.forEach( function(m) {
86 if (m.right.indexOf(rval) > -1) {
87 m.left.forEach(function(l) {
88 if (ret.indexOf(l) > -1) {
96 console.log("DROP LIST:");
105 findType : function (data, prop, value)
107 if (prop[0] == '|') {
110 return typeof(value);
114 findOptions : function(ename)
116 switch(ename.toLowerCase()) {
118 return [ 'true', 'false' ];
119 // everything else does not have options.
127 console.log("OOPS: = unknown type: " + ename);
131 confirmCanAdd: function(parent, child) {
132 // confirms that one obj can be added to another.
133 // returns true, for items, or list of properties that can hold it..
137 getDefaultPack: function(pname, cname) {
140 saveTemplate: function(name, data)
142 var gn = this.guessName(JSON.parse(data));
143 // store it in user's directory..
144 var appdir = GLib.get_home_dir() + '/.Builder';
146 if (!File.isDirectory(appdir+ '/' + gn)) {
147 File.mkdir(appdir+ '/' + gn);
149 File.write(appdir+ '/' + gn + '/' + name + '.json', data);
153 * list templates - in home directory (and app dir in future...)
154 * @param {String} name - eg. Gtk.Window..
155 * @return {Array} list of templates available..
157 listTemplates : function(name)
161 if (typeof(gn) != 'string') {
162 gn = this.guessName(gn);
166 var dir= GLib.get_home_dir() + '/.Builder/' + gn;
167 if (!File.isDirectory(dir)) {
171 File.list(dir).forEach(function(n) {
172 if (!n.match(/\.json$/)) {
177 path : dir + '/' + n,
178 name: n.replace(/\.json$/,'')
184 loadTemplate : function(path)
186 return JSON.parse(File.read(path));