Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Menu.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* Menu.c- menu definition
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 2000-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
9d2e6ef9 scottc1998-09-29 22:36:29 +000023#include "WPrefs.h"
24#include <assert.h>
25#include <ctype.h>
26
27#include <X11/keysym.h>
6f0d835b kojima2000-07-15 22:48:31 +000028#include <X11/cursorfont.h>
29
6f0d835b kojima2000-07-15 22:48:31 +000030#include "editmenu.h"
31
6f0d835b kojima2000-07-15 22:48:31 +000032typedef enum {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020033 NoInfo,
34 ExecInfo,
35 CommandInfo,
36 ExternalInfo,
37 PipeInfo,
38 DirectoryInfo,
39 WSMenuInfo,
40 WWindowListInfo,
41 LastInfo
6f0d835b kojima2000-07-15 22:48:31 +000042} InfoType;
43
44#define MAX_SECTION_SIZE 4
9d2e6ef9 scottc1998-09-29 22:36:29 +000045
46typedef struct _Panel {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020047 WMBox *box;
48 char *sectionName;
d3f29988 kojima1999-04-25 01:49:46 +000049
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020050 char *description;
6f0d835b kojima2000-07-15 22:48:31 +000051
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020052 CallbackRec callbacks;
53 WMWidget *parent;
6830b057 dan2004-10-12 21:28:27 +000054
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020055 WMFont *boldFont;
56 WMFont *normalFont;
57 WMColor *white;
58 WMColor *gray;
59 WMColor *black;
6f0d835b kojima2000-07-15 22:48:31 +000060
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020061 WMPixmap *markerPix[LastInfo];
6f0d835b kojima2000-07-15 22:48:31 +000062
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020063 WMPopUpButton *typeP;
6830b057 dan2004-10-12 21:28:27 +000064
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020065 WMWidget *itemPad[3];
66 int currentPad;
9d2e6ef9 scottc1998-09-29 22:36:29 +000067
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020068 WEditMenu *menu;
69 char *menuPath;
9d2e6ef9 scottc1998-09-29 22:36:29 +000070
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020071 WMFrame *optionsF;
9d2e6ef9 scottc1998-09-29 22:36:29 +000072
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020073 WMFrame *commandF;
74 WMTextField *commandT; /* command to run */
75 WMButton *browseB;
76 WMButton *xtermC; /* inside xterm? */
77b8fe05 dan2002-02-20 22:22:40 +000077
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020078 WMFrame *pathF;
79 WMTextField *pathT;
9d2e6ef9 scottc1998-09-29 22:36:29 +000080
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020081 WMFrame *pipeF;
82 WMTextField *pipeT;
83 WMButton *pipeCacheB;
9d2e6ef9 scottc1998-09-29 22:36:29 +000084
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020085 WMFrame *dpathF;
86 WMTextField *dpathT;
6f0d835b kojima2000-07-15 22:48:31 +000087
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020088 WMFrame *dcommandF;
89 WMTextField *dcommandT;
6f0d835b kojima2000-07-15 22:48:31 +000090
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020091 WMButton *dstripB;
6f0d835b kojima2000-07-15 22:48:31 +000092
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020093 WMFrame *shortF;
94 WMTextField *shortT;
95 WMButton *sgrabB;
96 WMButton *sclearB;
6f0d835b kojima2000-07-15 22:48:31 +000097
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020098 WMList *icommandL;
ce7db48e kojima2000-07-16 01:08:13 +000099
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200100 WMFrame *paramF;
101 WMTextField *paramT;
6830b057 dan2004-10-12 21:28:27 +0000102
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200103 WMButton *quickB;
6830b057 dan2004-10-12 21:28:27 +0000104
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200105 Bool dontAsk; /* whether to comfirm submenu remove */
106 Bool dontSave;
6830b057 dan2004-10-12 21:28:27 +0000107
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200108 Bool capturing;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000109
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200110 /* about the currently selected item */
111 WEditMenuItem *currentItem;
112 InfoType currentType;
113 WMWidget *sections[LastInfo][MAX_SECTION_SIZE];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000114} _Panel;
115
6f0d835b kojima2000-07-15 22:48:31 +0000116typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200117 InfoType type;
118 union {
119 struct {
120 int command;
121 char *parameter;
122 char *shortcut;
123 } command;
124 struct {
125 char *command;
126 char *shortcut;
127 } exec;
128 struct {
129 char *path;
130 } external;
131 struct {
132 char *command;
133 unsigned cached:1;
134 } pipe;
135 struct {
136 char *directory;
137 char *command;
138 unsigned stripExt:1;
139 } directory;
140 } param;
6f0d835b kojima2000-07-15 22:48:31 +0000141} ItemData;
142
6f0d835b kojima2000-07-15 22:48:31 +0000143static char *commandNames[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200144 "ARRANGE_ICONS",
145 "HIDE_OTHERS",
146 "SHOW_ALL",
147 "EXIT",
148 "SHUTDOWN",
149 "RESTART",
150 "RESTART",
151 "SAVE_SESSION",
152 "CLEAR_SESSION",
153 "REFRESH",
154 "INFO_PANEL",
155 "LEGAL_PANEL"
6f0d835b kojima2000-07-15 22:48:31 +0000156};
157
6f0d835b kojima2000-07-15 22:48:31 +0000158#define NEW(type) memset(wmalloc(sizeof(type)), 0, sizeof(type))
159
9d2e6ef9 scottc1998-09-29 22:36:29 +0000160#define ICON_FILE "menus"
161
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200162static void showData(_Panel * panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000163
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200164static void updateMenuItem(_Panel * panel, WEditMenuItem * item, WMWidget * changedWidget);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000165
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200166static void menuItemSelected(struct WEditMenuDelegate *delegate, WEditMenu * menu, WEditMenuItem * item);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000167
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200168static void menuItemDeselected(struct WEditMenuDelegate *delegate, WEditMenu * menu, WEditMenuItem * item);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000169
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200170static void menuItemCloned(struct WEditMenuDelegate *delegate, WEditMenu * menu,
171 WEditMenuItem * origItem, WEditMenuItem * newItem);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000172
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200173static void menuItemEdited(struct WEditMenuDelegate *delegate, WEditMenu * menu, WEditMenuItem * item);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000174
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200175static Bool shouldRemoveItem(struct WEditMenuDelegate *delegate, WEditMenu * menu, WEditMenuItem * item);
dd2d71fc kojima1999-05-15 17:38:05 +0000176
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200177static void freeItemData(ItemData * data);
dd2d71fc kojima1999-05-15 17:38:05 +0000178
6f0d835b kojima2000-07-15 22:48:31 +0000179static WEditMenuDelegate menuDelegate = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200180 NULL,
181 menuItemCloned,
182 menuItemEdited,
183 menuItemSelected,
184 menuItemDeselected,
185 shouldRemoveItem
dd2d71fc kojima1999-05-15 17:38:05 +0000186};
9d2e6ef9 scottc1998-09-29 22:36:29 +0000187
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200188static void dataChanged(void *self, WMNotification * notif)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000189{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200190 _Panel *panel = (_Panel *) self;
191 WEditMenuItem *item = panel->currentItem;
192 WMWidget *w = (WMWidget *) WMGetNotificationObject(notif);
6830b057 dan2004-10-12 21:28:27 +0000193
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200194 updateMenuItem(panel, item, w);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000195}
196
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200197static void buttonClicked(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000198{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200199 _Panel *panel = (_Panel *) data;
200 WEditMenuItem *item = panel->currentItem;
6830b057 dan2004-10-12 21:28:27 +0000201
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200202 updateMenuItem(panel, item, w);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000203}
204
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200205static void icommandLClicked(WMWidget * w, void *data)
ce7db48e kojima2000-07-16 01:08:13 +0000206{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200207 _Panel *panel = (_Panel *) data;
208 int cmd;
209
210 cmd = WMGetListSelectedItemRow(w);
211 if (cmd == 3 || cmd == 4) {
212 WMMapWidget(panel->quickB);
213 } else {
214 WMUnmapWidget(panel->quickB);
215 }
216 if (cmd == 6) {
217 WMMapWidget(panel->paramF);
218 } else {
219 WMUnmapWidget(panel->paramF);
220 }
ce7db48e kojima2000-07-16 01:08:13 +0000221}
222
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200223static void browseForFile(WMWidget * self, void *clientData)
77b8fe05 dan2002-02-20 22:22:40 +0000224{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200225 _Panel *panel = (_Panel *) clientData;
226 WMFilePanel *filePanel;
227 char *text, *oldprog, *newprog;
228
229 filePanel = WMGetOpenPanel(WMWidgetScreen(self));
230 text = WMGetTextFieldText(panel->commandT);
231
232 oldprog = wtrimspace(text);
233 wfree(text);
234
235 if (oldprog[0] == 0 || oldprog[0] != '/') {
236 wfree(oldprog);
237 oldprog = wstrdup("/");
238 } else {
239 char *ptr = oldprog;
240 while (*ptr && !isspace(*ptr))
241 ptr++;
242 *ptr = 0;
243 }
244
245 WMSetFilePanelCanChooseDirectories(filePanel, False);
246
247 if (WMRunModalFilePanelForDirectory(filePanel, panel->parent, oldprog, _("Select Program"), NULL) == True) {
248 newprog = WMGetFilePanelFileName(filePanel);
249 WMSetTextFieldText(panel->commandT, newprog);
250 updateMenuItem(panel, panel->currentItem, panel->commandT);
251 wfree(newprog);
252 }
253
254 wfree(oldprog);
77b8fe05 dan2002-02-20 22:22:40 +0000255}
1a7c397d kojima2000-07-16 04:05:49 +0000256
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200257static char *captureShortcut(Display * dpy, _Panel * panel)
1a7c397d kojima2000-07-16 04:05:49 +0000258{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200259 XEvent ev;
260 KeySym ksym;
261 char buffer[64];
262 char *key = NULL;
263
264 while (panel->capturing) {
265 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
266 WMNextEvent(dpy, &ev);
267 if (ev.type == KeyPress && ev.xkey.keycode != 0) {
268 ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0);
269 if (!IsModifierKey(ksym)) {
270 key = XKeysymToString(ksym);
271 panel->capturing = 0;
272 break;
273 }
274 }
275 WMHandleEvent(&ev);
276 }
277
278 if (!key)
279 return NULL;
280
281 buffer[0] = 0;
282
283 if (ev.xkey.state & ControlMask) {
284 strcat(buffer, "Control+");
285 }
286 if (ev.xkey.state & ShiftMask) {
287 strcat(buffer, "Shift+");
288 }
289 if (ev.xkey.state & Mod1Mask) {
290 strcat(buffer, "Mod1+");
291 }
292 if (ev.xkey.state & Mod2Mask) {
293 strcat(buffer, "Mod2+");
294 }
295 if (ev.xkey.state & Mod3Mask) {
296 strcat(buffer, "Mod3+");
297 }
298 if (ev.xkey.state & Mod4Mask) {
299 strcat(buffer, "Mod4+");
300 }
301 if (ev.xkey.state & Mod5Mask) {
302 strcat(buffer, "Mod5+");
303 }
304 strcat(buffer, key);
305
306 return wstrdup(buffer);
1a7c397d kojima2000-07-16 04:05:49 +0000307}
308
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200309static void sgrabClicked(WMWidget * w, void *data)
1a7c397d kojima2000-07-16 04:05:49 +0000310{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200311 _Panel *panel = (_Panel *) data;
312 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
313 char *shortcut;
314
315 if (w == panel->sclearB) {
316 WMSetTextFieldText(panel->shortT, "");
317 updateMenuItem(panel, panel->currentItem, panel->shortT);
318 return;
319 }
320
321 if (!panel->capturing) {
322 panel->capturing = 1;
323 WMSetButtonText(w, _("Cancel"));
324 XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime);
325 shortcut = captureShortcut(dpy, panel);
326 if (shortcut) {
327 WMSetTextFieldText(panel->shortT, shortcut);
328 updateMenuItem(panel, panel->currentItem, panel->shortT);
329 wfree(shortcut);
330 }
331 }
332 panel->capturing = 0;
333 WMSetButtonText(w, _("Capture"));
334 XUngrabKeyboard(dpy, CurrentTime);
1a7c397d kojima2000-07-16 04:05:49 +0000335}
336
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200337static void changedItemPad(WMWidget * w, void *data)
1a7c397d kojima2000-07-16 04:05:49 +0000338{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200339 _Panel *panel = (_Panel *) data;
340 int padn = WMGetPopUpButtonSelectedItem(w);
6830b057 dan2004-10-12 21:28:27 +0000341
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200342 WMUnmapWidget(panel->itemPad[panel->currentPad]);
343 WMMapWidget(panel->itemPad[padn]);
6830b057 dan2004-10-12 21:28:27 +0000344
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200345 panel->currentPad = padn;
1a7c397d kojima2000-07-16 04:05:49 +0000346}
347
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200348static WEditMenu *putNewSubmenu(WEditMenu * menu, char *title)
1a7c397d kojima2000-07-16 04:05:49 +0000349{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200350 WEditMenu *tmp;
351 WEditMenuItem *item;
1a7c397d kojima2000-07-16 04:05:49 +0000352
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200353 item = WAddMenuItemWithTitle(menu, title);
1a7c397d kojima2000-07-16 04:05:49 +0000354
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200355 tmp = WCreateEditMenu(WMWidgetScreen(menu), title);
356 WSetEditMenuAcceptsDrop(tmp, True);
357 WSetEditMenuDelegate(tmp, &menuDelegate);
358 WSetEditMenuSubmenu(menu, item, tmp);
1a7c397d kojima2000-07-16 04:05:49 +0000359
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200360 return tmp;
1a7c397d kojima2000-07-16 04:05:49 +0000361}
362
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200363static ItemData *putNewItem(_Panel * panel, WEditMenu * menu, int type, char *title)
1a7c397d kojima2000-07-16 04:05:49 +0000364{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200365 WEditMenuItem *item;
366 ItemData *data;
1a7c397d kojima2000-07-16 04:05:49 +0000367
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200368 item = WAddMenuItemWithTitle(menu, title);
1a7c397d kojima2000-07-16 04:05:49 +0000369
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200370 data = NEW(ItemData);
371 data->type = type;
372 WSetEditMenuItemData(item, data, (WMCallback *) freeItemData);
373 WSetEditMenuItemImage(item, panel->markerPix[type]);
6830b057 dan2004-10-12 21:28:27 +0000374
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200375 return data;
1a7c397d kojima2000-07-16 04:05:49 +0000376}
377
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200378static WEditMenu *makeFactoryMenu(WMWidget * parent, int width)
1a7c397d kojima2000-07-16 04:05:49 +0000379{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200380 WEditMenu *pad;
381
382 pad = WCreateEditMenuPad(parent);
383 WMResizeWidget(pad, width, 10);
384 WSetEditMenuMinSize(pad, wmksize(width, 0));
385 WSetEditMenuMaxSize(pad, wmksize(width, 0));
386 WSetEditMenuSelectable(pad, False);
387 WSetEditMenuEditable(pad, False);
388 WSetEditMenuIsFactory(pad, True);
389 WSetEditMenuDelegate(pad, &menuDelegate);
390
391 return pad;
1a7c397d kojima2000-07-16 04:05:49 +0000392}
393
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200394static void createPanel(_Panel * p)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000395{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200396 _Panel *panel = (_Panel *) p;
397 WMScreen *scr = WMWidgetScreen(panel->parent);
398 WMColor *black = WMBlackColor(scr);
399 WMColor *white = WMWhiteColor(scr);
400 WMColor *gray = WMGrayColor(scr);
401 WMFont *bold = WMBoldSystemFontOfSize(scr, 12);
402 WMFont *font = WMSystemFontOfSize(scr, 12);
403 WMLabel *label;
404 int width;
6830b057 dan2004-10-12 21:28:27 +0000405
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200406 menuDelegate.data = panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000407
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200408 panel->boldFont = bold;
409 panel->normalFont = font;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000410
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200411 panel->black = black;
412 panel->white = white;
413 panel->gray = gray;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000414
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200415 {
416 Pixmap pix;
417 Display *dpy = WMScreenDisplay(scr);
418 GC gc;
419 WMPixmap *pixm;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000420
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200421 pixm = WMCreatePixmap(scr, 7, 7, WMScreenDepth(scr), True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000422
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200423 pix = WMGetPixmapXID(pixm);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000424
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200425 XDrawLine(dpy, pix, WMColorGC(black), 0, 3, 6, 3);
426 XDrawLine(dpy, pix, WMColorGC(black), 3, 0, 3, 6);
427 /*
428 XDrawLine(dpy, pix, WMColorGC(black), 1, 0, 3, 3);
429 XDrawLine(dpy, pix, WMColorGC(black), 1, 6, 3, 3);
430 XDrawLine(dpy, pix, WMColorGC(black), 0, 0, 0, 6);
431 */
6f0d835b kojima2000-07-15 22:48:31 +0000432
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200433 pix = WMGetPixmapMaskXID(pixm);
6f0d835b kojima2000-07-15 22:48:31 +0000434
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200435 gc = XCreateGC(dpy, pix, 0, NULL);
6f0d835b kojima2000-07-15 22:48:31 +0000436
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200437 XSetForeground(dpy, gc, 0);
438 XFillRectangle(dpy, pix, gc, 0, 0, 7, 7);
6f0d835b kojima2000-07-15 22:48:31 +0000439
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200440 XSetForeground(dpy, gc, 1);
441 XDrawLine(dpy, pix, gc, 0, 3, 6, 3);
442 XDrawLine(dpy, pix, gc, 3, 0, 3, 6);
1a7c397d kojima2000-07-16 04:05:49 +0000443
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200444 panel->markerPix[ExternalInfo] = pixm;
445 panel->markerPix[PipeInfo] = pixm;
446 panel->markerPix[DirectoryInfo] = pixm;
447 panel->markerPix[WSMenuInfo] = pixm;
448 panel->markerPix[WWindowListInfo] = pixm;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000449
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200450 XFreeGC(dpy, gc);
451 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000452
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200453 panel->box = WMCreateBox(panel->parent);
454 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000455
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200456 panel->typeP = WMCreatePopUpButton(panel->box);
457 WMResizeWidget(panel->typeP, 150, 20);
458 WMMoveWidget(panel->typeP, 10, 10);
6830b057 dan2004-10-12 21:28:27 +0000459
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200460 WMAddPopUpButtonItem(panel->typeP, _("New Items"));
461 WMAddPopUpButtonItem(panel->typeP, _("Sample Commands"));
462 WMAddPopUpButtonItem(panel->typeP, _("Sample Submenus"));
1a7c397d kojima2000-07-16 04:05:49 +0000463
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200464 WMSetPopUpButtonAction(panel->typeP, changedItemPad, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000465
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200466 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
6830b057 dan2004-10-12 21:28:27 +0000467
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200468 {
469 WEditMenu *pad;
470 WEditMenu *smenu;
471 ItemData *data;
6830b057 dan2004-10-12 21:28:27 +0000472
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200473 pad = makeFactoryMenu(panel->box, 150);
474 WMMoveWidget(pad, 10, 40);
6830b057 dan2004-10-12 21:28:27 +0000475
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200476 data = putNewItem(panel, pad, ExecInfo, _("Run Program"));
477 data = putNewItem(panel, pad, CommandInfo, _("Internal Command"));
478 smenu = putNewSubmenu(pad, _("Submenu"));
479 data = putNewItem(panel, pad, ExternalInfo, _("External Submenu"));
480 data = putNewItem(panel, pad, PipeInfo, _("Generated Submenu"));
481 data = putNewItem(panel, pad, DirectoryInfo, _("Directory Contents"));
482 data = putNewItem(panel, pad, WSMenuInfo, _("Workspace Menu"));
483 data = putNewItem(panel, pad, WWindowListInfo, _("Window List Menu"));
6f0d835b kojima2000-07-15 22:48:31 +0000484
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200485 panel->itemPad[0] = pad;
486 }
6830b057 dan2004-10-12 21:28:27 +0000487
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200488 {
489 WEditMenu *pad;
490 ItemData *data;
491 WMScrollView *sview;
1a7c397d kojima2000-07-16 04:05:49 +0000492
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200493 sview = WMCreateScrollView(panel->box);
494 WMResizeWidget(sview, 150, 180);
495 WMMoveWidget(sview, 10, 40);
496 WMSetScrollViewHasVerticalScroller(sview, True);
1a7c397d kojima2000-07-16 04:05:49 +0000497
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200498 pad = makeFactoryMenu(panel->box, 130);
1a7c397d kojima2000-07-16 04:05:49 +0000499
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200500 WMSetScrollViewContentView(sview, WMWidgetView(pad));
6f0d835b kojima2000-07-15 22:48:31 +0000501
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200502 data = putNewItem(panel, pad, ExecInfo, _("XTerm"));
503 data->param.exec.command = "xterm -sb -sl 2000 -bg black -fg white";
1a7c397d kojima2000-07-16 04:05:49 +0000504
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200505 data = putNewItem(panel, pad, ExecInfo, _("rxvt"));
506 data->param.exec.command = "rxvt";
1a7c397d kojima2000-07-16 04:05:49 +0000507
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200508 data = putNewItem(panel, pad, ExecInfo, _("ETerm"));
509 data->param.exec.command = "eterm";
1a7c397d kojima2000-07-16 04:05:49 +0000510
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200511 data = putNewItem(panel, pad, ExecInfo, _("Run..."));
512 data->param.exec.command = _("%a(Run,Type command to run)");
1a7c397d kojima2000-07-16 04:05:49 +0000513
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200514 data = putNewItem(panel, pad, ExecInfo, _("Netscape"));
515 data->param.exec.command = "netscape";
1a7c397d kojima2000-07-16 04:05:49 +0000516
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200517 data = putNewItem(panel, pad, ExecInfo, _("gimp"));
518 data->param.exec.command = "gimp";
1a7c397d kojima2000-07-16 04:05:49 +0000519
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200520 data = putNewItem(panel, pad, ExecInfo, _("epic"));
521 data->param.exec.command = "xterm -e epic";
1a7c397d kojima2000-07-16 04:05:49 +0000522
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200523 data = putNewItem(panel, pad, ExecInfo, _("ee"));
524 data->param.exec.command = "ee";
1a7c397d kojima2000-07-16 04:05:49 +0000525
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200526 data = putNewItem(panel, pad, ExecInfo, _("xv"));
527 data->param.exec.command = "xv";
1a7c397d kojima2000-07-16 04:05:49 +0000528
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200529 data = putNewItem(panel, pad, ExecInfo, _("Acrobat Reader"));
530 data->param.exec.command = "acroread || /usr/local/Acrobat4/bin/acroread";
1a7c397d kojima2000-07-16 04:05:49 +0000531
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200532 data = putNewItem(panel, pad, ExecInfo, _("ghostview"));
533 data->param.exec.command = "gv";
1a7c397d kojima2000-07-16 04:05:49 +0000534
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200535 data = putNewItem(panel, pad, CommandInfo, _("Exit Window Maker"));
536 data->param.command.command = 3;
1a7c397d kojima2000-07-16 04:05:49 +0000537
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200538 WMMapWidget(pad);
1a7c397d kojima2000-07-16 04:05:49 +0000539
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200540 panel->itemPad[1] = sview;
541 }
6830b057 dan2004-10-12 21:28:27 +0000542
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200543 {
544 WEditMenu *pad, *smenu;
545 ItemData *data;
546 WMScrollView *sview;
6830b057 dan2004-10-12 21:28:27 +0000547
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200548 sview = WMCreateScrollView(panel->box);
549 WMResizeWidget(sview, 150, 180);
550 WMMoveWidget(sview, 10, 40);
551 WMSetScrollViewHasVerticalScroller(sview, True);
6830b057 dan2004-10-12 21:28:27 +0000552
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200553 pad = makeFactoryMenu(panel->box, 130);
1a7c397d kojima2000-07-16 04:05:49 +0000554
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200555 WMSetScrollViewContentView(sview, WMWidgetView(pad));
1a7c397d kojima2000-07-16 04:05:49 +0000556
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200557 data = putNewItem(panel, pad, ExternalInfo, _("Debian Menu"));
558 data->param.pipe.command = "/etc/X11/WindowMaker/menu.hook";
1a7c397d kojima2000-07-16 04:05:49 +0000559
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200560 data = putNewItem(panel, pad, PipeInfo, _("RedHat Menu"));
561 data->param.pipe.command = "wmconfig --output wmaker";
1a7c397d kojima2000-07-16 04:05:49 +0000562
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200563 data = putNewItem(panel, pad, PipeInfo, _("Menu Conectiva"));
564 data->param.pipe.command = "wmconfig --output wmaker";
1a7c397d kojima2000-07-16 04:05:49 +0000565
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200566 data = putNewItem(panel, pad, DirectoryInfo, _("Themes"));
567 data->param.directory.command = "setstyle";
568 data->param.directory.directory =
569 "/usr/share/WindowMaker/Themes /usr/local/share/WindowMaker/Themes $HOME/GNUstep/Library/WindowMaker/Themes";
570 data->param.directory.stripExt = 1;
1a7c397d kojima2000-07-16 04:05:49 +0000571
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200572 data = putNewItem(panel, pad, DirectoryInfo, _("Bg Images (scale)"));
573 data->param.directory.command = "wmsetbg -u -s";
574 data->param.directory.directory =
575 "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
576 data->param.directory.stripExt = 1;
1a7c397d kojima2000-07-16 04:05:49 +0000577
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200578 data = putNewItem(panel, pad, DirectoryInfo, _("Bg Images (tile)"));
579 data->param.directory.command = "wmsetbg -u -t";
580 data->param.directory.directory =
581 "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
582 data->param.directory.stripExt = 1;
1a7c397d kojima2000-07-16 04:05:49 +0000583
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200584 smenu = putNewSubmenu(pad, _("Assorted XTerms"));
1a7c397d kojima2000-07-16 04:05:49 +0000585
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200586 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Yellow on Blue"));
587 data->param.exec.command = "xterm -sb -sl 2000 -bg midnightblue -fg yellow";
1a7c397d kojima2000-07-16 04:05:49 +0000588
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200589 data = putNewItem(panel, smenu, ExecInfo, _("XTerm White on Black"));
590 data->param.exec.command = "xterm -sb -sl 2000 -bg black -fg white";
1a7c397d kojima2000-07-16 04:05:49 +0000591
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200592 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Black on White"));
593 data->param.exec.command = "xterm -sb -sl 2000 -bg white -fg black";
1a7c397d kojima2000-07-16 04:05:49 +0000594
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200595 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Black on Beige"));
596 data->param.exec.command = "xterm -sb -sl 2000 -bg '#bbbb99' -fg black";
1a7c397d kojima2000-07-16 04:05:49 +0000597
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200598 data = putNewItem(panel, smenu, ExecInfo, _("XTerm White on Green"));
599 data->param.exec.command = "xterm -sb -sl 2000 -bg '#228822' -fg white";
1a7c397d kojima2000-07-16 04:05:49 +0000600
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200601 data = putNewItem(panel, smenu, ExecInfo, _("XTerm White on Olive"));
602 data->param.exec.command = "xterm -sb -sl 2000 -bg '#335533' -fg white";
1a7c397d kojima2000-07-16 04:05:49 +0000603
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200604 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Blue on Blue"));
605 data->param.exec.command = "xterm -sb -sl 2000 -bg '#112244' -fg '#88aabb'";
1a7c397d kojima2000-07-16 04:05:49 +0000606
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200607 data = putNewItem(panel, smenu, ExecInfo, _("XTerm BIG FONTS"));
608 data->param.exec.command = "xterm -sb -sl 2000 -bg black -fg white -fn 10x20";
6830b057 dan2004-10-12 21:28:27 +0000609
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200610 WMMapWidget(pad);
6830b057 dan2004-10-12 21:28:27 +0000611
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200612 panel->itemPad[2] = sview;
613 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000614
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200615 width = FRAME_WIDTH - 20 - 150 - 10 - 2;
1a7c397d kojima2000-07-16 04:05:49 +0000616
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200617 panel->optionsF = WMCreateFrame(panel->box);
618 WMResizeWidget(panel->optionsF, width, FRAME_HEIGHT - 15);
619 WMMoveWidget(panel->optionsF, 10 + 150 + 10, 5);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000620
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200621 width -= 20;
6830b057 dan2004-10-12 21:28:27 +0000622
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200623 /* command */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000624
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200625 panel->commandF = WMCreateFrame(panel->optionsF);
626 WMResizeWidget(panel->commandF, width, 50);
627 WMMoveWidget(panel->commandF, 10, 20);
628 WMSetFrameTitle(panel->commandF, _("Program to Run"));
629 WMSetFrameTitlePosition(panel->commandF, WTPAtTop);
6830b057 dan2004-10-12 21:28:27 +0000630
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200631 panel->commandT = WMCreateTextField(panel->commandF);
632 WMResizeWidget(panel->commandT, width - 95, 20);
633 WMMoveWidget(panel->commandT, 10, 20);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000634
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200635 panel->browseB = WMCreateCommandButton(panel->commandF);
636 WMResizeWidget(panel->browseB, 70, 24);
637 WMMoveWidget(panel->browseB, width - 80, 18);
638 WMSetButtonText(panel->browseB, _("Browse"));
639 WMSetButtonAction(panel->browseB, browseForFile, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000640
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200641 WMAddNotificationObserver(dataChanged, panel, WMTextDidChangeNotification, panel->commandT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000642
6f0d835b kojima2000-07-15 22:48:31 +0000643#if 0
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200644 panel->xtermC = WMCreateSwitchButton(panel->commandF);
645 WMResizeWidget(panel->xtermC, width - 20, 20);
646 WMMoveWidget(panel->xtermC, 10, 50);
647 WMSetButtonText(panel->xtermC, _("Run the program inside a Xterm"));
6f0d835b kojima2000-07-15 22:48:31 +0000648#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200649 WMMapSubwidgets(panel->commandF);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000650
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200651 /* path */
7f9f8894 kojima1999-03-15 23:41:22 +0000652
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200653 panel->pathF = WMCreateFrame(panel->optionsF);
654 WMResizeWidget(panel->pathF, width, 150);
655 WMMoveWidget(panel->pathF, 10, 40);
656 WMSetFrameTitle(panel->pathF, _("Path for Menu"));
7f9f8894 kojima1999-03-15 23:41:22 +0000657
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200658 panel->pathT = WMCreateTextField(panel->pathF);
659 WMResizeWidget(panel->pathT, width - 20, 20);
660 WMMoveWidget(panel->pathT, 10, 20);
6830b057 dan2004-10-12 21:28:27 +0000661
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200662 WMAddNotificationObserver(dataChanged, panel, WMTextDidChangeNotification, panel->pathT);
7f9f8894 kojima1999-03-15 23:41:22 +0000663
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200664 label = WMCreateLabel(panel->pathF);
665 WMResizeWidget(label, width - 20, 80);
666 WMMoveWidget(label, 10, 50);
667 WMSetLabelText(label, _("Enter the path for a file containing a menu\n"
668 "or a list of directories with the programs you\n"
669 "want to have listed in the menu. Ex:\n"
670 "~/GNUstep/Library/WindowMaker/menu\n" "or\n" "/usr/X11R6/bin ~/xbin"));
7f9f8894 kojima1999-03-15 23:41:22 +0000671
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200672 WMMapSubwidgets(panel->pathF);
7f9f8894 kojima1999-03-15 23:41:22 +0000673
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200674 /* pipe */
7f9f8894 kojima1999-03-15 23:41:22 +0000675
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200676 panel->pipeF = WMCreateFrame(panel->optionsF);
677 WMResizeWidget(panel->pipeF, width, 155);
678 WMMoveWidget(panel->pipeF, 10, 30);
679 WMSetFrameTitle(panel->pipeF, _("Command"));
7f9f8894 kojima1999-03-15 23:41:22 +0000680
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200681 panel->pipeT = WMCreateTextField(panel->pipeF);
682 WMResizeWidget(panel->pipeT, width - 20, 20);
683 WMMoveWidget(panel->pipeT, 10, 20);
7f9f8894 kojima1999-03-15 23:41:22 +0000684
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200685 WMAddNotificationObserver(dataChanged, panel, WMTextDidChangeNotification, panel->pipeT);
7f9f8894 kojima1999-03-15 23:41:22 +0000686
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200687 label = WMCreateLabel(panel->pipeF);
688 WMResizeWidget(label, width - 20, 40);
689 WMMoveWidget(label, 10, 50);
690 WMSetLabelText(label, _("Enter a command that outputs a menu\n" "definition to stdout when invoked."));
7f9f8894 kojima1999-03-15 23:41:22 +0000691
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200692 panel->pipeCacheB = WMCreateSwitchButton(panel->pipeF);
693 WMResizeWidget(panel->pipeCacheB, width - 20, 40);
694 WMMoveWidget(panel->pipeCacheB, 10, 110);
695 WMSetButtonText(panel->pipeCacheB, _("Cache menu contents after opening for\n" "the first time"));
6830b057 dan2004-10-12 21:28:27 +0000696
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200697 WMMapSubwidgets(panel->pipeF);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000698
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200699 /* directory menu */
5db8b566 kojima2002-02-15 21:34:46 +0000700
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200701 panel->dcommandF = WMCreateFrame(panel->optionsF);
702 WMResizeWidget(panel->dcommandF, width, 90);
703 WMMoveWidget(panel->dcommandF, 10, 25);
704 WMSetFrameTitle(panel->dcommandF, _("Command to Open Files"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000705
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200706 panel->dcommandT = WMCreateTextField(panel->dcommandF);
707 WMResizeWidget(panel->dcommandT, width - 20, 20);
708 WMMoveWidget(panel->dcommandT, 10, 20);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000709
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200710 WMAddNotificationObserver(dataChanged, panel, WMTextDidChangeNotification, panel->dcommandT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000711
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200712 label = WMCreateLabel(panel->dcommandF);
713 WMResizeWidget(label, width - 20, 45);
714 WMMoveWidget(label, 10, 40);
715 WMSetLabelText(label, _("Enter the command you want to use to open the\n"
716 "files in the directories listed below."));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000717
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200718 WMMapSubwidgets(panel->dcommandF);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000719
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200720 panel->dpathF = WMCreateFrame(panel->optionsF);
721 WMResizeWidget(panel->dpathF, width, 80);
722 WMMoveWidget(panel->dpathF, 10, 125);
723 WMSetFrameTitle(panel->dpathF, _("Directories with Files"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000724
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200725 panel->dpathT = WMCreateTextField(panel->dpathF);
726 WMResizeWidget(panel->dpathT, width - 20, 20);
727 WMMoveWidget(panel->dpathT, 10, 20);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000728
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200729 WMAddNotificationObserver(dataChanged, panel, WMTextDidChangeNotification, panel->dpathT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000730
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200731 panel->dstripB = WMCreateSwitchButton(panel->dpathF);
732 WMResizeWidget(panel->dstripB, width - 20, 20);
733 WMMoveWidget(panel->dstripB, 10, 50);
734 WMSetButtonText(panel->dstripB, _("Strip extensions from file names"));
da36a4ee kojima1999-05-16 00:30:07 +0000735
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200736 WMSetButtonAction(panel->dstripB, buttonClicked, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000737
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200738 WMMapSubwidgets(panel->dpathF);
449a5fde kojima2000-04-02 00:04:06 +0000739
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200740 /* shortcut */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000741
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200742 panel->shortF = WMCreateFrame(panel->optionsF);
743 WMResizeWidget(panel->shortF, width, 50);
744 WMMoveWidget(panel->shortF, 10, 160);
745 WMSetFrameTitle(panel->shortF, _("Keyboard Shortcut"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000746
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200747 panel->shortT = WMCreateTextField(panel->shortF);
748 WMResizeWidget(panel->shortT, width - 20 - 150, 20);
749 WMMoveWidget(panel->shortT, 10, 20);
6f0d835b kojima2000-07-15 22:48:31 +0000750
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200751 WMAddNotificationObserver(dataChanged, panel, WMTextDidChangeNotification, panel->shortT);
6830b057 dan2004-10-12 21:28:27 +0000752
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200753 panel->sgrabB = WMCreateCommandButton(panel->shortF);
754 WMResizeWidget(panel->sgrabB, 70, 24);
755 WMMoveWidget(panel->sgrabB, width - 80, 18);
756 WMSetButtonText(panel->sgrabB, _("Capture"));
757 WMSetButtonAction(panel->sgrabB, sgrabClicked, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000758
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200759 panel->sclearB = WMCreateCommandButton(panel->shortF);
760 WMResizeWidget(panel->sclearB, 70, 24);
761 WMMoveWidget(panel->sclearB, width - 155, 18);
762 WMSetButtonText(panel->sclearB, _("Clear"));
763 WMSetButtonAction(panel->sclearB, sgrabClicked, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000764
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200765 WMMapSubwidgets(panel->shortF);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000766
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200767 /* internal command */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000768
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200769 panel->icommandL = WMCreateList(panel->optionsF);
770 WMResizeWidget(panel->icommandL, width, 80);
771 WMMoveWidget(panel->icommandL, 10, 20);
0261c326 dan1999-01-06 15:22:33 +0000772
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200773 WMSetListAction(panel->icommandL, icommandLClicked, panel);
0261c326 dan1999-01-06 15:22:33 +0000774
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200775 WMAddNotificationObserver(dataChanged, panel, WMListSelectionDidChangeNotification, panel->icommandL);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000776
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200777 WMInsertListItem(panel->icommandL, 0, _("Arrange Icons"));
778 WMInsertListItem(panel->icommandL, 1, _("Hide All Windows Except For The Focused One"));
779 WMInsertListItem(panel->icommandL, 2, _("Show All Windows"));
0261c326 dan1999-01-06 15:22:33 +0000780
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200781 WMInsertListItem(panel->icommandL, 3, _("Exit Window Maker"));
782 WMInsertListItem(panel->icommandL, 4, _("Exit X Session"));
783 WMInsertListItem(panel->icommandL, 5, _("Restart Window Maker"));
784 WMInsertListItem(panel->icommandL, 6, _("Start Another Window Manager : ("));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000785
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200786 WMInsertListItem(panel->icommandL, 7, _("Save Current Session"));
787 WMInsertListItem(panel->icommandL, 8, _("Clear Saved Session"));
788 WMInsertListItem(panel->icommandL, 9, _("Refresh Screen"));
789 WMInsertListItem(panel->icommandL, 10, _("Open Info Panel"));
790 WMInsertListItem(panel->icommandL, 11, _("Open Copyright Panel"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000791
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200792 panel->paramF = WMCreateFrame(panel->optionsF);
793 WMResizeWidget(panel->paramF, width, 50);
794 WMMoveWidget(panel->paramF, 10, 105);
795 WMSetFrameTitle(panel->paramF, _("Window Manager to Start"));
6830b057 dan2004-10-12 21:28:27 +0000796
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200797 panel->paramT = WMCreateTextField(panel->paramF);
798 WMResizeWidget(panel->paramT, width - 20, 20);
799 WMMoveWidget(panel->paramT, 10, 20);
7f9f8894 kojima1999-03-15 23:41:22 +0000800
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200801 WMAddNotificationObserver(dataChanged, panel, WMTextDidChangeNotification, panel->paramT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000802
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200803 WMMapSubwidgets(panel->paramF);
e7495baf dan1999-02-17 11:06:40 +0000804
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200805 panel->quickB = WMCreateSwitchButton(panel->optionsF);
806 WMResizeWidget(panel->quickB, width, 20);
807 WMMoveWidget(panel->quickB, 10, 120);
808 WMSetButtonText(panel->quickB, _("Do not confirm action."));
809 WMSetButtonAction(panel->quickB, buttonClicked, panel);
e7495baf dan1999-02-17 11:06:40 +0000810
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200811 label = WMCreateLabel(panel->optionsF);
812 WMResizeWidget(label, width + 5, FRAME_HEIGHT - 50);
813 WMMoveWidget(label, 7, 20);
814 WMSetLabelText(label,
815 _("Instructions:\n\n"
816 " - drag items from the left to the menu to add new items\n"
817 " - drag items out of the menu to remove items\n"
818 " - drag items in menu to change their position\n"
819 " - drag items with Control pressed to copy them\n"
820 " - double click in a menu item to change the label\n"
821 " - click on a menu item to change related information"));
822 WMMapWidget(label);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000823
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200824 WMRealizeWidget(panel->box);
825 WMMapSubwidgets(panel->box);
826 WMMapWidget(panel->box);
1a7c397d kojima2000-07-16 04:05:49 +0000827
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200828 {
829 int i;
830 for (i = 0; i < 3; i++)
831 WMUnmapWidget(panel->itemPad[i]);
832 }
833 changedItemPad(panel->typeP, panel);
1a7c397d kojima2000-07-16 04:05:49 +0000834
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200835 panel->sections[NoInfo][0] = label;
1a7c397d kojima2000-07-16 04:05:49 +0000836
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200837 panel->sections[ExecInfo][0] = panel->commandF;
838 panel->sections[ExecInfo][1] = panel->shortF;
1a7c397d kojima2000-07-16 04:05:49 +0000839
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200840 panel->sections[CommandInfo][0] = panel->icommandL;
841 panel->sections[CommandInfo][1] = panel->shortF;
6f0d835b kojima2000-07-15 22:48:31 +0000842
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200843 panel->sections[ExternalInfo][0] = panel->pathF;
1a7c397d kojima2000-07-16 04:05:49 +0000844
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200845 panel->sections[PipeInfo][0] = panel->pipeF;
b0d72a3d dan2003-07-01 23:00:25 +0000846
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200847 panel->sections[DirectoryInfo][0] = panel->dpathF;
848 panel->sections[DirectoryInfo][1] = panel->dcommandF;
b0d72a3d dan2003-07-01 23:00:25 +0000849
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200850 panel->currentType = NoInfo;
1a7c397d kojima2000-07-16 04:05:49 +0000851
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200852 showData(panel);
6830b057 dan2004-10-12 21:28:27 +0000853
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200854 {
855 WMPoint pos;
1a7c397d kojima2000-07-16 04:05:49 +0000856
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200857 pos = WMGetViewScreenPosition(WMWidgetView(panel->box));
1a7c397d kojima2000-07-16 04:05:49 +0000858
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200859 if (pos.x < 200) {
860 pos.x += FRAME_WIDTH + 20;
861 } else {
862 pos.x = 10;
863 }
1a7c397d kojima2000-07-16 04:05:49 +0000864
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200865 pos.y = WMAX(pos.y - 100, 0);
6f0d835b kojima2000-07-15 22:48:31 +0000866
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200867 if (panel->menu)
868 WEditMenuShowAt(panel->menu, pos.x, pos.y);
869 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000870}
871
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200872static void freeItemData(ItemData * data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000873{
497e34b6 dan2000-10-31 14:57:22 +0000874#define CFREE(d) if (d) wfree(d)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000875
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200876 /* TODO */
877 switch (data->type) {
878 case CommandInfo:
879 CFREE(data->param.command.parameter);
880 CFREE(data->param.command.shortcut);
881 break;
6830b057 dan2004-10-12 21:28:27 +0000882
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200883 case ExecInfo:
884 CFREE(data->param.exec.command);
885 CFREE(data->param.exec.shortcut);
886 break;
6830b057 dan2004-10-12 21:28:27 +0000887
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200888 case PipeInfo:
889 CFREE(data->param.pipe.command);
890 break;
6830b057 dan2004-10-12 21:28:27 +0000891
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200892 case ExternalInfo:
893 CFREE(data->param.external.path);
894 break;
6830b057 dan2004-10-12 21:28:27 +0000895
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200896 case DirectoryInfo:
897 CFREE(data->param.directory.command);
898 CFREE(data->param.directory.directory);
899 break;
6830b057 dan2004-10-12 21:28:27 +0000900
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200901 default:
902 break;
903 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000904
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200905 wfree(data);
6f0d835b kojima2000-07-15 22:48:31 +0000906#undef CFREE
907}
908
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200909static ItemData *parseCommand(WMPropList * item)
6f0d835b kojima2000-07-15 22:48:31 +0000910{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200911 ItemData *data = NEW(ItemData);
912 WMPropList *p;
913 char *command = NULL;
914 char *parameter = NULL;
915 char *shortcut = NULL;
916 int i = 1;
917
918 p = WMGetFromPLArray(item, i++);
919 command = WMGetFromPLString(p);
920 if (strcmp(command, "SHORTCUT") == 0) {
921 p = WMGetFromPLArray(item, i++);
922 shortcut = WMGetFromPLString(p);
923 p = WMGetFromPLArray(item, i++);
924 command = WMGetFromPLString(p);
925 }
926 p = WMGetFromPLArray(item, i++);
927 if (p)
928 parameter = WMGetFromPLString(p);
929
930 if (strcmp(command, "EXEC") == 0 || strcmp(command, "SHEXEC") == 0) {
931
932 data->type = ExecInfo;
933
934 data->param.exec.command = wstrdup(parameter);
935 if (shortcut)
936 data->param.exec.shortcut = wstrdup(shortcut);
937
938 } else if (strcmp(command, "OPEN_MENU") == 0) {
939 char *p;
940 /*
941 * dir menu, menu file
942 * dir WITH
943 * |pipe
944 */
945 p = parameter;
946 while (isspace(*p) && *p)
947 p++;
948 if (*p == '|') {
949 if (*(p + 1) == '|') {
950 p++;
951 data->param.pipe.cached = 0;
952 } else {
953 data->param.pipe.cached = 1;
954 }
955 data->type = PipeInfo;
956 data->param.pipe.command = wtrimspace(p + 1);
957 } else {
958 char *s;
959
960 p = wstrdup(p);
961
962 s = strstr(p, "WITH");
963 if (s) {
964 char **tokens;
965 char **ctokens;
966 int tokn;
967 int i, j;
968
969 data->type = DirectoryInfo;
970
971 *s = '\0';
972 s += 5;
973 while (*s && isspace(*s))
974 s++;
975 data->param.directory.command = wstrdup(s);
976
977 wtokensplit(p, &tokens, &tokn);
978 wfree(p);
979
980 ctokens = wmalloc(sizeof(char *) * tokn);
981
982 for (i = 0, j = 0; i < tokn; i++) {
983 if (strcmp(tokens[i], "-noext") == 0) {
984 wfree(tokens[i]);
985 data->param.directory.stripExt = 1;
986 } else {
987 ctokens[j++] = tokens[i];
988 }
989 }
990 data->param.directory.directory = wtokenjoin(ctokens, j);
991 wfree(ctokens);
992
993 wtokenfree(tokens, tokn);
994 } else {
995 data->type = ExternalInfo;
996 data->param.external.path = p;
997 }
998 }
999 } else if (strcmp(command, "WORKSPACE_MENU") == 0) {
1000 data->type = WSMenuInfo;
1001 } else if (strcmp(command, "WINDOWS_MENU") == 0) {
1002 data->type = WWindowListInfo;
1003 } else {
1004 int cmd;
1005
1006 if (strcmp(command, "ARRANGE_ICONS") == 0) {
1007 cmd = 0;
1008 } else if (strcmp(command, "HIDE_OTHERS") == 0) {
1009 cmd = 1;
1010 } else if (strcmp(command, "SHOW_ALL") == 0) {
1011 cmd = 2;
1012 } else if (strcmp(command, "EXIT") == 0) {
1013 cmd = 3;
1014 } else if (strcmp(command, "SHUTDOWN") == 0) {
1015 cmd = 4;
1016 } else if (strcmp(command, "RESTART") == 0) {
1017 if (parameter) {
1018 cmd = 6;
1019 } else {
1020 cmd = 5;
1021 }
1022 } else if (strcmp(command, "SAVE_SESSION") == 0) {
1023 cmd = 7;
1024 } else if (strcmp(command, "CLEAR_SESSION") == 0) {
1025 cmd = 8;
1026 } else if (strcmp(command, "REFRESH") == 0) {
1027 cmd = 9;
1028 } else if (strcmp(command, "INFO_PANEL") == 0) {
1029 cmd = 10;
1030 } else if (strcmp(command, "LEGAL_PANEL") == 0) {
1031 cmd = 11;
1032 } else {
1033 wwarning(_("unknown command '%s' in menu"), command);
1034 goto error;
1035 }
1036
1037 data->type = CommandInfo;
1038
1039 data->param.command.command = cmd;
1040 if (shortcut)
1041 data->param.command.shortcut = wstrdup(shortcut);
1042 if (parameter)
1043 data->param.command.parameter = wstrdup(parameter);
1044 }
1045
1046 return data;
1047
1048 error:
1049 wfree(data);
1050
1051 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001052}
1053
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001054static void updateFrameTitle(_Panel * panel, char *title, InfoType type)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001055{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001056 if (type != NoInfo) {
1057 char *tmp;
1058
1059 switch (type) {
1060 case ExecInfo:
1061 tmp = wstrconcat(title, _(": Execute Program"));
1062 break;
1063
1064 case CommandInfo:
1065 tmp = wstrconcat(title, _(": Perform Internal Command"));
1066 break;
1067
1068 case ExternalInfo:
1069 tmp = wstrconcat(title, _(": Open a Submenu"));
1070 break;
1071
1072 case PipeInfo:
1073 tmp = wstrconcat(title, _(": Program Generated Submenu"));
1074 break;
1075
1076 case DirectoryInfo:
1077 tmp = wstrconcat(title, _(": Directory Contents Menu"));
1078 break;
1079
1080 case WSMenuInfo:
1081 tmp = wstrconcat(title, _(": Open Workspaces Submenu"));
1082 break;
1083
1084 case WWindowListInfo:
1085 tmp = wstrconcat(title, _(": Open Window List Submenu"));
1086 break;
1087
1088 default:
1089 tmp = NULL;
1090 break;
1091 }
1092 WMSetFrameTitle(panel->optionsF, tmp);
1093 wfree(tmp);
1094 } else {
1095 WMSetFrameTitle(panel->optionsF, NULL);
1096 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001097}
1098
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001099static void changeInfoType(_Panel * panel, char *title, InfoType type)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001100{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001101 WMWidget **w;
6f0d835b kojima2000-07-15 22:48:31 +00001102
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001103 if (panel->currentType != type) {
6760c398 kojima2000-09-21 14:22:59 +00001104
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001105 w = panel->sections[panel->currentType];
6760c398 kojima2000-09-21 14:22:59 +00001106
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001107 while (*w) {
1108 WMUnmapWidget(*w);
1109 w++;
1110 }
1111 WMUnmapWidget(panel->paramF);
1112 WMUnmapWidget(panel->quickB);
6760c398 kojima2000-09-21 14:22:59 +00001113
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001114 w = panel->sections[type];
6830b057 dan2004-10-12 21:28:27 +00001115
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001116 while (*w) {
1117 WMMapWidget(*w);
1118 w++;
1119 }
1120 }
6f0d835b kojima2000-07-15 22:48:31 +00001121
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001122 updateFrameTitle(panel, title, type);
6f0d835b kojima2000-07-15 22:48:31 +00001123
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001124 panel->currentType = type;
6f0d835b kojima2000-07-15 22:48:31 +00001125}
1126
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001127static void updateMenuItem(_Panel * panel, WEditMenuItem * item, WMWidget * changedWidget)
6f0d835b kojima2000-07-15 22:48:31 +00001128{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001129 ItemData *data = WGetEditMenuItemData(item);
6830b057 dan2004-10-12 21:28:27 +00001130
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001131 assert(data != NULL);
6f0d835b kojima2000-07-15 22:48:31 +00001132
497e34b6 dan2000-10-31 14:57:22 +00001133#define REPLACE(v, d) if (v) wfree(v); v = d
6f0d835b kojima2000-07-15 22:48:31 +00001134
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001135 switch (data->type) {
1136 case ExecInfo:
1137 if (changedWidget == panel->commandT) {
1138 REPLACE(data->param.exec.command, WMGetTextFieldText(panel->commandT));
1139 }
1140 if (changedWidget == panel->shortT) {
1141 REPLACE(data->param.exec.shortcut, WMGetTextFieldText(panel->shortT));
1142 }
1143 break;
1144
1145 case CommandInfo:
1146 if (changedWidget == panel->icommandL) {
1147 data->param.command.command = WMGetListSelectedItemRow(panel->icommandL);
1148 }
1149 switch (data->param.command.command) {
1150 case 3:
1151 case 4:
1152 if (changedWidget == panel->quickB) {
1153 REPLACE(data->param.command.parameter, WMGetButtonSelected(panel->quickB)
1154 ? wstrdup("QUICK") : NULL);
1155 }
1156 break;
1157
1158 case 6:
1159 if (changedWidget == panel->paramT) {
1160 REPLACE(data->param.command.parameter, WMGetTextFieldText(panel->paramT));
1161 }
1162 break;
1163 }
1164 if (changedWidget == panel->shortT) {
1165 REPLACE(data->param.command.shortcut, WMGetTextFieldText(panel->shortT));
1166 }
1167
1168 break;
1169
1170 case PipeInfo:
1171 if (changedWidget == panel->pipeT) {
1172 REPLACE(data->param.pipe.command, WMGetTextFieldText(panel->pipeT));
1173 }
1174 if (changedWidget == panel->pipeCacheB) {
1175 data->param.pipe.cached = WMGetButtonSelected(panel->pipeCacheB);
1176 }
1177 break;
1178
1179 case ExternalInfo:
1180 if (changedWidget == panel->pathT) {
1181 REPLACE(data->param.external.path, WMGetTextFieldText(panel->pathT));
1182 }
1183 break;
1184
1185 case DirectoryInfo:
1186 if (changedWidget == panel->dpathT) {
1187 REPLACE(data->param.directory.directory, WMGetTextFieldText(panel->dpathT));
1188 }
1189 if (changedWidget == panel->dcommandT) {
1190 REPLACE(data->param.directory.command, WMGetTextFieldText(panel->dcommandT));
1191 }
1192 if (changedWidget == panel->dstripB) {
1193 data->param.directory.stripExt = WMGetButtonSelected(panel->dstripB);
1194 }
1195 break;
1196
1197 default:
1198 assert(0);
1199 break;
1200 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001201
6f0d835b kojima2000-07-15 22:48:31 +00001202#undef REPLACE
1203}
9d2e6ef9 scottc1998-09-29 22:36:29 +00001204
6f0d835b kojima2000-07-15 22:48:31 +00001205static void
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001206menuItemCloned(WEditMenuDelegate * delegate, WEditMenu * menu, WEditMenuItem * origItem, WEditMenuItem * newItem)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001207{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001208 ItemData *data = WGetEditMenuItemData(origItem);
1209 ItemData *newData;
6830b057 dan2004-10-12 21:28:27 +00001210
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001211 if (!data)
1212 return;
6830b057 dan2004-10-12 21:28:27 +00001213
6f0d835b kojima2000-07-15 22:48:31 +00001214#define DUP(s) (s) ? wstrdup(s) : NULL
9d2e6ef9 scottc1998-09-29 22:36:29 +00001215
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001216 newData = NEW(ItemData);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001217
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001218 newData->type = data->type;
6830b057 dan2004-10-12 21:28:27 +00001219
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001220 switch (data->type) {
1221 case ExecInfo:
1222 newData->param.exec.command = DUP(data->param.exec.command);
1223 newData->param.exec.shortcut = DUP(data->param.exec.shortcut);
1224 break;
6830b057 dan2004-10-12 21:28:27 +00001225
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001226 case CommandInfo:
1227 newData->param.command.command = data->param.command.command;
1228 newData->param.command.parameter = DUP(data->param.command.parameter);
1229 newData->param.command.shortcut = DUP(data->param.command.shortcut);
1230 break;
6830b057 dan2004-10-12 21:28:27 +00001231
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001232 case PipeInfo:
1233 newData->param.pipe.command = DUP(data->param.pipe.command);
1234 newData->param.pipe.cached = data->param.pipe.cached;
1235 break;
6830b057 dan2004-10-12 21:28:27 +00001236
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001237 case ExternalInfo:
1238 newData->param.external.path = DUP(data->param.external.path);
1239 break;
6830b057 dan2004-10-12 21:28:27 +00001240
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001241 case DirectoryInfo:
1242 newData->param.directory.directory = DUP(data->param.directory.directory);
1243 newData->param.directory.command = DUP(data->param.directory.command);
1244 newData->param.directory.stripExt = data->param.directory.stripExt;
1245 break;
6830b057 dan2004-10-12 21:28:27 +00001246
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001247 default:
1248 break;
1249 }
7f9f8894 kojima1999-03-15 23:41:22 +00001250
6f0d835b kojima2000-07-15 22:48:31 +00001251#undef DUP
9d2e6ef9 scottc1998-09-29 22:36:29 +00001252
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001253 WSetEditMenuItemData(newItem, newData, (WMCallback *) freeItemData);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001254}
1255
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001256static void menuItemEdited(struct WEditMenuDelegate *delegate, WEditMenu * menu, WEditMenuItem * item)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001257{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001258 _Panel *panel = (_Panel *) delegate->data;
1259 WEditMenu *submenu;
41ff1274 dan2000-09-23 03:49:58 +00001260
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001261 updateFrameTitle(panel, WGetEditMenuItemTitle(item), panel->currentType);
6ec98009 kojima2000-07-16 06:29:12 +00001262
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001263 submenu = WGetEditMenuSubmenu(menu, item);
1264 if (submenu) {
1265 WSetEditMenuTitle(submenu, WGetEditMenuItemTitle(item));
1266 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001267}
1268
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001269static Bool shouldRemoveItem(struct WEditMenuDelegate *delegate, WEditMenu * menu, WEditMenuItem * item)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001270{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001271 _Panel *panel = (_Panel *) delegate->data;
1272
1273 if (panel->dontAsk)
1274 return True;
1275
1276 if (WGetEditMenuSubmenu(menu, item)) {
1277 int res;
1278
1279 res = WMRunAlertPanel(WMWidgetScreen(menu), NULL,
1280 _("Remove Submenu"),
1281 _("Removing this item will destroy all items inside\n"
1282 "the submenu. Do you really want to do that?"),
1283 _("Yes"), _("No"), _("Yes, don't ask again."));
1284 switch (res) {
1285 case WAPRDefault:
1286 return True;
1287 case WAPRAlternate:
1288 return False;
1289 case WAPROther:
1290 panel->dontAsk = True;
1291 return True;
1292 }
1293 }
1294 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001295}
1296
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001297static void menuItemDeselected(WEditMenuDelegate * delegate, WEditMenu * menu, WEditMenuItem * item)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001298{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001299 _Panel *panel = (_Panel *) delegate->data;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001300
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001301 changeInfoType(panel, NULL, NoInfo);
6f0d835b kojima2000-07-15 22:48:31 +00001302}
9d2e6ef9 scottc1998-09-29 22:36:29 +00001303
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001304static void menuItemSelected(WEditMenuDelegate * delegate, WEditMenu * menu, WEditMenuItem * item)
6f0d835b kojima2000-07-15 22:48:31 +00001305{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001306 ItemData *data = WGetEditMenuItemData(item);
1307 _Panel *panel = (_Panel *) delegate->data;
1308
1309 panel->currentItem = item;
1310
1311 if (data) {
1312 changeInfoType(panel, WGetEditMenuItemTitle(item), data->type);
1313
1314 switch (data->type) {
1315 case NoInfo:
1316 break;
1317
1318 case ExecInfo:
1319 WMSetTextFieldText(panel->commandT, data->param.exec.command);
1320 WMSetTextFieldText(panel->shortT, data->param.exec.shortcut);
1321 break;
1322
1323 case CommandInfo:
1324 WMSelectListItem(panel->icommandL, data->param.command.command);
1325 WMSetListPosition(panel->icommandL, data->param.command.command - 2);
1326 WMSetTextFieldText(panel->shortT, data->param.command.shortcut);
1327
1328 switch (data->param.command.command) {
1329 case 3:
1330 case 4:
1331 WMSetButtonSelected(panel->quickB, data->param.command.parameter != NULL);
1332 break;
1333 case 6:
1334 WMSetTextFieldText(panel->paramT, data->param.command.parameter);
1335 break;
1336 }
1337
1338 icommandLClicked(panel->icommandL, panel);
1339 break;
1340
1341 case PipeInfo:
1342 WMSetTextFieldText(panel->pipeT, data->param.pipe.command);
1343 WMSetButtonSelected(panel->pipeCacheB, data->param.pipe.cached);
1344 break;
1345
1346 case ExternalInfo:
1347 WMSetTextFieldText(panel->pathT, data->param.external.path);
1348 break;
1349
1350 case DirectoryInfo:
1351 WMSetTextFieldText(panel->dpathT, data->param.directory.directory);
1352 WMSetTextFieldText(panel->dcommandT, data->param.directory.command);
1353 WMSetButtonSelected(panel->dstripB, data->param.directory.stripExt);
1354 break;
1355
1356 case WSMenuInfo:
1357 break;
1358
1359 default:
1360 break;
1361 }
1362 }
6f0d835b kojima2000-07-15 22:48:31 +00001363}
9d2e6ef9 scottc1998-09-29 22:36:29 +00001364
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001365static WEditMenu *buildSubmenu(_Panel * panel, WMPropList * pl)
6f0d835b kojima2000-07-15 22:48:31 +00001366{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001367 WMScreen *scr = WMWidgetScreen(panel->parent);
1368 WEditMenu *menu;
1369 WEditMenuItem *item;
1370 char *title;
1371 WMPropList *tp, *bp;
1372 int i;
6830b057 dan2004-10-12 21:28:27 +00001373
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001374 tp = WMGetFromPLArray(pl, 0);
1375 title = WMGetFromPLString(tp);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001376
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001377 menu = WCreateEditMenu(scr, title);
6830b057 dan2004-10-12 21:28:27 +00001378
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001379 for (i = 1; i < WMGetPropListItemCount(pl); i++) {
1380 WMPropList *pi;
6830b057 dan2004-10-12 21:28:27 +00001381
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001382 pi = WMGetFromPLArray(pl, i);
6830b057 dan2004-10-12 21:28:27 +00001383
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001384 tp = WMGetFromPLArray(pi, 0);
1385 bp = WMGetFromPLArray(pi, 1);
6830b057 dan2004-10-12 21:28:27 +00001386
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001387 title = WMGetFromPLString(tp);
6830b057 dan2004-10-12 21:28:27 +00001388
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001389 if (!bp || WMIsPLArray(bp)) { /* it's a submenu */
1390 WEditMenu *submenu;
6830b057 dan2004-10-12 21:28:27 +00001391
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001392 submenu = buildSubmenu(panel, pi);
6830b057 dan2004-10-12 21:28:27 +00001393
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001394 item = WAddMenuItemWithTitle(menu, title);
6830b057 dan2004-10-12 21:28:27 +00001395
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001396 WSetEditMenuSubmenu(menu, item, submenu);
1397 } else {
1398 ItemData *data;
6830b057 dan2004-10-12 21:28:27 +00001399
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001400 item = WAddMenuItemWithTitle(menu, title);
6830b057 dan2004-10-12 21:28:27 +00001401
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001402 data = parseCommand(pi);
6830b057 dan2004-10-12 21:28:27 +00001403
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001404 if (panel->markerPix[data->type])
1405 WSetEditMenuItemImage(item, panel->markerPix[data->type]);
1406 WSetEditMenuItemData(item, data, (WMCallback *) freeItemData);
1407 }
1408 }
9d2e6ef9 scottc1998-09-29 22:36:29 +00001409
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001410 WSetEditMenuAcceptsDrop(menu, True);
1411 WSetEditMenuDelegate(menu, &menuDelegate);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001412
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001413 WMRealizeWidget(menu);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001414
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001415 return menu;
6f0d835b kojima2000-07-15 22:48:31 +00001416}
9d2e6ef9 scottc1998-09-29 22:36:29 +00001417
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001418static void buildMenuFromPL(_Panel * panel, WMPropList * pl)
6f0d835b kojima2000-07-15 22:48:31 +00001419{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001420 panel->menu = buildSubmenu(panel, pl);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001421}
1422
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001423static WMPropList *getDefaultMenu(_Panel * panel)
416e3a82 dan1999-01-25 19:06:50 +00001424{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001425 WMPropList *menu;
1426 char *menuPath, *gspath;
416e3a82 dan1999-01-25 19:06:50 +00001427
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001428 gspath = wusergnusteppath();
416e3a82 dan1999-01-25 19:06:50 +00001429
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001430 menuPath = wmalloc(strlen(gspath) + 128);
1431 sprintf(menuPath, "%s/Library/WindowMaker/plmenu", gspath);
416e3a82 dan1999-01-25 19:06:50 +00001432
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001433 menu = WMReadPropListFromFile(menuPath);
6830b057 dan2004-10-12 21:28:27 +00001434
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001435 if (!menu) {
1436 char *buffer, *msg;
d8862b0b dan2004-10-26 03:40:44 +00001437
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001438 msg = _("Could not open default menu from '%s'");
1439 buffer = wmalloc(strlen(msg) + strlen(menuPath) + 10);
1440 sprintf(buffer, msg, menuPath);
1441 WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent,
1442 _("Error"), buffer, _("OK"), NULL, NULL);
1443 wfree(buffer);
1444 }
416e3a82 dan1999-01-25 19:06:50 +00001445
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001446 wfree(menuPath);
416e3a82 dan1999-01-25 19:06:50 +00001447
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001448 return menu;
416e3a82 dan1999-01-25 19:06:50 +00001449}
1450
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001451static void showData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001452{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001453 char *gspath;
1454 char *menuPath;
1455 WMPropList *pmenu;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001456
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001457 gspath = wusergnusteppath();
7f9f8894 kojima1999-03-15 23:41:22 +00001458
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001459 menuPath = wmalloc(strlen(gspath) + 32);
1460 strcpy(menuPath, gspath);
1461 strcat(menuPath, "/Defaults/WMRootMenu");
7f9f8894 kojima1999-03-15 23:41:22 +00001462
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001463 pmenu = WMReadPropListFromFile(menuPath);
6830b057 dan2004-10-12 21:28:27 +00001464
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001465 if (!pmenu || !WMIsPLArray(pmenu)) {
1466 int res;
6830b057 dan2004-10-12 21:28:27 +00001467
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001468 res = WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent,
1469 _("Warning"),
1470 _("The menu file format currently in use is not supported\n"
1471 "by this tool. Do you want to discard the current menu\n"
1472 "to use this tool?"),
1473 _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL);
6830b057 dan2004-10-12 21:28:27 +00001474
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001475 if (res == WAPRDefault) {
1476 pmenu = getDefaultMenu(panel);
6830b057 dan2004-10-12 21:28:27 +00001477
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001478 if (!pmenu) {
1479 pmenu = WMCreatePLArray(WMCreatePLString("Applications"), NULL);
1480 }
1481 } else {
1482 panel->dontSave = True;
1483 return;
1484 }
1485 }
6f0d835b kojima2000-07-15 22:48:31 +00001486
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001487 panel->menuPath = menuPath;
6f0d835b kojima2000-07-15 22:48:31 +00001488
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001489 buildMenuFromPL(panel, pmenu);
6f0d835b kojima2000-07-15 22:48:31 +00001490
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001491 WMReleasePropList(pmenu);
6f0d835b kojima2000-07-15 22:48:31 +00001492}
416e3a82 dan1999-01-25 19:06:50 +00001493
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001494static Bool notblank(char *s)
6f0d835b kojima2000-07-15 22:48:31 +00001495{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001496 if (s) {
1497 while (*s++) {
1498 if (!isspace(*s))
1499 return True;
1500 }
1501 }
1502 return False;
6f0d835b kojima2000-07-15 22:48:31 +00001503}
1504
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001505static WMPropList *processData(char *title, ItemData * data)
6f0d835b kojima2000-07-15 22:48:31 +00001506{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001507 WMPropList *item;
1508 char *s1;
1509 static WMPropList *pscut = NULL;
1510 static WMPropList *pomenu = NULL;
1511 int i;
1512
1513 if (!pscut) {
1514 pscut = WMCreatePLString("SHORTCUT");
1515 pomenu = WMCreatePLString("OPEN_MENU");
1516 }
1517
1518 item = WMCreatePLArray(WMCreatePLString(title), NULL);
1519
1520 switch (data->type) {
1521 case ExecInfo:
1522 if (data->param.exec.command == NULL)
1523 return NULL;
6f0d835b kojima2000-07-15 22:48:31 +00001524#if 1
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001525 if (strpbrk(data->param.exec.command, "&$*|><?`=;")) {
1526 s1 = "SHEXEC";
1527 } else {
1528 s1 = "EXEC";
1529 }
6830b057 dan2004-10-12 21:28:27 +00001530#else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001531 s1 = "SHEXEC";
6f0d835b kojima2000-07-15 22:48:31 +00001532#endif
1533
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001534 if (notblank(data->param.exec.shortcut)) {
1535 WMAddToPLArray(item, pscut);
1536 WMAddToPLArray(item, WMCreatePLString(data->param.exec.shortcut));
1537 }
1538
1539 WMAddToPLArray(item, WMCreatePLString(s1));
1540 WMAddToPLArray(item, WMCreatePLString(data->param.exec.command));
1541 break;
1542
1543 case CommandInfo:
1544 if (notblank(data->param.command.shortcut)) {
1545 WMAddToPLArray(item, pscut);
1546 WMAddToPLArray(item, WMCreatePLString(data->param.command.shortcut));
1547 }
1548
1549 i = data->param.command.command;
1550
1551 WMAddToPLArray(item, WMCreatePLString(commandNames[i]));
1552
1553 switch (i) {
1554 case 3:
1555 case 4:
1556 if (data->param.command.parameter) {
1557 WMAddToPLArray(item, WMCreatePLString(data->param.command.parameter));
1558 }
1559 break;
1560
1561 case 6: /* restart */
1562 if (data->param.command.parameter) {
1563 WMAddToPLArray(item, WMCreatePLString(data->param.command.parameter));
1564 }
1565 break;
1566 }
1567
1568 break;
1569
1570 case PipeInfo:
1571 if (!data->param.pipe.command)
1572 return NULL;
1573 WMAddToPLArray(item, pomenu);
1574 if (data->param.pipe.cached)
1575 s1 = wstrconcat("| ", data->param.pipe.command);
1576 else
1577 s1 = wstrconcat("|| ", data->param.pipe.command);
1578 WMAddToPLArray(item, WMCreatePLString(s1));
1579 wfree(s1);
1580 break;
1581
1582 case ExternalInfo:
1583 if (!data->param.external.path)
1584 return NULL;
1585 WMAddToPLArray(item, pomenu);
1586 WMAddToPLArray(item, WMCreatePLString(data->param.external.path));
1587 break;
1588
1589 case DirectoryInfo:
1590 if (!data->param.directory.directory || !data->param.directory.command)
1591 return NULL;
1592 {
1593 int l;
1594 char *tmp;
1595
1596 l = strlen(data->param.directory.directory);
1597 l += strlen(data->param.directory.command);
1598 l += 32;
1599
1600 WMAddToPLArray(item, pomenu);
1601
1602 tmp = wmalloc(l);
1603 sprintf(tmp, "%s%s WITH %s",
1604 data->param.directory.stripExt ? "-noext " : "",
1605 data->param.directory.directory, data->param.directory.command);
1606
1607 WMAddToPLArray(item, WMCreatePLString(tmp));
1608 wfree(tmp);
1609 }
1610 break;
1611
1612 case WSMenuInfo:
1613 WMAddToPLArray(item, WMCreatePLString("WORKSPACE_MENU"));
1614 break;
1615
1616 case WWindowListInfo:
1617 WMAddToPLArray(item, WMCreatePLString("WINDOWS_MENU"));
1618 break;
1619
1620 default:
1621 assert(0);
1622 break;
1623 }
1624
1625 return item;
6f0d835b kojima2000-07-15 22:48:31 +00001626}
1627
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001628static WMPropList *processSubmenu(WEditMenu * menu)
6f0d835b kojima2000-07-15 22:48:31 +00001629{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001630 WEditMenuItem *item;
1631 WMPropList *pmenu;
1632 WMPropList *pl;
1633 char *s;
1634 int i;
6830b057 dan2004-10-12 21:28:27 +00001635
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001636 s = WGetEditMenuTitle(menu);
1637 pl = WMCreatePLString(s);
6f0d835b kojima2000-07-15 22:48:31 +00001638
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001639 pmenu = WMCreatePLArray(pl, NULL);
6f0d835b kojima2000-07-15 22:48:31 +00001640
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001641 i = 0;
1642 while ((item = WGetEditMenuItem(menu, i++))) {
1643 WEditMenu *submenu;
6830b057 dan2004-10-12 21:28:27 +00001644
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001645 s = WGetEditMenuItemTitle(item);
6f0d835b kojima2000-07-15 22:48:31 +00001646
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001647 submenu = WGetEditMenuSubmenu(menu, item);
1648 if (submenu) {
1649 pl = processSubmenu(submenu);
1650 } else {
1651 pl = processData(s, WGetEditMenuItemData(item));
1652 }
6f0d835b kojima2000-07-15 22:48:31 +00001653
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001654 if (!pl)
1655 continue;
0e2ac9dd kojima2001-08-13 21:00:57 +00001656
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001657 WMAddToPLArray(pmenu, pl);
1658 }
6830b057 dan2004-10-12 21:28:27 +00001659
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001660 return pmenu;
6f0d835b kojima2000-07-15 22:48:31 +00001661}
6830b057 dan2004-10-12 21:28:27 +00001662
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001663static WMPropList *buildPLFromMenu(_Panel * panel)
6f0d835b kojima2000-07-15 22:48:31 +00001664{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001665 WMPropList *menu;
6830b057 dan2004-10-12 21:28:27 +00001666
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001667 menu = processSubmenu(panel->menu);
6830b057 dan2004-10-12 21:28:27 +00001668
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001669 return menu;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001670}
1671
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001672static void storeData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001673{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001674 WMPropList *menu;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001675
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001676 if (panel->dontSave)
1677 return;
33cc542e dan2001-10-04 03:07:34 +00001678
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001679 menu = buildPLFromMenu(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001680
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001681 WMWritePropListToFile(menu, panel->menuPath, True);
6f0d835b kojima2000-07-15 22:48:31 +00001682
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001683 WMReleasePropList(menu);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001684}
1685
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001686static void showMenus(_Panel * panel)
6760c398 kojima2000-09-21 14:22:59 +00001687{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001688 if (panel->menu)
1689 WEditMenuUnhide(panel->menu);
6760c398 kojima2000-09-21 14:22:59 +00001690}
1691
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001692static void hideMenus(_Panel * panel)
6760c398 kojima2000-09-21 14:22:59 +00001693{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001694 if (panel->menu)
1695 WEditMenuHide(panel->menu);
6760c398 kojima2000-09-21 14:22:59 +00001696}
1697
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001698Panel *InitMenu(WMScreen * scr, WMWidget * parent)
9d2e6ef9 scottc1998-09-29 22:36:29 +00001699{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001700 _Panel *panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001701
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001702 panel = wmalloc(sizeof(_Panel));
1703 memset(panel, 0, sizeof(_Panel));
9d2e6ef9 scottc1998-09-29 22:36:29 +00001704
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001705 panel->sectionName = _("Applications Menu Definition");
d3f29988 kojima1999-04-25 01:49:46 +00001706
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001707 panel->description = _("Edit the menu for launching applications.");
416e3a82 dan1999-01-25 19:06:50 +00001708
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001709 panel->parent = parent;
6760c398 kojima2000-09-21 14:22:59 +00001710
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001711 panel->callbacks.createWidgets = createPanel;
1712 panel->callbacks.updateDomain = storeData;
1713 panel->callbacks.showPanel = showMenus;
1714 panel->callbacks.hidePanel = hideMenus;
6830b057 dan2004-10-12 21:28:27 +00001715
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001716 AddSection(panel, ICON_FILE);
9d2e6ef9 scottc1998-09-29 22:36:29 +00001717
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001718 return panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +00001719}