/**
-Palete.map
- -> contains a list of parent and child classes
- // eg. what can be added to what.
-
-// defaults
-
-// node properties??
- (mostly from
-
-Known issues with Palete
-
-
-Object Add:
-
-SourceView/TextView - can add widget (which doesnt really seem to work) - as it's subclassing a container
-Gtk.Table - adding children? (nothing is currently allowed.
-
-
-Properties list
-- need to remove widgets from this..
-- help / show source interface etc..?
-- make wider?
-
-Events list
-- signature on insert
-- show source interface / help
-
+This basically provides all the data needed to add stuff to gtk objects
*/
public override void load ()
{
-<<<<<<< HEAD
-
- Gir.factory(this.project, "Gtk"); // triggers a load...
- var pr = (Project.Gtk) this.project;
-
-
- this.map = new Gee.ArrayList<Usage>();
- this.generic_child_widgets = new Gee.ArrayList<string>();
- this.generic_widget_children = new Gee.ArrayList<string>();
- this.all_no_parent = new Gee.ArrayList<string>();
- var top = new Gee.ArrayList<string>();
- top.add("*top");
- foreach(var key in pr.gir_cache.keys) {
- var gir = pr.gir_cache.get(key);
-
- this.build_generic_children(gir.classes);
- }
- // add containers.
- this.map.add(new Usage( top, this.all_no_parent));
- var alltop = new Gee.ArrayList<string>();
- alltop.add("*top");
-
-
- foreach(var k in this.generic_containers) {
- alltop.add(k);
- this.add_special_children(k, "Gtk.Menu", "_menu");
- }
- var u = new Usage( alltop, this.generic_child_widgets);
- this.map.add(u);
-
- u = new Usage( this.generic_child_widgets, this.generic_widget_children);
- this.map.add(u);
-
- foreach(var key in pr.gir_cache.keys) {
- var gir = pr.gir_cache.get(key);
- this.build_class_children_from_props(gir.classes);
- }
- // oddities.
-
- this.add_special_children("Gtk.Menu","Gtk.MenuItem", "");
- this.add_special_children("Gtk.MenuBar", "Gtk.MenuItem", "");
- this.add_special_children("Gtk.Toolbar", "Gtk.ToolItem", "");
- this.add_special_children("Gtk.MenuItem","Gtk.Box", "");
- this.add_special_children("Gtk.Notebook", "Gtk.Label", "label[]"); //??
- this.add_special_children("Gtk.Window","Gtk.HeaderBar", "titlebar");
-
- this.add_special_children("Gtk.Stack","Gtk.Label", "titles[]");
- this.add_special_children("Gtk.TreeView","Gtk.TreeViewColumn", ""); // any viewcolum added..
- this.add_special_children("Gtk.TreeViewColumn","Gtk.CellRenderer", "");
-
- this.add_special_children("Gtk.Dialog","Gtk.Button", "buttons[]");
- //this.add_special_children("Gtk.Dialog","Gtk.Button", "response_id");
- this.add_special_children("Gtk.RadioButton","Gtk.Button", "_group_name"); // fake property
-
- this.add_special_children("Gtk.ButtonBox","Gtk.Button", "");
-
-
-
- this.init_node_defaults();
- this.init_child_defaults();
-
- foreach(var m in this.map) {
- GLib.debug("Usage: %s", m.to_string());
- }
-
- }
-
-
-
-
- // containers that can contain only certial types of children, and should be ignored from the general bulk add.
- Gee.ArrayList<string> generic_child_widgets;
- Gee.ArrayList<string> generic_widget_children; // mostly events...
- Gee.ArrayList<string> all_no_parent;
-/*
- string[] special_containers = {
- "Gtk.Menu",
- "Gtk.MenuBar",
- "Gtk.Toolbar", // only toolbarItems.
-
- "Gtk.Assistant", // needs fake child? including fake page type
- "Gtk.Notebook", // needs fake child?
-
- };
- // children (or anythign that extends this) - that can not be added to a standard widget
- string[] special_containers_children = {
- "Gtk.MenuItem",
- "Gtk.ToolbarItem"
- };
- */
- // widgets that can not be added to anything? - including their children.
- string[] no_parent = { // except *top
- "Gtk.Window",
- "Gtk.Dialog",
- };
-
- string[] generic_containers = {
- "Gtk.Assistant",
- "Gtk.ActionBar",
- "Gtk.AspectFrame",
- "Gtk.Frame",
- "Gtk.Fixed",
- "Gtk.Box",
- "Gtk.Dialog",
- "Gtk.Expander", // add method is different..
- "Gtk.FlowBox",
- "Gtk.HeaderBar",
- "Gtk.InfoBar",
- "Gtk.ListBox",
- "Gtk.Overlay",
- "Gtk.Paned",
- "Gtk.Popover",
- "Gtk.PopoverMenu",
- "Gtk.Revealer",
- "Gtk.ScrolledWindow",
- "Gtk.Stack", // add with name?
- "Gtk.ToolItem",
- "Gtk.ToolPalette",
- "Gtk.Viewport",
- "Gtk.Window",
- "Gtk.Notebook",
- "Gtk.ApplicationWindow",
- "Gtk.Grid",
- "Gtk.SearchBar",
-
- };
-
- string[] widgets_blacklist = {
- "Gtk.Arrow", //Depricated
-
- "Gtk.ShortcutLabel",
- "Gtk.ShortcutsGroup",
- "Gtk.ShortcutsSection",
- "Gtk.ShortcutsShortcut",
- "Gtk.ShortcutsWindow",
- "Gtk.Socket",
- "Gtk.ToolItemGroup",
-
- //"Gtk.ButtonBox", << why ?
- "Gtk.CellView",
- "Gtk.EventBox",
- "Gtk.FlowBoxChild",
- "Gtk.Invisible",
- "Gtk.ListBoxRow",
- "Gtk.OffscreenWindow",
- "Gtk.Plug",
- "Gtk.HSV",
- "Gtk.ImageMenuItem", //deprecated? (not sure why it's not been picked up)
-
- "Gtk.Menu", // it's added as a special only?
- "Gtk.MenuItem",
- "Gtk.ToolItem",
-
- "WebKit.WebViewBase",
-
- "Gtk.HeaderBar", // only to window
- };
-
- /**
- * Gtk's heirachy of parent/children is not particulaly logical
- * Gtk.Containers - some are not really that good t being containers. Gtk.Bin (single only) - is a good flag for indicating
- * Gtk.Widgets - some are not great at being widgets
- * Gtk.Menu - should really only contain menuitems, but the API doesnt really restrict this.
- * The list goes on.
- *
- *
- */
-
- public void build_generic_children(Gee.HashMap<string,GirObject> classes)
- {
-
- GLib.debug("Build Generic Children");
- foreach(var cls in classes.values) {
-
- var fqn = cls.fqn();
-
- if (cls.is_deprecated) { // don't add depricated to our selection.
- //GLib.debug("Class %s is depricated", cls.fqn());
- continue;
- }
- var is_widget = cls.inherits.contains("Gtk.Widget") || cls.implements.contains("Gtk.Widget");
- var is_event = cls.inherits.contains("Gtk.EventController") || cls.implements.contains("Gtk.EventController");
- if (!is_widget && !is_event) {
- continue;
- }
- if (cls.is_abstract) {
- continue;
- }
- if (cls.nodetype == "Interface") {
- continue;
- }
- var is_black = false;
- for (var i = 0 ; i < this.widgets_blacklist.length; i++) {
- var black = this.widgets_blacklist[i];
-
- if (fqn == black || cls.implements.contains(black) || cls.inherits.contains(black)) {
- is_black = true;
- break;
- }
- }
- if (is_black) {
- continue;
- }
-
-
-
- for (var i = 0 ; i < this.no_parent.length; i++) {
- var black = this.no_parent[i];
-
- if (fqn == black || cls.implements.contains(black) || cls.inherits.contains(black)) {
- is_black = true;
- all_no_parent.add(fqn);
-
- break;
- }
-
-
- }
- if (is_black) {
- continue;
- }
- GLib.debug("Build Generic Children - add %s", fqn);
-
- if (is_event) {
- this.generic_widget_children.add(fqn);
- } else {
- this.generic_child_widgets.add(fqn);
- }
- //this.add_special_children(fqn, "Gtk.Menu", "_menu"); // fake propety
- }
-
- }
-
- public void add_special_children(string parent, string child, string prop)
- {
- this.getClass(parent);
- var cls_cn = this.getClass(child);
- var localopts_r = new Gee.ArrayList<string>();
- var localopts_l = new Gee.ArrayList<string>();
- localopts_l.add(parent);
-
- if (cls_cn == null) {
-=======
if (this.loaded) {
->>>>>>> wip_alan_T7440_handling_gtk4_and_bad_girs
return;
}
Gir.factory(this.project, "Gtk"); // triggers a load...
-<<<<<<< HEAD
-
- public void build_class_children_from_props(Gee.HashMap<string,GirObject> classes)
- {
-
-
-
- foreach(var cls in classes.values) {
-
-
- if (cls.is_deprecated) { // don't add depricated to our selection.
- //GLib.debug("Class %s is depricated", cls.fqn());
- continue;
- }
-
-
-
- // we can still add properties of abstract classes...
-
- if (cls.is_abstract || cls.nodetype == "Interface") {
- continue;
- }
-
-
- if (cls.props.size < 1) {
- continue;
- }
-
- var localopts_r = new Gee.ArrayList<string>();
- var localopts_l = new Gee.ArrayList<string>();
- localopts_l.add(cls.fqn());
-
- // we have a class that extends a widget - let's see if we can add the object based properties. here.
-
- var props = cls.props.values.to_array();
- for (var i = 0 ;i < props.length;i++) {
- var prop = props[i];
-
- if (!prop.type.contains(".")) {
- // not a namespaced object - ignore
- continue;
- }
- // gtkcontainer child is a abstract method - that can be called multiple times
- // gtkwidget parent - is a similar method
- if (!prop.is_readable && !prop.is_writable) {
- continue;
- }
- if (prop.is_deprecated) {
- continue;
- }
-
- if (prop.name == "parent" ||
- (prop.name == "child" && cls.fqn() != "Gtk.Popover") || // allow child only on popover.
- prop.name == "attached_to" ||
- prop.name == "mnemonic_widget" ||
- prop.name == "application" ||
- prop.name == "transient_for" ||
- prop.name == "screen" || // gtk windows.
- prop.name == "accel_closure" ||
- prop.name == "accel_widget" ||
- prop.name == "label_widget" ||
- prop.name == "align_widget" ||
- prop.name == "icon_widget" ||
- prop.name == "action_target" ||
- prop.name == "related_action" || // not sure if we should disable this.
- prop.name == "visible_child" ||
- prop.name == "attach_widget" || // gtk menu
- prop.name == "relative_to" || // popover
- // gtk4
- prop.name == "default_widget" ||
- prop.name == "focus_widget" ||
- prop.name == "key_capture_widget" ||
- prop.name == "root" ||
- prop.name == "layout_manager" ||
- 1 == 0
-
- ) {
- continue;
- }
-
-
-
- var propcls = this.getClass(prop.type);
- if (propcls == null || propcls.name == "GLib.Object") { // no point in adding generic glib objects
- continue;
- }
-
-
-
-
- // any other weird stuff.
- // Button.image -> can be a Gtk.Widget.. but really only makes sense as a Gtk.Image
- if (prop.name == "image" && propcls.name == "Gtk.Widget") {
- localopts_r.add( "Gtk.Image:image");
- continue;
-
- }
-
-
- // check if propcls is abstract?
- if (!propcls.is_abstract && propcls.nodetype != "Interface") {
- localopts_r.add( prop.type + ":" + prop.name);
- //GLib.debug("Add Widget Prop %s:%s (%s) - from %s", cls.fqn(), prop.name, prop.type, prop.propertyof);
- }
-
-
-
- //GLib.debug("Add Widget Prop %s:%s (%s) - from %s", cls.fqn(), prop.name, prop.type, prop.propertyof);
- foreach(var impl in propcls.implementations) {
- //GLib.debug("Add Widget Prop %s:%s (%s) - from %s", cls.fqn(), prop.name, prop.type, prop.propertyof);
- // in theory these can not be abstract?
-
- var impcls = this.getClass(impl);
- if (impcls.is_abstract || impcls.nodetype == "Interface") {
- continue;
- }
- //GLib.debug("Add Widget Prop %s:%s (%s)", cls.fqn(), prop.name, impl);
- localopts_r.add( impl + ":" + prop.name );
- }
-
-
-
-
- // lookup type -> is it an object
- // and not a enum..
- // if so then add it to localopts
-
- }
- if (localopts_r.size > 0) {
- this.map.add(new Usage(localopts_l, localopts_r));
- }
- }
-
-
-
-
-
- }
-=======
->>>>>>> wip_alan_T7440_handling_gtk4_and_bad_girs
public string doc(string what)
{
if (val.is_deprecated) {
continue;
}
+ if (!val.is_writable && !val.ctor_only ) { // if it's ctor we accept it.
+ continue;
+ }
+
if (val.type == "GLib.Object") { /// this is practually everything? ?? shoud we display it as a property?
continue;
}
//gtk box failing
//GLib.debug("No. of parmas %s %d", cls, ctor.params.size);
-<<<<<<< HEAD
- var m = ar.get(method);
- if (m != null) {
-
-
- foreach (var prop in m.paramset.params) {
- string[] opts;
-
- GLib.debug("adding proprty from ctor : %s, %s, %s", cls, prop.name, prop.type);
-
- var sub = this.getClass(prop.type);
- if (sub != null) { // can't add child classes here...
- GLib.debug("skipping ctor argument proprty is an object");
- continue;
- }
- var dval = "";
- switch (prop.type) {
- case "int":
- dval = "0";break;
- case "string":
- dval = ""; break;
- // anything else?
- default:
- this.typeOptions(cls, prop.name, prop.type, out opts);
- dval = opts.length > 0 ? opts[0] : "";
- break;
- }
-
- this.node_defaults.get(cls).add( new JsRender.NodeProp.prop( prop.name, prop.type, dval));
-
-
- }
-=======
foreach (var prop in ctor.paramset.params) {
string[] opts;
->>>>>>> wip_alan_T7440_handling_gtk4_and_bad_girs
}
}
this.child_defaults.get(cls).add( new JsRender.NodeProp.prop(propname, type, val));
}
-<<<<<<< HEAD
-
- public override void on_child_added(JsRender.Node? parent,JsRender.Node child)
- {
-
- if (parent != null && !child.has("* prop")) { // child has a property - no need for child properties
-
- if (this.child_defaults.has_key(parent.fqn())) {
- foreach(var k in this.child_defaults.get(parent.fqn())) {
- if (!child.has(k.to_index_key())) {
- child.set_prop(k.dupe());
- }
- }
- }
- }
- if (this.node_defaults.has_key(child.fqn())) {
- foreach(var k in this.node_defaults.get(child.fqn())) {
-
- if (!child.has(k.to_index_key())) {
- GLib.debug("Adding Property %s", k.to_tooltip());
- child.set_prop(k.dupe());
- }
- }
- }
-
- // if child is a struct
- var childcls = this.getClass(child.fqn());
- if (childcls != null && childcls.nodetype == "Struct") {
- // then we need to add all the props.
- foreach(var prop in childcls.props.values) {
- child.set_prop(prop.toNodeProp());
-
-
- }
-
-
- }
- // is child a Event - handled by nodetovala...
-
- // any other combo?
- switch(parent.fqn()) {
- case "Gtk.Dialog":
- if (child.has("* prop") && child.get_prop("* prop").val == "buttons[]") {
- child.set_prop( new JsRender.NodeProp.special("response_id", "1"));
- }
- break;
-
- }
-
- // not really
- //this.fillPack(child, parent);
-
-
-
-
- }
-=======
->>>>>>> wip_alan_T7440_handling_gtk4_and_bad_girs
public Gee.ArrayList<string> packages(Project.Gtk gproject)
{
}
- public override Gee.ArrayList<CompletionProposal> suggestComplete(
- JsRender.JsRender file,
- JsRender.Node? node,
- JsRender.NodeProp? xxxprop, // is this even used?
- string complete_string
- ) {
-
- var ret = new Gee.ArrayList<CompletionProposal>();
- // completion rules??
-
- // make sure data is loaded
- Gir.factory(this.project,"Gtk");
-
- // Roo......
-
- // this. (based on the node type)
- // this.xxx // Node and any determination...
-
- if (complete_string.index_of(".",0) < 0) {
- // string does not have a '.'
- // offer up vala keywords... / _this .. / look for var string = .. in the code..
-
- var max = (int)Vala.TokenType.YIELD +1;
- for (var i =0; i < max;i++) {
- var m = (Vala.TokenType)i;
- var s = m.to_string();
- var ss = s.slice(1,-1);
- if (s[0] == '`' && GLib.Regex.match_simple("^[a-z]+$", ss) &&
- complete_string != ss && ss.index_of(complete_string,0) == 0 ) {
- var sci = new CompletionProposal(ss,ss, "vala : " + ss);
- ret.add(sci);
- }
- }
- var miter = ((Project.Gtk)this.project).gir_cache.map_iterator();
- while (miter.next()) {
- var ss = miter.get_key();
-
- if (complete_string != ss && ss.index_of(complete_string,0) == 0 ) {
- var sci = new CompletionProposal(ss,ss, "vala namespace: " + ss);
- ret.add(sci);
-
- }
- }
-
-
- if (complete_string != "_this" && "_this".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
- var sci = new CompletionProposal("_this - the top level element","_this",
- "Reference to the container object instance of this file");
- ret.add(sci);
-
- }
- // basic types..
-
- return ret;
- }
-
-
- // got at least one ".".
- var parts = complete_string.split(".");
- var curtype = "";
- var cur_instance = false;
- if (parts[0] == "this") {
- // work out from the node, what the type is...
- if (node == null) {
- print("node is empty - no return\n");
- return ret; // no idea..
- }
- curtype = "*" + node.fqn();
- cur_instance = true;
- } else {
- if (((Project.Gtk)this.project).gir_cache.get(parts[0]) == null) {
- return ret;
- }
- curtype = parts[0];
- }
- // all Gtk.... etc.. types...
-
-
- //if (parts[0] == "Roo") {
- // curtype = "Roo";
- // cur_instance = false;
- //}
-
- var prevbits = parts[0] + ".";
- for(var i =1; i < parts.length; i++) {
- print("matching %d/%d\n", i, parts.length);
- var is_last = i == parts.length -1;
-
-
-
- // look up all the properties of the type...
- var cls = this.getClass(curtype);
- if (cls == null && curtype[0] != '*') {
- print("could not get class of curtype %s\n", curtype);
- return ret;
- }
-
- if (!is_last) {
-
- if (curtype[0] == '*' && parts[i] == "el") {
- curtype = curtype.substring(1);
- prevbits += parts[i] + ".";
- continue;
- }
-
- // only exact matches from here on...
- if (cur_instance) {
- if (cls == null) {
- return ret;
- }
- if (cls.props.has_key(parts[i])) {
- var clsprop = cls.props.get(parts[i]);
- if (clsprop.type.index_of(".",0) > -1) {
- // type is another roo object..
- curtype = clsprop.type;
- prevbits += parts[i] + ".";
- continue;
- }
- return ret;
- }
-
-
-
- // check methods?? - we do not export that at present..
- return ret; //no idea...
- }
- var look = prevbits + parts[i];
- var scls = this.getClass(look);
- if (scls == null) {
- return ret;
- }
- curtype = look;
- prevbits += parts[i] + ".";
- continue;
-
- }
-
- // got to the last element..
- print("Got last element\n");
- if (curtype == "") { // should not happen.. we would have returned already..
- return ret;
- }
- print("Got last element type %s\n",curtype);
- if (!cur_instance) {
- print("matching instance");
- // it's a static reference..
- var citer = cls.classes.map_iterator();
- while (citer.next()) {
- var scls = citer.get_key();
-
- if (parts[i].length > 0 && scls.index_of(parts[i],0) != 0) {
- continue;
- }
- // got a starting match..
- var sci = new CompletionProposal(prevbits + scls,prevbits + scls,scls);
- ret.add(sci);
-
-
- }
- // methods....
- citer = cls.methods.map_iterator();
- while (citer.next()) {
- var scls = citer.get_key();
-
- if (parts[i].length > 0 && scls.index_of(parts[i],0) != 0) {
- continue;
- }
- // got a starting match..
-
- var sci = new CompletionProposal(prevbits + scls + citer.get_value().sig,prevbits + scls,scls);
- ret.add(sci);
-
- }
-
- // enums....
- citer = cls.consts.map_iterator();
- while (citer.next()) {
- var scls = citer.get_key();
-
- if (parts[i].length > 0 && scls.index_of(parts[i],0) != 0) {
- continue;
- }
- // got a starting match..
- var sci = new CompletionProposal(prevbits + scls + citer.get_value().sig,prevbits + scls,scls);
- ret.add(sci);
-
- }
-
-
- return ret;
- }
- print("matching property");
- if (cls == null) {
- return ret;
- }
-
-
- var citer = cls.methods.map_iterator();
- while (citer.next()) {
- var cprop = citer.get_value();
- // does the name start with ...
- if (parts[i].length > 0 && cprop.name.index_of(parts[i],0) != 0) {
- continue;
- }
- // got a matching property...
- // return type?
- var sci = new CompletionProposal( cprop.name + cprop.sig + " : ("+ cprop.propertyof + ")",
- prevbits + cprop.name + "(",cprop.doctxt);
- ret.add(sci);
-
-
- }
-
- // get the properties / methods and subclasses.. of cls..
- // we have cls.. - see if the string matches any of the properties..
- citer = cls.props.map_iterator();
- while (citer.next()) {
- var cprop = citer.get_value();
- // does the name start with ...
- if (parts[i].length > 0 && cprop.name.index_of(parts[i],0) != 0) {
- continue;
- }
- // got a matching property...
- var sci = new CompletionProposal(cprop.name + " : " + cprop.type + " ("+ cprop.propertyof + ")",
- prevbits + cprop.name,cprop.doctxt);
- ret.add(sci);
-
-
-
- }
-
-
- return ret;
-
-
-
-
-
- }
-
-
-
-
-
-
- return ret;
- }
+
void add_classes_from_method(GirObject cls, string method , Gee.ArrayList<string> ret)
// skip dupe // skip depricated
// skip not object // skip GLib.Object (base)
+
+ //if (cls.fqn() == "GLib.Menu" && method == "append_submenu") {
+ // ty = m.paramset.params.get(1).type;
+ // GLib.debug("add %s method %s arg1 = %s", cls.fqn(), method, ty);
+ // this.addRealClasses(ret, ty);
+ //}
+
}
void addRealClasses(Gee.ArrayList<string> ret, string cn, bool allow_root = false)
this.add_classes_from_method(cls, "add_tick_callback", ret); // wtf does this do.
this.add_classes_from_method(cls, "append", ret);
this.add_classes_from_method(cls, "append_column", ret); // columnview column
- this.add_classes_from_method(cls, "append_item", ret); // GLib.Menu
+ this.add_classes_from_method(cls, "append_item", ret); // GLib.Menu
+ //this.add_classes_from_method(cls, "append_submenu", ret); // GLib.Menu - complicated to support
this.add_classes_from_method(cls, "attach", ret); // grid column
this.add_classes_from_method(cls, "pack_start", ret); // headerbar (also has pack end?)