Re: How to link expand/compact behavior of two treeviews?



The linking of the scrollbars was easy, but I also need to link the
expand/compact behavior of the two views (so when the user clicks
the little triangle to expand the children in one view, the triangle
also gets "clicked" in the other treeview)

I am doing something like this in Gtk2::Ex::TreeMaker

You can find the code in CPAN or at 
http://cvs.sourceforge.net/viewcvs.py/gtk2-perl-ex/Gtk2-Ex/TreeMaker/lib/Gtk2/Ex/TreeMaker.pm?rev=1.21&view=markup

Look at the portion that says...

# Private method to enable the freezepane.
sub _synchronize_trees {
        my ($tree_view_frozen, $tree_view_full) = @_;

        # First, we will synchronize the row-expansion/collapse
        $tree_view_frozen->signal_connect('row-expanded' =>
                sub {
                        my ($view, $iter, $path) = @_;
                        $tree_view_full->expand_row($path,0);
                }
        ); 
        $tree_view_frozen->signal_connect('row-collapsed' =>
                sub {
                        my ($view, $iter, $path) = @_;
                        $tree_view_full->collapse_row($path);
                }
        ); 

        # Next, we will synchronize the row selection
        $tree_view_frozen->get_selection->signal_connect('changed' =>
                sub {
                        my ($selection) = @_;
                        _synchronize_tree_selection($tree_view_frozen, $tree_view_full, $selection);
                }
        ); 
        $tree_view_full->get_selection->signal_connect('changed' =>
                sub {
                        my ($selection) = @_;
                        _synchronize_tree_selection($tree_view_full, $tree_view_frozen, $selection);
                }
        ); 
}


# Synchronize the tree selections
sub _synchronize_tree_selection {
        my ($thisview, $otherview, $this_selection) = @_;
        return unless ($thisview and $otherview and $this_selection);
        my ($selected_model, $selected_iter) = $this_selection->get_selected;
        return unless ($selected_model and $selected_iter);
        $otherview->get_selection->select_path
($selected_model->get_path($selected_iter));
}


Good luck !



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]