|
|
|
@ -1,8 +1,22 @@
@@ -1,8 +1,22 @@
|
|
|
|
|
# |
|
|
|
|
# |
|
|
|
|
# WARNING - THIS IS CHEWBACCA CODE - IT DOES NOT MAKE SENSE. DO NOT MAKE ANY CHANGES TO THIS FILE, |
|
|
|
|
# FOR IT FUNCTIONS IF AND ONLY IF THE CODE IS EXACTLY AS IT IS AND EVEN THEN ONLY WORKS |
|
|
|
|
# PROPERLY DURING A FULL MOON ON THE THIRD THURSRDAY OF ODD-NUMBERED MONTHS IN THE SPRING WHEN THERE'S |
|
|
|
|
# SNOW ON THE GROUND. |
|
|
|
|
# |
|
|
|
|
# YOU HAVE BEEN WARNED. DO NOT BLAME ME IF THIS CODE DOES NOT WORK, EATS YOUR CHILDREN, OR FAXES |
|
|
|
|
# HUNDREDS OF COPIES OF ITSELF TO GUAM. |
|
|
|
|
# |
|
|
|
|
# IT DOES NOT MAKE SENSE!!!! (Look at the monkey, look at the silly monkey...) |
|
|
|
|
# |
|
|
|
|
# - batkins (8-21-03) |
|
|
|
|
# |
|
|
|
|
|
|
|
|
|
package Tk::BrowseEdit; |
|
|
|
|
|
|
|
|
|
use Tk; |
|
|
|
|
use Tk::Font; |
|
|
|
|
use Tk::ColorChoice; |
|
|
|
|
use base 'Tk::Frame'; |
|
|
|
|
use Data::Dumper; |
|
|
|
|
|
|
|
|
@ -27,7 +41,6 @@ sub Populate
@@ -27,7 +41,6 @@ sub Populate
|
|
|
|
|
-font => $self->Font(-family => 'times', -weight => 'bold', -size => '8'), |
|
|
|
|
-command => [sub { |
|
|
|
|
my ($self) = @_; |
|
|
|
|
print "hit b\n"; |
|
|
|
|
$self->toggleTag('<b>'); |
|
|
|
|
}, $self] |
|
|
|
|
)->pack(-pady => 0, -side => 'left', -fill => 'both'); |
|
|
|
@ -51,11 +64,13 @@ $self]);
@@ -51,11 +64,13 @@ $self]);
|
|
|
|
|
)->pack(-pady => 0, -side => 'left', -fill => 'both'); |
|
|
|
|
$self->bind('<Control-U>', [sub { shift->{'<b>'}->invoke; }, $self]); |
|
|
|
|
|
|
|
|
|
$self->{'<back>'} = $self->{panel}->Button(-text => 'A', -relief => 'flat', -background => 'blue', |
|
|
|
|
$self->{'<back>'} = $self->{panel}->Button(-text => 'back', -relief => 'flat', -background => 'blue', |
|
|
|
|
-activebackground => 'blue', |
|
|
|
|
-font => $self->Font(-family => 'times', -size => '8'), |
|
|
|
|
-command => [sub { |
|
|
|
|
my ($self) = @_; |
|
|
|
|
my $color = $self->pick_color; |
|
|
|
|
return if $color eq "NOTACOLOR"; |
|
|
|
|
|
|
|
|
|
$self->toggleTag("<font back=\"$color\">", '<back>'); |
|
|
|
|
}, $self] |
|
|
|
@ -85,21 +100,19 @@ sub toggleTag
@@ -85,21 +100,19 @@ sub toggleTag
|
|
|
|
|
if(!defined($self->{text}->tagRanges('sel'))) |
|
|
|
|
{ |
|
|
|
|
# no selection - modify current position |
|
|
|
|
print "starting\n"; |
|
|
|
|
my $cur_tag = ($self->{text}->tagNames('insert'))[0] || ""; |
|
|
|
|
print "tag names gotten\n"; |
|
|
|
|
if ($cur_tag =~ /$tag/i) |
|
|
|
|
{ |
|
|
|
|
# tag is defined for this region - remove it |
|
|
|
|
|
|
|
|
|
return if $cur_tag eq ""; |
|
|
|
|
$self->{text}->tagRemove($cur_tag, 'insert'); |
|
|
|
|
print "tagremove $cur_tag\n"; |
|
|
|
|
$cur_tag =~ s/$tag//i; |
|
|
|
|
$self->create_tag($cur_tag); |
|
|
|
|
$self->insert('insert', '%%%ignore%%%', [$cur_tag, 'elide']); |
|
|
|
|
$self->{text}->tagAdd($cur_tag, 'insert'); |
|
|
|
|
$self->insert('insert', chr(255), [$cur_tag, 'elide']) if $cur_tag ne ""; |
|
|
|
|
$self->insert('insert', chr(255), ['elide']) if $cur_tag eq ""; |
|
|
|
|
$self->{$button}->configure(-relief => 'flat'); |
|
|
|
|
print "done\n"; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
@ -107,10 +120,10 @@ sub toggleTag
@@ -107,10 +120,10 @@ sub toggleTag
|
|
|
|
|
$self->{text}->tagRemove($cur_tag, 'insert'); |
|
|
|
|
$cur_tag .= $tag; |
|
|
|
|
return unless $cur_tag && $cur_tag ne ""; |
|
|
|
|
$self->create_tag($cur_tag); |
|
|
|
|
$self->insert('insert', '%%%ignore%%%', [$cur_tag, 'elide']); |
|
|
|
|
$self->tagAdd($cur_tag, 'insert'); |
|
|
|
|
print "tagadd $cur_tag\n"; |
|
|
|
|
$self->create_tag($cur_tag) unless $cur_tag eq ""; |
|
|
|
|
$self->insert('insert', chr(255), [$cur_tag, 'elide']) if $cur_tag ne ""; |
|
|
|
|
$self->insert('insert', chr(255), ['elide']) if $cur_tag eq ""; |
|
|
|
|
$self->{text}->tagAdd($cur_tag, 'insert'); |
|
|
|
|
$self->{$button}->configure(-relief => 'sunken'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -146,10 +159,9 @@ sub toggleTag
@@ -146,10 +159,9 @@ sub toggleTag
|
|
|
|
|
|
|
|
|
|
unless($removed) |
|
|
|
|
{ |
|
|
|
|
$self->create_tag($new_tag); |
|
|
|
|
self->create_tag($new_tag); |
|
|
|
|
return unless $tag; |
|
|
|
|
$self->{text}->tagAdd($tag, $self->{text}->tagRanges('sel')); |
|
|
|
|
print "Added $tag\n"; |
|
|
|
|
$self->{$tag}->configure(-relief => 'sunken'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -172,9 +184,10 @@ sub create_tag
@@ -172,9 +184,10 @@ sub create_tag
|
|
|
|
|
{ |
|
|
|
|
$fontparams{-slant} = 'italic'; |
|
|
|
|
} |
|
|
|
|
if($tag =~ /<font back='(.*?)'>/) |
|
|
|
|
if($tag =~ /<font back=('|")(.*?)('|")>/) |
|
|
|
|
{ |
|
|
|
|
$fontparams{-slant} = 'italic'; |
|
|
|
|
$tagparams{-background} = $2; |
|
|
|
|
print "set background"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
my $font = $self->Font(%fontparams); |
|
|
|
@ -192,34 +205,47 @@ sub to_html
@@ -192,34 +205,47 @@ sub to_html
|
|
|
|
|
my $chars = 0; |
|
|
|
|
my ($curtag, $prevtag) = ("", ""); |
|
|
|
|
my %all_tags; |
|
|
|
|
|
|
|
|
|
while($self->{text}->index($pos) != $self->{text}->index('end')) |
|
|
|
|
{ |
|
|
|
|
print Dumper([$self->{text}->tagNames($pos)]) . "\n"; |
|
|
|
|
%all_tags = (); |
|
|
|
|
$all_tags{$_} = $_ for $self->{text}->tagNames($pos); |
|
|
|
|
delete @all_tags{'elide', 'sel', ''}; |
|
|
|
|
|
|
|
|
|
$curtag = (keys %all_tags)[0]; |
|
|
|
|
delete $all_tags{'sel'}; |
|
|
|
|
delete $all_tags{'elide'}; |
|
|
|
|
delete $all_tags{''}; |
|
|
|
|
|
|
|
|
|
print Dumper(\%all_tags); |
|
|
|
|
print $self->{text}->get($pos) . "\n"; |
|
|
|
|
|
|
|
|
|
if($curtag =~ /$prevtag/) |
|
|
|
|
if(scalar(keys %all_tags) == 0 && $prevtag eq "") |
|
|
|
|
{ |
|
|
|
|
($temp = $curtag) =~ s/$prevtag//; |
|
|
|
|
$res .= $temp; |
|
|
|
|
$pos = $self->{text}->index('0.0 + ' . ++$chars . " chars"); |
|
|
|
|
$res .= $self->{text}->get($pos); |
|
|
|
|
$prevtag = ""; |
|
|
|
|
next; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
$curtag = (keys %all_tags)[0] || ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($prevtag =~ /$curtag/) |
|
|
|
|
{ |
|
|
|
|
# tag added |
|
|
|
|
($temp = $prevtag) =~ s/$curtag//; |
|
|
|
|
$res .= end_tag($temp); |
|
|
|
|
} |
|
|
|
|
elsif($curtag =~ /$prevtag/) |
|
|
|
|
{ |
|
|
|
|
# tag removed |
|
|
|
|
($temp = $curtag) =~ s/$prevtag//; |
|
|
|
|
$res .= $temp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$prevtag = $curtag; |
|
|
|
|
|
|
|
|
|
$res .= $self->{text}->get($pos); |
|
|
|
|
$pos = $self->{text}->index('0.0 + ' . ++$chars . " chars"); |
|
|
|
|
} |
|
|
|
|
$res =~ s/\%*ignore\%*//g; |
|
|
|
|
|
|
|
|
|
my $chr = chr(255); |
|
|
|
|
$res =~ s/$chr//g; |
|
|
|
|
return $res; |
|
|
|
|
} |
|
|
|
|
sub end_tag |
|
|
|
@ -235,11 +261,11 @@ sub pick_color
@@ -235,11 +261,11 @@ sub pick_color
|
|
|
|
|
my $dlg = $self->Parent->DialogBox(-title => 'Choose Color', -buttons => |
|
|
|
|
['OK', 'Cancel'], -default_button => 'OK'); |
|
|
|
|
|
|
|
|
|
$dlg->ColorChoice->pack; |
|
|
|
|
my $wid = $dlg->ColorChoice->pack; |
|
|
|
|
my $res = $dlg->Show(); |
|
|
|
|
|
|
|
|
|
return unless $res eq "OK"; |
|
|
|
|
|
|
|
|
|
return "NOTACOLOR" unless $res eq "OK"; |
|
|
|
|
return $wid->{color}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
1; |
|
|
|
|