1
1
import Gtk from "gi://Gtk?version=4.0" ;
2
2
3
- const grid_view = workbench . builder . get_object ( "grid_view" ) ;
3
+ const grid_view = workbench . builder . get_object < Gtk . GridView > ( "grid_view" ) ;
4
4
const add = workbench . builder . get_object ( "add" ) ;
5
5
const remove = workbench . builder . get_object ( "remove" ) ;
6
6
@@ -13,7 +13,7 @@ const string_model = new Gtk.StringList({
13
13
const model = new Gtk . SingleSelection ( { model : string_model } ) ;
14
14
15
15
const 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 ) => {
17
17
const listBox = new Gtk . Box ( {
18
18
width_request : 160 ,
19
19
height_request : 160 ,
@@ -27,12 +27,12 @@ factory_for_grid_view.connect("setup", (_self, listItem) => {
27
27
listBox . append ( label ) ;
28
28
listItem . set_child ( listBox ) ;
29
29
} ) ;
30
- factory_for_grid_view . connect ( "bind" , ( _self , listItem ) => {
30
+ factory_for_grid_view . connect ( "bind" , ( _self , listItem : Gtk . ListItem ) => {
31
31
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 ;
34
34
35
- labelWidget . label = modelItem . string ;
35
+ labelWidget . label = modelItem . string
36
36
} ) ;
37
37
38
38
//View
@@ -47,7 +47,7 @@ model.model.connect("items-changed", (_list, position, removed, added) => {
47
47
model . connect ( "selection-changed" , ( ) => {
48
48
const selected_item = model . get_selected ( ) ;
49
49
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 ) } ` ,
51
51
) ;
52
52
} ) ;
53
53
@@ -57,11 +57,11 @@ grid_view.factory = factory_for_grid_view;
57
57
// Controller
58
58
add . connect ( "clicked" , ( ) => {
59
59
const new_item = `New item ${ item } ` ;
60
- model . model . append ( new_item ) ;
60
+ string_model . append ( new_item ) ;
61
61
item ++ ;
62
62
} ) ;
63
63
64
64
remove . connect ( "clicked" , ( ) => {
65
65
const selected_item = model . get_selected ( ) ;
66
- model . model . remove ( selected_item ) ;
66
+ string_model . remove ( selected_item ) ;
67
67
} ) ;
0 commit comments