At 9:16 am -0500 20/03/01, Morbus Iff wrote:
>I can throw in a dummy window and run this script, however. Of course, the
>menus never work (why don't they work? sniff, sniff), and the error appears
>when I stop the script (as per END).
>
>What am I doing wrong?
I suspect the main reason is you have not got an "Editor" window up
your MenuBar? I get the same error you do on running your script for
that reason.
One of the difficulties with altering the MenuBar is that you can
never be sure what Menus (particularly the external editor) are up on
any particular machine. You really have to ask the machine. You might
find the following script helpful:
#!perl
use Mac::Menus;
for $m (128..65535) {
$menuHandle = GetMenuHandle($m);
if($menuHandle) {
$str = getBits($menuHandle->enableFlags);
push @list, join(' ', $m, $str, $menuHandle->menuData);
}
}
sub getBits {
my ($n) = @_;
my $out;
for (0..31) {
$out .= ($n & 1);
$n = $n >> 1;
}
$out
}
foreach (@list) {print "$_\n" }
With your script, after removing references to ID==133 and adjusting
the order of the Menus to suit, it seems to work.
You need a 'pause' of some kind at the end to view the new MenuBar --
I have added a 'getc' just as a quick expedient.
HTH,
Alan Fry
-------------
#!/usr/bin/perl
use Mac::Menus;
use strict;
my $oldEdit = GetMenuHandle(130);
my $oldFile = GetMenuHandle(129);
#my $oldEditor = GetMenuHandle(133); # absent?
my $newMenu = new_menu();
my $newEdit = $$newMenu[0]->{menu};
my $newFile = $$newMenu[1]->{menu};
#DeleteMenu(133); # assume not present
DeleteMenu(130);
DeleteMenu(129);
InsertMenu $newEdit, 131; # before 'Window' (was 133)
InsertMenu $newFile, 2048;
DrawMenuBar();
DisableItem($newEdit, 1);
DisableItem($newEdit, 2);
DisableItem($newEdit, 3);
DisableItem($newEdit, 4);
sub new_menu {
my $newFile = MacMenu->new ( 2049, 'newFile', ( # 'new' added for clarity
['Quit', \&file_menu, 'Q'] ) );
my $newEdit = MacMenu->new ( 2048, 'newEdit', ( # 'new added for clarity
['Cut', \&edit_menu, 'X'],
['Copy', \&edit_menu, 'C'],
['Paste', \&edit_menu, 'V'],
['Clear', \&edit_menu, ''],
)
);
return [$newEdit, $newFile];
}
sub edit_menu { my ($menu, $item) = @_; 1; }
sub file_menu {
my ($menu, $item) = @_;
if ($menu == 2049 and $item == 1) { exit; }
}
sub restore_menu_bar {
DeleteMenu(2048);
DeleteMenu(2049);
InsertMenu($oldEdit, 131); # before Window (was 133)
InsertMenu($oldFile, 130);
#InsertMenu($oldEditor, 134); # omit
DrawMenuBar();
}
getc; # pause to admire handiwork -- CR to end
END { restore_menu_bar(); }
__END__