Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy up store interface and fix selected #123

Merged
merged 2 commits into from
Sep 27, 2014

Conversation

jverzani
Copy link
Contributor

This pull request does two things: it adds a few methods for manipulating GtkListStore and GtkTreeStore objects and it fixes the selected method and adds selected_rows to mirror gtk_tree_selection_get_selected and gtk_tree_selection_get_selected_rows (which don't work with G_.select or G_.selected_rows, as far as I could tell).

The changes to the store methods are summarized below with - meaning dropped, + meaning added:

store interface

push!(listStore::GtkListStore, values::Tuple)
unshift!(listStore::GtkListStore, values::Tuple)
insert!(listStore::GtkListStoreLeaf, index::Int, values) 
+ insert!(listStore::GtkListStoreLeaf, iter::TRI, values) 
empty!(listStore::GtkListStore)

delete!(listStore::GtkListStore, iter::TRI)
+ deleteat!(store, iter::TRI)
-splice!(listStore::GtkListStoreLeaf, index::Int) 
+ deleteat!(listStore::GtkListStoreLeaf, index::Int) 
+ pop! = deleteat!(store, length(store))


length(listStore::GtkListStore)
+ size(listStore) = (length(listStore, Gtk.ncolumns(GtkTreeModel(listStore))))


isvalid(listStore::GtkListStore, iter::TRI)

indexing

+ getindex(listStore::GtkListStore, iter::TRI, column::Integer)) = getindex(GtkTreeModel(listStore), iter, column)
+ getindex(listStore::GtkListStore, iter::TRI) = getindex(GtkTreeModel(listStore), iter)
+ getindex(listStore, row::int, column) = getindex(listStore, iter_from_index(listStore, row), column)
+ getindex(listStore, row::int) = getindex(listStore, iter_from_index(listStore, row))

what of setindex! ??

no symmetry here, should this be addressed?

get store from a view

getproperty(view, :model, Gtk.GtkListStore)

set store for view, setproperty! fails

Gtk.G_.model(view, store)

Tree store

push!(treeStore::GtkTreeStore, values::Tuple, parent=nothing)
unshift!(treeStore::GtkTreeStore, values::Tuple, parent=nothing)
insert!(treeStore::GtkTreeStoreLeaf, index::Vector{Int}, values; how::Symbol=:parent, where::Symbol=:after)

delete!(treeStore::GtkTreeStore, iter::TRI)
deleteat!(treeStore::GtkTreeStore, iter::TRI) = delete!(treeStore::GtkTreeStore, iter::TRI))
empty!(treeStore::GtkTreeStore)
+ deleteat!(treeStore::GtkTreeStoreLeaf, iter::TRI) ## delete at
-splice!(treeStore::GtkTreeStoreLeaf, index::Vector{Int}) ## delete at as new name
+deleteat!(treeStore::GtkTreeStoreLeaf, index::Vector{Int}) 


isvalid(treeStore::GtkTreeStore, iter::TRI)
isancestor(treeStore::GtkTreeStore, iter::TRI, descendant::TRI)
depth(treeStore::GtkTreeStore, iter::TRI)

getindex(treeModel::GtkTreeModel, iter::TRI, column::Integer)
getindex(treeModel::GtkTreeModel, iter::TRI)

setindex!(treeModel::GtkTreeModel, value, iter::TRI, column::Integer)
setindex!(treeModel::GtkTreeModel, values, iter::TRI)

Selection

- selected(GtkTreeSelection): returned (model, iter) but with error
+ selected(GtkTreeSelection): return GtkTreeIter or error if no selection
select!(GtkTreeSelection, Iter)
+ selected_rows(GtkTreeSelection) return GtkTreeIter[]
selectall!(GtkTreeSelection)

