Remember to save your workspace before running this, as it parses the last saved workspace. Anyone know if "save workspace" is macro-able?
Code: Select all
# TKDiff for Textpad
#
# DOS command should be:
# perl c:\userdata\temp\textpad\filecompare.pl "$WspDir\$WspBaseName.tws" "$File"
#
# Default uses tkdiff for windows (http://texttest.carmen.se/TextTest/docs/tkdiffInstall.zip)
# Could be updated to use about any diff tool.
#
# Note that this always parses a TWS file to get list of filenames. Make sure to save workspace before
# running this.
#
use Tk;
my $twsfilename = $ARGV[0];
open (INFILE, "<$twsfilename") || die "Failed to open $twsfilename";
my @twslines = (<INFILE>);
close INFILE;
my $main = MainWindow->new();
#$main->minsize( qw(250 250) );
$main->title("Compare Textpad files");
#$main->configure(-background=>'cyan');
#$main->geometry('+10+300');
my $file0frame = $main->Frame()->pack(-side=>'left');
my $file1frame = $main->Frame()->pack(-side=>'left');
my $filename0 = $ARGV[1];
my $filename1;
my @filenames = ();
foreach (@twslines) {
split(/ECOD../, $_);
foreach (@_) {
if ($_ =~ /^(.+?)\x01/gi) {
my $tmpfilename = $1;
unless (-f $tmpfilename) {next;}
@filenames = (@filenames, $tmpfilename);
$file0frame->Radiobutton(-variable=>\$filename0, -text=>'', -value=>$tmpfilename)->pack(-side=>'top', -anchor=>'w');
$file1frame->Radiobutton(-variable=>\$filename1, -text=>$tmpfilename, -value=>$tmpfilename)->pack(-side=>'top', -anchor=>'w');
}
}
}
my $btnFrm = $main->Frame()->pack(-side=>'bottom', -fill=>'y');
my $runbutton = $btnFrm->Button(-text=>'Compare', -command=> sub {&compare})->pack(-side=>'right',-pady=>2,-anchor=>'w');
MainLoop;
sub compare {
if (($filename0 ne "") && ($filename1 ne "")) {
print "comparing $filename0 $filename1\n";
#my $cmd = "\"BC2.exe\" \"$filename0\" \"$filename1\"";
my $cmd = "\"tkdiff\" \"$filename0\" \"$filename1\"";
print "$cmd\n";
`$cmd`;
exit 0;
} else {
print "something isn't selected\n";
}
}