Design Advice on Menubar Handling

David Burgun dburgun at dsl.pipex.com
Sat Apr 23 09:13:01 EDT 2005


Hi All,

I was wondering if anyone could offer some advice on the best way to 
acheive the following:

I have a "MainMenu" Stack which the default menu for the app. When 
the App first starts up it and no Stacks are open. The Deisgn I have 
followed is that each Stack is in fact a main stack in it's own right 
and they all link to a "Global" stack dymanically via the "start 
using" command. This allows the Stack to be opened and used in it's 
own right (if it doesn't need a menubar or if it uses it's own 
menubar), or the Stack can choose to use the "MainMenuBar" (and 
dynamically link to the "MainMenu" stack via the "start using" 
command). I am now in the process of adding Menu Button Objects 
dynamically to the "MainMenu" Stack. This allows a flexible 
environment in which to do development work and testing and also to 
provide updates to users (you only need send the new or changed 
stacks, not the while Standalone).

Anyway, this has given rise to some design issues and I was wondering 
if anyone had any suggestion or advice on the subject.

The first problem is that if there are no other open active stacks 
then the "MainMenu" will need a default menubar. This is not a 
problem initially. The problem comes when I call "StackX" in response 
to (say) a "Open" command and then "StackX" wants to use one of the 
Menu Button already being used by "MainMenu", which can be done, but 
how to restore the "MainMenuState" once the Stack is done?  In more 
detail:

MainMenu - has default Menu Items, opens calls StackX
StackX       - Wants to change the File menu for it's own use
                      It can do so, but when the user closes StackX.
MainMenu - Still contains the Menu Items from StackX.

The are a number of ways to get around this:

1.  When "MainMenu" dispatches a Stack it does this:

goto stack myStackFullPathName

  I could add a line that sends a message to the target stack as so:

send "AddMainMenuObject" to stack myStackFullPathName,

a refinement would be to add a custom property to the target stack:

if cpStackRequiresMainMenu of stack myStackFullPathName then
   send "AddMainMenuObject myGroupMainMenu" to stack myStackFullPathName,
end if

But this is error prone if the Handler doesn't exist it will cause an 
error, so it would be better to add a test to see if the handler 
exists. This would slow things down a bit, but since this is only 
done when a new stack is being opened the lag shouldn't be too 
noticable.

AddMainMenuObject handler would then modify the the standard menubar 
as necessary and

2.  Have StackX retreives the Object using the dynamic linkage 
described above to access functions in the stack script that return 
the object and then does essentially the same as 1.

In both these cases the Menubar object is copied into a card of 
StackX where it is the modified and set as the new menubar.

There are other ways which involve making copies of the the MainMenu 
menubar object at stack open and restoring them at stack close, but 
these seem error prone, so it's 1 or 2 unless you have a better way 
of doing it!

In options 1 and 2, there will be a menunar object left in StackX, 
should I delete it at stack close and maybe also stack preOpen ???

If I didn't then I'd have the Stack embedded for use when running the 
stack without mainmenu loaded.

All comments, suggestions and advice on a postcard please!
All the Best
Dave




























More information about the use-livecode mailing list