Changeset 12412


Ignore:
Timestamp:
08/31/10 02:54:16 (18 months ago)
Author:
adamk
Message:

browse_message responses now correctly overlay existing directory entries, adding or removing entries as needed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Wx/Directory.pm

    r12406 r12412  
    259259    my $files  = delete $self->{files}  or return; 
    260260    my $expand = delete $self->{expand} or return; 
     261    my $lock   = $self->main->lock('UPDATE'); 
    261262    my @stack  = (); 
    262     my $lock   = $self->main->lock('UPDATE'); 
    263263    shift @$files; 
    264264    foreach my $path ( @$files ) { 
     
    434434    while ( @_ ) { 
    435435        if ( $child->IsOk ) { 
    436  
    437             # We are not past the last entry 
    438             my $current = $tree->GetPlData($child); 
    439             if ( $current->name eq $_[0]->name ) { 
    440                 # Already exists, discard the duplicate 
    441                 shift; 
    442             } elsif ( 
    443                 $current->is_directory < $_[0]->is_directory 
    444                 and 
    445                 lc($current->name) gt lc($_[0]->name) 
    446             ) { 
     436            # Are we before, after, or a duplicate 
     437            my $compare = $self->compare( $_[0], $tree->GetPlData($child) ); 
     438            if ( $compare > 0 ) { 
     439                # Deleted entry, remove the current position 
     440                my $delete = $child; 
     441                ($child, $cookie) = $tree->GetNextChild($cursor, $cookie); 
     442                $tree->Delete($delete); 
     443 
     444            } elsif ( $compare < 0 ) { 
     445                # New entry, insert before the current position 
    447446                my $path = shift; 
    448447                $tree->InsertItem( 
     
    454453                    Wx::TreeItemData->new($path),      # Embedded data 
    455454                ); 
    456                 $position += 1; 
     455                $position++; 
     456 
    457457            } else { 
     458                # Already exists, discard the duplicate 
    458459                ($child, $cookie) = $tree->GetNextChild($cursor, $cookie); 
    459                 $position += 1; 
     460                $position++; 
     461                shift @_; 
    460462            } 
    461463 
     
    652654} 
    653655 
     656# Compare two paths to see which should be first 
     657sub compare { 
     658    my $self  = shift; 
     659    my $left  = shift; 
     660    my $right = shift; 
     661    return ( 
     662        $right->is_directory <=> $left->is_directory 
     663        or 
     664        lc($left->name) cmp lc($right->name) 
     665    ); 
     666} 
     667 
    6546681; 
    655669 
Note: See TracChangeset for help on using the changeset viewer.