Changeset 5576

Show
Ignore:
Timestamp:
06/25/09 07:05:11 (14 months ago)
Author:
submersible_toaster
Message:

slow progress. add Open menu and shortcut to DocBrowser?. adjust ->help and ->display behaviour - hopefully for the better.

Location:
trunk/Padre/lib/Padre
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/DocBrowser/document.pm

    r5548 r5576  
    107107        ); 
    108108 
    109         exists $EXT_MIME{$suffix} 
     109        my $type =  
     110        exists $EXT_MIME{$suffix} 
    110111                ? $EXT_MIME{$suffix} 
    111112                : ''; 
     113    return $type; 
    112114} 
    113115 
  • trunk/Padre/lib/Padre/Wx/DocBrowser.pm

    r5567 r5576  
    1818use Padre::DocBrowser       (); 
    1919use Padre::Util qw( _T ); 
     20use Wx::Perl::Dialog::Simple (); 
    2021 
    2122our $VERSION = '0.37'; 
     
    144145        #my @menu_id; 
    145146        $exitMenu->Append(Wx::wxID_CLOSE, Wx::gettext("&Close\tCtrl+W") ); 
     147        $exitMenu->Append(Wx::wxID_OPEN , Wx::gettext("&Open\tCtrl+O") ); 
    146148        my $exitID = Wx::NewId; 
    147149         
     
    158160        Wx::Event::EVT_MENU( $self, $exitID, sub { $_[0]->_close(); } ); 
    159161        Wx::Event::EVT_MENU( $self, Wx::wxID_CLOSE, sub { $_[0]->_close_tab(); } ); 
    160          
     162        Wx::Event::EVT_MENU( $self, Wx::wxID_OPEN , sub { $_[0]->_open_doc(); } ); 
    161163         
    162164        $self->SetAutoLayout(1); 
     
    195197                _HASH($hint) ? %$hint : (), 
    196198        ); 
    197         if ( _INVOCANT($query) and $query->can('mimetype') ) { 
    198                 my $task = Padre::Task::DocBrowser->new( 
    199                         document         => $query, 
    200                         type             => 'docs', 
    201                         args             => \%hints, 
    202                         main_thread_only => sub { 
    203                                 $self->display( $_[0], $query ); 
    204                         }, 
    205                 ); 
    206                 $task->schedule; 
    207                 return 1; 
     199         
     200        if ( _INVOCANT($query) and $query->isa('Padre::DocBrowser::document') ) { 
     201 
     202 
     203        return $self->display( $query ) if  
     204            $self->viewer_for( $query->guess_mimetype ); 
     205 
     206            my $render = $self->provider->viewer_for( $query->mimetype ); 
     207            my $generate=$self->provider->provider_for( $query->mimetype ); 
     208             
     209            if ( $generate ) { 
     210            my $task = Padre::Task::DocBrowser->new( 
     211                document         => $query, 
     212                type             => 'docs', 
     213                args             => \%hints, 
     214                main_thread_only => sub { 
     215                    $self->display( $_[0], $query ); 
     216                }, 
     217            ); 
     218            $task->schedule; 
     219            return 1; 
     220                } 
     221                if ( $render ) { 
     222                    my $talk = Padre::Task::DocBrowser->new( 
     223                document          => $query, 
     224                type              => 'browse', 
     225                args              => \%hints, 
     226                main_thread_only  => sub { 
     227                    $self->display( $_[0] , $query ); 
     228                } 
     229                    ); 
     230                     
     231                } 
     232                $self->not_found( $query , \%hints ); 
     233        return; 
    208234        } elsif ( defined $query ) { 
    209                 my $task = Padre::Task::DocBrowser->new( 
     235            my $task = Padre::Task::DocBrowser->new( 
    210236                        document         => $query, 
    211237                        type             => 'resolve', 
    212238                        args             => \%hints, 
    213239                        main_thread_only => sub { 
    214                                 $self->help( $_[0], referrer => $query ); 
     240                                $self->help( $_[0], {referrer => $query} ); 
    215241                        } 
    216242                ); 
     
    251277        my ( $self, $docs, $query ) = @_; 
    252278        if ( _INSTANCE( $docs, 'Padre::DocBrowser::document' ) ) { 
     279             
     280            # if doc is html just display it  
     281            # TODO, a means to register other wx display windows such as ?! 
     282            return $self->ShowPage( $docs , $query ) 
     283            if ( $self->viewer_for( $docs->mimetype ) ); 
     284             
    253285                my $task = Padre::Task::DocBrowser->new( 
    254286                        document         => $docs, 
    255287                        type             => 'browse', 
    256288                        main_thread_only => sub { 
    257                                 $self->ShowPage( $_[0], $query ); 
     289                                $self->display( $_[0], $query ); 
    258290                        } 
    259291                ); 
    260292                $task->schedule; 
    261         } 
    262  
     293                return 1; 
     294        } 
     295    else { 
     296        $self->not_found( $docs, $query ); 
     297         
     298    } 
    263299} 
    264300 
    265301sub ShowPage { 
    266302        my ( $self, $docs, $query ) = @_; 
    267  
    268303        unless ( _INSTANCE( $docs, 'Padre::DocBrowser::document' ) ) { 
    269304                return $self->not_found($query); 
     
    341376    # Erk - shouldn't this be ->get_text or something. 
    342377        $doc->body( Encode::encode( 'utf8', $padredoc->{original_content} ) ); 
     378         
     379        $doc->mimetype( $doc->guess_mimetype ) unless $doc->mimetype; 
     380         
    343381        return $doc; 
    344382} 
     
    346384sub not_found { 
    347385        # trying a dialog rather than the open tab. 
    348     my ( $self, $query ) = @_; 
    349      
     386    my ( $self, $query, $hints ) = @_; 
     387    $query ||= $hints->{referrer};  
    350388    use Wx qw(wxOK wxCENTRE wxICON_INFORMATION); 
    351389    my $notFound = Wx::MessageDialog->new( $self,  
     
    356394        $notFound->ShowModal; 
    357395        $notFound->Destroy; 
    358  
    359          
    360          
    361 #    my $html = qq| 
    362 #<html><body> 
    363 #<h1>Not Found</h1> 
    364 #<p>Could not find documentation for 
    365 #<pre>$query</pre> 
    366 #</p> 
    367 #</body> 
    368 #</html> 
    369 #|; 
    370 #    my $frame = Padre::Wx::HtmlWindow->new($self); 
    371 #    $self->notebook->AddPage( $frame, 'Not Found', 1 ); 
    372 #    $frame->SetPage($html); 
    373396 
    374397} 
     
    412435         
    413436}        
    414          
     437 
     438 
     439sub _open_doc { 
     440        my $self = shift; 
     441        my $filename = Wx::Perl::Dialog::Simple::file_selector(); 
     442        if ( defined $filename ) { 
     443        my $doc = Padre::DocBrowser::document->load( $filename ); 
     444        $self->help( $doc, $filename ); 
     445    } 
     446} 
     447 
     448sub viewer_for { 
     449    my ($self,$mimetype) = @_; 
     450    return unless defined $mimetype; 
     451    if ( exists $VIEW{$mimetype} ) { 
     452        return $VIEW{$mimetype}; 
     453    } 
     454} 
    415455 
    4164561;