Menubar Handling
David Burgun
dburgun at dsl.pipex.com
Wed Apr 5 07:54:01 EDT 2006
Hi,
It's funny how things come up on the list and others are walking the
same or similar path at the same time.
I am just revising my Menubar handling at the moment. Menubar's
don't fit in very well with way the rest of RunRev works IMO.
In a typical application you may want to add new menu's to the
menubar or you may want to change the text of an existing menu item
or the action associated with a menu action. An example of this is:
Main Window, has a button that allows a user to choose a file and you
want to use the "open" (or any other) menu item to perform the same
action as pressing the button. If then case you also want the menu
item to be enabled/disabled at the same time as the Button.
However, in another window, you want the File menu item to be
disabled completely or you may want to have another action associated
with the Open Item or you may want to change the text of the item or
both.
I am trying to build a General Menubar manager stack and have come up
with the following method of operation:
The Menubar handling is all contained on one stack - Menubar.rev.
This starts off with a dummy menubar group which has a number (say
16) of menu "buttons". Each of the buttons has an empty menu items
list. When a stack requires a menu bar, it does the following:
--
-- Create a New Menubar
--
put "MainMenubar" into myMenubarName
put "File,Edit,Help" into myMenuButtonList
put MenubarNewMenuBar(myMenubarName,myMenuButtonList) into
myMenubarLongID
if myMenubarLongID = empty
-- Handle Error
end if
--
-- Add a File Menu to the Menubar
--
put "File" into myMenuName
if MenubarNewMenu(myMenubarLongID,myMenuName) = false
--Handle Error
end if
--
-- Add an Item to the Menu in the Menubar
--
put 1 into myMenuItemNumber
put "Open" into myMenuItemText
if MenubarSetMenuText(myMenubarLongID,myMenuName,myMenuItemNumber,
myMenuItemText) = false
--Handle Error
end if
--
-- Attach a Handler to the Menu Item of the Menu of the Menubar
--
put "MenuBarFileOpenHandler" into myHandlerName
put the long id of this stack into myHandlerLocation
MeubarSetMenuItemSelectedHandler(myMenubarLongID,
myMenuItemNumber,myHandlerName,myHandlerLocation)
--
-- Enable the Menu Item of the Menu in the Menubar
--
MenubarSetMenuItemEnabledState(myMenubarLongID, myMenuName,
myMenuItemNumber,true)
put MenubarGetMenuGroupName(myMenubarLongID) into myMenubarGroupName
set the menubar of this stack to myMenubarGroupName
Now when "Open" is Selected in the "File" Menu in the Menubar,
myHandlerName in myHandlerLocation will be sent a message as so:
on MenuBarFileOpenHandler
end MenuBarFileOpenHandler
That's basically as far as I've got, which works for one stack, the
problem I have is changing the menubar when another stack or card is
run. For instance if I want the open item to be disabled when a card
is selected, or I want the same action(s), but related to the new
stack or card, e.g. Open is selected in Stack A, I want to do one
thing, but if Stack B is in control then I want the open action sent
to StackB.
This seems like a lot of work, but I can't see anyway around it,
unless you hand-sculpt the menubar handling for each application.
Has anyone else done something similar? Anyone else have any advice
or suggestions on the best way to achieve a general Menubar stack/
module? It just seems like a monster waste of time for each RunRev
developer to have to go thru this over and over again for each app
that requires a menubar.
On 3 Mar 2006, at 02:03, Mark Schonewille wrote:
> Hi Karen,
>
> It seems you haven't got a repy to your question, yet. In the
> menubar script (or the script of the group that serves as menubar),
> you could put a menuPick handler. Have a look at the docs for info
> about the menuPick handler.
>
> The menuPick handler could call scripts in the main stack or send
> commands to other stacks and objects. Depending on what you are
> trying to do, your menuPick handler might look like
>
> on menuPick theMenuItem
> switch theMenuItem
> case "Open..."
> runOpenHandlerInMainStack
> break
> case "Something Else"
> send "runSomeHandlerInSubstack" to the topstack
> break
> end switch
> end menuPick
>
> The second "case" will work fine, if the main stack also has a
> "something" handlers. It would be easiest to put all scripts in the
> main stack, without using the "send" command, but if each of your
> substacks should act differently upon a user's menu selection,
> "send" is a very useful command.
Ok, but what if you want different Menu entries depending on which
stack in the "topstack" ? Also how do you enable/disable menu items
depending on which stack/card/whatever is in control?
Thanks a lot
All the Best
Dave
More information about the use-livecode
mailing list