App-Codit
view release on metacpan or search on metacpan
lib/App/Codit/Plugins/Diff.pm view on Meta::CPAN
my $mode = 'File to document';
$self->{MODE} = \$mode;
my $mb = $mf->Menubutton(
-anchor => 'w',
-textvariable => \$mode,
)->pack(@padding, -side => 'left', -expand => 1, -fill => 'x');
my @menu = ();
for ('File to document', 'Document to file') {
my $operation = $_;
push @menu, [command => $operation,
-command => sub { $mode = $operation },
];
}
$mb->configure(-menu => $mb->Menu(
-menuitems => \@menu,
));
#style selection
my $sf = $sm->Frame->pack(-fill =>'x');
$sf->Label(
-anchor =>'e',
-width => 7,
-text => 'Style:',
)->pack(-side => 'left');
my $style = 'Unified';
$self->{STYLE} = \$style;
my $sb = $sf->Menubutton(
-anchor => 'w',
-textvariable => \$style,
)->pack(@padding, -side => 'left', -expand => 1, -fill => 'x');
my @smenu = ();
for ('Unified', 'Context', 'OldStyle') {
my $operation = $_;
push @smenu, [command => $operation,
-command => sub { $style = $operation },
];
}
$sb->configure(-menu => $sb->Menu(
-menuitems => \@smenu,
));
my $sa = $page->Frame(
-relief => 'groove',
-borderwidth => 2,
)->pack(@padding, -expand => 1, -fill => 'both');
$sa->Button(
-text => 'Diff',
-command => ['Diff', $self],
)->pack(@padding, -fill => 'x');
$sa->Button(
-text => 'Clear',
-command => ['Clear', $self],
)->pack(@padding, -fill => 'x');
$sa->Button(
-text => 'Export',
-command => ['Export', $self],
)->pack(@padding, -fill => 'x');
my $fam = $self->configGet('-contentfontfamily');
$fam = 'Courier' unless defined $fam;
my $siz = $self->configGet('-contentfontsize');
$siz = 10 unless defined $siz;
my $txt = $sa->CodeText(
-font => "{$fam} $siz",
-readonly => 1,
-showfolds => 0,
-shownumbers => 0,
-showstatus => 0,
-syntax => 'Diff',
-width => 40,
-wrap => 'none',
)->pack(@padding, -fill => 'both', -expand => 1);
$self->{TXT} = $txt;
return $self;
}
sub Clear {
my $self = shift;
my $txt = $self->{TXT};
$txt->delete('0.0', 'end');
}
sub Diff {
my $self = shift;
my $txt = $self->{TXT};
$txt->delete('0.0', 'end');
my $widg = $self->mdi->docWidget;
my $source = $widg->get('0.0', 'end - 1 char');
my $file = $self->GetFile;
my $mode = $self->GetMode;
my $style = $self->GetStyle;
my $diff = '';
if ($mode eq 'File to document') {
$diff = diff($file, \$source, { STYLE => $style });
} else {
$diff = diff(\$source, $file, { STYLE => $style });
}
$txt->insert('end', $diff);
}
sub Export {
my $self = shift;
my ($file) = $self->pickFileSave;
my $txt = $self->{TXT};
$txt->saveExport($file) if defined $file;
}
sub GetFile {
my $self = shift;
my $m = $self->{FILEENTRY};
return $m->get;
}
sub GetMode {
my $self = shift;
my $m = $self->{MODE};
return $$m;
}
sub GetStyle {
my $self = shift;
my $m = $self->{STYLE};
return $$m;
( run in 0.943 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )