Changeset 12400
- Timestamp:
- 08/30/10 05:47:05 (18 months ago)
- Location:
- trunk/Padre/lib/Padre/Wx
- Files:
-
- 3 edited
-
Directory.pm (modified) (5 diffs)
-
Directory/TreeCtrl.pm (modified) (1 diff)
-
TreeCtrl.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/Wx/Directory.pm
r12399 r12400 100 100 $self->{tree}->SetPlData( 101 101 $self->{tree}->GetRootItem, 102 Wx::TreeItemData->new( 103 Padre::Wx::Directory::Path->directory, 104 ), 102 Padre::Wx::Directory::Path->directory, 105 103 ); 106 104 Wx::Event::EVT_TREE_ITEM_EXPANDED( … … 258 256 my $self = shift; 259 257 my $tree = $self->{tree}; 260 my $files = delete $self->{files}; 258 my $root = $tree->GetRootItem; 259 my $files = delete $self->{files} or return; 261 260 my $expand = delete $self->{expand} or return; 262 my @stack = $tree->GetRootItem; 263 foreach my $i ( 0 .. $#$files ) { 261 my @stack = (); 262 my $lock = $self->main->lock('UPDATE'); 263 foreach my $i ( 1 .. $#$files ) { 264 264 my $path = $files->[$i]; 265 265 my $image = $path->type ? 'folder' : 'package'; 266 unless ( $tree->GetPlData($stack[-1])->GetData->is_parent($path) ) { 267 if ( $files->[$i - 1]->is_parent($path) ) { 268 # Descending 269 push @stack, $tree->GetLastChild($stack[-1]); 270 } else { 271 # Ascending 272 while ( @stack ) { 273 pop @stack; 274 if ( $tree->GetPlData($stack[-1])->GetData->is_parent($path) ) { 275 last; 276 } 277 } 278 } 279 } 280 $tree->AppendItem( 281 $stack[-1], # Parent node 266 while (@stack) { 267 268 # If we are not the child of the deepest element in 269 # the stack, move up a level and try again 270 last if $tree->GetPlData( $stack[-1] )->is_parent($path); 271 272 # We have finished filling the directory. 273 # Now it (maybe) has children, we can expand it. 274 my $complete = pop @stack; 275 if ( $expand->{ $tree->GetPlData($complete)->unix } ) { 276 $tree->Expand($complete); 277 } 278 } 279 280 # If there is anything left on the stack it is our parent 281 my $parent = $stack[-1] || $root; 282 283 # Add the next item to that parent 284 my $item = $tree->AppendItem( 285 $parent, # Parent node 282 286 $path->name, # Label 283 287 $tree->{images}->{$image}, # Icon … … 285 289 Wx::TreeItemData->new($path), # Embedded data 286 290 ); 287 } 288 } 289 291 292 # If it is a folder, it goes onto the stack 293 if ( $path->type == 1 ) { 294 push @stack, $item; 295 } 296 } 297 298 # Apply the same Expand logic above to any remaining stack elements 299 while (@stack) { 300 my $complete = pop @stack; 301 if ( $expand->{ $tree->GetPlData($complete)->unix } ) { 302 $tree->Expand($complete); 303 } 304 } 305 306 # If we moved during the fill, move back 307 my $first = ($tree->GetFirstChild($root))[0]; 308 $tree->ScrollTo($first) if $first->IsOk; 309 310 return 1; 311 } 312 290 313 291 314 … … 335 358 root => $self->{root}, 336 359 files => $self->tree->GetChildrenPlData, 337 expand => $self->tree-> GetExpandedPlData,360 expand => $self->tree->expanded, 338 361 ); 339 362 } … … 354 377 if ( $stash->{root} ) { 355 378 # We have a cached state 379 $self->{files} = $stash->{files}; 356 380 $self->{expand} = $stash->{expand}; 381 $self->refill; 357 382 } 358 383 } 359 384 360 # Flush the search box and start the rerender 361 if ( $self->{expand} ) { 362 $self->browse( @{$self->{expand}} ); 363 } else { 364 $self->browse; 365 } 385 # Flush the search box and restart 386 $self->browse; 366 387 } 367 388 -
trunk/Padre/lib/Padre/Wx/Directory/TreeCtrl.pm
r12378 r12400 185 185 # Returns a reference to a HASH of ->unix path strings. 186 186 sub expanded { 187 my $self = shift; 188 my @queue = $self->GetRootItem; 189 my %expand = (); 190 while (@queue) { 191 my $parent = shift @queue; 192 my ( $child, $cookie ) = $self->GetFirstChild($parent); 193 while ($child) { 194 if ( $self->IsExpanded($child) ) { 195 $expand{ $self->GetPlData($child)->unix } = 1; 196 push @queue, $child; 197 } 198 ( $child, $cookie ) = $self->GetNextChild( $parent, $cookie ); 199 } 200 } 201 return \%expand; 187 my $self = shift; 188 my $items = $self->GetExpandedPlData; 189 my %hash = map { $_->unix => 1 } @$items; 190 return \%hash; 202 191 } 203 192 -
trunk/Padre/lib/Padre/Wx/TreeCtrl.pm
r12399 r12400 43 43 while ( @queue ) { 44 44 my $item = shift @queue; 45 push @data, $self->GetPlData($item)->GetData; 46 47 # Continue if we have no child nodes 48 next unless $self->GetChildrenCount( $item, 0 ); 45 push @data, $self->GetPlData($item); 49 46 50 47 # Processing children last to first and unshifting onto the 51 48 # queue, lets us achieve depth-first top-down within the need 52 49 # for intermediate storage or grepping. 53 my ( $child, $cookie )= $self->GetLastChild($item);54 while ( $c ookie) {50 my $child = $self->GetLastChild($item); 51 while ( $child->IsOk ) { 55 52 unshift @queue, $child; 56 ( $child, $cookie ) = $self->GetPreviousChild( $item, $cookie);53 $child = $self->GetPrevSibling($child); 57 54 } 58 55 } … … 69 66 while ( @queue ) { 70 67 my $item = shift @queue; 71 push @data, $self->GetPlData($item) ->GetData;68 push @data, $self->GetPlData($item); 72 69 73 70 # Processing children last to first and unshifting onto the 74 71 # queue, lets us achieve depth-first top-down within the need 75 72 # for intermediate storage or grepping. 76 my ( $child, $cookie )= $self->GetLastChild($item);77 while ( $c ookie) {78 if ( $self->IsExpanded ) {73 my $child = $self->GetLastChild($item); 74 while ( $child->IsOk ) { 75 if ( $self->IsExpanded($child) ) { 79 76 unshift @queue, $child; 80 77 } 81 ( $child, $cookie ) = $self->GetPreviousChild( $item, $cookie);78 $child = $self->GetPrevSibling($child); 82 79 } 83 80 }
Note: See TracChangeset
for help on using the changeset viewer.
