Re: Directory/file browser as TreeView

Ratcliffe, Jeffrey (Peters) wrote:
(having to store the directory path as a hidden
column seems rather hackish to me - but I couldn't work out how to get the
parent from an iter)

From Gtk2::TreeModel(3pm):

       treeiter = $tree_model->iter_parent ($child)

           * $child (Gtk2::TreeIter)

           Returns a new iter pointing to $child?s parent node, or undef if
           $child doesn?t have a parent.  $child is unaltered.

use constant TRUE  => 1;
use constant FALSE => 0;

use Glib qw(TRUE FALSE);

my $window = Gtk2::Window -> new;
$window -> signal_connect ( 'delete_event', sub { Gtk2 -> main_quit; } );

Connect this to 'destroy' instead of 'delete-event'.  The handler for
'delete-event' is supposed to return a boolean value saying "i handled this"
or "i didn't handle this", that is typically used to inhibit destruction of
the window.  You're not doing that, though.  The default action from
'delete-event' is to destroy the window, which will cause the 'destroy' event
to fire.  Of course, you can also get 'destroy' from other places in your
program.  So, if you connect the quit of the main loop to the main window's
'destroy' rather than 'delete-event', you get a more robust program.

my $child = $tree_store->append(undef);
$tree_store->set($child, 0, '/', 1, '/');
add_to_tree($tree_store, $child, '/', '/');

For shame!  Use File::Spec to manipulate the paths portably!  :-)

muppet <scott at asofyet dot org>

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