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...
71 public string to_name()
74 case RAW: return "Raw Property (not quoted or escaped)";
75 case METHOD : return "User Defined Method";
76 case SIGNAL : return "Vala Signal"; // vala signal
77 case USER : return "User Defined Property"; // user defined.
78 case SPECIAL : return "Special Property (eg. prop / arg / ctor / init)"; // * prop| args | ctor | init
79 case LISTENER : return "Listener / Signal Handler"; // always raw...
81 case NONE: return "None??";
82 case CTOR: return "Constructor?";
83 case PROP: return "Gtk/Roo Property";
84 default: return "oops";
94 public class JsRender.NodeProp : Object {
97 private string _name = "";
103 if (this._name == value) {
108 this.updated_count++;
109 if (this.parent != null) {
110 // causes props/ listeners array to get updated.
111 this.parent.updated_count++;
114 } // can not be updated... ?? you have to remove / replace?
115 private NodePropType _ptype;
117 public NodePropType ptype {
122 if (this._ptype == value) {
126 if (this.parent != null) {
127 // causes props/ listeners array to get updated.
128 this.parent.updated_count++;
132 private string _rtype = "";
133 public string rtype {
138 if (this._rtype == value) {
142 if (this.parent != null) {
143 this.parent.updated_count++;
146 this.updated_count++;
150 private string _val = "";
156 if (this._val == value) {
161 if (this.parent != null) {
162 this.parent.updated_count++;
164 this.updated_count++;
169 private int _updated_count = 0;
170 public int updated_count {
172 return this._updated_count;
176 // set things that are used to display values.
177 this.to_display_name_prop = value.to_string();
178 this.to_tooltip_name_prop = value.to_string();
180 this.val_short = value.to_string();
181 this.val_tooltip = value.to_string();
182 this._updated_count = value;
185 } // changes to this trigger updates on the tree..
187 public string sort_name {
189 if (this.add_node == null) {
192 return this.name + " " + this.add_node.fqn();
199 public Node? parent; // the parent node.
202 public int start_line = 0;
203 public int end_line = 0;
205 // used by display list..
206 public GLib.ListStore childstore; // WILL BE USED FOR properties with mutliple types
207 public Node? add_node = null; // used when we list potentional nodes for properties in add list.
209 public string propertyof { get; set; }
212 public NodeProp(string name, NodePropType ptype, string rtype, string val) {
217 this.childstore = new GLib.ListStore( typeof(NodeProp));
222 public bool equals(NodeProp p)
224 return this.name == p.name
226 this.ptype == p.ptype
228 this.rtype == p.rtype
233 public NodeProp dupe()
235 return new NodeProp(this.name, this.ptype, this.rtype, this.val);
239 public NodeProp.from_json(string key, string inval)
242 var kkv = key.strip().split(" ");
244 for (var i = 0; i < kkv.length; i++) {
245 if (kkv[i].length > 0 ) {
253 this.ptype = NodePropType.PROP;
258 if (kk[0].length > 1) {
259 // void fred (no type)
261 this.ptype = NodePropType.PROP;
265 this.rtype = ""; // no return type, only a ptype indicator.
266 this.ptype = NodePropType.from_string(kk[0]);
269 default: // 3 or more... (ignores spaces..)
272 this.ptype = NodePropType.from_string(kk[0]);
279 public string to_json_key()
282 if (this.rtype == null) { // not sure why this happens.!?
285 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
286 var oabbr = NodePropType.to_abbr(this.ptype);
287 if (oabbr.length > 0) {
293 case NodePropType.LISTENER :
296 case NodePropType.PROP:
297 return ortype + this.name;
299 case NodePropType.RAW:
300 case NodePropType.METHOD:
301 case NodePropType.SIGNAL:
302 case NodePropType.USER :
303 return oabbr + ortype + this.name;
307 case NodePropType.SPECIAL:
308 return oabbr + this.name;
309 case NodePropType.NONE: // not used
310 case NodePropType.CTOR:
318 public string to_index_key()
321 case NodePropType.PROP:
322 case NodePropType.RAW:
323 case NodePropType.METHOD :
324 case NodePropType.SIGNAL :
325 case NodePropType.USER :
328 case NodePropType.SPECIAL :
329 return "* " + this.name;
331 // in seperate list..
332 case NodePropType.LISTENER :
335 case NodePropType.NONE: // not used
336 case NodePropType.CTOR:
344 // how it appears on the property list. -
348 public string val_short {
354 if (this._val.index_of("\n") < 0) {
357 var vals = this._val.split("\n");
358 return vals[0] + (vals.length > 1 ? " ..." : "");
362 public string val_tooltip {
368 return "<tt>" + GLib.Markup.escape_text(this.val) + "</tt>";
374 public string to_display_name_prop {
379 return this.to_display_name();
385 public string to_display_name()
388 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
389 // before we showed "@" for signals
391 case NodePropType.PROP:
392 return GLib.Markup.escape_text(this.name);
394 case NodePropType.RAW:
395 return "<span style=\"italic\">" + GLib.Markup.escape_text(this.name) + "</span>";
397 case NodePropType.METHOD :
398 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span color=\"#008000\" font_weight=\"bold\">" + GLib.Markup.escape_text( this.name) + "</span>";
400 case NodePropType.SIGNAL : // purpley
401 return "<span color=\"#ea00d6\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name)+ "</span>";
403 case NodePropType.USER :
404 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
406 case NodePropType.SPECIAL :
407 return "<span color=\"#0000CC\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
409 // in seperate list..
410 case NodePropType.LISTENER :
411 return "<b>" + this.name + "</b>";
413 case NodePropType.NONE: // not used
414 case NodePropType.CTOR:
422 public string to_tooltip_name_prop {
427 return this.to_tooltip_name();
431 public string to_tooltip_name()
434 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
435 // before we showed "@" for signals
437 case NodePropType.PROP:
438 case NodePropType.SIGNAL:
439 case NodePropType.RAW:
440 case NodePropType.SPECIAL :
441 case NodePropType.LISTENER :
442 return GLib.Markup.escape_text(this.name) ;
444 case NodePropType.METHOD :
445 case NodePropType.USER :
446 return GLib.Markup.escape_text(this.rtype) + " " + GLib.Markup.escape_text( this.name) ;
450 case NodePropType.NONE: // not used
451 case NodePropType.CTOR:
458 // used ot sort the dispaly list of properties.
459 public string to_sort_key()
463 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
464 // before we showed "@" for signals
466 case NodePropType.PROP:
469 case NodePropType.RAW:
472 case NodePropType.METHOD :
475 case NodePropType.SIGNAL :
478 case NodePropType.USER :
481 case NodePropType.SPECIAL :
484 // in seperate list..
485 case NodePropType.LISTENER :
486 return "0" + this.name;
488 case NodePropType.NONE: // not used
489 case NodePropType.CTOR:
495 // this is really only used for stuct ctors at present
496 // which are only props (although RAW might be valid)
497 public string value_to_code()
499 switch (this.ptype) {
500 case NodePropType.PROP:
503 case NodePropType.METHOD :
504 case NodePropType.RAW:
505 case NodePropType.SIGNAL :
506 case NodePropType.USER :
507 case NodePropType.SPECIAL :
508 case NodePropType.LISTENER :
509 case NodePropType.NONE: // not used
510 case NodePropType.CTOR:
513 if (this.rtype.contains(".")) {
519 switch (this.rtype) {
521 return "\"" + this.rtype.escape() + "\"";
523 return this.val.down();
537 public string to_tooltip()
541 case NodePropType.PROP:
542 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
543 case NodePropType.LISTENER :
544 // thsi might look a bit odd on javascript?
545 return "on " + this.name + " " + this.val;
547 case NodePropType.RAW:
548 return this.rtype + " " + this.name + " = " + this.val;
549 case NodePropType.METHOD :
550 // functions - js FRED function () { } <<< could probably be cleaner..
551 // functions - vala FRED () { }
552 return this.rtype + " " + this.name + " " + this.val;
553 case NodePropType.SIGNAL :
554 return "signal: " + this.rtype + " " + this.name + " " + this.val;
555 case NodePropType.USER :
556 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
558 case NodePropType.SPECIAL:
559 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
561 case NodePropType.NONE: // not used
562 case NodePropType.CTOR:
570 public string to_property_option_markup(bool isbold)
572 return isbold ? "<b>" + this.name + "</b>" : this.name;
575 public string to_property_option_tooltip()
577 return this.to_property_option_markup( false ); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
581 public bool is(NodeProp comp) {
582 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
583 return comp.ptype == this.ptype && comp.name == this.name;
585 return comp.to_index_key() == this.to_index_key();
591 public NodeProp.listenerfromjson(string str, string inval)
595 this.ptype = NodePropType.LISTENER;
600 // regular addition - should work for properties
601 public NodeProp.prop(string name, string rtype = "", string val = "")
603 this(name, NodePropType.PROP, rtype, val);
605 public NodeProp.raw(string name, string rtype = "", string val = "")
607 this(name, NodePropType.RAW, rtype, val);
610 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
612 this(name, NodePropType.METHOD, rtype, val);
614 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
616 this(name, NodePropType.METHOD, "", val);
619 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
620 public NodeProp.special(string name, string val = "")
622 this(name, NodePropType.SPECIAL, "", val);
625 public NodeProp.listener(string name, string val = "")
627 this(name, NodePropType.LISTENER, "", val);
630 public NodeProp.user(string name, string rtype = "", string val = "")
632 this(name, NodePropType.USER, rtype, val);
634 public NodeProp.sig(string name, string rtype = "void", string val = "()")
636 this(name, NodePropType.SIGNAL, rtype, val);
638 public void appendChild(NodeProp child)
640 this.childstore.append(child);
645 could use enums.. but basically.
646 0 - > inline text editor
650 public bool useTextArea()
653 var use_textarea = false;
655 //------------ things that require the text editor...
657 if (this.ptype == NodePropType.LISTENER) {
660 if (this.ptype == NodePropType.METHOD) {
664 if ( this.name == "init" && this.ptype == NodePropType.SPECIAL) {
667 if (this.val.length > 40 || this.val.index_of("\n") > -1) { // long value...