Padre
view release on metacpan or search on metacpan
lib/Padre/Wx/Dialog/Diff.pm view on Meta::CPAN
my $new_text = $diff->{new_text};
my $start = $editor->PositionFromLine($line);
my $end = $editor->GetLineEndPosition( $line + $diff->{lines_added} ) + 1;
$editor->SetTargetStart($start);
$editor->SetTargetEnd( $start + length($new_text) );
$editor->ReplaceTarget( $old_text ? $old_text : '' );
$self->Hide;
}
sub show {
my $self = shift;
my $editor = shift;
my $line = shift;
my $diff = shift;
my $pt = shift;
my $type = $diff->{type} or return;
# Store editor reference so we can access it in revert
$self->{editor} = $editor;
$self->{line} = $line;
$self->{diff} = $diff;
# Inherit font from current editor
my $font = $editor->GetFont;
$self->{status_label}->SetFont($font);
$self->{text_ctrl}->SetFont($font);
# Hack to workaround Wx::PopupWindow relative positioning bug
if (Padre::Constant::WIN32) {
$self->Move( $self->main->ScreenToClient( $editor->ClientToScreen($pt) ) );
} else {
$self->Move( $editor->ClientToScreen($pt) );
}
my $color;
if ( $type eq 'A' ) {
$color = Padre::Wx::Editor::DARK_GREEN();
} elsif ( $type eq 'D' ) {
$color = Padre::Wx::Editor::LIGHT_RED();
} elsif ( $type eq 'C' ) {
$color = Padre::Wx::Editor::LIGHT_BLUE();
} else {
$color = Wx::Colour->new("black");
}
$self->{text_ctrl}->SetBackgroundColour($color);
$self->{status_label}->SetValue( $diff->{message} );
if ( $diff->{old_text} ) {
$self->{text_ctrl}->SetValue( $diff->{old_text} );
$self->{text_ctrl}->Show(1);
} else {
$self->{text_ctrl}->Show(0);
}
# Hide when the editor loses focus
my $popup = $self;
Wx::Event::EVT_KILL_FOCUS(
$editor,
sub {
$popup->Hide;
}
);
Wx::Event::EVT_KEY_UP(
$editor,
sub {
my ( $self, $event ) = @_;
if ( $event->GetKeyCode == Wx::WXK_ESCAPE ) {
# Escape hides the diff box
$popup->Hide;
}
$event->Skip;
}
);
my $panel = $self->{text_ctrl}->GetParent;
$panel->Layout;
$panel->Fit;
$self->Fit;
$self->Show(1);
}
1;
# Copyright 2008-2016 The Padre development team as listed in Padre.pm.
# LICENSE
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl 5 itself.
( run in 1.033 second using v1.01-cache-2.11-cpan-364913b4093 )