2 Copyright © 1995-2007, 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 ******************************************************************************/
87 const struct TagItem
*tagState
= taglist
;
88 const struct TagItem
*tag
;
90 struct AppMenuItem
*appMenuItem
;
92 appMenuItem
= AllocVec(sizeof(struct AppMenuItem
), MEMF_CLEAR
);
94 if (appMenuItem
== NULL
)
99 appMenuItem
->ami_ID
= id
;
100 appMenuItem
->ami_UserData
= userdata
;
101 appMenuItem
->ami_Text
= text
;
102 appMenuItem
->ami_MsgPort
= msgport
;
104 while ((tag
= NextTagItem(&tagState
)))
108 case WBAPPMENUA_CommandKeyString
:
110 STRPTR key
= (STRPTR
)tag
->ti_Data
;
112 if (keyUsed(key
, WorkbenchBase
))
114 appMenuItem
->ami_CommandKey
= "";
118 appMenuItem
->ami_CommandKey
= key
;
127 AddTail(&(WorkbenchBase
->wb_AppMenuItems
), (struct Node
*)appMenuItem
);
130 /* NotifyWorkbench(WBNOTIFY_Create, WBNOTIFY_AppMenuItem, WorkbenchBase);
136 } /* AddAppMenuItemA */
139 BOOL
keyUsed(STRPTR key
, struct WorkbenchBase
*WorkbenchBase
)
141 struct AppMenuItem
*ami
;
144 if (strlen(key
) == 0)
151 ForeachNode(&WorkbenchBase
->wb_AppMenuItems
, ami
)
153 if (strlen(ami
->ami_CommandKey
) != 0 &&
154 ami
->ami_CommandKey
[0] == key
[0])