Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / workbench / addappmenuitema.c
blobd1d7e010864e7b6ea3fb9d7755583e9d09376d45
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Add a menuitem to Workbench's list of AppMenuItems.
6 */
9 #include <string.h>
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 /*****************************************************************************
23 NAME */
24 #include <proto/workbench.h>
26 AROS_LH5(struct AppMenuItem *, AddAppMenuItemA,
27 /* SYNOPSIS */
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),
34 /* LOCATION */
35 struct WorkbenchBase *, WorkbenchBase, 12, Workbench)
37 /* FUNCTION
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).
42 INPUTS
44 id -- menu item identifier; for your convenience (ignored by
45 workbench.library)
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
49 a textual item
50 msgport -- port to which notification messages regarding the menu
51 item will be sent
52 taglist -- tags (see below)
54 TAGS
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.
60 [default = NULL]
62 RESULT
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.
68 NOTES
70 Contrary to AmigaOS, this function will report success even when there
71 is no running workbench application.
73 EXAMPLE
75 BUGS
77 SEE ALSO
79 RemoveAppMenuItem()
81 INTERNALS
83 ******************************************************************************/
85 AROS_LIBFUNC_INIT
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)
96 return 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)))
106 switch (tag->ti_Tag)
108 case WBAPPMENUA_CommandKeyString:
110 STRPTR key = (STRPTR)tag->ti_Data;
112 if (keyUsed(key, WorkbenchBase))
114 appMenuItem->ami_CommandKey = "";
116 else
118 appMenuItem->ami_CommandKey = key;
121 break;
126 LockWorkbench();
127 AddTail(&(WorkbenchBase->wb_AppMenuItems), (struct Node *)appMenuItem);
128 UnlockWorkbench();
130 /* NotifyWorkbench(WBNOTIFY_Create, WBNOTIFY_AppMenuItem, WorkbenchBase);
133 return appMenuItem;
135 AROS_LIBFUNC_EXIT
136 } /* AddAppMenuItemA */
139 BOOL keyUsed(STRPTR key, struct WorkbenchBase *WorkbenchBase)
141 struct AppMenuItem *ami;
142 BOOL found = FALSE;
144 if (strlen(key) == 0)
146 return FALSE;
149 LockWorkbench();
151 ForeachNode(&WorkbenchBase->wb_AppMenuItems, ami)
153 if (strlen(ami->ami_CommandKey) != 0 &&
154 ami->ami_CommandKey[0] == key[0])
156 found = TRUE;
157 break;
161 UnlockWorkbench();
163 return found;