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 bool can_have_opt_list()
125 public static NodePropType nameToType(string str)
127 foreach(var np in alltypes()) {
128 if (np.to_name() == str) {
135 public static string[] get_pulldown_list()
137 // eventually it needs to be smarter.... - but i did not have internet so could not use listmodels for the dropdown
140 foreach(var np in alltypes()) {
152 public class JsRender.NodeProp : Object {
159 private string _name = "";
165 if (this._name == value) {
170 this.updated_count++;
171 if (this.parent != null) {
172 // causes props/ listeners array to get updated.
173 this.parent.updated_count++;
176 } // can not be updated... ?? you have to remove / replace?
177 private NodePropType _ptype;
179 public NodePropType ptype {
184 if (this._ptype == value) {
188 if (this.parent != null) {
189 // causes props/ listeners array to get updated.
190 this.parent.updated_count++;
194 private string _rtype = "";
195 public string rtype {
200 if (this._rtype == value) {
204 if (this.parent != null) {
205 this.parent.updated_count++;
208 this.updated_count++;
212 private string _val = "";
218 if (this._val == value) {
223 if (this.parent != null) {
224 this.parent.updated_count++;
226 this.updated_count++;
231 private int _updated_count = 0;
232 public int updated_count {
234 return this._updated_count;
238 // set things that are used to display values.
239 this.to_display_name_prop = value.to_string();
240 this.to_tooltip_name_prop = value.to_string();
242 this.val_short = value.to_string();
243 this.val_tooltip = value.to_string();
244 this._updated_count = value;
247 } // changes to this trigger updates on the tree..
249 public string sort_name {
251 if (this.add_node == null) {
254 return this.name + " " + this.add_node.fqn();
260 private string last_ptype_check = "";
261 public bool is_invalid_ptype {
267 public bool update_is_valid_ptype(Project.Project project)
270 if (this.parent == null) {
273 // what types are we interested in checking?
275 if (this.ptype != NodePropType.PROP && this.ptype != NodePropType.USER) {
278 if (this.name == "xtype" || this.name == "xns" || this.name == "id" ) { // flaky..
281 if (this.name == this.last_ptype_check) {
282 return this.is_invalid_ptype;
284 if (project.xtype != "Gtk") { // js not handled?
287 this.last_ptype_check = this.name;
289 var cls = Palete.Gir.factoryFqn(project, this.parent.fqn());
291 this.is_invalid_ptype = false;
294 var is_native = cls.props.has_key(this.name);
295 if ( is_native && this.ptype == NodePropType.PROP ) {
296 this.is_invalid_ptype = false;
299 if ( !is_native && this.ptype == NodePropType.USER ) {
300 this.is_invalid_ptype = false;
304 this.is_invalid_ptype = true;
311 public Node? parent; // the parent node.
314 public int start_line = 0;
315 public int end_line = 0;
317 // used by display list..
318 public GLib.ListStore childstore; // WILL BE USED FOR properties with mutliple types
319 public Node? add_node = null; // used when we list potentional nodes for properties in add list.
321 public string propertyof { get; set; }
324 public NodeProp(string name, NodePropType ptype, string rtype, string val) {
329 this.childstore = new GLib.ListStore( typeof(NodeProp));
332 public string ptype_as_string {
333 get { return this.ptype.to_string(); }
338 public bool equals(NodeProp p)
340 return this.name == p.name
342 this.ptype == p.ptype
344 this.rtype == p.rtype
349 public NodeProp dupe()
351 return new NodeProp(this.name, this.ptype, this.rtype, this.val);
355 public NodeProp.from_json(string key, string inval)
358 var kkv = key.strip().split(" ");
360 for (var i = 0; i < kkv.length; i++) {
361 if (kkv[i].length > 0 ) {
369 this.ptype = NodePropType.PROP;
374 if (kk[0].length > 1) {
375 // void fred (no type)
377 this.ptype = NodePropType.PROP;
381 this.rtype = ""; // no return type, only a ptype indicator.
382 this.ptype = NodePropType.from_string(kk[0]);
385 default: // 3 or more... (ignores spaces..)
388 this.ptype = NodePropType.from_string(kk[0]);
395 public string to_json_key()
398 if (this.rtype == null) { // not sure why this happens.!?
401 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
402 var oabbr = NodePropType.to_abbr(this.ptype);
403 if (oabbr.length > 0) {
409 case NodePropType.LISTENER :
412 case NodePropType.PROP:
413 return ortype + this.name;
415 case NodePropType.RAW:
416 case NodePropType.METHOD:
417 case NodePropType.SIGNAL:
418 case NodePropType.USER :
419 return oabbr + ortype + this.name;
423 case NodePropType.SPECIAL:
424 return oabbr + this.name;
425 case NodePropType.NONE: // not used
426 case NodePropType.CTOR:
434 public string to_index_key()
437 case NodePropType.PROP:
438 case NodePropType.RAW:
439 case NodePropType.METHOD :
440 case NodePropType.SIGNAL :
441 case NodePropType.USER :
444 case NodePropType.SPECIAL :
445 return "* " + this.name;
447 // in seperate list..
448 case NodePropType.LISTENER :
451 case NodePropType.NONE: // not used
452 case NodePropType.CTOR:
460 // how it appears on the property list. -
464 public string val_short {
470 if (this._val.index_of("\n") < 0) {
473 var vals = this._val.split("\n");
474 return vals[0] + (vals.length > 1 ? " ..." : "");
478 public string val_tooltip {
484 return "<tt>" + GLib.Markup.escape_text(this.val) + "</tt>";
490 public string to_display_name_prop {
495 return this.to_display_name();
501 public string to_display_name()
503 var bg = this.is_invalid_ptype ? " bgcolor=\"red\"" : "";
504 var nm = GLib.Markup.escape_text(this.name);
505 var rt = GLib.Markup.escape_text(this.rtype);
506 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
507 // before we showed "@" for signals
509 case NodePropType.PROP:
510 return @"<span$bg>$nm</span>";
512 case NodePropType.RAW:
513 return @"<span style=\"italic\">$nm</span>";
515 case NodePropType.METHOD :
516 return @"<i>$rt</i> <span color=\"#008000\" font_weight=\"bold\">$nm</span>";
518 case NodePropType.SIGNAL : // purpley
519 return @"<span color=\"#ea00d6\" font_weight=\"bold\">$nm</span>";
521 case NodePropType.USER :
522 return @"<i>$rt</i> <span$bg font_weight=\"bold\">$nm</span>";
524 case NodePropType.SPECIAL :
525 return @"<span color=\"#0000CC\" font_weight=\"bold\">$nm</span>";
527 // in seperate list..
528 case NodePropType.LISTENER :
529 return @"<b>$nm</b>";
531 case NodePropType.NONE: // not used
532 case NodePropType.CTOR:
540 public string to_tooltip_name_prop {
545 return this.to_tooltip_name();
549 public string to_tooltip_name()
552 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
553 // before we showed "@" for signals
555 case NodePropType.PROP:
556 case NodePropType.SIGNAL:
557 case NodePropType.RAW:
558 case NodePropType.SPECIAL :
559 case NodePropType.LISTENER :
560 return GLib.Markup.escape_text(this.name) ;
562 case NodePropType.METHOD :
563 case NodePropType.USER :
564 return GLib.Markup.escape_text(this.rtype) + " " + GLib.Markup.escape_text( this.name) ;
568 case NodePropType.NONE: // not used
569 case NodePropType.CTOR:
576 // used ot sort the dispaly list of properties.
577 public string to_sort_key()
581 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
582 // before we showed "@" for signals
584 case NodePropType.PROP:
587 case NodePropType.RAW:
590 case NodePropType.METHOD :
593 case NodePropType.SIGNAL :
596 case NodePropType.USER :
599 case NodePropType.SPECIAL :
602 // in seperate list..
603 case NodePropType.LISTENER :
604 return "0" + this.name;
606 case NodePropType.NONE: // not used
607 case NodePropType.CTOR:
613 // this is really only used for stuct ctors at present
614 // which are only props (although RAW might be valid)
615 public string value_to_code()
617 switch (this.ptype) {
618 case NodePropType.PROP:
621 case NodePropType.METHOD :
622 case NodePropType.RAW:
623 case NodePropType.SIGNAL :
624 case NodePropType.USER :
625 case NodePropType.SPECIAL :
626 case NodePropType.LISTENER :
627 case NodePropType.NONE: // not used
628 case NodePropType.CTOR:
631 if (this.rtype.contains(".")) {
637 switch (this.rtype) {
639 return "\"" + this.rtype.escape() + "\"";
641 return this.val.down();
655 public string to_tooltip()
659 case NodePropType.PROP:
660 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
661 case NodePropType.LISTENER :
662 // thsi might look a bit odd on javascript?
663 return "on " + this.name + " " + this.val;
665 case NodePropType.RAW:
666 return this.rtype + " " + this.name + " = " + this.val;
667 case NodePropType.METHOD :
668 // functions - js FRED function () { } <<< could probably be cleaner..
669 // functions - vala FRED () { }
670 return this.rtype + " " + this.name + " " + this.val;
671 case NodePropType.SIGNAL :
672 return "signal: " + this.rtype + " " + this.name + " " + this.val;
673 case NodePropType.USER :
674 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
676 case NodePropType.SPECIAL:
677 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
679 case NodePropType.NONE: // not used
680 case NodePropType.CTOR:
688 public string to_property_option_markup(bool isbold)
690 return isbold ? "<b>" + this.name + "</b>" : this.name;
693 public string to_property_option_tooltip()
695 return this.to_property_option_markup( false ); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
699 public bool is(NodeProp comp) {
700 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
701 return comp.ptype == this.ptype && comp.name == this.name;
703 return comp.to_index_key() == this.to_index_key();
709 public NodeProp.listenerfromjson(string str, string inval)
713 this.ptype = NodePropType.LISTENER;
718 // regular addition - should work for properties
719 public NodeProp.prop(string name, string rtype = "", string val = "")
721 this(name, NodePropType.PROP, rtype, val);
723 public NodeProp.raw(string name, string rtype = "", string val = "")
725 this(name, NodePropType.RAW, rtype, val);
728 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
730 this(name, NodePropType.METHOD, rtype, val);
732 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
734 this(name, NodePropType.METHOD, "", val);
737 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
738 public NodeProp.special(string name, string val = "")
740 this(name, NodePropType.SPECIAL, "", val);
743 public NodeProp.listener(string name, string val = "")
745 this(name, NodePropType.LISTENER, "", val);
748 public NodeProp.user(string name, string rtype = "", string val = "")
750 this(name, NodePropType.USER, rtype, val);
752 public NodeProp.sig(string name, string rtype = "void", string val = "()")
754 this(name, NodePropType.SIGNAL, rtype, val);
756 public void appendChild(NodeProp child)
758 this.childstore.append(child);
764 could use enums.. but basically.
765 0 - > inline text editor
769 public bool useTextArea()
772 var use_textarea = false;
774 //------------ things that require the text editor...
776 if (this.ptype == NodePropType.LISTENER) {
779 if (this.ptype == NodePropType.METHOD) {
783 if ( this.name == "init" && this.ptype == NodePropType.SPECIAL) {
786 if (this.val.length > 40 || this.val.index_of("\n") > -1) { // long value...