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();
239 private string last_ptype_check = "";
240 public bool is_invalid_ptype {
246 public bool update_is_valid_ptype(Project.Project project)
249 if (this.parent == null) {
252 // what types are we interested in checking?
254 if (this.ptype != NodePropType.PROP && this.ptype != NodePropType.USER) {
257 if (this.name == "xtype" || this.name == "xns" || this.name == "id" ) { // flaky..
260 if (this.name == this.last_ptype_check) {
261 return this.is_invalid_ptype;
263 if (project.xtype != "Gtk") { // js not handled?
266 this.last_ptype_check = this.name;
268 var cls = Palete.Gir.factoryFqn(project, this.parent.fqn());
270 this.is_invalid_ptype = false;
273 var is_native = cls.props.has_key(this.name);
274 if ( is_native && this.ptype == NodePropType.PROP ) {
275 this.is_invalid_ptype = false;
278 if ( !is_native && this.ptype == NodePropType.USER ) {
279 this.is_invalid_ptype = false;
283 this.is_invalid_ptype = true;
290 public Node? parent; // the parent node.
293 public int start_line = 0;
294 public int end_line = 0;
296 // used by display list..
297 public GLib.ListStore childstore; // WILL BE USED FOR properties with mutliple types
298 public Node? add_node = null; // used when we list potentional nodes for properties in add list.
300 public string propertyof { get; set; }
303 public NodeProp(string name, NodePropType ptype, string rtype, string val) {
308 this.childstore = new GLib.ListStore( typeof(NodeProp));
311 public string ptype_as_string {
312 get { return this.ptype.to_string(); }
317 public bool equals(NodeProp p)
319 return this.name == p.name
321 this.ptype == p.ptype
323 this.rtype == p.rtype
328 public NodeProp dupe()
330 return new NodeProp(this.name, this.ptype, this.rtype, this.val);
334 public NodeProp.from_json(string key, string inval)
337 var kkv = key.strip().split(" ");
339 for (var i = 0; i < kkv.length; i++) {
340 if (kkv[i].length > 0 ) {
348 this.ptype = NodePropType.PROP;
353 if (kk[0].length > 1) {
354 // void fred (no type)
356 this.ptype = NodePropType.PROP;
360 this.rtype = ""; // no return type, only a ptype indicator.
361 this.ptype = NodePropType.from_string(kk[0]);
364 default: // 3 or more... (ignores spaces..)
367 this.ptype = NodePropType.from_string(kk[0]);
374 public string to_json_key()
377 if (this.rtype == null) { // not sure why this happens.!?
380 var ortype = this.rtype + (this.rtype.length > 0 ? " " : "");
381 var oabbr = NodePropType.to_abbr(this.ptype);
382 if (oabbr.length > 0) {
388 case NodePropType.LISTENER :
391 case NodePropType.PROP:
392 return ortype + this.name;
394 case NodePropType.RAW:
395 case NodePropType.METHOD:
396 case NodePropType.SIGNAL:
397 case NodePropType.USER :
398 return oabbr + ortype + this.name;
402 case NodePropType.SPECIAL:
403 return oabbr + this.name;
404 case NodePropType.NONE: // not used
405 case NodePropType.CTOR:
413 public string to_index_key()
416 case NodePropType.PROP:
417 case NodePropType.RAW:
418 case NodePropType.METHOD :
419 case NodePropType.SIGNAL :
420 case NodePropType.USER :
423 case NodePropType.SPECIAL :
424 return "* " + this.name;
426 // in seperate list..
427 case NodePropType.LISTENER :
430 case NodePropType.NONE: // not used
431 case NodePropType.CTOR:
439 // how it appears on the property list. -
443 public string val_short {
449 if (this._val.index_of("\n") < 0) {
452 var vals = this._val.split("\n");
453 return vals[0] + (vals.length > 1 ? " ..." : "");
457 public string val_tooltip {
463 return "<tt>" + GLib.Markup.escape_text(this.val) + "</tt>";
469 public string to_display_name_prop {
474 return this.to_display_name();
480 public string to_display_name()
482 var bg = this.is_invalid_ptype ? " bgcolor=\"red\"" : "";
483 var nm = GLib.Markup.escape_text(this.name);
484 var rt = GLib.Markup.escape_text(this.rtype);
485 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
486 // before we showed "@" for signals
488 case NodePropType.PROP:
489 return @"<span$bg>$nm</span>";
491 case NodePropType.RAW:
492 return @"<span style=\"italic\">$nm</span>";
494 case NodePropType.METHOD :
495 return @"<i>$rt</i> <span color=\"#008000\" font_weight=\"bold\">$nm</span>";
497 case NodePropType.SIGNAL : // purpley
498 return @"<span color=\"#ea00d6\" font_weight=\"bold\">$nm</span>";
500 case NodePropType.USER :
501 return @"<i>$rt</i> <span$bg font_weight=\"bold\">$nm</span>";
503 case NodePropType.SPECIAL :
504 return @"<span color=\"#0000CC\" font_weight=\"bold\">$nm</span>";
506 // in seperate list..
507 case NodePropType.LISTENER :
508 return @"<b>$nm</b>";
510 case NodePropType.NONE: // not used
511 case NodePropType.CTOR:
519 public string to_tooltip_name_prop {
524 return this.to_tooltip_name();
528 public string to_tooltip_name()
531 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
532 // before we showed "@" for signals
534 case NodePropType.PROP:
535 case NodePropType.SIGNAL:
536 case NodePropType.RAW:
537 case NodePropType.SPECIAL :
538 case NodePropType.LISTENER :
539 return GLib.Markup.escape_text(this.name) ;
541 case NodePropType.METHOD :
542 case NodePropType.USER :
543 return GLib.Markup.escape_text(this.rtype) + " " + GLib.Markup.escape_text( this.name) ;
547 case NodePropType.NONE: // not used
548 case NodePropType.CTOR:
555 // used ot sort the dispaly list of properties.
556 public string to_sort_key()
560 //return (this.rtype.length > 0 ? this.rtype + " " : "") + this.name;
561 // before we showed "@" for signals
563 case NodePropType.PROP:
566 case NodePropType.RAW:
569 case NodePropType.METHOD :
572 case NodePropType.SIGNAL :
575 case NodePropType.USER :
578 case NodePropType.SPECIAL :
581 // in seperate list..
582 case NodePropType.LISTENER :
583 return "0" + this.name;
585 case NodePropType.NONE: // not used
586 case NodePropType.CTOR:
592 // this is really only used for stuct ctors at present
593 // which are only props (although RAW might be valid)
594 public string value_to_code()
596 switch (this.ptype) {
597 case NodePropType.PROP:
600 case NodePropType.METHOD :
601 case NodePropType.RAW:
602 case NodePropType.SIGNAL :
603 case NodePropType.USER :
604 case NodePropType.SPECIAL :
605 case NodePropType.LISTENER :
606 case NodePropType.NONE: // not used
607 case NodePropType.CTOR:
610 if (this.rtype.contains(".")) {
616 switch (this.rtype) {
618 return "\"" + this.rtype.escape() + "\"";
620 return this.val.down();
634 public string to_tooltip()
638 case NodePropType.PROP:
639 return this.rtype + " " + this.name + " = \"" + this.val + "\"";
640 case NodePropType.LISTENER :
641 // thsi might look a bit odd on javascript?
642 return "on " + this.name + " " + this.val;
644 case NodePropType.RAW:
645 return this.rtype + " " + this.name + " = " + this.val;
646 case NodePropType.METHOD :
647 // functions - js FRED function () { } <<< could probably be cleaner..
648 // functions - vala FRED () { }
649 return this.rtype + " " + this.name + " " + this.val;
650 case NodePropType.SIGNAL :
651 return "signal: " + this.rtype + " " + this.name + " " + this.val;
652 case NodePropType.USER :
653 return "user defined: " + this.rtype + " " + this.name + " = " + this.val;
655 case NodePropType.SPECIAL:
656 return "special property: " + this.rtype + " " + this.name + " = " + this.val;
658 case NodePropType.NONE: // not used
659 case NodePropType.CTOR:
667 public string to_property_option_markup(bool isbold)
669 return isbold ? "<b>" + this.name + "</b>" : this.name;
672 public string to_property_option_tooltip()
674 return this.to_property_option_markup( false ); // fixme will probaly want help info (possibly by havinga reference to the GirObject that its created from
678 public bool is(NodeProp comp) {
679 if (comp.ptype == NodePropType.LISTENER || this.ptype == NodePropType.LISTENER ) {
680 return comp.ptype == this.ptype && comp.name == this.name;
682 return comp.to_index_key() == this.to_index_key();
688 public NodeProp.listenerfromjson(string str, string inval)
692 this.ptype = NodePropType.LISTENER;
697 // regular addition - should work for properties
698 public NodeProp.prop(string name, string rtype = "", string val = "")
700 this(name, NodePropType.PROP, rtype, val);
702 public NodeProp.raw(string name, string rtype = "", string val = "")
704 this(name, NodePropType.RAW, rtype, val);
707 public NodeProp.valamethod(string name, string rtype = "void", string val = "() {\n\n}")
709 this(name, NodePropType.METHOD, rtype, val);
711 public NodeProp.jsmethod(string name, string val = "function() {\n\n}")
713 this(name, NodePropType.METHOD, "", val);
716 // vala (and js) specials.. props etc.. - they only have name/value (not type) - type is in xns/xtype
717 public NodeProp.special(string name, string val = "")
719 this(name, NodePropType.SPECIAL, "", val);
722 public NodeProp.listener(string name, string val = "")
724 this(name, NodePropType.LISTENER, "", val);
727 public NodeProp.user(string name, string rtype = "", string val = "")
729 this(name, NodePropType.USER, rtype, val);
731 public NodeProp.sig(string name, string rtype = "void", string val = "()")
733 this(name, NodePropType.SIGNAL, rtype, val);
735 public void appendChild(NodeProp child)
737 this.childstore.append(child);
743 could use enums.. but basically.
744 0 - > inline text editor
748 public bool useTextArea()
751 var use_textarea = false;
753 //------------ things that require the text editor...
755 if (this.ptype == NodePropType.LISTENER) {
758 if (this.ptype == NodePropType.METHOD) {
762 if ( this.name == "init" && this.ptype == NodePropType.SPECIAL) {
765 if (this.val.length > 40 || this.val.index_of("\n") > -1) { // long value...