2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 Add a menuitem to Workbench's list of AppMenuItems.
11 #include <exec/types.h>
12 #include <exec/ports.h>
13 #include <utility/tagitem.h>
15 #include "workbench_intern.h"
16 #include <workbench/workbench.h>
17 #include <proto/utility.h>
19 BOOL
keyUsed(STRPTR key
, struct WorkbenchBase
*WorkbenchBase
);
21 /*****************************************************************************
24 #include <proto/workbench.h>
26 AROS_LH5(struct AppMenuItem
*, AddAppMenuItemA
,
28 AROS_LHA(ULONG
, id
, D0
),
29 AROS_LHA(ULONG
, userdata
, D1
),
30 AROS_LHA(APTR
, text
, A0
),
31 AROS_LHA(struct MsgPort
*, msgport
, A1
),
32 AROS_LHA(struct TagItem
*, taglist
, A3
),
35 struct WorkbenchBase
*, WorkbenchBase
, 12, Workbench
)
39 Try to add a menu item to workbench.library's list of AppMenuItems (this
40 will be shown in the 'Tools' menu strip in Workbench).
44 id -- menu item identifier; for your convenience (ignored by
46 userdata -- user specific data (ignored by workbench.library)
47 text -- menu item text; any text consisting merely of '-','_' and
48 '~' characters corresponds to a separator bar instead of
50 msgport -- port to which notification messages regarding the menu
52 taglist -- tags (see below)
56 WBAPPMENUA_CommandKeyString (STRPTR)
57 Command key assigned to this menu item. If the string is empty, it will
58 be ignored as will it if the command key is already in use by another
59 menu item. Only the first character of the string will be used.
64 A pointer to an AppMenuItem which you pass to RemoveAppMenuItem() when
65 you want to remove the menu item. If it was not possible to add the menu
66 item, NULL will be returned.
70 Contrary to AmigaOS, this function will report success even when there
71 is no running workbench application.
83 ******************************************************************************/
86 AROS_LIBBASE_EXT_DECL(struct WorkbenchBase
*, WorkbenchBase
)
88 struct TagItem
*tagState
= taglist
;
91 struct AppMenuItem
*appMenuItem
;
93 appMenuItem
= AllocVec(sizeof(struct AppMenuItem
), MEMF_ANY
| MEMF_CLEAR
);
95 if (appMenuItem
== NULL
)
100 appMenuItem
->ami_ID
= id
;
101 appMenuItem
->ami_UserData
= userdata
;
102 appMenuItem
->ami_Text
= text
;
103 appMenuItem
->ami_MsgPort
= msgport
;
105 while ((tag
= NextTagItem(&tagState
)))
109 case WBAPPMENUA_CommandKeyString
:
111 STRPTR key
= (STRPTR
)tag
->ti_Data
;
113 if (keyUsed(key
, WorkbenchBase
))
115 appMenuItem
->ami_CommandKey
= "";
119 appMenuItem
->ami_CommandKey
= key
;
128 AddTail(&(WorkbenchBase
->wb_AppMenuItems
), (struct Node
*)appMenuItem
);
131 /* NotifyWorkbench(WBNOTIFY_Create, WBNOTIFY_AppMenuItem, WorkbenchBase);
137 } /* AddAppMenuItemA */
140 BOOL
keyUsed(STRPTR key
, struct WorkbenchBase
*WorkbenchBase
)
142 struct AppMenuItem
*ami
;
145 if (strlen(key
) == 0)
152 ForeachNode(&WorkbenchBase
->wb_AppMenuItems
, ami
)
154 if (strlen(ami
->ami_CommandKey
) != 0 &&
155 ami
->ami_CommandKey
[0] == key
[0])