3 This is a replacement for our key/value
8 public enum JsRender.NodePropType
11 NONE, // fake value - used in popoveraddprop.
12 CTOR, // not used exetp getProperties for?
15 // these are all stored as properties, and should not overlap.
22 // in theory we could have user defined properties that overlap - but probably not a good idea.
27 // specials - these should be in a seperate list?
32 // listerens can definatly overlap as they are stored in a seperate list. << no need to use this for listeners?
37 public static string to_abbr(NodePropType intype)
42 case METHOD : return "|";
43 case SIGNAL : return "@"; // vala signal
44 case USER : return "#"; // user defined.
45 case SPECIAL : return "*"; // * prop| args | ctor | init
46 case LISTENER : return ""; // always raw...
56 // only usefull for reall values.
57 public static NodePropType from_string(string str)
60 //case "" : return PROP;
62 case "|": return METHOD;
63 case "@": return SIGNAL;
64 case "#": return USER;
65 case "*": return SPECIAL;
66 //case "": return case LISTENER : return "" // always raw...
76 public class JsRender.NodeProp : Object {
80 public string name = "";
81 public NodePropType ptype;
82 public string rtype = ""; // return or type
83 public string val = "";
84 public int start_line = 0;
85 public int end_line = 0;
89 public NodeProp(string name, NodePropType ptype, string rtype, string val) {
96 public NodeProp dupe()
98 return new NodeProp(this.name, this.ptype, this.rtype, this.val);
102 public NodeProp.from_json(string key, string inval)
105 var kkv = key.strip().split(" ");
107 for (var i = 0; i < kkv.length; i++) {
108 if (kkv[i].length > 0 ) {
116 this.ptype = NodePropType.PROP;
121 if (kk[0].length > 1) {
122 // void fred (no type)
124 this.ptype = NodePropType.PROP;
128 this.rtype = ""; // no return type, only a ptype indicator.
129 this.ptype = NodePropType.from_string(kk[0]);
132 default: // 3 or more... (ignores spaces..)
135 this.ptype = NodePropType.from_string(kk[0]);
142 public string to_json_key()
145 if (this.rtype == null) { // not sure why this happens.!?
148 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
149 var oabbr = NodePropType.to_abbr(this.ptype);
150 if (oabbr.length > 0) {
156 case NodePropType.LISTENER :
159 case NodePropType.PROP:
160 return ortype + this.name;
162 case NodePropType.RAW:
163 case NodePropType.METHOD:
164 case NodePropType.SIGNAL:
165 case NodePropType.USER :
166 return oabbr + ortype + this.name;
170 case NodePropType.SPECIAL:
171 return oabbr + this.name;
172 case NodePropType.NONE: // not used
173 case NodePropType.CTOR:
181 public string to_index_key()
184 case NodePropType.PROP:
185 case NodePropType.RAW:
186 case NodePropType.METHOD :
187 case NodePropType.SIGNAL :
188 case NodePropType.USER :
191 case NodePropType.SPECIAL :
192 return "* " + this.name;
194 // in seperate list..
195 case NodePropType.LISTENER :
198 case NodePropType.NONE: // not used
199 case NodePropType.CTOR:
207 // how it appears on the property list. --
208 public string to_display_name()
211 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
212 // before we showed "@" for signals
214 case NodePropType.PROP:
217 case NodePropType.RAW:
218 return "<span style=\"italic\">" + GLib.Markup.escape_text(this.name) + "</span>";
220 case NodePropType.METHOD :
221 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span color=\"#008000\" font_weight=\"bold\">" + GLib.Markup.escape_text( this.name) + "</span>";
223 case NodePropType.SIGNAL : // purpley
224 return "<span color=\"#ea00d6\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name)+ "</span>";
226 case NodePropType.USER :
227 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
229 case NodePropType.SPECIAL :
230 return "<span color=\"#0000CC\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
232 // in seperate list..
233 case NodePropType.LISTENER :
234 return "<b>" + this.name + "</b>";
236 case NodePropType.NONE: // not used
237 case NodePropType.CTOR:
245 // used ot sort the dispaly list of properties.
246 public string to_sort_key()
250 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
251 // before we showed "@" for signals
253 case NodePropType.PROP:
256 case NodePropType.RAW:
259 case NodePropType.METHOD :
262 case NodePropType.SIGNAL :
265 case NodePropType.USER :
268 case NodePropType.SPECIAL :
271 // in seperate list..
272 case NodePropType.LISTENER :
273 return "0" + this.name;
275 case NodePropType.NONE: // not used
276 case NodePropType.CTOR:
282 // this is really only used for stuct ctors at present
283 // which are only props (although RAW might be valid)
284 public string value_to_code()
286 switch (this.ptype) {
287 case NodePropType.PROP:
290 case NodePropType.METHOD :
291 case NodePropType.RAW:
292 case NodePropType.SIGNAL :
293 case NodePropType.USER :
294 case NodePropType.SPECIAL :
295 case NodePropType.LISTENER :
296 case NodePropType.NONE: // not used
297 case NodePropType.CTOR:
300 if (this.rtype.contains(".")) {
306 switch (this.rtype) {
308 return "\"" + this.rtype.escape() + "\"";
310 return this.val.down();
324 public string to_tooltip()
328 case NodePropType.PROP:
329 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
330 case NodePropType.LISTENER :
331 // thsi might look a bit odd on javascript?
332 return "on " + this.name + " " + this.val;
334 case NodePropType.RAW:
335 return this.rtype + " " + this.name + " = " + this.val;
336 case NodePropType.METHOD :
337 // functions - js FRED function () { } <<< could probably be cleaner..
338 // functions - vala FRED () { }
339 return this.rtype + " " + this.name + " " + this.val;
340 case NodePropType.SIGNAL :
341 return "signal: " + this.rtype + " " + this.name + " " + this.val;
342 case NodePropType.USER :
343 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
345 case NodePropType.SPECIAL:
346 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
348 case NodePropType.NONE: // not used
349 case NodePropType.CTOR:
357 public string to_property_option_markup(bool isbold)
359 return isbold ? "<b>" + this.name + "</b>" : this.name;
362 public string to_property_option_tooltip()
364 return this.to_property_option_markup( false ); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
368 public bool is(NodeProp comp) {
369 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
370 return comp.ptype == this.ptype && comp.name == this.name;
372 return comp.to_index_key() == this.to_index_key();
378 public NodeProp.listenerfromjson(string str, string inval)
382 this.ptype = NodePropType.LISTENER;
387 // regular addition - should work for properties
388 public NodeProp.prop(string name, string rtype = "", string val = "")
390 this(name, NodePropType.PROP, rtype, val);
392 public NodeProp.raw(string name, string rtype = "", string val = "")
394 this(name, NodePropType.RAW, rtype, val);
397 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
399 this(name, NodePropType.METHOD, rtype, val);
401 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
403 this(name, NodePropType.METHOD, "", val);
406 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
407 public NodeProp.special(string name, string val = "")
409 this(name, NodePropType.SPECIAL, "", val);
412 public NodeProp.listener(string name, string val = "")
414 this(name, NodePropType.LISTENER, "", val);
417 public NodeProp.user(string name, string rtype = "", string val = "")
419 this(name, NodePropType.USER, rtype, val);
421 public NodeProp.sig(string name, string rtype = "void", string val = "()")
423 this(name, NodePropType.SIGNAL, rtype, val);