ui-rules-enforcer: Check special treeview expander column order
As the weld::TreeView doc says, two special expander columns
for toggle buttons and images can be used that can be accessed
by index -1 in the weld::TreeView API:
/* Model column indexes are considered to begin at 0, but with special columns
before index 0. A expander image column (and an additional optional toggle
button column when enable_toggle_buttons is used). Column index -1 is
reserved to access those columns.
*/
class VCL_DLLPUBLIC TreeView : virtual public ItemView
While the vcl implementation in SalInstanceTreeView doesn't
currently take into account the .ui file at all, the gtk3
vcl implementation (GtkInstanceTreeView) does (and the
native Qt implementation in QtInstanceTreeView also does).
The vcl implementation always shows the toggle button/column
before the image/pixbuf one.
(See e.g. how SvTreeListBox::SetTabs calls
AddTab( nStartPos, TABFLAGS_CHECKBTN );
before
AddTab(nStartPos, TABFLAGS_CONTEXTBMP);
and how SalInstanceTreeView::do_insert also first
inserts an item if the SvTreeFlags::CHKBTN flag
is set before inserting a SvLBoxContextBmp for the
special bitmap/expander column.)
For consistency with the vcl implementation,
make sure the toggle renderer also comes first
in .ui files, which means it will be rendered
first when using gtk3 as well.
Ensure that by adding a rule to ui-rules-enforcer.
The two issues that the new rule detected were
already addressed in previous commits
Change-Id: I3a959d71cd91d5bfc20ba8abe50a3c7b1c189df3
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Thu Jun 18 17:58:49 2026 +0200
tdf#130857 dbaccess: Have special toggle before pixbuf col in dbtreelist.ui
and
Change-Id: Ie1bd0a96a79a9818f3aa573edb29e76363dbfe44
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Thu Jun 18 18:24:34 2026 +0200
tdf#130857 dbaccess: Show checkbox in front of icon in "Tables Filter" dlg
, so running
$ for a in `git ls-files "*.ui"`; do bin/ui-rules-enforcer.py $a; done
doesn't detect any additional issues right now, but can be used
to avoid/detect new issues in the future.
Change-Id: I1f7c8c6456ed2e8ba4d8018d69fb12b40204536a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206986
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
This commit is contained in:
@@ -623,6 +623,47 @@ def enforce_menuitem_id(current):
|
||||
if not child.attrib.get("id"):
|
||||
raise Exception(sys.argv[1] + ': menu item does not have an id set' , child.text)
|
||||
|
||||
def collect_treeview_cell_renderers(element):
|
||||
renderers = []
|
||||
for child in element:
|
||||
child_class = child.get("class")
|
||||
if child_class and child_class.startswith("GtkCellRenderer"):
|
||||
renderers.append(child_class)
|
||||
renderers = renderers + collect_treeview_cell_renderers(child)
|
||||
return renderers
|
||||
|
||||
def collect_treeview_columns(element):
|
||||
"""Returns a nested list, containing a list of renderers used in each treeview column."""
|
||||
columns = []
|
||||
for child in element:
|
||||
child_class = child.get("class")
|
||||
if child_class and child_class == "GtkTreeViewColumn":
|
||||
columns.append(collect_treeview_cell_renderers(child))
|
||||
columns = columns + collect_treeview_columns(child)
|
||||
return columns
|
||||
|
||||
def enforce_treeview_column_rules(current):
|
||||
# skip "vcl/uiconfig/ui/combobox.ui", only used by gtk3 vcl plugin for a custom combobox implementation
|
||||
if sys.argv[1] == "vcl/uiconfig/ui/combobox.ui":
|
||||
return
|
||||
|
||||
if not current.get("class") == "GtkTreeView":
|
||||
for child in current:
|
||||
enforce_treeview_column_rules(child)
|
||||
return
|
||||
|
||||
columns = collect_treeview_columns(current)
|
||||
# Ensure that the treeview has at least one column
|
||||
if not columns:
|
||||
raise Exception(sys.argv[1] + ": treeview has no columns: ", current.attrib.get("id"))
|
||||
|
||||
# If the first column makes use of special toggle and pixbuf columns
|
||||
# to be accessed with column index -1 at the same time (see also doc in
|
||||
# GtkInstanceTreeView ctor), make sure that the toggle column comes first,
|
||||
# to match behavior of the vcl implementation
|
||||
if len(columns[0]) >= 2 and columns[0][0] == "GtkCellRendererPixbuf" and columns[0][1] == "GtkCellRendererToggle":
|
||||
raise Exception(sys.argv[1] + ": treeview has special toggle and pixbuf columns/renderers in wrong order: ", current.attrib.get("id"))
|
||||
|
||||
with open(sys.argv[1], encoding="utf-8") as f:
|
||||
header = f.readline()
|
||||
f.seek(0)
|
||||
@@ -656,6 +697,7 @@ remove_expander_spacing(root)
|
||||
enforce_menubutton_indicator_consistency(root)
|
||||
enforce_label_child_is_label(root)
|
||||
enforce_menuitem_id(root)
|
||||
enforce_treeview_column_rules(root)
|
||||
enforce_active_in_group_consistency(root)
|
||||
enforce_entry_text_column_id_column_for_gtkcombobox(root)
|
||||
remove_entry_shadow_type(root)
|
||||
|
||||
Reference in New Issue
Block a user