Changeset 5576
- Timestamp:
- 06/25/09 07:05:11 (14 months ago)
- Location:
- trunk/Padre/lib/Padre
- Files:
-
- 2 modified
-
DocBrowser/document.pm (modified) (1 diff)
-
Wx/DocBrowser.pm (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/DocBrowser/document.pm
r5548 r5576 107 107 ); 108 108 109 exists $EXT_MIME{$suffix} 109 my $type = 110 exists $EXT_MIME{$suffix} 110 111 ? $EXT_MIME{$suffix} 111 112 : ''; 113 return $type; 112 114 } 113 115 -
trunk/Padre/lib/Padre/Wx/DocBrowser.pm
r5567 r5576 18 18 use Padre::DocBrowser (); 19 19 use Padre::Util qw( _T ); 20 use Wx::Perl::Dialog::Simple (); 20 21 21 22 our $VERSION = '0.37'; … … 144 145 #my @menu_id; 145 146 $exitMenu->Append(Wx::wxID_CLOSE, Wx::gettext("&Close\tCtrl+W") ); 147 $exitMenu->Append(Wx::wxID_OPEN , Wx::gettext("&Open\tCtrl+O") ); 146 148 my $exitID = Wx::NewId; 147 149 … … 158 160 Wx::Event::EVT_MENU( $self, $exitID, sub { $_[0]->_close(); } ); 159 161 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(); } ); 161 163 162 164 $self->SetAutoLayout(1); … … 195 197 _HASH($hint) ? %$hint : (), 196 198 ); 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; 208 234 } elsif ( defined $query ) { 209 my $task = Padre::Task::DocBrowser->new(235 my $task = Padre::Task::DocBrowser->new( 210 236 document => $query, 211 237 type => 'resolve', 212 238 args => \%hints, 213 239 main_thread_only => sub { 214 $self->help( $_[0], referrer => $query);240 $self->help( $_[0], {referrer => $query} ); 215 241 } 216 242 ); … … 251 277 my ( $self, $docs, $query ) = @_; 252 278 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 253 285 my $task = Padre::Task::DocBrowser->new( 254 286 document => $docs, 255 287 type => 'browse', 256 288 main_thread_only => sub { 257 $self-> ShowPage( $_[0], $query );289 $self->display( $_[0], $query ); 258 290 } 259 291 ); 260 292 $task->schedule; 261 } 262 293 return 1; 294 } 295 else { 296 $self->not_found( $docs, $query ); 297 298 } 263 299 } 264 300 265 301 sub ShowPage { 266 302 my ( $self, $docs, $query ) = @_; 267 268 303 unless ( _INSTANCE( $docs, 'Padre::DocBrowser::document' ) ) { 269 304 return $self->not_found($query); … … 341 376 # Erk - shouldn't this be ->get_text or something. 342 377 $doc->body( Encode::encode( 'utf8', $padredoc->{original_content} ) ); 378 379 $doc->mimetype( $doc->guess_mimetype ) unless $doc->mimetype; 380 343 381 return $doc; 344 382 } … … 346 384 sub not_found { 347 385 # trying a dialog rather than the open tab. 348 my ( $self, $query ) = @_;349 386 my ( $self, $query, $hints ) = @_; 387 $query ||= $hints->{referrer}; 350 388 use Wx qw(wxOK wxCENTRE wxICON_INFORMATION); 351 389 my $notFound = Wx::MessageDialog->new( $self, … … 356 394 $notFound->ShowModal; 357 395 $notFound->Destroy; 358 359 360 361 # my $html = qq|362 #<html><body>363 #<h1>Not Found</h1>364 #<p>Could not find documentation for365 #<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);373 396 374 397 } … … 412 435 413 436 } 414 437 438 439 sub _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 448 sub viewer_for { 449 my ($self,$mimetype) = @_; 450 return unless defined $mimetype; 451 if ( exists $VIEW{$mimetype} ) { 452 return $VIEW{$mimetype}; 453 } 454 } 415 455 416 456 1;
