11import Gtk from "gi://Gtk?version=4.0" ;
22
3- const grid_view = workbench . builder . get_object ( "grid_view" ) ;
3+ const grid_view = workbench . builder . get_object < Gtk . GridView > ( "grid_view" ) ;
44const add = workbench . builder . get_object ( "add" ) ;
55const remove = workbench . builder . get_object ( "remove" ) ;
66
@@ -13,7 +13,7 @@ const string_model = new Gtk.StringList({
1313const model = new Gtk . SingleSelection ( { model : string_model } ) ;
1414
1515const factory_for_grid_view = new Gtk . SignalListItemFactory ( ) ;
16- factory_for_grid_view . connect ( "setup" , ( _self , listItem ) => {
16+ factory_for_grid_view . connect ( "setup" , ( _self , listItem : Gtk . ListItem ) => {
1717 const listBox = new Gtk . Box ( {
1818 width_request : 160 ,
1919 height_request : 160 ,
@@ -27,12 +27,12 @@ factory_for_grid_view.connect("setup", (_self, listItem) => {
2727 listBox . append ( label ) ;
2828 listItem . set_child ( listBox ) ;
2929} ) ;
30- factory_for_grid_view . connect ( "bind" , ( _self , listItem ) => {
30+ factory_for_grid_view . connect ( "bind" , ( _self , listItem : Gtk . ListItem ) => {
3131 const listBox = listItem . get_child ( ) ;
32- const modelItem = listItem . get_item ( ) ;
33- const labelWidget = listBox . get_last_child ( ) ;
32+ const modelItem = listItem . get_item ( ) as Gtk . StringObject ;
33+ const labelWidget = listBox . get_last_child ( ) as Gtk . Label ;
3434
35- labelWidget . label = modelItem . string ;
35+ labelWidget . label = modelItem . string
3636} ) ;
3737
3838//View
@@ -47,7 +47,7 @@ model.model.connect("items-changed", (_list, position, removed, added) => {
4747model . connect ( "selection-changed" , ( ) => {
4848 const selected_item = model . get_selected ( ) ;
4949 console . log (
50- `Model item selected from view: ${ model . model . get_string ( selected_item ) } ` ,
50+ `Model item selected from view: ${ string_model . get_string ( selected_item ) } ` ,
5151 ) ;
5252} ) ;
5353
@@ -57,11 +57,11 @@ grid_view.factory = factory_for_grid_view;
5757// Controller
5858add . connect ( "clicked" , ( ) => {
5959 const new_item = `New item ${ item } ` ;
60- model . model . append ( new_item ) ;
60+ string_model . append ( new_item ) ;
6161 item ++ ;
6262} ) ;
6363
6464remove . connect ( "clicked" , ( ) => {
6565 const selected_item = model . get_selected ( ) ;
66- model . model . remove ( selected_item ) ;
66+ string_model . remove ( selected_item ) ;
6767} ) ;
0 commit comments