[Gtk-sharp-list] Problem getting a TreePath from a TreeModelSort by x and y coords
Michael Hutchinson
m.j.hutchinson at gmail.com
Tue Feb 9 23:51:16 EST 2010
On Tue, Feb 9, 2010 at 7:24 PM, Matthew Pirocchi
<matthew.pirocchi at gmail.com> wrote:
> I have a ListStore that is filtered and then sorted. It looks
> something like this:
>
> // Create a model for the cards
> cardListStore = new ListStore (typeof (Card));
>
> // Set up the tree view
> cardFilter = new TreeModelFilter (cardListStore, null);
> cardFilter.VisibleFunc = new TreeModelFilterVisibleFunc (FilterCards);
> cardSort = new TreeModelSort (cardFilter);
> cardTreeView.Model = cardSort;
>
> I want to have a get a context menu specific for each row when I
> right-click on it. My click handler looks something like this:
>
> [GLib.ConnectBeforeAttribute]
> void HandleCardTreeViewButtonPressEvent (object o, ButtonPressEventArgs args)
> {
> if (args.Event.Button != 3)
> return;
>
> TreePath path;
> // If right click on empty space
> if (!cardTreeView.GetPathAtPos (Convert.ToInt32 (args.Event.X),
> Convert.ToInt32 (args.Event.Y),
> out path)) {
> MakeCardEmptySpaceContextMenu ().Popup ();
> return;
> }
>
> TreeIter iter;
> if (!cardListStore.GetIter (out iter, path))
> return;
>
> Card card = (Card) cardListStore.GetValue (iter, 0);
>
> MakeCardContextMenu (card, iter).Popup ();
> }
>
> This works when the ListStore is not filtered or sorted. But when it
> is, it gives the wrong row.
>
> For example, say the rows look like this before they are sorted:
>
> A
> B
> C
>
> And after they are sorted, they look like this:
>
> B
> A
> C
>
> Right-clicking on the second row ("A") will give you "B", because
> that's where B was before the model was sorted. The same thing happens
> for filtering. Say the model, after it is filtered, looks like this:
>
> A
> C
>
> Right-clicking on the second row ("C") would still give you "B".
>
> Any idea how to work around this?
Since the model "seen" by the view is the sorted model, shouldn't you
get the value from that? i.e.
TreeIter iter;
if (!cardSort.GetIter (out iter, path))
return;
Card card = (Card) cardSort.GetValue (iter, 0);
--
Michael Hutchinson
http://mjhutchinson.com
More information about the Gtk-sharp-list
mailing list