/usr/bin/tkx-ed is in libtkx-perl 1.09-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | #!/usr/bin/perl -w
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell
# tkx-ed - Simple text editor
use strict;
use Tkx;
use File::Basename qw(basename);
(my $PROGNAME = $0) =~ s,.*[\\/],,;
my $IS_AQUA = Tkx::tk_windowingsystem() eq "aqua";
if ($IS_AQUA) {
$PROGNAME = "Tkx Editor";
# when invoked directly via "open 'Tkx Editor.app'" it will be passed
# something like "-psn_0_5154026" which we don't really care about.
shift(@ARGV) if @ARGV && $ARGV[0] =~ /-psn/;
# The console can pop up unexpectedly from the tkkit
Tkx::catch("console hide");
# Set the process name that is displayed in the Activity Monitor
# and the Force Quit dialog
eval {
Tkx::package_require('tclCarbonProcesses');
my $psn = Tkx::carbon__getCurrentProcess();
Tkx::carbon__setFrontProcess($psn);
Tkx::carbon__setProcessName($psn, $PROGNAME);
};
warn $@ if $@;
Tkx::interp_alias("", "::tk::mac::OpenDocument", "", [\&load]);
}
Tkx::package_require("BWidget");
eval {
Tkx::package_require("style");
Tkx::style__use("as", -priority => 70);
};
if ($@) {
$@ =~ s/ at .*//;
warn "Using plain look: $@";
}
# state
my $file = "";
# set up main window
my $mw = Tkx::widget->new(".");
my $sw = $mw->new_ScrolledWindow();
$sw->g_pack(
-fill => "both",
-expand => 1,
);
my($t, $tw);
eval {
Tkx::package_require("ctext");
# A ctext's true text widget is a subwidget
$t = $sw->new_ctext();
$tw = $t->_kid("t");
};
if ($@) {
# fallback is the standard widget
$@ =~ s/ at .*//;
warn "Using plain text: $@";
$t = $sw->new_text();
$tw = $t;
}
$t->configure(
-bd => 1,
-undo => 1,
-wrap => "none",
);
$sw->setwidget($t);
$mw->configure(-menu => mk_menu($mw));
if (@ARGV) {
Tkx::after_idle([\&load, $ARGV[0]])
}
else {
new();
}
Tkx::MainLoop();
exit;
sub mk_menu {
my $mw = shift;
Tkx::option_add("*Menu.tearOff", 0);
my $m = $mw->new_menu();
my $fm = $m->new_menu();
my $em = $m->new_menu();
my $hm = $m->new_menu();
my $control = ($^O eq "darwin") ? "Command" : "Control";
my $ctrl = ($^O eq "darwin") ? "Command-" : "Ctrl+";
$m->add_cascade(
-label => "File",
-menu => $fm,
);
$m->add_cascade(
-label => "Edit",
-menu => $em,
);
$m->add_cascade(
-label => "Help",
-menu => $hm,
);
# File menu
$fm->add_command(
-label => "New",
-accelerator => $ctrl . "N",
-command => \&new,
);
Tkx::bind("all", "<$control-n>", \&new);
$fm->add_command(
-label => "Open...",
-accelerator => $ctrl . "O",
-command => \&my_open,
);
Tkx::bind("all", "<$control-o>", \&my_open);
$fm->add_command(
-label => "Save",
-accelerator => $ctrl . "S",
-command => \&save,
);
Tkx::bind("all", "<$control-s>", \&save);
$fm->add_command(
-label => "Save As...",
-command => \&save_as,
);
unless ($IS_AQUA) {
$fm->add_command(
-label => "Exit",
-underline => 1,
-accelerator => $ctrl . "Q",
-command => [\&Tkx::destroy, $mw],
);
Tkx::bind("all", "<$control-q>", [\&Tkx::destroy, $mw]);
}
# Edit menu
$em->add_command(
-label => "Cut",
-command => [\&Tkx::event_generate, $tw, "<<Cut>>"]
);
$em->add_command(
-label => "Copy",
-command => [\&Tkx::event_generate, $tw, "<<Copy>>"],
);
$em->add_command(
-label => "Paste",
-command => [\&Tkx::event_generate, $tw, "<<Paste>>"],
);
# Help menu
$hm->add_command(
-label => "View $PROGNAME source",
-command => sub { load(__FILE__) },
);
my $about_menu = $hm;
if ($IS_AQUA) {
# On Mac OS we want about box to appear in the application
# menu. Anything added to a menu with the name "apple" will
# appear in this menu.
$about_menu = $m->new_menu(
-name => "apple",
);
$m->add_cascade(
-menu => $about_menu,
);
}
$about_menu->add_command(
-label => "About $PROGNAME",
-command => sub {
Tkx::tk___messageBox(
-parent => $mw,
-title => "About \u$PROGNAME",
-type => "ok",
-icon => "info",
-message => "$PROGNAME v$Tkx::VERSION\n" .
"Copyright 2005 ActiveState. " .
"All rights reserved.",
);
},
);
return $m;
}
sub new {
$t->delete("1.0", "end");
set_file("");
}
sub my_open {
my $f = Tkx::tk___getOpenFile(
-parent => $mw,
);
load($f) if length $f;
}
sub load {
my $f = shift;
open(my $fh, "<:utf8", $f) || die "Can't open '$f': $!";
$t->delete("1.0", "end");
$t->insert("end", scalar do { local $/; <$fh> });
set_file($f);
}
sub set_file {
$file = shift;
update_title();
}
sub save {
return save_as() unless length $file;
_save($file);
}
sub save_as {
my $f = Tkx::tk___getSaveFile(
-parent => $mw,
);
if (length $f) {
_save($f);
set_file($f);
}
}
sub _save {
my $f = shift;
open(my $fh, ">", $f) || die "Can't open '$file': $!";
print $fh $t->get("1.0", "end - 1 char");
close($fh) || die "Can't write '$file': $!";
}
sub update_title {
my $title;
if (length $file) {
$title = basename($file);
}
else {
$title = "<no name>";
}
$title .= " - " . $PROGNAME unless $IS_AQUA;
$mw->g_wm_title($title);
}
__END__
=head1 NAME
tkx-ed - Simple editor
=head1 SYNOPSIS
tkx-ed [<file>]
=head1 DESCRIPTION
The F<tkx-ed> program is a simple text editor implemented with the
C<Tkx> toolkit. Its main purpose is to demonstrate how this kind of
application is written, so please take a look at its source code.
When the editor starts up it shows a blank page where you can start
entering text directly.
If a file name is passed on the command line then the editor will
visit this file initially.
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Copyright 2005 ActiveState. All rights reserved.
=head1 SEE ALSO
L<Tkx>
|