milkbone57 22 years ago
parent
commit
522daa426f
  1. 73
      plugins/Tk-GUI/Tk/BrowseEdit.pm

73
plugins/Tk-GUI/Tk/BrowseEdit.pm

@ -4,6 +4,7 @@ use Tk;
use Tk::Font; use Tk::Font;
use Tk::ColorChoice; use Tk::ColorChoice;
use base 'Tk::Frame'; use base 'Tk::Frame';
use Data::Dumper;
use strict; use strict;
use warnings; use warnings;
@ -89,27 +90,27 @@ sub toggleTag
print "tag names gotten\n"; print "tag names gotten\n";
if ($cur_tag =~ /$tag/i) if ($cur_tag =~ /$tag/i)
{ {
# tag is not defined for this range - add it from the composite tag name and then add the resulting # tag is defined for this region - remove it
# tag, creating it if necessary
return unless $cur_tag ne ""; return if $cur_tag eq "";
$self->{text}->tagRemove($cur_tag, 'insert'); $self->{text}->tagRemove($cur_tag, 'insert');
print "tagremove $cur_tag\n";
$cur_tag =~ s/$tag//i; $cur_tag =~ s/$tag//i;
print "creating tag\n";
$self->create_tag($cur_tag); $self->create_tag($cur_tag);
print "tag created\n";
$self->insert('insert', '%%%ignore%%%', [$cur_tag, 'elide']); $self->insert('insert', '%%%ignore%%%', [$cur_tag, 'elide']);
$self->tagAdd($cur_tag, 'insert');
$self->{$button}->configure(-relief => 'flat'); $self->{$button}->configure(-relief => 'flat');
print "done\n"; print "done\n";
} }
else else
{ {
# tag not enabled for this range - remove it # tag not enabled for this range - add it
$self->{text}->tagRemove($cur_tag, 'insert'); $self->{text}->tagRemove($cur_tag, 'insert');
$cur_tag .= $tag; $cur_tag .= $tag;
return unless $cur_tag && $cur_tag ne "";
$self->create_tag($cur_tag); $self->create_tag($cur_tag);
$self->insert('insert', '%%%ignore%%%', [$cur_tag, 'elide']); $self->insert('insert', '%%%ignore%%%', [$cur_tag, 'elide']);
$self->tagAdd($cur_tag, 'insert'); $self->tagAdd($cur_tag, 'insert');
print "tagadd $cur_tag\n";
$self->{$button}->configure(-relief => 'sunken'); $self->{$button}->configure(-relief => 'sunken');
} }
} }
@ -146,7 +147,9 @@ sub toggleTag
unless($removed) unless($removed)
{ {
$self->create_tag($new_tag); $self->create_tag($new_tag);
return unless $tag;
$self->{text}->tagAdd($tag, $self->{text}->tagRanges('sel')); $self->{text}->tagAdd($tag, $self->{text}->tagRanges('sel'));
print "Added $tag\n";
$self->{$tag}->configure(-relief => 'sunken'); $self->{$tag}->configure(-relief => 'sunken');
} }
} }
@ -183,34 +186,38 @@ sub to_html
my ($self, $start, $end) = @_; my ($self, $start, $end) = @_;
$start ||= '0.0'; $start ||= '0.0';
$end ||= 'end'; $end ||= 'end';
my @tags = $self->{text}->tagNames;
my $res; my ($res, $temp);
my $pos = '1.0'; my $pos = '1.0';
my $chars; my $chars = 0;
my %curtags; my ($curtag, $prevtag) = ("", "");
my %chartags; my %all_tags;
my (@addtags, @deltags);
while($self->{text}->index($pos) != $self->{text}->index('end')) while($self->{text}->index($pos) != $self->{text}->index('end'))
{ {
%chartags = (); print Dumper([$self->{text}->tagNames($pos)]) . "\n";
$chartags{$_} = 1 for $self->{text}->tagNames($pos); $all_tags{$_} = $_ for $self->{text}->tagNames($pos);
delete $chartags{'elide'}; delete @all_tags{'elide', 'sel', ''};
delete $chartags{'sel'};
for (keys %chartags) $curtag = (keys %all_tags)[0];
{
push @addtags, $_ unless $curtags{$_} print Dumper(\%all_tags);
} print $self->{text}->get($pos) . "\n";
for (keys %curtags)
{ if($curtag =~ /$prevtag/)
push @deltags, $_ if !$chartags{$_}; {
} ($temp = $curtag) =~ s/$prevtag//;
%curtags = (); $res .= $temp;
$curtags{$_} = 1 for keys %chartags; }
$res .= $_ for @addtags; else
$res .= end_tag($_) for @deltags; {
@deltags = @addtags = (); ($temp = $prevtag) =~ s/$curtag//;
$res .= $self->{text}->get($pos); $res .= end_tag($temp);
$pos = $self->{text}->index('0.0 + ' . ++$chars . " chars"); }
$prevtag = $curtag;
$res .= $self->{text}->get($pos);
$pos = $self->{text}->index('0.0 + ' . ++$chars . " chars");
} }
$res =~ s/\%*ignore\%*//g; $res =~ s/\%*ignore\%*//g;
return $res; return $res;
@ -218,7 +225,7 @@ sub to_html
sub end_tag sub end_tag
{ {
my ($tag) = @_; my ($tag) = @_;
$tag =~ s/^</<\//; $tag =~ s/^</<\//g;
return $tag; return $tag;
} }

Loading…
Cancel
Save