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";
89 public static NodePropType[] alltypes()
104 public static NodePropType nameToType(string str)
106 foreach(var np in alltypes()) {
107 if (np.to_name() == str) {
114 public static string[] get_pulldown_list()
116 // eventually it needs to be smarter.... - but i did not have internet so could not use listmodels for the dropdown
119 foreach(var np in alltypes()) {
131 public class JsRender.NodeProp : Object {
138 private string _name = "";
144 if (this._name == value) {
149 this.updated_count++;
150 if (this.parent != null) {
151 // causes props/ listeners array to get updated.
152 this.parent.updated_count++;
155 } // can not be updated... ?? you have to remove / replace?
156 private NodePropType _ptype;
158 public NodePropType ptype {
163 if (this._ptype == value) {
167 if (this.parent != null) {
168 // causes props/ listeners array to get updated.
169 this.parent.updated_count++;
173 private string _rtype = "";
174 public string rtype {
179 if (this._rtype == value) {
183 if (this.parent != null) {
184 this.parent.updated_count++;
187 this.updated_count++;
191 private string _val = "";
197 if (this._val == value) {
202 if (this.parent != null) {
203 this.parent.updated_count++;
205 this.updated_count++;
210 private int _updated_count = 0;
211 public int updated_count {
213 return this._updated_count;
217 // set things that are used to display values.
218 this.to_display_name_prop = value.to_string();
219 this.to_tooltip_name_prop = value.to_string();
221 this.val_short = value.to_string();
222 this.val_tooltip = value.to_string();
223 this._updated_count = value;
226 } // changes to this trigger updates on the tree..
228 public string sort_name {
230 if (this.add_node == null) {
233 return this.name + " " + this.add_node.fqn();
240 public Node? parent; // the parent node.
243 public int start_line = 0;
244 public int end_line = 0;
246 // used by display list..
247 public GLib.ListStore childstore; // WILL BE USED FOR properties with mutliple types
248 public Node? add_node = null; // used when we list potentional nodes for properties in add list.
250 public string propertyof { get; set; }
253 public NodeProp(string name, NodePropType ptype, string rtype, string val) {
258 this.childstore = new GLib.ListStore( typeof(NodeProp));
261 public string ptype_as_string {
262 get { return this.ptype.to_string(); }
267 public bool equals(NodeProp p)
269 return this.name == p.name
271 this.ptype == p.ptype
273 this.rtype == p.rtype
278 public NodeProp dupe()
280 return new NodeProp(this.name, this.ptype, this.rtype, this.val);
284 public NodeProp.from_json(string key, string inval)
287 var kkv = key.strip().split(" ");
289 for (var i = 0; i < kkv.length; i++) {
290 if (kkv[i].length > 0 ) {
298 this.ptype = NodePropType.PROP;
303 if (kk[0].length > 1) {
304 // void fred (no type)
306 this.ptype = NodePropType.PROP;
310 this.rtype = ""; // no return type, only a ptype indicator.
311 this.ptype = NodePropType.from_string(kk[0]);
314 default: // 3 or more... (ignores spaces..)
317 this.ptype = NodePropType.from_string(kk[0]);
324 public string to_json_key()
327 if (this.rtype == null) { // not sure why this happens.!?
330 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
331 var oabbr = NodePropType.to_abbr(this.ptype);
332 if (oabbr.length > 0) {
338 case NodePropType.LISTENER :
341 case NodePropType.PROP:
342 return ortype + this.name;
344 case NodePropType.RAW:
345 case NodePropType.METHOD:
346 case NodePropType.SIGNAL:
347 case NodePropType.USER :
348 return oabbr + ortype + this.name;
352 case NodePropType.SPECIAL:
353 return oabbr + this.name;
354 case NodePropType.NONE: // not used
355 case NodePropType.CTOR:
363 public string to_index_key()
366 case NodePropType.PROP:
367 case NodePropType.RAW:
368 case NodePropType.METHOD :
369 case NodePropType.SIGNAL :
370 case NodePropType.USER :
373 case NodePropType.SPECIAL :
374 return "* " + this.name;
376 // in seperate list..
377 case NodePropType.LISTENER :
380 case NodePropType.NONE: // not used
381 case NodePropType.CTOR:
389 // how it appears on the property list. -
393 public string val_short {
399 if (this._val.index_of("\n") < 0) {
402 var vals = this._val.split("\n");
403 return vals[0] + (vals.length > 1 ? " ..." : "");
407 public string val_tooltip {
413 return "<tt>" + GLib.Markup.escape_text(this.val) + "</tt>";
419 public string to_display_name_prop {
424 return this.to_display_name();
430 public string to_display_name()
433 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
434 // before we showed "@" for signals
436 case NodePropType.PROP:
437 return GLib.Markup.escape_text(this.name);
439 case NodePropType.RAW:
440 return "<span style=\"italic\">" + GLib.Markup.escape_text(this.name) + "</span>";
442 case NodePropType.METHOD :
443 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span color=\"#008000\" font_weight=\"bold\">" + GLib.Markup.escape_text( this.name) + "</span>";
445 case NodePropType.SIGNAL : // purpley
446 return "<span color=\"#ea00d6\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name)+ "</span>";
448 case NodePropType.USER :
449 return "<i>" + GLib.Markup.escape_text(this.rtype) + "</i> <span font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
451 case NodePropType.SPECIAL :
452 return "<span color=\"#0000CC\" font_weight=\"bold\">" + GLib.Markup.escape_text(this.name) + "</span>";
454 // in seperate list..
455 case NodePropType.LISTENER :
456 return "<b>" + this.name + "</b>";
458 case NodePropType.NONE: // not used
459 case NodePropType.CTOR:
467 public string to_tooltip_name_prop {
472 return this.to_tooltip_name();
476 public string to_tooltip_name()
479 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
480 // before we showed "@" for signals
482 case NodePropType.PROP:
483 case NodePropType.SIGNAL:
484 case NodePropType.RAW:
485 case NodePropType.SPECIAL :
486 case NodePropType.LISTENER :
487 return GLib.Markup.escape_text(this.name) ;
489 case NodePropType.METHOD :
490 case NodePropType.USER :
491 return GLib.Markup.escape_text(this.rtype) + " " + GLib.Markup.escape_text( this.name) ;
495 case NodePropType.NONE: // not used
496 case NodePropType.CTOR:
503 // used ot sort the dispaly list of properties.
504 public string to_sort_key()
508 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
509 // before we showed "@" for signals
511 case NodePropType.PROP:
514 case NodePropType.RAW:
517 case NodePropType.METHOD :
520 case NodePropType.SIGNAL :
523 case NodePropType.USER :
526 case NodePropType.SPECIAL :
529 // in seperate list..
530 case NodePropType.LISTENER :
531 return "0" + this.name;
533 case NodePropType.NONE: // not used
534 case NodePropType.CTOR:
540 // this is really only used for stuct ctors at present
541 // which are only props (although RAW might be valid)
542 public string value_to_code()
544 switch (this.ptype) {
545 case NodePropType.PROP:
548 case NodePropType.METHOD :
549 case NodePropType.RAW:
550 case NodePropType.SIGNAL :
551 case NodePropType.USER :
552 case NodePropType.SPECIAL :
553 case NodePropType.LISTENER :
554 case NodePropType.NONE: // not used
555 case NodePropType.CTOR:
558 if (this.rtype.contains(".")) {
564 switch (this.rtype) {
566 return "\"" + this.rtype.escape() + "\"";
568 return this.val.down();
582 public string to_tooltip()
586 case NodePropType.PROP:
587 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
588 case NodePropType.LISTENER :
589 // thsi might look a bit odd on javascript?
590 return "on " + this.name + " " + this.val;
592 case NodePropType.RAW:
593 return this.rtype + " " + this.name + " = " + this.val;
594 case NodePropType.METHOD :
595 // functions - js FRED function () { } <<< could probably be cleaner..
596 // functions - vala FRED () { }
597 return this.rtype + " " + this.name + " " + this.val;
598 case NodePropType.SIGNAL :
599 return "signal: " + this.rtype + " " + this.name + " " + this.val;
600 case NodePropType.USER :
601 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
603 case NodePropType.SPECIAL:
604 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
606 case NodePropType.NONE: // not used
607 case NodePropType.CTOR:
615 public string to_property_option_markup(bool isbold)
617 return isbold ? "<b>" + this.name + "</b>" : this.name;
620 public string to_property_option_tooltip()
622 return this.to_property_option_markup( false ); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
626 public bool is(NodeProp comp) {
627 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
628 return comp.ptype == this.ptype && comp.name == this.name;
630 return comp.to_index_key() == this.to_index_key();
636 public NodeProp.listenerfromjson(string str, string inval)
640 this.ptype = NodePropType.LISTENER;
645 // regular addition - should work for properties
646 public NodeProp.prop(string name, string rtype = "", string val = "")
648 this(name, NodePropType.PROP, rtype, val);
650 public NodeProp.raw(string name, string rtype = "", string val = "")
652 this(name, NodePropType.RAW, rtype, val);
655 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
657 this(name, NodePropType.METHOD, rtype, val);
659 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
661 this(name, NodePropType.METHOD, "", val);
664 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
665 public NodeProp.special(string name, string val = "")
667 this(name, NodePropType.SPECIAL, "", val);
670 public NodeProp.listener(string name, string val = "")
672 this(name, NodePropType.LISTENER, "", val);
675 public NodeProp.user(string name, string rtype = "", string val = "")
677 this(name, NodePropType.USER, rtype, val);
679 public NodeProp.sig(string name, string rtype = "void", string val = "()")
681 this(name, NodePropType.SIGNAL, rtype, val);
683 public void appendChild(NodeProp child)
685 this.childstore.append(child);
691 could use enums.. but basically.
692 0 - > inline text editor
696 public bool useTextArea()
699 var use_textarea = false;
701 //------------ things that require the text editor...
703 if (this.ptype == NodePropType.LISTENER) {
706 if (this.ptype == NodePropType.METHOD) {
710 if ( this.name == "init" && this.ptype == NodePropType.SPECIAL) {
713 if (this.val.length > 40 || this.val.index_of("\n") > -1) { // long value...