Changeset 12378


Ignore:
Timestamp:
08/27/10 00:28:57 (18 months ago)
Author:
adamk
Message:

Directory tree improvements

Location:
trunk/Padre
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/TaskHandle.pm

    r12338 r12378  
    313313    # Pull off the queue 
    314314    my $queue = $handle->queue or return 0; 
    315     push @$inbox, $queue->dequeue; 
     315    foreach my $message ( $queue->dequeue ) { 
     316        if ( $message->[0] eq 'cancel' ) { 
     317            $self->{cancel} = 1; 
     318            next; 
     319        } 
     320    } 
     321 
     322    # Check the message for valid structure 
    316323    my $message = shift @$inbox or return 0; 
    317  
    318     # Check the message for valid structure 
    319324    unless ( Params::Util::_ARRAY($message) ) { 
    320325        TRACE('Non-ARRAY message received by a worker thread') if DEBUG; 
     
    336341 
    337342    # Pull from the inbox first 
    338     my $inbox  = $handle->inbox or return 0; 
     343    my $inbox = $handle->inbox or return 0; 
    339344    if ( @$inbox ) { 
    340345        return shift @$inbox; 
     
    343348    # Pull off the queue, non-blocking 
    344349    my $queue = $handle->queue or return 0; 
    345     push @$inbox, $queue->dequeue_nb; 
     350    foreach my $message ( $queue->dequeue ) { 
     351        if ( $message->[0] eq 'cancel' ) { 
     352            $self->{cancel} = 1; 
     353            next; 
     354        } 
     355    } 
     356 
     357    # Check the message for valid structure 
    346358    my $message = shift @$inbox or return 0; 
    347  
    348     # Check the message for valid structure 
    349359    unless ( Params::Util::_ARRAY($message) ) { 
    350360        TRACE('Non-ARRAY message received by a worker thread') if DEBUG; 
  • trunk/Padre/lib/Padre/Wx/Directory.pm

    r12330 r12378  
    104104    # Create the tree control 
    105105    $self->{tree} = Padre::Wx::Directory::TreeCtrl->new($self); 
     106    $self->{tree}->SetPlData( 
     107        $self->{tree}->GetRootItem, 
     108        Wx::TreeItemData->new( 
     109            Padre::Wx::Directory::Path->directory, 
     110        ), 
     111    ); 
     112    Wx::Event::EVT_TREE_ITEM_EXPANDED( 
     113        $self, 
     114        $self->{tree}, 
     115        sub { 
     116            shift->on_expand(@_); 
     117        } 
     118    ); 
    106119 
    107120    # Fill the panel 
     
    183196            $search->ShowCancelButton(0); 
    184197            $self->task_reset; 
    185             $self->refresh_render; 
     198            $self->clear; 
     199            $self->browse; 
    186200        } else { 
    187201            # Changing search term 
     
    204218} 
    205219 
     220sub on_expand { 
     221    my $self  = shift; 
     222    my $event = shift; 
     223    my $item  = $event->GetItem; 
     224    my $path  = $self->{tree}->GetPlData($item); 
     225    return $self->browse( $path ); 
     226} 
     227 
    206228 
    207229 
     
    276298        if ( $ide->project_exists( $self->{root} ) ) { 
    277299            my $stash = Padre::Cache::stash( 
    278                 __PACKAGE__, 
    279                 $ide->project( $self->{root} ), 
     300                __PACKAGE__ => $ide->project( $self->{root} ), 
    280301            ); 
    281302            %$stash = ( 
     
    295316        if ($project) { 
    296317            my $stash = Padre::Cache::stash( 
    297                 __PACKAGE__, 
    298                 $project, 
     318                __PACKAGE__ => $project, 
    299319            ); 
    300320            if ( $stash->{root} ) { 
     
    306326        } 
    307327 
    308         # Flush the search box and rerender the tree 
    309         $self->{search}->SetValue(''); 
    310         $self->{search}->ShowCancelButton(0); 
    311         $self->refresh_render; 
    312  
    313         # Trigger the refresh task to update the temporary state 
    314         $self->task_request( 
    315             task      => 'Padre::Wx::Directory::Task', 
    316             on_finish => 'refresh_finish', 
    317             recursive => 1, 
    318             @options, 
    319         ); 
    320  
     328        # Flush the search box and start the rerender 
     329        $self->clear; 
     330        $self->browse; 
    321331    } 
    322332 
     
    394404 
    395405    return 1; 
     406} 
     407 
     408 
     409 
     410 
     411 
     412###################################################################### 
     413# Browse Methods 
     414 
     415sub browse { 
     416    TRACE( $_[0] ) if DEBUG; 
     417    my $self = shift; 
     418    my $path = shift || Padre::Wx::Directory::Path->directory; 
     419    return if $self->searching; 
     420 
     421    # Switch tasks to the browse task 
     422    $self->task_reset; 
     423    $self->task_request( 
     424        task       => 'Padre::Wx::Directory::Browse', 
     425        on_message => 'browse_message', 
     426        on_finish  => 'browse_finish', 
     427        list       => [ $path ], 
     428    ); 
     429 
     430    return; 
     431} 
     432 
     433sub browse_message { 
     434    TRACE( $_[0] ) if DEBUG; 
     435    my $self   = shift; 
     436    my $task   = shift; 
     437    my $parent = shift; 
     438 
     439    # Find the parent, discarding the message if we can't find it 
     440    my $tree   = $self->{tree}; 
     441    my $cursor = $tree->GetRootItem; 
     442    foreach my $name ( $parent->path ) { 
     443        # Locate the child to descend to. 
     444        # Discard the entire message if the target child doesn't exist. 
     445        $cursor = $tree->GetChildByText( $cursor, $name ) or return 1; 
     446    } 
     447 
     448    # Temporarily skip if we've already filled this node. 
     449    # TODO: Upgrade this to make it update the list instead. 
     450    if ( $tree->GetChildrenCount($cursor) ) { 
     451        return; 
     452    } 
     453 
     454    # Add the files to the cursor 
     455    while ( @_ ) { 
     456        my $path  = shift; 
     457        my $image = $path->type ? 'folder' : 'package'; 
     458 
     459        # Add the child to the parent 
     460        $tree->AppendItem( 
     461            $cursor,                      # Parent node 
     462            $path->name,                  # Label 
     463            $tree->{images}->{$image},    # Icon 
     464            -1,                           # Wx Identifier 
     465            Wx::TreeItemData->new($path), # Embedded data 
     466        ); 
     467    } 
     468 
     469    return 1; 
     470} 
     471 
     472sub browse_finish { 
     473    TRACE( $_[0] ) if DEBUG; 
     474    my $self = shift; 
     475    my $task = shift; 
    396476} 
    397477 
  • trunk/Padre/lib/Padre/Wx/Directory/Path.pm

    r12251 r12378  
    3333    return bless [ 
    3434        DIRECTORY, 
    35         File::Spec::Unix->catfile(@_), 
     35        File::Spec::Unix->catfile( @_ ? @_ : ('') ), 
    3636        @_, 
    3737    ], $class; 
  • trunk/Padre/lib/Padre/Wx/Directory/TreeCtrl.pm

    r12251 r12378  
    66use File::Spec                 (); 
    77use Padre::Constant            (); 
    8 use Padre::Wx                  (); 
     8use Padre::Wx::TreeCtrl        (); 
    99use Padre::Wx::Role::Main      (); 
    1010use Padre::Wx::Directory::Path (); 
     
    1313our @ISA     = qw{ 
    1414    Padre::Wx::Role::Main 
    15     Wx::TreeCtrl 
     15    Padre::Wx::TreeCtrl 
    1616}; 
    1717 
  • trunk/Padre/t/61-directory-path.t

    r11727 r12378  
    33use strict; 
    44use warnings; 
    5 use Test::More tests => 18; 
     5use Test::More tests => 25; 
    66use Test::NoWarnings; 
    77use Storable                   (); 
     
    6262    is_deeply( $file, $round, 'File round-trips ok' ); 
    6363} 
     64 
     65 
     66 
     67 
     68 
     69###################################################################### 
     70# Test the null directory case 
     71 
     72SCOPE: { 
     73    my $directory = Padre::Wx::Directory::Path->directory; 
     74    isa_ok( $directory, 'Padre::Wx::Directory::Path' ); 
     75    is( $directory->type, Padre::Wx::Directory::Path::DIRECTORY, '->type ok' ); 
     76    is( $directory->name, '',                                    '->name ok' ); 
     77    is( $directory->unix, '',                                    '->unix ok' ); 
     78    is_deeply( [ $directory->path ], [ ], '->path ok' ); 
     79    is( $directory->is_file,      0, '->is_file ok' ); 
     80    is( $directory->is_directory, 1, '->is_directory ok' ); 
     81} 
Note: See TracChangeset for help on using the changeset viewer.