Tk-Workspace
view release on metacpan or search on metacpan
WorkspaceText.pm view on Meta::CPAN
package Tk::WorkspaceText;
# Temp version for CPAN
$VERSION=0.57;
my $RCSRevKey = '$Revision: 0.58 $';
$RCSRevKey =~ /Revision: (.*?) /;
$VERSION=$1;
require Exporter;
use Tk qw(Ev);
Construct Tk::Widget 'WorkspaceText';
use base qw(Tk::TextUndo Tk::Toplevel);
#
# Bound in Tk::Text.pm
#
sub InsertKeypress {
my ($w,$char)=@_;
$w -> SUPER::InsertKeypress($char);
$w -> {modified} = '1' if (defined $char && $char ne '');
}
sub Insert {
my $w = shift;
my $string = shift;
$w -> SUPER::Insert($string);
$w -> {modified} = '1';
}
sub Delete {
my ($w) = @_;
$w -> SUPER::Delete;
$w -> {modified} = '1';
}
sub Backspace {
my ($w) = @_;
$w -> SUPER::Backspace;
$w -> {modified} = '1';
}
sub clipboardColumnCut {
my ($w) = @_;
$w-> Column_Copy_or_Cut(1);
$w -> {modified} = '1';
}
sub clipboardColumnPaste {
my ($w) = @_;
$w -> SUPER::clipboardColumnPaste;
$w -> {modified} = '1';
}
sub ClassInit {
my ($class,$mw) = @_;
$class->SUPER::ClassInit($mw);
$Tk::prevPos = undef;
$mw -> bind($class, '<Tab>', 'fixed_tabs');
$mw -> bind($class, '<Alt-h>', 'selectPara');
$mw -> bind($class, '<Alt-l>', 'paragraphFill');
$mw -> bind($class, '<Control-v>', ['SetCursor',Ev('ScrollPages',1)]);
$mw -> bind($class, '<Control-r>', ['SetCursor',Ev('ScrollPages',-1)]);
$mw -> bind($class, '<Control-period>', 'center');
return $class;
}
sub InitObject {
my ($w, $args) = @_;
$w -> {modified} = '';
$w -> {fixedtabs} = '8';
$w -> {fillcolumn} = '65';
$w -> bind ('<Tab>', sub{ $w -> fixed_tabs });
return $w;
}
sub Populate {
my ($w, $args) = @_;
$w -> SUPER::Populate($args);
return $w;
}
sub paragraphFill {
my ($w) = @_;
my ($tmpline, $breakpos);
my ($insertrow,$insertcol) = split /\./, $w -> index ('insert');
$previndex = $w -> prevPara ($w -> index ('insert'));
$nextindex = $w -> nextPara ($w -> index ('insert'));
my $t = $w -> get ("$previndex linestart", "$nextindex - 1 line");
$t =~ s/\n/ /smg;
$w -> delete ("$previndex linestart", "$nextindex - 1 line");
$w -> markSet ('insert', "$previndex linestart");
while (length ($t) >= $w -> {fillcolumn}) {
$tmpline = substr ($t, 0, $w -> {fillcolumn});
$breakpos = rindex ($tmpline, ' ');
$tmpline = substr ($t, 0, $breakpos);
# Remove the extra space unless it's an indented line
$tmpline =~ s/^ // unless ($tmpline =~ /^(\t|\s\s+)/) ;
$w -> insert('insert', "$tmpline\n");
$t = substr ($t, $breakpos);
}
$t =~ s/^ //;
# Trim the extra space from the end of the last line.
chop $t;
$w -> insert('insert', "$t\n");
$w -> markSet ('insert', "$insertrow.$insertcol");
$w -> {modified} = '1';
}
sub selectPara {
my ($w) = @_;
( run in 1.645 second using v1.01-cache-2.11-cpan-81fc1098f69 )