@@ -6,11 +6,13 @@ use gtk4::{self as gtk, glib, pango};
66use tablepro_core:: Value ;
77
88use super :: RowDetailPane ;
9+ use crate :: i18n:: gettext;
910use crate :: services:: change_tracker:: CellState ;
1011use crate :: services:: grid:: { GridColumn , auto_filled_sentinel, display_text} ;
1112use crate :: ui:: data_grid:: tracked_values:: cell_description;
1213use crate :: ui:: data_grid:: { DataGrid , GridRow , ServerValue , TrackedValues } ;
1314use crate :: ui:: handler_guard:: HandlerGuard ;
15+ use crate :: ui:: icons;
1416
1517/// The data columns in the order the fields list shows them: the ones on
1618/// screen as the grid shows them, then the hidden ones.
@@ -62,22 +64,58 @@ pub fn field_value(tracked: &TrackedValues, row: &GridRow, column: &GridColumn)
6264 }
6365}
6466
65- /// A field's row: its name and type on one line, its value on the next.
67+ fn is_primary_key ( column : & GridColumn ) -> bool {
68+ column. catalog . as_ref ( ) . is_some_and ( |catalog| catalog. primary_key )
69+ }
70+
71+ // The key has no role of its own, so the label is where a screen reader hears it.
72+ pub ( super ) fn field_label ( column : & GridColumn ) -> String {
73+ let mut parts = vec ! [ column. name. clone( ) ] ;
74+ let type_name = & column. value_type ( ) . name ;
75+ if !type_name. is_empty ( ) {
76+ parts. push ( type_name. clone ( ) ) ;
77+ }
78+ if is_primary_key ( column) {
79+ parts. push ( gettext ( "primary key" ) ) ;
80+ }
81+ parts. join ( ", " )
82+ }
83+
84+ fn marker ( icon : & str ) -> gtk:: Image {
85+ let image = gtk:: Image :: builder ( ) . icon_name ( icon) . visible ( false ) . build ( ) ;
86+ image. set_accessible_role ( gtk:: AccessibleRole :: Presentation ) ;
87+ image
88+ }
89+
6690fn field_row ( ) -> gtk:: Box {
91+ let key = marker ( icons:: PRIMARY_KEY ) ;
92+ // Dimmed as a libadwaita property row's title, so the eye lands on the value.
6793 let name = gtk:: Label :: builder ( )
6894 . xalign ( 0.0 )
6995 . hexpand ( true )
70- . ellipsize ( pango:: EllipsizeMode :: End )
96+ . ellipsize ( pango:: EllipsizeMode :: Middle )
7197 . build ( ) ;
98+ name. add_css_class ( "dimmed" ) ;
99+ let edited = marker ( icons:: DOCUMENT_EDIT ) ;
100+ // Match the pending value beneath the marker.
101+ edited. add_css_class ( "warning" ) ;
72102 let kind = gtk:: Label :: builder ( )
73103 . xalign ( 1.0 )
74104 . ellipsize ( pango:: EllipsizeMode :: End )
75105 . build ( ) ;
76106 kind. add_css_class ( "caption" ) ;
77107 kind. add_css_class ( "dimmed" ) ;
108+ let type_icon = marker ( icons:: TEXT_X_GENERIC ) ;
109+ type_icon. set_visible ( true ) ;
110+ type_icon. add_css_class ( "dimmed" ) ;
111+ let type_box = gtk:: Box :: new ( gtk:: Orientation :: Horizontal , 3 ) ;
112+ type_box. append ( & type_icon) ;
113+ type_box. append ( & kind) ;
78114 let top = gtk:: Box :: new ( gtk:: Orientation :: Horizontal , 6 ) ;
115+ top. append ( & key) ;
79116 top. append ( & name) ;
80- top. append ( & kind) ;
117+ top. append ( & edited) ;
118+ top. append ( & type_box) ;
81119 let value = gtk:: Inscription :: builder ( )
82120 . hexpand ( true )
83121 . min_chars ( 1 )
@@ -96,6 +134,29 @@ fn field_row() -> gtk::Box {
96134 row
97135}
98136
137+ struct FieldParts {
138+ key : gtk:: Image ,
139+ name : gtk:: Label ,
140+ edited : gtk:: Image ,
141+ kind : gtk:: Label ,
142+ value : gtk:: Inscription ,
143+ }
144+
145+ fn field_parts ( row : & gtk:: Widget ) -> Option < FieldParts > {
146+ let top = row. first_child ( ) ?;
147+ let key = top. first_child ( ) ?;
148+ let name = key. next_sibling ( ) ?;
149+ let edited = name. next_sibling ( ) ?;
150+ let kind = edited. next_sibling ( ) ?. last_child ( ) ?;
151+ Some ( FieldParts {
152+ key : key. downcast ( ) . ok ( ) ?,
153+ name : name. downcast ( ) . ok ( ) ?,
154+ edited : edited. downcast ( ) . ok ( ) ?,
155+ kind : kind. downcast ( ) . ok ( ) ?,
156+ value : row. last_child ( ) ?. downcast ( ) . ok ( ) ?,
157+ } )
158+ }
159+
99160fn set_class ( widget : & impl IsA < gtk:: Widget > , class : & str , on : bool ) {
100161 match on {
101162 true => widget. as_ref ( ) . add_css_class ( class) ,
@@ -192,26 +253,27 @@ impl RowDetailPane {
192253 let Some ( row_box) = item. child ( ) else {
193254 return ;
194255 } ;
195- let top = row_box. first_child ( ) ;
196- let ( Some ( name) , Some ( kind) , Some ( shown) ) = (
197- top. as_ref ( )
198- . and_then ( |top| top. first_child ( ) )
199- . and_downcast :: < gtk:: Label > ( ) ,
200- top. as_ref ( )
201- . and_then ( |top| top. last_child ( ) )
202- . and_downcast :: < gtk:: Label > ( ) ,
203- row_box. last_child ( ) . and_downcast :: < gtk:: Inscription > ( ) ,
204- ) else {
256+ let Some ( FieldParts {
257+ key,
258+ name,
259+ edited,
260+ kind,
261+ value : shown,
262+ } ) = field_parts ( & row_box)
263+ else {
205264 return ;
206265 } ;
266+ key. set_visible ( is_primary_key ( & column) ) ;
207267 name. set_label ( & column. name ) ;
208268 kind. set_label ( & column. value_type ( ) . name ) ;
209- item. set_accessible_label ( & column. name ) ;
269+ item. set_accessible_label ( & field_label ( & column) ) ;
210270 let Some ( row) = self . current_row ( ) else {
271+ edited. set_visible ( false ) ;
211272 shown. set_text ( None ) ;
212273 return ;
213274 } ;
214275 let value = field_value ( & grid. tracked ( ) , & row, & column) ;
276+ edited. set_visible ( value. modified ) ;
215277 shown. set_text ( Some ( & value. text ) ) ;
216278 shown. set_attributes ( Some ( & value_attributes ( & value) ) ) ;
217279 set_class ( & shown, "dimmed" , value. placeholder || value. deleted ) ;
0 commit comments