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 if (this.parent != null) {
109 // causes props/ listeners array to get updated.
110 this.parent.updated_count++;
113 } // can not be updated... ?? you have to remove / replace?
114 private NodePropType _ptype;
116 public NodePropType ptype {
121 if (this._ptype == value) {
125 if (this.parent != null) {
126 // causes props/ listeners array to get updated.
127 this.parent.updated_count++;
131 private string _rtype = "";
132 public string rtype {
137 if (this._rtype == value) {
141 if (this.parent != null) {
142 this.parent.updated_count++;
144 this.to_display_name_prop = "";
145 this.to_tooltip_name_prop = "";
146 this.updated_count++;
150 private string _val = "";
156 if (this._val == value) {
161 if (this.parent != null) {
162 this.parent.updated_count++;
165 this.val_tooltip = "";
166 this.updated_count++;
172 private int _updated_count = 0;
173 public int updated_count {
175 return this._updated_count;
179 // set things that are used to display values.
180 this.to_display_name_prop = "";
181 this.to_tooltip_name_prop = "";
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));
221 public bool equals(NodeProp p)
223 return this.name == p.name
225 this.ptype == p.ptype
227 this.rtype == p.rtype
232 public NodeProp dupe()
234 return new NodeProp(this.name, this.ptype, this.rtype, this.val);
238 public NodeProp.from_json(string key, string inval)
241 var kkv = key.strip().split(" ");
243 for (var i = 0; i < kkv.length; i++) {
244 if (kkv[i].length > 0 ) {
252 this.ptype = NodePropType.PROP;
257 if (kk[0].length > 1) {
258 // void fred (no type)
260 this.ptype = NodePropType.PROP;
264 this.rtype = ""; // no return type, only a ptype indicator.
265 this.ptype = NodePropType.from_string(kk[0]);
268 default: // 3 or more... (ignores spaces..)
271 this.ptype = NodePropType.from_string(kk[0]);
278 public string to_json_key()
281 if (this.rtype == null) { // not sure why this happens.!?
284 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
285 var oabbr = NodePropType.to_abbr(this.ptype);
286 if (oabbr.length > 0) {
292 case NodePropType.LISTENER :
295 case NodePropType.PROP:
296 return ortype + this.name;
298 case NodePropType.RAW:
299 case NodePropType.METHOD:
300 case NodePropType.SIGNAL:
301 case NodePropType.USER :
302 return oabbr + ortype + this.name;
306 case NodePropType.SPECIAL:
307 return oabbr + this.name;
308 case NodePropType.NONE: // not used
309 case NodePropType.CTOR:
317 public string to_index_key()
320 case NodePropType.PROP:
321 case NodePropType.RAW:
322 case NodePropType.METHOD :
323 case NodePropType.SIGNAL :
324 case NodePropType.USER :
327 case NodePropType.SPECIAL :
328 return "* " + this.name;
330 // in seperate list..
331 case NodePropType.LISTENER :
334 case NodePropType.NONE: // not used
335 case NodePropType.CTOR:
343 // how it appears on the property list. -
347 public string val_short {
353 if (this._val.index_of("\n") < 0) {
356 var vals = this._val.split("\n");
357 return vals[0] + (vals.length > 1 ? " ..." : "");
361 public string val_tooltip {
367 return "<tt>" + GLib.Markup.escape_text(this.val) + "</tt>";
373 public string to_display_name_prop {
378 return this.to_display_name();
384 public string to_display_name()
387 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
388 // before we showed "@" for signals
390 case NodePropType.PROP:
391 return GLib.Markup.escape_text(this.name);
393 case NodePropType.RAW:
394 return "<span style=\"italic\">" + GLib.Markup.escape_text(this.name) + "</span>";
396 case NodePropType.METHOD :
397 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span color=\"#008000\" font_weight=\"bold\">" + GLib.Markup.escape_text( this.name) + "</span>";
399 case NodePropType.SIGNAL : // purpley
400 return "<span color=\"#ea00d6\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name)+ "</span>";
402 case NodePropType.USER :
403 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
405 case NodePropType.SPECIAL :
406 return "<span color=\"#0000CC\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
408 // in seperate list..
409 case NodePropType.LISTENER :
410 return "<b>" + this.name + "</b>";
412 case NodePropType.NONE: // not used
413 case NodePropType.CTOR:
421 public string to_tooltip_name_prop {
426 return this.to_tooltip_name();
430 public string to_tooltip_name()
433 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
434 // before we showed "@" for signals
436 case NodePropType.PROP:
437 case NodePropType.SIGNAL:
438 case NodePropType.RAW:
439 case NodePropType.SPECIAL :
440 case NodePropType.LISTENER :
441 return GLib.Markup.escape_text(this.name) ;
443 case NodePropType.METHOD :
444 case NodePropType.USER :
445 return GLib.Markup.escape_text(this.rtype) + " " + GLib.Markup.escape_text( this.name) ;
449 case NodePropType.NONE: // not used
450 case NodePropType.CTOR:
457 // used ot sort the dispaly list of properties.
458 public string to_sort_key()
462 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
463 // before we showed "@" for signals
465 case NodePropType.PROP:
468 case NodePropType.RAW:
471 case NodePropType.METHOD :
474 case NodePropType.SIGNAL :
477 case NodePropType.USER :
480 case NodePropType.SPECIAL :
483 // in seperate list..
484 case NodePropType.LISTENER :
485 return "0" + this.name;
487 case NodePropType.NONE: // not used
488 case NodePropType.CTOR:
494 // this is really only used for stuct ctors at present
495 // which are only props (although RAW might be valid)
496 public string value_to_code()
498 switch (this.ptype) {
499 case NodePropType.PROP:
502 case NodePropType.METHOD :
503 case NodePropType.RAW:
504 case NodePropType.SIGNAL :
505 case NodePropType.USER :
506 case NodePropType.SPECIAL :
507 case NodePropType.LISTENER :
508 case NodePropType.NONE: // not used
509 case NodePropType.CTOR:
512 if (this.rtype.contains(".")) {
518 switch (this.rtype) {
520 return "\"" + this.rtype.escape() + "\"";
522 return this.val.down();
536 public string to_tooltip()
540 case NodePropType.PROP:
541 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
542 case NodePropType.LISTENER :
543 // thsi might look a bit odd on javascript?
544 return "on " + this.name + " " + this.val;
546 case NodePropType.RAW:
547 return this.rtype + " " + this.name + " = " + this.val;
548 case NodePropType.METHOD :
549 // functions - js FRED function () { } <<< could probably be cleaner..
550 // functions - vala FRED () { }
551 return this.rtype + " " + this.name + " " + this.val;
552 case NodePropType.SIGNAL :
553 return "signal: " + this.rtype + " " + this.name + " " + this.val;
554 case NodePropType.USER :
555 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
557 case NodePropType.SPECIAL:
558 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
560 case NodePropType.NONE: // not used
561 case NodePropType.CTOR:
569 public string to_property_option_markup(bool isbold)
571 return isbold ? "<b>" + this.name + "</b>" : this.name;
574 public string to_property_option_tooltip()
576 return this.to_property_option_markup( false ); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
580 public bool is(NodeProp comp) {
581 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
582 return comp.ptype == this.ptype && comp.name == this.name;
584 return comp.to_index_key() == this.to_index_key();
590 public NodeProp.listenerfromjson(string str, string inval)
594 this.ptype = NodePropType.LISTENER;
599 // regular addition - should work for properties
600 public NodeProp.prop(string name, string rtype = "", string val = "")
602 this(name, NodePropType.PROP, rtype, val);
604 public NodeProp.raw(string name, string rtype = "", string val = "")
606 this(name, NodePropType.RAW, rtype, val);
609 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
611 this(name, NodePropType.METHOD, rtype, val);
613 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
615 this(name, NodePropType.METHOD, "", val);
618 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
619 public NodeProp.special(string name, string val = "")
621 this(name, NodePropType.SPECIAL, "", val);
624 public NodeProp.listener(string name, string val = "")
626 this(name, NodePropType.LISTENER, "", val);
629 public NodeProp.user(string name, string rtype = "", string val = "")
631 this(name, NodePropType.USER, rtype, val);
633 public NodeProp.sig(string name, string rtype = "void", string val = "()")
635 this(name, NodePropType.SIGNAL, rtype, val);
637 public void appendChild(NodeProp child)
639 this.childstore.append(child);
644 could use enums.. but basically.
645 0 - > inline text editor
649 public bool useTextArea()
652 var use_textarea = false;
654 //------------ things that require the text editor...
656 if (this.ptype == NodePropType.LISTENER) {
659 if (this.ptype == NodePropType.METHOD) {
663 if ( this.name == "init" && this.ptype == NodePropType.SPECIAL) {
666 if (this.val.length > 40 || this.val.index_of("\n") > -1) { // long value...