Sorry if this late response serves no purpose for you. (I
was trolling in super-search for discussions about binding
the tab character in Tk::Text... still looking... but found
your node and had a suggestion.)
Yes, you do need to provide your own code to copy text changes
between two Text widgets. And probably the nicest way to do
this (from the user's perspective) would be to bind your own
"copyText" function to a suitable event for the Text widget
class. The best event to use probably depends on the app,
but my first thought would be something like:
$mainwindow->bind( 'Tk::Text', '<Leave>', [\©Text, $tw1, $tw2] )
+;
where $tw1 and $tw2 are the widget references for the two
Text windows that you want to keep in sync.
This binding says that whenever the mouse cursor moves out of
any Text widget, "copyText()" will be called, receiving that
particular widget reference as it's first arg, and the two
text widget references as second and third args. The sub
then goes something like this (not tested):
sub copyText {
my ($trigger,$tw1,$tw2) = @_;
my ($src,$dst,$txt);
if ($trigger eq $tw1) {
$src = $tw1;
$dst = $tw2;
} else {
$src = $tw2;
$dst = $tw1;
}
$txt = $src->get('1.0','end');
$dst->delete('1.0','end');
$dst->insert('1.0',$txt);
}
Of course, if the Text contents are complicated (tags, images,
etc -- anything other than simple, plain text), then this sub
needs to be a little more complicated....
|