[gi-docgen/ebassi/element-type] generate: Handle the element-type attribute for ListModels




commit fbcbd3a5830817606c3f517b45bb49afe6b1ff28
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Jun 23 16:52:20 2021 +0100

    generate: Handle the element-type attribute for ListModels
    
    When returning a GListModel, GTK annotates the element type held inside
    the list model with:
    
        (attributes element-type=GtkWindow)
    
    as the `(element-type)` annotation can only work for arrays, linked
    lists, and hash tables.
    
    We still want to indicate what is the expected type inside a GListModel,
    as it's completely opaque otherwise.

 gidocgen/gdgenerate.py                     | 12 +++++++++++-
 gidocgen/templates/basic/class_method.html |  1 +
 gidocgen/templates/basic/function.html     |  1 +
 gidocgen/templates/basic/method.html       |  1 +
 gidocgen/templates/basic/signal.html       |  1 +
 gidocgen/templates/basic/type_func.html    |  1 +
 gidocgen/templates/basic/vfunc.html        |  1 +
 7 files changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/gidocgen/gdgenerate.py b/gidocgen/gdgenerate.py
index 635fa63..6dc7fc4 100644
--- a/gidocgen/gdgenerate.py
+++ b/gidocgen/gdgenerate.py
@@ -526,6 +526,7 @@ class TemplateReturnValue:
             self.type_cname = type_name_to_cname(retval.target.name, True)
         self.is_array = isinstance(retval.target, gir.ArrayType)
         self.is_list = isinstance(retval.target, gir.ListType)
+        self.is_list_model = self.type_name in ['Gio.ListModel', 'GListModel']
         self.transfer = retval.transfer or 'none'
         if isinstance(call, gir.Method):
             self.transfer_note = METHOD_RETVAL_TRANSFER_MODES[retval.transfer or 'none']
@@ -541,6 +542,8 @@ class TemplateReturnValue:
         if self.is_list:
             self.value_type = retval.target.value_type.name
             self.value_type_cname = retval.target.value_type.ctype
+        if self.is_list_model:
+            self.value_type = retval.attributes.get('element-type', 'GObject')
         if self.type_name in ['utf8', 'filename']:
             self.string_note = STRING_TYPES[self.type_name]
         if retval.doc is not None:
@@ -553,18 +556,25 @@ class TemplateReturnValue:
             name = self.value_type
         elif self.is_list:
             name = self.value_type
+        elif self.is_list_model:
+            name = self.value_type
         elif self.type_name is not None:
             name = self.type_name
         else:
             name = None
         if name is not None:
             if name.startswith(namespace.name):
-                self.link = gen_type_link(namespace, name[len(namespace.name) + 1:])
+                if '.' in name:
+                    self.link = gen_type_link(namespace, name[len(namespace.name) + 1:])
+                else:
+                    self.link = gen_type_link(namespace, name[len(namespace.name):])
             else:
                 if self.is_array:
                     self.link = f"<code>{self.value_type_cname}</code>"
                 elif self.is_list:
                     self.link = f"<code>{self.value_type_cname}</code>"
+                elif self.is_list_model:
+                    self.link = f"<code>{self.value_type}</code>"
 
     @property
     def is_pointer(self):
diff --git a/gidocgen/templates/basic/class_method.html b/gidocgen/templates/basic/class_method.html
index a26e93f..9337586 100644
--- a/gidocgen/templates/basic/class_method.html
+++ b/gidocgen/templates/basic/class_method.html
@@ -156,6 +156,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
             <td>
             {%- if class_method.return_value.is_array -%}An array of&nbsp;{%- endif -%}
             {%- if class_method.return_value.is_list -%}A list of&nbsp;{%- endif -%}
+            {%- if class_method.return_value.is_list_model -%}A list model of&nbsp;{%- endif -%}
             {%- if class_method.return_value.link -%}
             {{ class_method.return_value.link|safe }}
             {%- else -%}
diff --git a/gidocgen/templates/basic/function.html b/gidocgen/templates/basic/function.html
index 08ed87b..4f8ffcf 100644
--- a/gidocgen/templates/basic/function.html
+++ b/gidocgen/templates/basic/function.html
@@ -163,6 +163,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
             <td>
             {%- if func.return_value.is_array -%}An array of&nbsp;{%- endif -%}
             {%- if func.return_value.is_list -%}A list of&nbsp;{%- endif -%}
+            {%- if func.return_value.is_list_model -%}A list model of&nbsp;{%- endif -%}
             {%- if func.return_value.link -%}
             {{ func.return_value.link|safe }}
             {%- else -%}
diff --git a/gidocgen/templates/basic/method.html b/gidocgen/templates/basic/method.html
index 49d1fe1..fc8e9c2 100644
--- a/gidocgen/templates/basic/method.html
+++ b/gidocgen/templates/basic/method.html
@@ -158,6 +158,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
             <td>
             {%- if method.return_value.is_array -%}An array of&nbsp;{%- endif -%}
             {%- if method.return_value.is_list -%}A list of&nbsp;{%- endif -%}
+            {%- if method.return_value.is_list_model -%}A list model of&nbsp;{%- endif -%}
             {%- if method.return_value.link -%}
             {{ method.return_value.link|safe }}
             {%- else -%}
diff --git a/gidocgen/templates/basic/signal.html b/gidocgen/templates/basic/signal.html
index ea27925..68ef3f8 100644
--- a/gidocgen/templates/basic/signal.html
+++ b/gidocgen/templates/basic/signal.html
@@ -168,6 +168,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
             <td>
             {%- if signal.return_value.is_array -%}An array of&nbsp;{%- endif -%}
             {%- if signal.return_value.is_list -%}A list of&nbsp;{%- endif -%}
+            {%- if signal.return_value.is_list_model -%}A list model of&nbsp;{%- endif -%}
             {%- if signal.return_value.link -%}
             {{ signal.return_value.link|safe }}
             {%- else -%}
diff --git a/gidocgen/templates/basic/type_func.html b/gidocgen/templates/basic/type_func.html
index babde7a..aadadfb 100644
--- a/gidocgen/templates/basic/type_func.html
+++ b/gidocgen/templates/basic/type_func.html
@@ -158,6 +158,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
             <td>
             {%- if type_func.return_value.is_array -%}An array of&nbsp;{%- endif -%}
             {%- if type_func.return_value.is_list -%}A list of&nbsp;{%- endif -%}
+            {%- if type_func.return_value.is_list_model -%}A list model of&nbsp;{%- endif -%}
             {%- if type_func.return_value.link -%}
             {{ type_func.return_value.link|safe }}
             {%- else -%}
diff --git a/gidocgen/templates/basic/vfunc.html b/gidocgen/templates/basic/vfunc.html
index ef48af9..b62c08a 100644
--- a/gidocgen/templates/basic/vfunc.html
+++ b/gidocgen/templates/basic/vfunc.html
@@ -158,6 +158,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
             <td>
             {%- if vfunc.return_value.is_array -%}An array of&nbsp;{%- endif -%}
             {%- if vfunc.return_value.is_list -%}A list of&nbsp;{%- endif -%}
+            {%- if vfunc.return_value.is_list_model -%}A list model of&nbsp;{%- endif -%}
             {%- if vfunc.return_value.link -%}
             {{ vfunc.return_value.link|safe }}
             {%- else -%}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]