Tcl-pTk

 view release on metacpan or  search on metacpan

lib/Tcl/pTk/TextUndo.pm  view on Meta::CPAN

{
 my ($w, $index1, $index2) = @_;
 my %tags;
 my @result = ( 'insert' => $index1 );
 my $str   = '';

 ###############################################################
 # get tags in range and return them in a format that
 # can be inserted.
 # $text->insert('1.0', $string1, [tag1,tag2], $string2, [tag2, tag3]);
 # note, have to break tags up into sequential order
 # in reference to _all_ tags.
 ###############################################################

 $w->dump('-text','-tag', -command => sub {
  my ($kind,$value,$posn) = @_;
  if ($kind eq 'text')
   {
    $str .= $value;
   }
  else
   {
    push(@result,$str,[keys %tags]) if (length $str);
    $str = '';
    if ($kind eq 'tagon')
     {
      $tags{$value} = 1;
     }
    elsif ($kind eq 'tagoff')
     {
      delete $tags{$value};
     }
   }
 }, $index1, $index2);
 push(@result,$str,[keys %tags]) if (length $str);
 return \@result;
}

############################################################
# override subroutines which are collections of low level
# routines executed in sequence.
# wrap a globstart and globend around the SUPER:: version of routine.
############################################################

sub ReplaceSelectionsWith
{
 my $w = shift;
 $w->addGlobStart;
 $w->SUPER::ReplaceSelectionsWith(@_);
 $w->addGlobEnd;
}

sub FindAndReplaceAll
{
 my $w = shift;
 $w->addGlobStart;
 $w->SUPER::FindAndReplaceAll(@_);
 $w->addGlobEnd;
}

sub clipboardCut
{
 my $w = shift;
 $w->addGlobStart;
 $w->SUPER::clipboardCut(@_);
 $w->addGlobEnd;
}

sub clipboardPaste
{
 my $w = shift;
 $w->addGlobStart;
 $w->SUPER::clipboardPaste(@_);
 $w->addGlobEnd;
}

sub clipboardColumnCut
{
 my $w = shift;
 $w->addGlobStart;
 $w->SUPER::clipboardColumnCut(@_);
 $w->addGlobEnd;
}

sub clipboardColumnPaste
{
 my $w = shift;
 $w->addGlobStart;
 $w->SUPER::clipboardColumnPaste(@_);
 $w->addGlobEnd;
}

# Greg: this method is more tightly coupled to the base class
# than I would prefer, but I know of no other way to do it.

sub Insert
{
 my ($w,$char)=@_;
 return if $char eq '';
 $w->addGlobStart;
 $w->SUPER::Insert($char);
 $w->addGlobEnd;
 $w->see('insert');
}


sub InsertKeypress
{
 my ($w,$char)=@_;
 return if $char eq '';
 if ($char =~ /^\S$/ and !$w->OverstrikeMode and !$w->tagRanges('sel'))
  {
   my $index = $w->index('insert');
   my $undo_item = $w->getUndoAtIndex(-1);
   if (defined($undo_item) &&
       ($undo_item->[0] eq 'delete') &&
       ($undo_item->[2] == $index)
      )
    {
     $w->SUPER::insert($index,$char);
     $undo_item->[2] = $w->index('insert');
     return;
    }
  }
 $w->addGlobStart;
 $w->SUPER::InsertKeypress($char);
 $w->addGlobEnd;
}

############################################################
sub TextUndoFileProgress
{
 my ($w,$action,$filename,$count,$val,$total) = @_;
 return unless(defined($filename) and defined($count));

 my $popup = $w->{'FILE_PROGRESS_POP_UP'};
 unless (defined($popup))
  {
   $w->update;
   $popup = $w->Toplevel(-title => "File Progress",-popover => $w);
   $popup->transient($w->toplevel);
   $popup->withdraw;
   $popup->resizable('no','no');
   $popup->Label(-textvariable => \$popup->{ACTION})->pack;
   $popup->Label(-textvariable => \$popup->{FILENAME})->pack;
   $popup->Label(-textvariable => \$popup->{COUNT})->pack;
   my $f = $popup->Frame(-height => 10, -border => 2, -relief => 'sunken')->pack(-fill => 'x');
   my $i = $f->Frame(-background => 'blue', -relief => 'raised', -border => 2);
   $w->{'FILE_PROGRESS_POP_UP'} = $popup;



( run in 1.116 second using v1.01-cache-2.11-cpan-2398b32b56e )