Changeset 12399
- Timestamp:
- 08/30/10 02:39:48 (18 months ago)
- Location:
- trunk/Padre/lib/Padre
- Files:
-
- 5 edited
-
Cache.pm (modified) (2 diffs)
-
Document.pm (modified) (1 diff)
-
Project.pm (modified) (2 diffs)
-
Wx/Directory.pm (modified) (10 diffs)
-
Wx/TreeCtrl.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/Cache.pm
r12251 r12399 14 14 15 15 sub stash { 16 my $class = shift; 16 17 my $owner = shift; 17 18 my $key = shift; … … 29 30 30 31 $DATA{$key}->{$owner} 31 or $DATA{$key}->{$owner} = {};32 or $DATA{$key}->{$owner} = {}; 32 33 } 33 34 34 35 sub release { 35 delete $DATA{ $_[ 0] };36 delete $DATA{ $_[1] }; 36 37 } 37 38 -
trunk/Padre/lib/Padre/Document.pm
r12283 r12399 343 343 sub DESTROY { 344 344 if ( defined $_[0]->{filename} ) { 345 Padre::Cache ::release( $_[0]->{filename} );345 Padre::Cache->release( $_[0]->{filename} ); 346 346 } 347 347 } -
trunk/Padre/lib/Padre/Project.pm
r12251 r12399 6 6 use strict; 7 7 use warnings; 8 use File::Spec (); 8 use File::Spec (); 9 use Padre::Cache (); 9 10 10 11 our $VERSION = '0.69'; … … 317 318 if ( defined $_[0]->{root} ) { 318 319 require Padre::Cache; 319 Padre::Cache ::release( $_[0]->{root} );320 Padre::Cache->release( $_[0]->{root} ); 320 321 } 321 322 } -
trunk/Padre/lib/Padre/Wx/Directory.pm
r12378 r12399 56 56 # Where is the current root directory of the tree 57 57 $self->{root} = ''; 58 59 # The list of all files to build into the tree60 $self->{files} = [];61 62 # The directories in the tree that should be expanded63 $self->{expand} = {};64 58 65 59 # Create the search control … … 194 188 # Leaving search mode 195 189 $self->{searching} = 0; 196 $search->ShowCancelButton(0);197 190 $self->task_reset; 198 191 $self->clear; 192 $self->refill; 199 193 $self->browse; 200 194 } else { … … 208 202 } else { 209 203 # Entering search mode 210 $self->{expand} = $self->tree-> expanded;204 $self->{expand} = $self->tree->GetExpandedPlData; 211 205 $self->{searching} = 1; 212 206 $search->ShowCancelButton(1); … … 260 254 } 261 255 256 # Refill the tree from storage 257 sub refill { 258 my $self = shift; 259 my $tree = $self->{tree}; 260 my $files = delete $self->{files}; 261 my $expand = delete $self->{expand} or return; 262 my @stack = $tree->GetRootItem; 263 foreach my $i ( 0 .. $#$files ) { 264 my $path = $files->[$i]; 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 282 $path->name, # Label 283 $tree->{images}->{$image}, # Icon 284 -1, # Wx Identifier 285 Wx::TreeItemData->new($path), # Embedded data 286 ); 287 } 288 } 289 262 290 263 291 … … 285 313 ); 286 314 287 # Before we change anything, store the expansion state288 unless ( $self->searching ) {289 $self->{expand} = $self->tree->expanded;290 }291 292 315 # Switch project states if needed 293 316 unless ( $self->{root} eq $root ) { … … 297 320 # if we potentially need it again later. 298 321 if ( $ide->project_exists( $self->{root} ) ) { 299 my $stash = Padre::Cache ::stash(322 my $stash = Padre::Cache->stash( 300 323 __PACKAGE__ => $ide->project( $self->{root} ), 301 324 ); 302 %$stash = ( 303 root => $self->{root}, 304 files => $self->{files}, 305 expand => $self->{expand}, 306 ); 307 } 308 309 # Flush the now-unusable state 325 if ( $self->{searching} ) { 326 # Save the stored browse state 327 %$stash = ( 328 root => $self->{root}, 329 files => $self->{files}, 330 expand => $self->{expand}, 331 ); 332 } else { 333 # Capture the browse state fresh. 334 %$stash = ( 335 root => $self->{root}, 336 files => $self->tree->GetChildrenPlData, 337 expand => $self->tree->GetExpandedPlData, 338 ); 339 } 340 } 341 342 # Flush the now-unusable local state 343 $self->clear; 310 344 $self->{root} = $root; 311 $self->{files} = [];312 $self->{expand} = {};345 $self->{files} = undef; 346 $self->{expand} = undef; 313 347 314 348 # Do we have an (out of date) cached state we can use? 315 # If so, display it immediately and update it later .316 if ( $project) {317 my $stash = Padre::Cache ::stash(349 # If so, display it immediately and update it later on. 350 if ( $project ) { 351 my $stash = Padre::Cache->stash( 318 352 __PACKAGE__ => $project, 319 353 ); 320 354 if ( $stash->{root} ) { 321 322 355 # We have a cached state 323 $self->{files} = $stash->{files};324 356 $self->{expand} = $stash->{expand}; 325 357 } … … 327 359 328 360 # Flush the search box and start the rerender 329 $self->clear; 330 $self->browse; 361 if ( $self->{expand} ) { 362 $self->browse( @{$self->{expand}} ); 363 } else { 364 $self->browse; 365 } 331 366 } 332 367 … … 334 369 } 335 370 336 sub refresh_finish { 371 372 373 374 375 ###################################################################### 376 # Browse Methods 377 378 sub browse { 337 379 TRACE( $_[0] ) if DEBUG; 338 380 my $self = shift; 339 my $task = shift;340 $self->{files} = $task->{model};341 $self->refresh_render;342 }343 344 # This is a primitive first attempt to get familiar with the tree API345 sub refresh_render {346 TRACE( $_[0] ) if DEBUG;347 my $self = shift;348 my $tree = $self->tree;349 my $root = $tree->GetRootItem;350 my $expand = $self->{expand};351 352 # Flush the old tree contents353 # TO DO: This is inefficient, upgrade to something that does the354 # equivalent of a treewise diff application, modifying the tree355 # to get the result we want instead of rebuilding it entirely.356 my $lock = $self->main->lock('UPDATE');357 $tree->DeleteChildren($root);358 359 # Fill the new tree360 my @stack = ();361 my @files = @{$self->{files}};362 while (@files) {363 my $path = shift @files;364 my $image = $path->type ? 'folder' : 'package';365 while (@stack) {366 367 # If we are not the child of the deepest element in368 # the stack, move up a level and try again369 last if $tree->GetPlData( $stack[-1] )->is_parent($path);370 371 # We have finished filling the directory.372 # Now it (maybe) has children, we can expand it.373 my $complete = pop @stack;374 if ( $expand->{ $tree->GetPlData($complete)->unix } ) {375 $tree->Expand($complete);376 }377 }378 379 # If there is anything left on the stack it is our parent380 my $parent = $stack[-1] || $root;381 382 # Add the next item to that parent383 my $item = $tree->AppendItem(384 $parent, # Parent node385 $path->name, # Label386 $tree->{images}->{$image}, # Icon387 -1, # Wx Identifier388 Wx::TreeItemData->new($path), # Embedded data389 );390 391 # If it is a folder, it goes onto the stack392 if ( $path->type == 1 ) {393 push @stack, $item;394 }395 }396 397 # Apply the same Expand logic above to any remaining stack elements398 while (@stack) {399 my $complete = pop @stack;400 if ( $expand->{ $tree->GetPlData($complete)->unix || 0 } ) {401 $tree->Expand($complete);402 }403 }404 405 return 1;406 }407 408 409 410 411 412 ######################################################################413 # Browse Methods414 415 sub browse {416 TRACE( $_[0] ) if DEBUG;417 my $self = shift;418 my $path = shift || Padre::Wx::Directory::Path->directory;419 381 return if $self->searching; 420 382 … … 425 387 on_message => 'browse_message', 426 388 on_finish => 'browse_finish', 427 list => [ $path],389 list => [ @_ ? @_ : Padre::Wx::Directory::Path->directory ], 428 390 ); 429 391 … … 475 437 my $task = shift; 476 438 } 439 477 440 478 441 -
trunk/Padre/lib/Padre/Wx/TreeCtrl.pm
r12378 r12399 35 35 } 36 36 37 # Fetch a list of all Perl data elements for all nodes 38 # in depth-first top-to-bottom order. 39 sub GetChildrenPlData { 40 my $self = shift; 41 my @queue = $self->GetRootItem; 42 my @data = (); 43 while ( @queue ) { 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 ); 49 50 # Processing children last to first and unshifting onto the 51 # queue, lets us achieve depth-first top-down within the need 52 # for intermediate storage or grepping. 53 my ( $child, $cookie ) = $self->GetLastChild($item); 54 while ( $cookie ) { 55 unshift @queue, $child; 56 ( $child, $cookie ) = $self->GetPreviousChild( $item, $cookie ); 57 } 58 } 59 60 return \@data; 61 } 62 63 # Fetch a list of the Perl data elements for expanded nodes 64 # in depth-first top to bottom order. 65 sub GetExpandedPlData { 66 my $self = shift; 67 my @queue = $self->GetRootItem; 68 my @data = (); 69 while ( @queue ) { 70 my $item = shift @queue; 71 push @data, $self->GetPlData($item)->GetData; 72 73 # Processing children last to first and unshifting onto the 74 # queue, lets us achieve depth-first top-down within the need 75 # for intermediate storage or grepping. 76 my ( $child, $cookie ) = $self->GetLastChild($item); 77 while ( $cookie ) { 78 if ( $self->IsExpanded ) { 79 unshift @queue, $child; 80 } 81 ( $child, $cookie ) = $self->GetPreviousChild( $item, $cookie ); 82 } 83 } 84 85 return \@data; 86 } 87 37 88 1;
Note: See TracChangeset
for help on using the changeset viewer.
