For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > June 2004 > Disable File->Exit from the popup menu?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Disable File->Exit from the popup menu?
ad

2004-06-18, 3:57 am

Hi,

Is it possible to disable only the File->Exit popup option from Text
widget and keep the rest of the functions?

Thank you.
zentara

2004-06-18, 8:56 am

On Thu, 17 Jun 2004 22:19:17 -0400, ad <as@no-span.org> wrote:

>Hi,
>
>Is it possible to disable only the File->Exit popup option from Text
>widget and keep the rest of the functions?
>
>Thank you.


Here is a snippet which shows you the idea. Ask again if you need
a working script.

my $textmenu = $text->menu;
#get the menu associated with 'File'
my $filemenu=$textmenu->entrycget('File',-menu);
#Delete the unwanted commands
$filemenu->delete(5,6); #delete off of bottom first
$filemenu->delete(0,2); #range 0,1,2
$filemenu->insert(0,'command',-label=>'SaveAs',



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Ernie Miller

2004-06-25, 6:47 pm


"zentara" <zentara@highstream.net> wrote in message
news:50k5d0hal53ddmuevobro38peci3srejc6@
4ax.com...
> On Thu, 17 Jun 2004 22:19:17 -0400, ad <as@no-span.org> wrote:
>
>
> Here is a snippet which shows you the idea. Ask again if you need
> a working script.
>
> my $textmenu = $text->menu;
> #get the menu associated with 'File'
> my $filemenu=$textmenu->entrycget('File',-menu);
> #Delete the unwanted commands
> $filemenu->delete(5,6); #delete off of bottom first
> $filemenu->delete(0,2); #range 0,1,2
> $filemenu->insert(0,'command',-label=>'SaveAs',
>


Or, if you want to override the way that every text widget gets created,
override Tk::Text::FillMenu. Here's what I do to replace the normal menu
with only the edit commands:

sub Tk::Text::FillMenu {
my ($w, $menu) = @_;
my @items = ();
foreach my $op ($w->clipEvents) {
if ($op eq 'Cut') {
push(@items,['command', -label => "Cut", -command => sub {

$w->clipboardCut;

$menu->Unpost();
}]);
} elsif ($op eq 'Copy') {
push(@items,['command', -label => "Copy", -command => sub {

$w->clipboardCopy;

$menu->Unpost();
}]);
} elsif ($op eq 'Paste') {
push(@items,['command', -label => "Paste", -command => sub {

$w->clipboardPaste;

$menu->Unpost();
}]);
}
}
foreach (@items) {
$menu->add(@$_);
}

return $menu;
}


ad

2004-06-25, 6:47 pm


>
> my $textmenu = $text->menu;
> #get the menu associated with 'File'
> my $filemenu=$textmenu->entrycget('File',-menu);
> #Delete the unwanted commands
> $filemenu->delete(5,6); #delete off of bottom first
> $filemenu->delete(0,2); #range 0,1,2
> $filemenu->insert(0,'command',-label=>'SaveAs',


This worked just like I hope it would. Thanks for all the responses.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com