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.from_json(string key, string inval)
99 var kkv = key.strip().split(" ");
101 for (var i = 0; i < kkv.length; i++) {
102 if (kkv[i].length > 0 ) {
110 this.ptype = NodePropType.PROP;
115 if (kk[0].length > 1) {
116 // void fred (no type)
118 this.ptype = NodePropType.PROP;
122 this.rtype = ""; // no return type, only a ptype indicator.
123 this.ptype = NodePropType.from_string(kk[0]);
126 default: // 3 or more... (ignores spaces..)
129 this.ptype = NodePropType.from_string(kk[0]);
136 public string to_json_key()
139 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
140 var oabbr = NodePropType.to_abbr(this.ptype);
141 if (oabbr.length > 0) {
147 case NodePropType.LISTENER :
150 case NodePropType.PROP:
151 return ortype + this.name;
153 case NodePropType.RAW:
154 case NodePropType.METHOD:
155 case NodePropType.SIGNAL:
156 case NodePropType.USER :
157 return oabbr + ortype + this.name;
161 case NodePropType.SPECIAL:
162 return oabbr + this.name;
163 case NodePropType.NONE: // not used
164 case NodePropType.CTOR:
173 public string to_index_key()
176 case NodePropType.PROP:
177 case NodePropType.RAW:
178 case NodePropType.METHOD :
179 case NodePropType.SIGNAL :
180 case NodePropType.USER :
183 case NodePropType.SPECIAL :
184 return "* " + this.name;
186 // in seperate list..
187 case NodePropType.LISTENER :
190 case NodePropType.NONE: // not used
191 case NodePropType.CTOR:
199 // how it appears on the property list. --
200 public string to_display_name()
203 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
204 // before we showed "@" for signals
206 case NodePropType.PROP:
209 case NodePropType.RAW:
210 return "<span style=\"italic\">" + GLib.Markup.escape_text(this.name) + "</span>";
212 case NodePropType.METHOD :
213 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span color=\"#008000\" font_weight=\"bold\">" + GLib.Markup.escape_text( this.name) + "</span>";
215 case NodePropType.SIGNAL : // purpley
216 return "<span color=\"#ea00d6\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name)+ "</span>";
218 case NodePropType.USER :
219 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
221 case NodePropType.SPECIAL :
222 return "<span color=\"#0000CC\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
224 // in seperate list..
225 case NodePropType.LISTENER :
226 return "<b>" + this.name + "</b>";
228 case NodePropType.NONE: // not used
229 case NodePropType.CTOR:
237 // used ot sort the dispaly list of properties.
238 public string to_sort_key()
242 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
243 // before we showed "@" for signals
245 case NodePropType.PROP:
248 case NodePropType.RAW:
251 case NodePropType.METHOD :
254 case NodePropType.SIGNAL :
257 case NodePropType.USER :
260 case NodePropType.SPECIAL :
263 // in seperate list..
264 case NodePropType.LISTENER :
265 return "0" + this.name;
267 case NodePropType.NONE: // not used
268 case NodePropType.CTOR:
279 public string to_tooltip()
283 case NodePropType.PROP:
284 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
285 case NodePropType.LISTENER :
286 // thsi might look a bit odd on javascript?
287 return "on " + this.name + " " + this.val;
289 case NodePropType.RAW:
290 return this.rtype + " " + this.name + " = " + this.val;
291 case NodePropType.METHOD :
292 // functions - js FRED function () { } <<< could probably be cleaner..
293 // functions - vala FRED () { }
294 return this.rtype + " " + this.name + " " + this.val;
295 case NodePropType.SIGNAL :
296 return "signal: " + this.rtype + " " + this.name + " " + this.val;
297 case NodePropType.USER :
298 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
300 case NodePropType.SPECIAL:
301 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
303 case NodePropType.NONE: // not used
304 case NodePropType.CTOR:
312 public string to_property_option_markup()
314 return "<b>" + this.name + "</b> <i>" + this.rtype + "</i>";
317 public string to_property_option_tooltip()
319 return this.to_property_option_markup(); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
323 public bool is(NodeProp comp) {
324 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
325 return comp.ptype == this.ptype && comp.name == this.name;
327 return comp.to_index_key() == this.to_index_key();
333 public NodeProp.listenerfromjson(string str, string inval)
337 this.ptype = NodePropType.LISTENER;
342 // regular addition - should work for properties
343 public NodeProp.prop(string name, string rtype = "", string val = "")
345 this(name, NodePropType.PROP, rtype, val);
347 public NodeProp.raw(string name, string rtype = "", string val = "")
349 this(name, NodePropType.RAW, rtype, val);
352 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
354 this(name, NodePropType.METHOD, rtype, val);
356 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
358 this(name, NodePropType.METHOD, "", val);
361 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
362 public NodeProp.special(string name, string val = "")
364 this(name, NodePropType.SPECIAL, "", val);
367 public NodeProp.listener(string name, string val = "")
369 this(name, NodePropType.LISTENER, "", val);
372 public NodeProp.user(string name, string rtype = "", string val = "")
374 this(name, NodePropType.USER, rtype, val);
376 public NodeProp.sig(string name, string rtype = "void", string val = "()")
378 this(name, NodePropType.SIGNAL, rtype, val);