home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-01-19 | 3.7 KB | 133 lines | [TEXT/MPS ] |
- Program SetMenu;
- {
- This program is an MPW tool which links a specified menu item
- to a hierarchical menu, or removes such a link. Call it from
- the MPW Shell as follows:
-
- SetSubMenu [menuName [itemName [subMenuName]]]
-
- where menuName is the name of the menu to be altered, itemName is the
- name of the menu item, and subMenuName is the name of the submenu
- to link to. If subMenuName is omitted, then any existing link from
- the menu item to a hierarchical menu is removed.
-
- If the second and third arguments are omitted, a list of all submenus
- attached to the specified menu is written to the standard output.
- If the first argument is omitted as well, this list includes submenus
- attached to all menus (both top-level and hierarchical) in the current
- menu list. In both cases, this list takes the form of a sequence of
- SetSubMenu commands which will reconstruct the menu hierarchy.
-
- First working version by LDO 1989 January 4.
- Modified 1989 January 6 to add listing function.
- Modified 1989 January 9 to allow adding submenus to submenus and
- use nicer quoting function.
- Modified 1989 January 19 to check that submenu actually exists
- before listing link, just in case.
- }
-
- Uses
- MemTypes,
- QuickDraw,
- OSIntf,
- ToolIntf,
- IntEnv,
- MenuStuffCommon;
-
- Var
- TheMenu, TheSubMenu : MenuHandle;
- ItemNo : LongInt;
- ExistingCmd : Char;
-
- Procedure ListSubMenus
- (
- ThisMenu : MenuHandle;
- Ignored1, Ignored2 : univ LongInt
- );
- { handler which lists the hierarchical connections for
- the specified menu. }
-
- Var
- ThisItem : Integer;
- ThisItemCmd, ThisItemMark : Char;
- ThisMenuName, ThisItemName, SubMenuName : Str255;
- SubMenu : MenuHandle;
-
- Begin
- ThisMenuName := ThisMenu^^.MenuData;
- For ThisItem := 1 to CountMItems(ThisMenu) do
- Begin
- GetItemCmd(ThisMenu, ThisItem, ThisItemCmd);
- If Ord(ThisItemCmd) = hMenuCmd then
- Begin
- GetItem(ThisMenu, ThisItem, ThisItemName);
- GetItemMark(ThisMenu, ThisItem, ThisItemMark);
- SubMenu := GetMHandle(Ord(ThisItemMark));
- If SubMenu <> Nil then
- Begin
- SubMenuName := SubMenu^^.MenuData;
- Writeln(Output, ArgV^[0]^, ' ', Quote(ThisMenuName), ' ',
- Quote(ThisItemName), ' ', Quote(SubMenuName))
- End {If}
- End {If}
- End {For}
- End {ListSubMenus};
-
- Begin {SetSubMenu}
- InitGraf(@ThePort);
- If ArgC > 1 then
- Begin
- TheMenu := FindMenu(ArgV^[1]^);
- If TheMenu = Nil then
- TheMenu := FindSubMenu(ArgV^[1]^);
- If TheMenu <> Nil then
- If ArgC > 2 then
- Begin
- ItemNo := FindItem(TheMenu, ArgV^[2]^);
- If ItemNo > 0 then
- If ArgC > 3 then
- Begin
- { add link to hierarchical menu }
- TheSubMenu := FindSubMenu(ArgV^[3]^);
- If TheSubMenu <> Nil then
- Begin
- SetItemCmd(TheMenu, ItemNo, Chr(hMenuCmd));
- SetItemMark(TheMenu, ItemNo, Chr(TheSubMenu^^.MenuID))
- End
- else
- Begin
- Writeln(Diagnostic, '### ', ArgV^[0]^, ' - submenu "', ArgV^[3]^, '" not found');
- IEExit(2)
- End
- End
- else
- Begin
- { remove link to hierarchical menu }
- GetItemCmd(TheMenu, ItemNo, ExistingCmd);
- If Ord(ExistingCmd) = hMenuCmd then
- Begin
- SetItemCmd(TheMenu, ItemNo, Chr(0));
- SetItemMark(TheMenu, ItemNo, Chr(0))
- End {If}
- End
- else
- Begin
- Writeln(Diagnostic, '### ', ArgV^[0]^, ' - item "', ArgV^[2]^, '" not found');
- IEExit(2)
- End
- End
- else
- ListSubMenus(TheMenu, Nil, Nil)
- else
- Begin
- Writeln(Diagnostic, '### ', ArgV^[0]^, ' - menu "', ArgV^[1]^, '" not found');
- IEExit(2)
- End
- End
- else
- Begin
- TraverseMenus(@ListSubMenus, Nil);
- TraverseSubMenus(@ListSubMenus, Nil)
- End
- End {SetSubMenu}.
-