Re: Directory/file browser as TreeView



* Ratcliffe, Jeffrey (Peters) <Jeffrey Ratcliffe External eads com> [2006-09-29 14:16]:
sub add_to_tree {
 my ($tree_store, $parent, $dir, $path) = @_;
 
 my $tree_model = $tree_view->get_model();

# If $parent already has children, then remove them first
 my $child = $tree_model->iter_children ($parent);
 while ($child) {
  $tree_store->remove ($child);
  $child = $tree_model->iter_children ($parent);
 }
 
# Add children from directory listing
 opendir(DIRHANDLE, $path) || die "Cannot open directory: $!\n";
 foreach my $subdir (sort readdir(DIRHANDLE)) {
  if ($subdir ne '.' and $subdir ne '..'
                                    and -d $path.$subdir and -r $path.$subdir) {
   my $child = $tree_store->append($parent);
   $tree_store->set($child, 0, $subdir, 1, "$path$subdir/");
  }
 }
 closedir(DIRHANDLE);
}

A better idea would be to install an idle callback that reads one
directory entry per call. This will prevent the program from
becoming unresponsive when the user expands into a subdirectory
with 10,000 files.

You can do this pretty easily by using a lexical directory handle
and hooking up a closure that captures it as the idle callback.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



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