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 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
146 var oabbr = NodePropType.to_abbr(this.ptype);
147 if (oabbr.length > 0) {
153 case NodePropType.LISTENER :
156 case NodePropType.PROP:
157 return ortype + this.name;
159 case NodePropType.RAW:
160 case NodePropType.METHOD:
161 case NodePropType.SIGNAL:
162 case NodePropType.USER :
163 return oabbr + ortype + this.name;
167 case NodePropType.SPECIAL:
168 return oabbr + this.name;
169 case NodePropType.NONE: // not used
170 case NodePropType.CTOR:
178 public string to_index_key()
181 case NodePropType.PROP:
182 case NodePropType.RAW:
183 case NodePropType.METHOD :
184 case NodePropType.SIGNAL :
185 case NodePropType.USER :
188 case NodePropType.SPECIAL :
189 return "* " + this.name;
191 // in seperate list..
192 case NodePropType.LISTENER :
195 case NodePropType.NONE: // not used
196 case NodePropType.CTOR:
204 // how it appears on the property list. --
205 public string to_display_name()
208 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
209 // before we showed "@" for signals
211 case NodePropType.PROP:
214 case NodePropType.RAW:
215 return "<span style=\"italic\">" + GLib.Markup.escape_text(this.name) + "</span>";
217 case NodePropType.METHOD :
218 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span color=\"#008000\" font_weight=\"bold\">" + GLib.Markup.escape_text( this.name) + "</span>";
220 case NodePropType.SIGNAL : // purpley
221 return "<span color=\"#ea00d6\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name)+ "</span>";
223 case NodePropType.USER :
224 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
226 case NodePropType.SPECIAL :
227 return "<span color=\"#0000CC\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
229 // in seperate list..
230 case NodePropType.LISTENER :
231 return "<b>" + this.name + "</b>";
233 case NodePropType.NONE: // not used
234 case NodePropType.CTOR:
242 // used ot sort the dispaly list of properties.
243 public string to_sort_key()
247 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
248 // before we showed "@" for signals
250 case NodePropType.PROP:
253 case NodePropType.RAW:
256 case NodePropType.METHOD :
259 case NodePropType.SIGNAL :
262 case NodePropType.USER :
265 case NodePropType.SPECIAL :
268 // in seperate list..
269 case NodePropType.LISTENER :
270 return "0" + this.name;
272 case NodePropType.NONE: // not used
273 case NodePropType.CTOR:
279 // this is really only used for stuct ctors at present
280 // which are only props (although RAW might be valid)
281 public string value_to_code()
283 switch (this.ptype) {
284 case NodePropType.PROP:
287 case NodePropType.METHOD :
288 case NodePropType.RAW:
289 case NodePropType.SIGNAL :
290 case NodePropType.USER :
291 case NodePropType.SPECIAL :
292 case NodePropType.LISTENER :
293 case NodePropType.NONE: // not used
294 case NodePropType.CTOR:
297 if (this.rtype.contains(".")) {
303 switch (this.rtype) {
305 return "\"" + this.rtype.escape() + "\"";
307 return this.val.down();
321 public string to_tooltip()
325 case NodePropType.PROP:
326 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
327 case NodePropType.LISTENER :
328 // thsi might look a bit odd on javascript?
329 return "on " + this.name + " " + this.val;
331 case NodePropType.RAW:
332 return this.rtype + " " + this.name + " = " + this.val;
333 case NodePropType.METHOD :
334 // functions - js FRED function () { } <<< could probably be cleaner..
335 // functions - vala FRED () { }
336 return this.rtype + " " + this.name + " " + this.val;
337 case NodePropType.SIGNAL :
338 return "signal: " + this.rtype + " " + this.name + " " + this.val;
339 case NodePropType.USER :
340 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
342 case NodePropType.SPECIAL:
343 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
345 case NodePropType.NONE: // not used
346 case NodePropType.CTOR:
354 public string to_property_option_markup(bool isbold)
356 return isbold ? "<b>" + this.name + "</b>" : this.name;
359 public string to_property_option_tooltip()
361 return this.to_property_option_markup( false ); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
365 public bool is(NodeProp comp) {
366 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
367 return comp.ptype == this.ptype && comp.name == this.name;
369 return comp.to_index_key() == this.to_index_key();
375 public NodeProp.listenerfromjson(string str, string inval)
379 this.ptype = NodePropType.LISTENER;
384 // regular addition - should work for properties
385 public NodeProp.prop(string name, string rtype = "", string val = "")
387 this(name, NodePropType.PROP, rtype, val);
389 public NodeProp.raw(string name, string rtype = "", string val = "")
391 this(name, NodePropType.RAW, rtype, val);
394 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
396 this(name, NodePropType.METHOD, rtype, val);
398 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
400 this(name, NodePropType.METHOD, "", val);
403 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
404 public NodeProp.special(string name, string val = "")
406 this(name, NodePropType.SPECIAL, "", val);
409 public NodeProp.listener(string name, string val = "")
411 this(name, NodePropType.LISTENER, "", val);
414 public NodeProp.user(string name, string rtype = "", string val = "")
416 this(name, NodePropType.USER, rtype, val);
418 public NodeProp.sig(string name, string rtype = "void", string val = "()")
420 this(name, NodePropType.SIGNAL, rtype, val);