| 1 | package Padre::Document::PSGI; | ||
| 2 | |||
| 3 | use 5.008; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use Padre::Debug; | ||
| 8 | use Padre::Document::Perl; | ||
| 9 | use Padre::MimeTypes; | ||
| 10 | |||
| 11 | our @ISA = 'Padre::Document::Perl'; | ||
| 12 | |||
| 13 | use Class::XSAccessor accessors => [qw(icon_path icon_set panel plugin process)]; | ||
| 14 | |||
| 15 | sub on_load { | ||
| 16 | my $self = shift; | ||
| 17 | |||
| 18 | TRACE('->on_load') if DEBUG; | ||
| 19 | |||
| 20 | require Scalar::Util; | ||
| 21 | Scalar::Util::weaken( $self->{plugin} ); | ||
| 22 | } | ||
| 23 | |||
| 24 | # Care needs to be taken that this is called *after* the new tab has been | ||
| 25 | # created, otherwise you'll end up setting the icon on the wrong tab | ||
| 26 | sub set_tab_icon { | ||
| 27 | my $self = shift; | ||
| 28 | return if $self->icon_set; | ||
| 29 | |||
| 30 | TRACE(' setting icon to ' . $self->icon_path) if DEBUG; | ||
| 31 | |||
| 32 | my $main = Padre->ide->wx->main; | ||
| 33 | my $id = $main->find_id_of_editor( $self->editor ); | ||
| 34 | my $icon = Wx::Bitmap->new( $self->icon_path, Wx::wxBITMAP_TYPE_PNG ); | ||
| 35 | $main->notebook->SetPageBitmap( $id, $icon ); | ||
| 36 | |||
| 37 | $self->icon_set(1); | ||
| 38 | } | ||
| 39 | |||
| 40 | sub restore_cursor_position { | ||
| 41 | my $self = shift; | ||
| 42 | |||
| 43 | # editor_enable gets called before the tab has been created when opening a new psgi file, | ||
| 44 | # so we set the icon inside this method which is conveniently triggered after the tab | ||
| 45 | # has been created in Padre::Wx::Main::setup_editor | ||
| 46 | $self->set_tab_icon; | ||
| 47 | |||
| 48 | return $self->SUPER::restore_cursor_position(@_); | ||
| 49 | } | ||
| 50 | |||
| 51 | # (ab)use L<remove_tempfile> to hook in our Document onClose handler | ||
| 52 | sub store_cursor_position { | ||
| 53 | my $self = shift; | ||
| 54 | $self->plugin->on_doc_close($self) if (caller(1))[3] eq 'Padre::Wx::Main::close'; | ||
| 55 | return $self->SUPER::store_cursor_position(@_); | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; |