unselect!(selection::GtkTreeSelection, iter::TRI
unselectall!(GtkTreeSelection)

Adds tests for `insert!` and selection
This cleans up the interface for GtkListStore and GtkTreeStore a bit and fixes `selected` and adds `selected_rows`. This summarizes the changes (+ means added, - means dropped)

## store interface

push!(listStore::GtkListStore, values::Tuple)
unshift!(listStore::GtkListStore, values::Tuple)
insert!(listStore::GtkListStoreLeaf, index::Int, values) 
+ insert!(listStore::GtkListStoreLeaf, iter::TRI, values) 
empty!(listStore::GtkListStore)

delete!(listStore::GtkListStore, iter::TRI)
+ deleteat!(store, iter::TRI)
-splice!(listStore::GtkListStoreLeaf, index::Int) 
+ deleteat!(listStore::GtkListStoreLeaf, index::Int) 
+ pop! = deleteat!(store, length(store))


length(listStore::GtkListStore)
+ size(listStore) = (length(listStore, Gtk.ncolumns(GtkTreeModel(listStore))))


isvalid(listStore::GtkListStore, iter::TRI)

## indexing
+ getindex(listStore::GtkListStore, iter::TRI, column::Integer)) = getindex(GtkTreeModel(listStore), iter, column)
+ getindex(listStore::GtkListStore, iter::TRI) = getindex(GtkTreeModel(listStore), iter)
+ getindex(listStore, row::int, column) = getindex(listStore, iter_from_index(listStore, row), column)
+ getindex(listStore, row::int) = getindex(listStore, iter_from_index(listStore, row))

## what of setindex!

## no symmetry here
## get store from a view
getproperty(view, :model, Gtk.GtkListStore)
## set store for view, setproperty! fails 
Gtk.G_.model(view, store)


## Tree store
push!(treeStore::GtkTreeStore, values::Tuple, parent=nothing)
unshift!(treeStore::GtkTreeStore, values::Tuple, parent=nothing)
insert!(treeStore::GtkTreeStoreLeaf, index::Vector{Int}, values; how::Symbol=:parent, where::Symbol=:after)

delete!(treeStore::GtkTreeStore, iter::TRI)
deleteat!(treeStore::GtkTreeStore, iter::TRI) = delete!(treeStore::GtkTreeStore, iter::TRI))
empty!(treeStore::GtkTreeStore)
+ deleteat!(treeStore::GtkTreeStoreLeaf, iter::TRI) ## delete at
-splice!(treeStore::GtkTreeStoreLeaf, index::Vector{Int}) ## delete at
deleteat!(treeStore::GtkTreeStoreLeaf, index::Vector{Int}) 


isvalid(treeStore::GtkTreeStore, iter::TRI)
isancestor(treeStore::GtkTreeStore, iter::TRI, descendant::TRI)
depth(treeStore::GtkTreeStore, iter::TRI)

getindex(treeModel::GtkTreeModel, iter::TRI, column::Integer)
getindex(treeModel::GtkTreeModel, iter::TRI)

setindex!(treeModel::GtkTreeModel, value, iter::TRI, column::Integer)
setindex!(treeModel::GtkTreeModel, values, iter::TRI)



## Selection
- selected(GtkTreeSelection): returned (model, iter) but with error
+ selected(GtkTreeSelection): return GtkTreeIter or error if no selection
select!(GtkTreeSelection, Iter)
+ selected_rows(GtkTreeSelection) return GtkTreeIter[] or error if no selection
selectall!(GtkTreeSelection)

unselect!(selection::GtkTreeSelection, iter::TRI
unselectall!(GtkTreeSelection)
@vtjnash
Copy link
Contributor

vtjnash commented Sep 27, 2014

+ selected_rows(GtkTreeSelection) return GtkTreeIter[] or error if no selection

I think you meant it returns an empty array if no selection (which is probably what we want)?

@jverzani
Copy link
Contributor Author

Oops. For selected_rows it returns and empty array, not an error in that case.

vtjnash added a commit that referenced this pull request Sep 27, 2014
tidy up store interface and fix selected
@vtjnash vtjnash merged commit 4a12d30 into JuliaGraphics:master Sep 27, 2014
@vtjnash
Copy link
Contributor

vtjnash commented Sep 27, 2014

thanks!

This was referenced Sep 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants