I am currently trying to filter a TreeView based on the input of a text box, while still allowing the cells of the TreeView to be editable by the user.
The problem I’m running into is not being able to translate an edit on the TreeView while it’s using the TreeModelFilter into an edit on the child model, which is a ListStore.
The signal_connect for the cell (CellRendererText) editing looks like this:
renderer.signal_connect('edited') do |w, s1, s2|
cell_edited(s1, s2, treeview, $status)
end
def cell_edited(path, str, trvu, cell)
if str != ""
iter = @store.get_iter(path)
iter[cell] = str
end
end
Which I will admit to being something I found doing a search for editing TreeViews in Gtk2, as I am a GTK2 and GUI newbie in general.
How do I go about translating the path in the TreeViewFilter to the path in the child model (the ListStore)?
Or put more simply: when a user edits a cell in the table while it’s filtered, how do I update the correct non-filtered entry in the list?
First of all, You could write your code like below. Its more concise, and it checks to make sure that the path is valid:
You’re doing everything correctly for a normal treeview, but when you make a Gtk::TreeModelFilter, you need to convert from the filtered iter to the child’s iter using:
Gtk::TreeModelFilter#convert_iter_to_child_iter(filter_iter)
http://ruby-gnome2.sourceforge.jp/ja/hiki.cgi?Gtk%3A%3ATreeModelFilter
So your code should read:
You should have a look at visualruby.net. I’ll be releasing a new version that has a great listview/treeview where you have a much easier (and more rubyish) api. The Gtk stuff gets very complicated.