@@ -106,7 +106,7 @@ function iter_from_string_index(store, index::String)
106
106
if ! isvalid (store, iter)
107
107
error (" invalid index: $index " )
108
108
end
109
- iter
109
+ iter
110
110
end
111
111
112
112
# ## GtkListStore
@@ -143,6 +143,13 @@ function unshift!(listStore::GtkListStore, values::Tuple)
143
143
iter[]
144
144
end
145
145
146
+ # # insert before
147
+ function Base. insert! (listStore:: GtkListStoreLeaf , iter:: TRI , values)
148
+ newiter = Gtk. mutable (GtkTreeIter)
149
+ ccall ((:gtk_list_store_insert_before ,Gtk. libgtk),Void,(Ptr{GObject},Ptr{GtkTreeIter},Ptr{GtkTreeIter}), listStore, newiter, iter)
150
+ list_store_set_values (listStore, newiter, values)
151
+ newiter[]
152
+ end
146
153
147
154
148
155
function delete! (listStore:: GtkListStore , iter:: TRI )
@@ -151,28 +158,26 @@ function delete!(listStore::GtkListStore, iter::TRI)
151
158
listStore
152
159
end
153
160
161
+ Base. deleteat! (listStore:: GtkListStore , iter:: TRI ) = delete! (listStore, iter)
162
+
163
+
154
164
empty! (listStore:: GtkListStore ) =
155
165
ccall ((:gtk_list_store_clear ,libgtk), Void, (Ptr{GObject},),listStore)
156
166
157
167
# # by index
158
168
159
169
# # insert into a list store after index
160
170
function Base. insert! (listStore:: GtkListStoreLeaf , index:: Int , values)
161
- index < 1 && return (unshift! (listStore, values))
162
-
163
- index = min (index, length (listStore))
164
- iter = Gtk. mutable (GtkTreeIter)
165
- siter = iter_from_index (listStore, index)
166
- ccall ((:gtk_list_store_insert_after ,Gtk. libgtk),Void,(Ptr{GObject},Ptr{GtkTreeIter},Ptr{GtkTreeIter}), listStore, iter, siter)
167
- list_store_set_values (listStore, iter, values)
168
- iter
169
- end
171
+ index > length (listStore) && return (push! (listStore, values))
170
172
171
- function Base. splice! (listStore:: GtkListStoreLeaf , index:: Int )
172
173
iter = iter_from_index (listStore, index)
173
- delete ! (listStore, iter)
174
+ insert ! (listStore, iter, values )
174
175
end
175
176
177
+ Base. deleteat! (listStore:: GtkListStoreLeaf , index:: Int ) = delete! (listStore, iter_from_index (listStore, index))
178
+ Base. pop! (listStore:: GtkListStoreLeaf ) = deleteat! (listStore, length (listStore))
179
+ Base. shift! (listSTore:: GtkListStoreLeaf ) = deleteat! (listStore, 1 )
180
+
176
181
177
182
178
183
@@ -183,6 +188,15 @@ isvalid(listStore::GtkListStore, iter::TRI) =
183
188
length (listStore:: GtkListStore ) =
184
189
ccall ((:gtk_tree_model_iter_n_children ,libgtk), Cint, (Ptr{GObject},Ptr{GtkTreeIter}),listStore, C_NULL )
185
190
191
+ size (listStore:: GtkListStore ) = (length (listStore), ncolumns (GtkTreeModel (listStore)))
192
+
193
+ Base. getindex (listStore:: GtkListStore , iter:: TRI , column:: Integer ) = getindex (GtkTreeModel (listStore), iter, column)
194
+ Base. getindex (listStore:: GtkListStore , iter:: TRI ) = getindex (GtkTreeModel (listStore), iter)
195
+ Base. getindex (listStore:: GtkListStore , row:: Int , column) = getindex (listStore, iter_from_index (listStore, row), column)
196
+ Base. getindex (listStore:: GtkListStore , row:: Int ) = getindex (listStore, iter_from_index (listStore, row))
197
+
198
+
199
+
186
200
# ## GtkTreeStore
187
201
188
202
function GtkTreeStoreLeaf (types:: Type... )
@@ -226,18 +240,10 @@ function unshift!(treeStore::GtkTreeStore, values::Tuple, parent=nothing)
226
240
iter[]
227
241
end
228
242
229
- function delete! (treeStore:: GtkTreeStore , iter:: TRI )
230
- # not sure what to do with the return value here
231
- deleted = ccall ((:gtk_tree_store_remove ,libgtk),Cint,(Ptr{GObject},Ptr{GtkTreeIter}), treeStore, mutable (iter))
232
- treeStore
233
- end
234
-
235
-
236
- # # insert by index
237
243
# # index can be :parent or :sibling
238
244
# # insertion can be :after or :before
239
- function Base. insert! (treeStore:: GtkTreeStoreLeaf , index :: Vector{Int} , values; how:: Symbol = :parent , where :: Symbol = :after )
240
- piter = iter_from_index (treeStore, index)
245
+ function Base. insert! (treeStore:: GtkTreeStoreLeaf , piter :: TRI , values; how:: Symbol = :parent , where :: Symbol = :after )
246
+
241
247
iter = Gtk. mutable (GtkTreeIter)
242
248
if how == :parent
243
249
if where == :after
@@ -257,6 +263,21 @@ function Base.insert!(treeStore::GtkTreeStoreLeaf, index::Vector{Int}, values; h
257
263
end
258
264
259
265
266
+ function delete! (treeStore:: GtkTreeStore , iter:: TRI )
267
+ # not sure what to do with the return value here
268
+ deleted = ccall ((:gtk_tree_store_remove ,libgtk),Cint,(Ptr{GObject},Ptr{GtkTreeIter}), treeStore, mutable (iter))
269
+ treeStore
270
+ end
271
+
272
+ Base. deleteat! (treeStore:: GtkTreeStore , iter:: TRI ) = delete! (treeStore, iter)
273
+
274
+ # # insert by index
275
+ function Base. insert! (treeStore:: GtkTreeStoreLeaf , index:: Vector{Int} , values; how:: Symbol = :parent , where :: Symbol = :after )
276
+ piter = iter_from_index (treeStore, index)
277
+ insert! (treeStore, iter, values; how= how, where = where )
278
+ end
279
+
280
+
260
281
function Base. splice! (treeStore:: GtkTreeStoreLeaf , index:: Vector{Int} )
261
282
iter = iter_from_index (treeStore, index)
262
283
delete! (treeStore, iter)
@@ -409,24 +430,49 @@ add_attribute(treeColumn::GtkTreeViewColumn, renderer::GtkCellRenderer,
409
430
(Ptr{GObject},Ptr{GObject},Ptr{Uint8},Cint),treeColumn,renderer,bytestring (attribute),column)
410
431
411
432
# ## GtkTreeSelection
412
-
413
433
function selected (selection:: GtkTreeSelection )
434
+ hasselection (selection) || error (" No selection for GtkTreeSelection" )
435
+
414
436
model = mutable (Ptr{GtkTreeModel})
415
437
iter = mutable (GtkTreeIter)
438
+
416
439
ret = bool (ccall ((:gtk_tree_selection_get_selected ,libgtk),Cint,
417
440
(Ptr{GObject},Ptr{Ptr{GtkTreeModel}},Ptr{GtkTreeIter}),selection,model,iter))
418
- if ! ret
419
- error (" No selection of GtkTreeSelection" )
441
+
442
+ ! ret && error (" No selection of GtkTreeSelection" )
443
+
444
+ iter[]
445
+ end
446
+
447
+ function selected_rows (selection:: GtkTreeSelection )
448
+ hasselection (selection) || return GtkTreeIter[]
449
+
450
+ model = mutable (Ptr{GtkTreeModel})
451
+
452
+ paths = Gtk. GLib. GList (ccall ((:gtk_tree_selection_get_selected_rows , Gtk. libgtk),
453
+ Ptr{Gtk. _GSList{Gtk. GtkTreePath}},
454
+ (Ptr{GObject}, Ptr{GtkTreeModel}),
455
+ selection, model))
456
+
457
+ iters = GtkTreeIter[]
458
+ for path in paths
459
+ it = mutable (GtkTreeIter)
460
+ ret = bool ( ccall ((:gtk_tree_model_get_iter ,libgtk), Cint, (Ptr{GObject},Ptr{GtkTreeIter},Ptr{GtkTreePath}),
461
+ model,it,path))
462
+ ret && push! (iters, it[])
420
463
end
421
- convert (GtkTreeModel, model[]), iter[]
464
+
465
+ iters
466
+
422
467
end
423
468
469
+
424
470
length (selection:: GtkTreeSelection ) =
425
471
ccall ((:gtk_tree_selection_count_selected_rows ,libgtk), Cint, (Ptr{GObject},),selection)
426
472
427
473
hasselection (selection:: GtkTreeSelection ) = length (selection) > 0
428
474
429
- select! (selection:: GtkTreeSelection , iter:: TRI ) =
475
+ Base . select! (selection:: GtkTreeSelection , iter:: TRI ) =
430
476
ccall ((:gtk_tree_selection_select_iter ,libgtk), Void,
431
477
(Ptr{GObject},Ptr{GtkTreeIter}),selection, mutable (iter))
432
478
0 commit comments