added WMAddTabViewItemWithVie()
[wmaker-crm.git] / WPrefs.app / Menu.c
blob842a6fcaa220d438d1a40965975706cd6fca0bc9
1 /* Menu.c- menu definition
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 2000 Alfredo K. Kojima
6 *
7 * 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.
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.
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
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "WPrefs.h"
25 #include <assert.h>
26 #include <ctype.h>
28 #include <X11/keysym.h>
29 #include <X11/cursorfont.h>
32 #include "editmenu.h"
35 typedef enum {
36 NoInfo,
37 ExecInfo,
38 CommandInfo,
39 ExternalInfo,
40 PipeInfo,
41 DirectoryInfo,
42 WSMenuInfo,
43 LastInfo
44 } InfoType;
46 #define MAX_SECTION_SIZE 4
48 typedef struct _Panel {
49 WMFrame *frame;
50 char *sectionName;
52 char *description;
54 CallbackRec callbacks;
55 WMWindow *win;
58 WMFont *boldFont;
59 WMFont *normalFont;
60 WMColor *white;
61 WMColor *gray;
62 WMColor *black;
64 WMPixmap *markerPix[LastInfo];
66 WMPopUpButton *typeP;
68 WMWidget *itemPad[3];
69 int currentPad;
71 WEditMenu *menu;
72 char *menuPath;
74 WMFrame *optionsF;
76 WMFrame *commandF;
77 WMTextField *commandT; /* command to run */
78 WMButton *xtermC; /* inside xterm? */
80 WMFrame *pathF;
81 WMTextField *pathT;
83 WMFrame *pipeF;
84 WMTextField *pipeT;
86 WMFrame *dpathF;
87 WMTextField *dpathT;
89 WMFrame *dcommandF;
90 WMTextField *dcommandT;
92 WMButton *dstripB;
94 WMFrame *shortF;
95 WMTextField *shortT;
96 WMButton *sgrabB;
97 WMButton *sclearB;
99 WMList *icommandL;
101 WMFrame *paramF;
102 WMTextField *paramT;
104 WMButton *quickB;
106 Bool dontAsk; /* whether to comfirm submenu remove */
107 Bool dontSave;
109 Bool capturing;
112 /* about the currently selected item */
113 WEditMenuItem *currentItem;
114 InfoType currentType;
115 WMWidget *sections[LastInfo][MAX_SECTION_SIZE];
116 } _Panel;
119 typedef struct {
120 InfoType type;
121 union {
122 struct {
123 int command;
124 char *parameter;
125 char *shortcut;
126 } command;
127 struct {
128 char *command;
129 char *shortcut;
130 } exec;
131 struct {
132 char *path;
133 } external;
134 struct {
135 char *command;
136 } pipe;
137 struct {
138 char *directory;
139 char *command;
140 unsigned stripExt:1;
141 } directory;
142 } param;
143 } ItemData;
147 static char *commandNames[] = {
148 "ARRANGE_ICONS",
149 "HIDE_OTHERS",
150 "SHOW_ALL",
151 "EXIT",
152 "SHUTDOWN",
153 "RESTART",
154 "RESTART",
155 "SAVE_SESSION",
156 "CLEAR_SESSION",
157 "REFRESH",
158 "INFO_PANEL",
159 "LEGAL_PANEL"
164 #define NEW(type) memset(wmalloc(sizeof(type)), 0, sizeof(type))
167 #define ICON_FILE "menus"
171 static void showData(_Panel *panel);
174 static void updateMenuItem(_Panel *panel, WEditMenuItem *item,
175 WMWidget *changedWidget);
177 static void menuItemSelected(struct WEditMenuDelegate *delegate,
178 WEditMenu *menu, WEditMenuItem *item);
180 static void menuItemDeselected(struct WEditMenuDelegate *delegate,
181 WEditMenu *menu, WEditMenuItem *item);
183 static void menuItemCloned(struct WEditMenuDelegate *delegate, WEditMenu *menu,
184 WEditMenuItem *origItem, WEditMenuItem *newItem);
186 static void menuItemEdited(struct WEditMenuDelegate *delegate, WEditMenu *menu,
187 WEditMenuItem *item);
189 static Bool shouldRemoveItem(struct WEditMenuDelegate *delegate,
190 WEditMenu *menu, WEditMenuItem *item);
193 static void freeItemData(ItemData *data);
197 static WEditMenuDelegate menuDelegate = {
198 NULL,
199 menuItemCloned,
200 menuItemEdited,
201 menuItemSelected,
202 menuItemDeselected,
203 shouldRemoveItem
207 static void
208 dataChanged(void *self, WMNotification *notif)
210 _Panel *panel = (_Panel*)self;
211 WEditMenuItem *item = panel->currentItem;
212 WMWidget *w = (WMWidget*)WMGetNotificationObject(notif);
214 updateMenuItem(panel, item, w);
218 static void
219 buttonClicked(WMWidget *w, void *data)
221 _Panel *panel = (_Panel*)data;
222 WEditMenuItem *item = panel->currentItem;
224 updateMenuItem(panel, item, w);
228 static void
229 icommandLClicked(WMWidget *w, void *data)
231 _Panel *panel = (_Panel*)data;
232 int cmd;
234 cmd = WMGetListSelectedItemRow(w);
235 if (cmd == 3 || cmd == 4) {
236 WMMapWidget(panel->quickB);
237 } else {
238 WMUnmapWidget(panel->quickB);
240 if (cmd == 6) {
241 WMMapWidget(panel->paramF);
242 } else {
243 WMUnmapWidget(panel->paramF);
255 static char*
256 captureShortcut(Display *dpy, _Panel *panel)
258 XEvent ev;
259 KeySym ksym;
260 char buffer[64];
261 char *key = NULL;
263 while (panel->capturing) {
264 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
265 WMNextEvent(dpy, &ev);
266 if (ev.type==KeyPress && ev.xkey.keycode!=0) {
267 ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0);
268 if (!IsModifierKey(ksym)) {
269 key=XKeysymToString(ksym);
270 panel->capturing = 0;
271 break;
274 WMHandleEvent(&ev);
277 if (!key)
278 return NULL;
280 buffer[0] = 0;
282 if (ev.xkey.state & ControlMask) {
283 strcat(buffer, "Control+");
285 if (ev.xkey.state & ShiftMask) {
286 strcat(buffer, "Shift+");
288 if (ev.xkey.state & Mod1Mask) {
289 strcat(buffer, "Mod1+");
291 if (ev.xkey.state & Mod2Mask) {
292 strcat(buffer, "Mod2+");
294 if (ev.xkey.state & Mod3Mask) {
295 strcat(buffer, "Mod3+");
297 if (ev.xkey.state & Mod4Mask) {
298 strcat(buffer, "Mod4+");
300 if (ev.xkey.state & Mod5Mask) {
301 strcat(buffer, "Mod5+");
303 strcat(buffer, key);
305 return wstrdup(buffer);
310 static void
311 sgrabClicked(WMWidget *w, void *data)
313 _Panel *panel = (_Panel*)data;
314 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
315 char *shortcut;
318 if (w == panel->sclearB) {
319 WMSetTextFieldText(panel->shortT, "");
320 updateMenuItem(panel, panel->currentItem, panel->shortT);
321 return;
324 if (!panel->capturing) {
325 panel->capturing = 1;
326 WMSetButtonText(w, _("Cancel"));
327 XGrabKeyboard(dpy, WMWidgetXID(panel->win), True, GrabModeAsync,
328 GrabModeAsync, CurrentTime);
329 shortcut = captureShortcut(dpy, panel);
330 if (shortcut) {
331 WMSetTextFieldText(panel->shortT, shortcut);
332 updateMenuItem(panel, panel->currentItem, panel->shortT);
333 wfree(shortcut);
336 panel->capturing = 0;
337 WMSetButtonText(w, _("Capture"));
338 XUngrabKeyboard(dpy, CurrentTime);
342 static void
343 changedItemPad(WMWidget *w, void *data)
345 _Panel *panel = (_Panel*)data;
346 int padn = WMGetPopUpButtonSelectedItem(w);
348 WMUnmapWidget(panel->itemPad[panel->currentPad]);
349 WMMapWidget(panel->itemPad[padn]);
351 panel->currentPad = padn;
355 static WEditMenu*
356 putNewSubmenu(WEditMenu *menu, char *title)
358 WEditMenu *tmp;
359 WEditMenuItem *item;
361 item = WAddMenuItemWithTitle(menu, title);
363 tmp = WCreateEditMenu(WMWidgetScreen(menu), title);
364 WSetEditMenuAcceptsDrop(tmp, True);
365 WSetEditMenuDelegate(tmp, &menuDelegate);
366 WSetEditMenuSubmenu(menu, item, tmp);
368 return tmp;
372 static ItemData*
373 putNewItem(_Panel *panel, WEditMenu *menu, int type, char *title)
375 WEditMenuItem *item;
376 ItemData *data;
378 item = WAddMenuItemWithTitle(menu, title);
380 data = NEW(ItemData);
381 data->type = type;
382 WSetEditMenuItemData(item, data, (WMCallback*)freeItemData);
383 WSetEditMenuItemImage(item, panel->markerPix[type]);
385 return data;
389 static WEditMenu*
390 makeFactoryMenu(WMWidget *parent, int width)
392 WEditMenu *pad;
394 pad = WCreateEditMenuPad(parent);
395 WMResizeWidget(pad, width, 10);
396 WSetEditMenuMinSize(pad, wmksize(width, 0));
397 WSetEditMenuMaxSize(pad, wmksize(width, 0));
398 WSetEditMenuSelectable(pad, False);
399 WSetEditMenuEditable(pad, False);
400 WSetEditMenuIsFactory(pad, True);
401 WSetEditMenuDelegate(pad, &menuDelegate);
403 return pad;
407 static void
408 createPanel(_Panel *p)
410 _Panel *panel = (_Panel*)p;
411 WMScreen *scr = WMWidgetScreen(panel->win);
412 WMColor *black = WMBlackColor(scr);
413 WMColor *white = WMWhiteColor(scr);
414 WMColor *gray = WMGrayColor(scr);
415 WMFont *bold = WMBoldSystemFontOfSize(scr, 12);
416 WMFont *font = WMSystemFontOfSize(scr, 12);
417 WMLabel *label;
418 int width;
421 menuDelegate.data = panel;
424 panel->boldFont = bold;
425 panel->normalFont = font;
427 panel->black = black;
428 panel->white = white;
429 panel->gray = gray;
432 Pixmap pix;
433 Display *dpy = WMScreenDisplay(scr);
434 GC gc;
435 WMPixmap *pixm;
437 pixm = WMCreatePixmap(scr, 7, 7, WMScreenDepth(scr), True);
439 pix = WMGetPixmapXID(pixm);
441 XDrawLine(dpy, pix, WMColorGC(black), 0, 3, 6, 3);
442 XDrawLine(dpy, pix, WMColorGC(black), 3, 0, 3, 6);
444 XDrawLine(dpy, pix, WMColorGC(black), 1, 0, 3, 3);
445 XDrawLine(dpy, pix, WMColorGC(black), 1, 6, 3, 3);
446 XDrawLine(dpy, pix, WMColorGC(black), 0, 0, 0, 6);
449 pix = WMGetPixmapMaskXID(pixm);
451 gc = XCreateGC(dpy, pix, 0, NULL);
453 XSetForeground(dpy, gc, 0);
454 XFillRectangle(dpy, pix, gc, 0, 0, 7, 7);
456 XSetForeground(dpy, gc, 1);
457 XDrawLine(dpy, pix, gc, 0, 3, 6, 3);
458 XDrawLine(dpy, pix, gc, 3, 0, 3, 6);
460 panel->markerPix[ExternalInfo] = pixm;
461 panel->markerPix[PipeInfo] = pixm;
462 panel->markerPix[DirectoryInfo] = pixm;
463 panel->markerPix[WSMenuInfo] = pixm;
465 XFreeGC(dpy, gc);
469 panel->frame = WMCreateFrame(panel->win);
470 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
471 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
473 panel->typeP = WMCreatePopUpButton(panel->frame);
474 WMResizeWidget(panel->typeP, 150, 20);
475 WMMoveWidget(panel->typeP, 10, 10);
477 WMAddPopUpButtonItem(panel->typeP, _("New Items"));
478 WMAddPopUpButtonItem(panel->typeP, _("Sample Commands"));
479 WMAddPopUpButtonItem(panel->typeP, _("Sample Submenus"));
481 WMSetPopUpButtonAction(panel->typeP, changedItemPad, panel);
483 WMSetPopUpButtonSelectedItem(panel->typeP, 0);
486 WEditMenu *pad;
487 WEditMenu *smenu;
488 ItemData *data;
490 pad = makeFactoryMenu(panel->frame, 150);
491 WMMoveWidget(pad, 10, 40);
493 data = putNewItem(panel, pad, ExecInfo, "Run Program");
494 data = putNewItem(panel, pad, CommandInfo, "Internal Command");
495 smenu = putNewSubmenu(pad, "Submenu");
496 data = putNewItem(panel, pad, ExternalInfo, "External Submenu");
497 data = putNewItem(panel, pad, PipeInfo, "Generated Submenu");
498 data = putNewItem(panel, pad, DirectoryInfo, "Directory Contents");
499 data = putNewItem(panel, pad, WSMenuInfo, "Workspace Menu");
501 panel->itemPad[0] = pad;
505 WEditMenu *pad;
506 ItemData *data;
507 WMScrollView *sview;
509 sview = WMCreateScrollView(panel->frame);
510 WMResizeWidget(sview, 150, 180);
511 WMMoveWidget(sview, 10, 40);
512 WMSetScrollViewHasVerticalScroller(sview, True);
514 pad = makeFactoryMenu(panel->frame, 130);
516 WMSetScrollViewContentView(sview, WMWidgetView(pad));
518 data = putNewItem(panel, pad, ExecInfo, _("XTerm"));
519 data->param.exec.command = "xterm -sb -sl 2000 -bg black -fg white";
521 data = putNewItem(panel, pad, ExecInfo, _("rxvt"));
522 data->param.exec.command = "rxvt";
524 data = putNewItem(panel, pad, ExecInfo, _("ETerm"));
525 data->param.exec.command = "eterm";
527 data = putNewItem(panel, pad, ExecInfo, _("Run..."));
528 data->param.exec.command = "%a(Run,Type command to run)";
530 data = putNewItem(panel, pad, ExecInfo, _("Netscape"));
531 data->param.exec.command = "netscape";
533 data = putNewItem(panel, pad, ExecInfo, _("gimp"));
534 data->param.exec.command = "gimp";
536 data = putNewItem(panel, pad, ExecInfo, _("epic"));
537 data->param.exec.command = "xterm -e epic";
539 data = putNewItem(panel, pad, ExecInfo, _("ee"));
540 data->param.exec.command = "ee";
542 data = putNewItem(panel, pad, ExecInfo, _("xv"));
543 data->param.exec.command = "xv";
545 data = putNewItem(panel, pad, ExecInfo, _("Acrobat Reader"));
546 data->param.exec.command = "acroread || /usr/local/Acrobat4/bin/acroread";
548 data = putNewItem(panel, pad, ExecInfo, _("ghostview"));
549 data->param.exec.command = "gv";
551 data = putNewItem(panel, pad, CommandInfo, _("Exit Window Maker"));
552 data->param.command.command = 3;
554 WMMapWidget(pad);
556 panel->itemPad[1] = sview;
561 WEditMenu *pad, *smenu;
562 ItemData *data;
563 WMScrollView *sview;
565 sview = WMCreateScrollView(panel->frame);
566 WMResizeWidget(sview, 150, 180);
567 WMMoveWidget(sview, 10, 40);
568 WMSetScrollViewHasVerticalScroller(sview, True);
570 pad = makeFactoryMenu(panel->frame, 130);
572 WMSetScrollViewContentView(sview, WMWidgetView(pad));
574 data = putNewItem(panel, pad, ExternalInfo, _("Debian Menu"));
575 data->param.pipe.command = "/etc/X11/WindowMaker/menu.hook";
577 data = putNewItem(panel, pad, PipeInfo, _("RedHat Menu"));
578 data->param.pipe.command = "wmconfig --output wmaker";
580 data = putNewItem(panel, pad, PipeInfo, _("Menu Conectiva"));
581 data->param.pipe.command = "wmconfig --output wmaker";
583 data = putNewItem(panel, pad, DirectoryInfo, _("Themes"));
584 data->param.directory.command = "setstyle";
585 data->param.directory.directory = "/usr/share/WindowMaker/Themes /usr/local/share/WindowMaker/Themes $HOME/GNUstep/Library/WindowMaker/Themes";
586 data->param.directory.stripExt = 1;
588 data = putNewItem(panel, pad, DirectoryInfo, _("Bg Images (scale)"));
589 data->param.directory.command = "wmsetbg -u -s";
590 data->param.directory.directory = "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
591 data->param.directory.stripExt = 1;
593 data = putNewItem(panel, pad, DirectoryInfo, _("Bg Images (tile)"));
594 data->param.directory.command = "wmsetbg -u -t";
595 data->param.directory.directory = "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
596 data->param.directory.stripExt = 1;
598 smenu = putNewSubmenu(pad, _("Assorted XTerms"));
600 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Yellow on Blue"));
601 data->param.exec.command = "xterm -sb -sl 2000 -bg midnightblue -fg yellow";
603 data = putNewItem(panel, smenu, ExecInfo, _("XTerm White on Black"));
604 data->param.exec.command = "xterm -sb -sl 2000 -bg black -fg white";
606 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Black on White"));
607 data->param.exec.command = "xterm -sb -sl 2000 -bg white -fg black";
609 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Black on Beige"));
610 data->param.exec.command = "xterm -sb -sl 2000 -bg '#bbbb99' -fg black";
612 data = putNewItem(panel, smenu, ExecInfo, _("XTerm White on Green"));
613 data->param.exec.command = "xterm -sb -sl 2000 -bg '#228822' -fg white";
615 data = putNewItem(panel, smenu, ExecInfo, _("XTerm White on Olive"));
616 data->param.exec.command = "xterm -sb -sl 2000 -bg '#335533' -fg white";
618 data = putNewItem(panel, smenu, ExecInfo, _("XTerm Blue on Blue"));
619 data->param.exec.command = "xterm -sb -sl 2000 -bg '#112244' -fg '#88aabb'";
621 data = putNewItem(panel, smenu, ExecInfo, _("XTerm BIG FONTS"));
622 data->param.exec.command = "xterm -sb -sl 2000 -bg black -fg white -fn 10x20";
624 WMMapWidget(pad);
626 panel->itemPad[2] = sview;
630 width = FRAME_WIDTH - 20 - 150 - 10;
632 panel->optionsF = WMCreateFrame(panel->frame);
633 WMResizeWidget(panel->optionsF, width, FRAME_HEIGHT - 15);
634 WMMoveWidget(panel->optionsF, 10 + 150 + 10, 5);
636 width -= 20;
638 /* command */
640 panel->commandF = WMCreateFrame(panel->optionsF);
641 WMResizeWidget(panel->commandF, width, 50);
642 WMMoveWidget(panel->commandF, 10, 20);
643 WMSetFrameTitle(panel->commandF, _("Program to Run"));
645 panel->commandT = WMCreateTextField(panel->commandF);
646 WMResizeWidget(panel->commandT, width - 20, 20);
647 WMMoveWidget(panel->commandT, 10, 20);
649 WMAddNotificationObserver(dataChanged, panel,
650 WMTextDidChangeNotification,
651 panel->commandT);
653 #if 0
654 panel->xtermC = WMCreateSwitchButton(panel->commandF);
655 WMResizeWidget(panel->xtermC, width - 20, 20);
656 WMMoveWidget(panel->xtermC, 10, 50);
657 WMSetButtonText(panel->xtermC, _("Run the program inside a Xterm"));
658 #endif
659 WMMapSubwidgets(panel->commandF);
662 /* path */
664 panel->pathF = WMCreateFrame(panel->optionsF);
665 WMResizeWidget(panel->pathF, width, 150);
666 WMMoveWidget(panel->pathF, 10, 40);
667 WMSetFrameTitle(panel->pathF, _("Path for Menu"));
669 panel->pathT = WMCreateTextField(panel->pathF);
670 WMResizeWidget(panel->pathT, width - 20, 20);
671 WMMoveWidget(panel->pathT, 10, 20);
673 WMAddNotificationObserver(dataChanged, panel,
674 WMTextDidChangeNotification,
675 panel->pathT);
677 label = WMCreateLabel(panel->pathF);
678 WMResizeWidget(label, width - 20, 80);
679 WMMoveWidget(label, 10, 50);
680 WMSetLabelText(label, _("Enter the path for a file containing a menu\n"
681 "or a list of directories with the programs you\n"
682 "want to have listed in the menu. Ex:\n"
683 "~/GNUstep/Library/WindowMaker/menu\n"
684 "or\n"
685 "/usr/X11R6/bin ~/xbin"));
687 WMMapSubwidgets(panel->pathF);
690 /* pipe */
692 panel->pipeF = WMCreateFrame(panel->optionsF);
693 WMResizeWidget(panel->pipeF, width, 100);
694 WMMoveWidget(panel->pipeF, 10, 50);
695 WMSetFrameTitle(panel->pipeF, _("Command"));
697 panel->pipeT = WMCreateTextField(panel->pipeF);
698 WMResizeWidget(panel->pipeT, width - 20, 20);
699 WMMoveWidget(panel->pipeT, 10, 20);
701 WMAddNotificationObserver(dataChanged, panel,
702 WMTextDidChangeNotification,
703 panel->pipeT);
706 label = WMCreateLabel(panel->pipeF);
707 WMResizeWidget(label, width - 20, 40);
708 WMMoveWidget(label, 10, 50);
709 WMSetLabelText(label, _("Enter a command that outputs a menu\n"
710 "definition to stdout when invoked."));
712 WMMapSubwidgets(panel->pipeF);
715 /* directory menu */
717 panel->dcommandF = WMCreateFrame(panel->optionsF);
718 WMResizeWidget(panel->dcommandF, width, 90);
719 WMMoveWidget(panel->dcommandF, 10, 25);
720 WMSetFrameTitle(panel->dcommandF, _("Command to Open Files"));
722 panel->dcommandT = WMCreateTextField(panel->dcommandF);
723 WMResizeWidget(panel->dcommandT, width - 20, 20);
724 WMMoveWidget(panel->dcommandT, 10, 20);
726 WMAddNotificationObserver(dataChanged, panel,
727 WMTextDidChangeNotification,
728 panel->dcommandT);
731 label = WMCreateLabel(panel->dcommandF);
732 WMResizeWidget(label, width - 20, 45);
733 WMMoveWidget(label, 10, 40);
734 WMSetLabelText(label, _("Enter the command you want to use to open the\n"
735 "files in the directories listed below."));
737 WMMapSubwidgets(panel->dcommandF);
740 panel->dpathF = WMCreateFrame(panel->optionsF);
741 WMResizeWidget(panel->dpathF, width, 80);
742 WMMoveWidget(panel->dpathF, 10, 125);
743 WMSetFrameTitle(panel->dpathF, _("Directories with Files"));
745 panel->dpathT = WMCreateTextField(panel->dpathF);
746 WMResizeWidget(panel->dpathT, width - 20, 20);
747 WMMoveWidget(panel->dpathT, 10, 20);
749 WMAddNotificationObserver(dataChanged, panel,
750 WMTextDidChangeNotification,
751 panel->dpathT);
753 panel->dstripB = WMCreateSwitchButton(panel->dpathF);
754 WMResizeWidget(panel->dstripB, width - 20, 20);
755 WMMoveWidget(panel->dstripB, 10, 50);
756 WMSetButtonText(panel->dstripB, _("Strip extensions from file names"));
758 WMSetButtonAction(panel->dstripB, buttonClicked, panel);
760 WMMapSubwidgets(panel->dpathF);
763 /* shortcut */
765 panel->shortF = WMCreateFrame(panel->optionsF);
766 WMResizeWidget(panel->shortF, width, 50);
767 WMMoveWidget(panel->shortF, 10, 160);
768 WMSetFrameTitle(panel->shortF, _("Keyboard Shortcut"));
770 panel->shortT = WMCreateTextField(panel->shortF);
771 WMResizeWidget(panel->shortT, width - 20 - 170, 20);
772 WMMoveWidget(panel->shortT, 10, 20);
774 WMAddNotificationObserver(dataChanged, panel,
775 WMTextDidChangeNotification,
776 panel->shortT);
778 panel->sgrabB = WMCreateCommandButton(panel->shortF);
779 WMResizeWidget(panel->sgrabB, 80, 24);
780 WMMoveWidget(panel->sgrabB, width - 90, 18);
781 WMSetButtonText(panel->sgrabB, _("Capture"));
782 WMSetButtonAction(panel->sgrabB, sgrabClicked, panel);
784 panel->sclearB = WMCreateCommandButton(panel->shortF);
785 WMResizeWidget(panel->sclearB, 80, 24);
786 WMMoveWidget(panel->sclearB, width - 175, 18);
787 WMSetButtonText(panel->sclearB, _("Clear"));
788 WMSetButtonAction(panel->sclearB, sgrabClicked, panel);
790 WMMapSubwidgets(panel->shortF);
792 /* internal command */
794 panel->icommandL = WMCreateList(panel->optionsF);
795 WMResizeWidget(panel->icommandL, width, 80);
796 WMMoveWidget(panel->icommandL, 10, 20);
798 WMSetListAction(panel->icommandL, icommandLClicked, panel);
800 WMAddNotificationObserver(dataChanged, panel,
801 WMListSelectionDidChangeNotification,
802 panel->icommandL);
804 WMInsertListItem(panel->icommandL, 0, _("Arrange Icons"));
805 WMInsertListItem(panel->icommandL, 1, _("Hide All Windows Except For The Focused One"));
806 WMInsertListItem(panel->icommandL, 2, _("Show All Windows"));
808 WMInsertListItem(panel->icommandL, 3, _("Exit Window Maker"));
809 WMInsertListItem(panel->icommandL, 4, _("Exit X Session"));
810 WMInsertListItem(panel->icommandL, 5, _("Restart Window Maker"));
811 WMInsertListItem(panel->icommandL, 6, _("Start Another Window Manager : ("));
813 WMInsertListItem(panel->icommandL, 7, _("Save Current Session"));
814 WMInsertListItem(panel->icommandL, 8, _("Clear Saved Session"));
815 WMInsertListItem(panel->icommandL, 9, _("Refresh Screen"));
816 WMInsertListItem(panel->icommandL, 10, _("Open Info Panel"));
817 WMInsertListItem(panel->icommandL, 11, _("Open Copyright Panel"));
820 panel->paramF = WMCreateFrame(panel->optionsF);
821 WMResizeWidget(panel->paramF, width, 50);
822 WMMoveWidget(panel->paramF, 10, 105);
823 WMSetFrameTitle(panel->paramF, _("Window Manager to Start"));
825 panel->paramT = WMCreateTextField(panel->paramF);
826 WMResizeWidget(panel->paramT, width - 20, 20);
827 WMMoveWidget(panel->paramT, 10, 20);
829 WMAddNotificationObserver(dataChanged, panel,
830 WMTextDidChangeNotification,
831 panel->paramT);
833 WMMapSubwidgets(panel->paramF);
836 panel->quickB = WMCreateSwitchButton(panel->optionsF);
837 WMResizeWidget(panel->quickB, width, 20);
838 WMMoveWidget(panel->quickB, 10, 120);
839 WMSetButtonText(panel->quickB, _("Do not confirm action."));
840 WMSetButtonAction(panel->quickB, buttonClicked, panel);
845 label = WMCreateLabel(panel->optionsF);
846 WMResizeWidget(label, width - 20, FRAME_HEIGHT - 50);
847 WMMoveWidget(label, 10, 20);
848 WMSetLabelText(label,
849 _("Instructions:\n\n"
850 " - drag items from the left to the menu to add new items\n"
851 " - drag items out of the menu to remove items\n"
852 " - drag items in menu to change their position\n"
853 " - double click in a menu item to change the label\n"
854 " - click on a menu item to change related information"));
855 WMMapWidget(label);
857 WMRealizeWidget(panel->frame);
858 WMMapSubwidgets(panel->frame);
859 WMMapWidget(panel->frame);
863 int i;
864 for (i = 0; i < 3; i++)
865 WMUnmapWidget(panel->itemPad[i]);
867 changedItemPad(panel->typeP, panel);
869 panel->sections[NoInfo][0] = label;
871 panel->sections[ExecInfo][0] = panel->commandF;
872 panel->sections[ExecInfo][1] = panel->shortF;
874 panel->sections[CommandInfo][0] = panel->icommandL;
875 panel->sections[CommandInfo][1] = panel->shortF;
877 panel->sections[ExternalInfo][0] = panel->pathF;
879 panel->sections[PipeInfo][0] = panel->pipeF;
881 panel->sections[DirectoryInfo][0] = panel->dpathF;
882 panel->sections[DirectoryInfo][1] = panel->dcommandF;
884 panel->currentType = NoInfo;
886 showData(panel);
889 WMPoint pos;
891 pos = WMGetViewScreenPosition(WMWidgetView(panel->frame));
893 if (pos.x < 200) {
894 pos.x += FRAME_WIDTH + 20;
895 } else {
896 pos.x = 10;
899 pos.y = WMAX(pos.y - 100, 0);
901 WEditMenuShowAt(panel->menu, pos.x, pos.y);
908 static void
909 freeItemData(ItemData *data)
911 #define CFREE(d) if (d) wfree(d)
913 /* TODO */
914 switch (data->type) {
915 case CommandInfo:
916 CFREE(data->param.command.parameter);
917 CFREE(data->param.command.shortcut);
918 break;
920 case ExecInfo:
921 CFREE(data->param.exec.command);
922 CFREE(data->param.exec.shortcut);
923 break;
925 case PipeInfo:
926 CFREE(data->param.pipe.command);
927 break;
929 case ExternalInfo:
930 CFREE(data->param.external.path);
931 break;
933 case DirectoryInfo:
934 CFREE(data->param.directory.command);
935 CFREE(data->param.directory.directory);
936 break;
938 default:
939 break;
942 wfree(data);
943 #undef CFREE
947 static ItemData*
948 parseCommand(proplist_t item)
950 ItemData *data = NEW(ItemData);
951 proplist_t p;
952 char *command = NULL;
953 char *parameter = NULL;
954 char *shortcut = NULL;
955 int i = 1;
958 p = PLGetArrayElement(item, i++);
959 command = PLGetString(p);
960 if (strcmp(command, "SHORTCUT") == 0) {
961 p = PLGetArrayElement(item, i++);
962 shortcut = PLGetString(p);
963 p = PLGetArrayElement(item, i++);
964 command = PLGetString(p);
966 p = PLGetArrayElement(item, i++);
967 if (p)
968 parameter = PLGetString(p);
970 if (strcmp(command, "EXEC") == 0 || strcmp(command, "SHEXEC") == 0) {
972 data->type = ExecInfo;
974 data->param.exec.command = wstrdup(parameter);
975 if (shortcut)
976 data->param.exec.shortcut = wstrdup(shortcut);
978 } else if (strcmp(command, "OPEN_MENU") == 0) {
979 char *p;
981 * dir menu, menu file
982 * dir WITH
983 * |pipe (TODO: ||pipe)
985 p = parameter;
986 while (isspace(*p) && *p) p++;
987 if (*p == '|') {
988 data->type = PipeInfo;
989 data->param.pipe.command = wtrimspace(p+1);
990 } else {
991 char *s;
993 p = wstrdup(p);
995 s = strstr(p, "WITH");
996 if (s) {
997 char **tokens;
998 char **ctokens;
999 int tokn;
1000 int i, j;
1002 data->type = DirectoryInfo;
1004 *s = '\0';
1005 s += 5;
1006 while (*s && isspace(*s)) s++;
1007 data->param.directory.command = wstrdup(s);
1009 wtokensplit(p, &tokens, &tokn);
1010 wfree(p);
1012 ctokens = wmalloc(sizeof(char*)*tokn);
1014 for (i = 0, j = 0; i < tokn; i++) {
1015 if (strcmp(tokens[i], "-noext") == 0) {
1016 wfree(tokens[i]);
1017 data->param.directory.stripExt = 1;
1018 } else {
1019 ctokens[j++] = tokens[i];
1022 data->param.directory.directory = wtokenjoin(ctokens, j);
1023 wfree(ctokens);
1025 wtokenfree(tokens, tokn);
1026 } else {
1027 data->type = ExternalInfo;
1028 data->param.external.path = p;
1031 } else if (strcmp(command, "WORKSPACE_MENU") == 0) {
1032 data->type = WSMenuInfo;
1033 } else {
1034 int cmd;
1036 if (strcmp(command, "ARRANGE_ICONS") == 0) {
1037 cmd = 0;
1038 } else if (strcmp(command, "HIDE_OTHERS") == 0) {
1039 cmd = 1;
1040 } else if (strcmp(command, "SHOW_ALL") == 0) {
1041 cmd = 2;
1042 } else if (strcmp(command, "EXIT") == 0) {
1043 cmd = 3;
1044 } else if (strcmp(command, "SHUTDOWN") == 0) {
1045 cmd = 4;
1046 } else if (strcmp(command, "RESTART") == 0) {
1047 if (parameter) {
1048 cmd = 6;
1049 } else {
1050 cmd = 5;
1052 } else if (strcmp(command, "SAVE_SESSION") == 0) {
1053 cmd = 7;
1054 } else if (strcmp(command, "CLEAR_SESSION") == 0) {
1055 cmd = 8;
1056 } else if (strcmp(command, "REFRESH") == 0) {
1057 cmd = 9;
1058 } else if (strcmp(command, "INFO_PANEL") == 0) {
1059 cmd = 10;
1060 } else if (strcmp(command, "LEGAL_PANEL") == 0) {
1061 cmd = 11;
1062 } else {
1063 wwarning(_("unknown command '%s' in menu"), command);
1064 goto error;
1067 data->type = CommandInfo;
1069 data->param.command.command = cmd;
1070 if (shortcut)
1071 data->param.command.shortcut = wstrdup(shortcut);
1072 if (parameter)
1073 data->param.command.parameter = wstrdup(parameter);
1076 return data;
1078 error:
1079 wfree(data);
1081 return NULL;
1087 static void
1088 updateFrameTitle(_Panel *panel, char *title, InfoType type)
1090 if (type != NoInfo) {
1091 char *tmp;
1093 switch (type) {
1094 case ExecInfo:
1095 tmp = wstrconcat(title, _(": Execute Program"));
1096 break;
1098 case CommandInfo:
1099 tmp = wstrconcat(title, _(": Perform Internal Command"));
1100 break;
1102 case ExternalInfo:
1103 tmp = wstrconcat(title, _(": Open a Submenu"));
1104 break;
1106 case PipeInfo:
1107 tmp = wstrconcat(title, _(": Program Generated Submenu"));
1108 break;
1110 case DirectoryInfo:
1111 tmp = wstrconcat(title, _(": Directory Contents Menu"));
1112 break;
1114 case WSMenuInfo:
1115 tmp = wstrconcat(title, _(": Open Workspaces Submenu"));
1116 break;
1118 default:
1119 tmp = NULL;
1120 break;
1122 WMSetFrameTitle(panel->optionsF, tmp);
1123 wfree(tmp);
1124 } else {
1125 WMSetFrameTitle(panel->optionsF, NULL);
1131 static void
1132 changeInfoType(_Panel *panel, char *title, InfoType type)
1134 WMWidget **w;
1136 if (panel->currentType != type) {
1138 w = panel->sections[panel->currentType];
1140 while (*w) {
1141 WMUnmapWidget(*w);
1142 w++;
1144 WMUnmapWidget(panel->paramF);
1145 WMUnmapWidget(panel->quickB);
1148 w = panel->sections[type];
1150 while (*w) {
1151 WMMapWidget(*w);
1152 w++;
1156 updateFrameTitle(panel, title, type);
1158 panel->currentType = type;
1164 static void
1165 updateMenuItem(_Panel *panel, WEditMenuItem *item, WMWidget *changedWidget)
1167 ItemData *data = WGetEditMenuItemData(item);
1169 assert(data != NULL);
1171 #define REPLACE(v, d) if (v) wfree(v); v = d
1173 switch (data->type) {
1174 case ExecInfo:
1175 if (changedWidget == panel->commandT) {
1176 REPLACE(data->param.exec.command,
1177 WMGetTextFieldText(panel->commandT));
1179 if (changedWidget == panel->shortT) {
1180 REPLACE(data->param.exec.shortcut,
1181 WMGetTextFieldText(panel->shortT));
1183 break;
1185 case CommandInfo:
1186 if (changedWidget == panel->icommandL) {
1187 data->param.command.command =
1188 WMGetListSelectedItemRow(panel->icommandL);
1190 switch (data->param.command.command) {
1191 case 3:
1192 case 4:
1193 if (changedWidget == panel->quickB) {
1194 REPLACE(data->param.command.parameter,
1195 WMGetButtonSelected(panel->quickB)
1196 ? wstrdup("QUICK") : NULL);
1198 break;
1200 case 6:
1201 if (changedWidget == panel->paramT) {
1202 REPLACE(data->param.command.parameter,
1203 WMGetTextFieldText(panel->paramT));
1205 break;
1207 if (changedWidget == panel->shortT) {
1208 REPLACE(data->param.command.shortcut,
1209 WMGetTextFieldText(panel->shortT));
1213 break;
1215 case PipeInfo:
1216 if (changedWidget == panel->pipeT) {
1217 REPLACE(data->param.pipe.command,
1218 WMGetTextFieldText(panel->pipeT));
1220 break;
1222 case ExternalInfo:
1223 if (changedWidget == panel->pathT) {
1224 REPLACE(data->param.external.path,
1225 WMGetTextFieldText(panel->pathT));
1227 break;
1229 case DirectoryInfo:
1230 if (changedWidget == panel->dpathT) {
1231 REPLACE(data->param.directory.directory,
1232 WMGetTextFieldText(panel->dpathT));
1234 if (changedWidget == panel->dcommandT) {
1235 REPLACE(data->param.directory.command,
1236 WMGetTextFieldText(panel->dcommandT));
1238 if (changedWidget == panel->dstripB) {
1239 data->param.directory.stripExt =
1240 WMGetButtonSelected(panel->dstripB);
1242 break;
1244 default:
1245 assert(0);
1246 break;
1249 #undef REPLACE
1254 static void
1255 menuItemCloned(WEditMenuDelegate *delegate, WEditMenu *menu,
1256 WEditMenuItem *origItem, WEditMenuItem *newItem)
1258 ItemData *data = WGetEditMenuItemData(origItem);
1259 ItemData *newData;
1261 if (!data)
1262 return;
1264 #define DUP(s) (s) ? wstrdup(s) : NULL
1266 newData = NEW(ItemData);
1268 newData->type = data->type;
1270 switch (data->type) {
1271 case ExecInfo:
1272 newData->param.exec.command = DUP(data->param.exec.command);
1273 newData->param.exec.shortcut = DUP(data->param.exec.shortcut);
1274 break;
1276 case CommandInfo:
1277 newData->param.command.command = data->param.command.command;
1278 newData->param.command.parameter = DUP(data->param.command.parameter);
1279 newData->param.command.shortcut = DUP(data->param.command.shortcut);
1280 break;
1282 case PipeInfo:
1283 newData->param.pipe.command = DUP(data->param.pipe.command);
1284 break;
1286 case ExternalInfo:
1287 newData->param.external.path = DUP(data->param.external.path);
1288 break;
1290 case DirectoryInfo:
1291 newData->param.directory.directory = DUP(data->param.directory.directory);
1292 newData->param.directory.command = DUP(data->param.directory.command);
1293 newData->param.directory.stripExt = data->param.directory.stripExt;
1294 break;
1296 default:
1297 break;
1300 #undef DUP
1302 WSetEditMenuItemData(newItem, newData, (WMCallback*)freeItemData);
1306 static void
1307 menuItemEdited(struct WEditMenuDelegate *delegate, WEditMenu *menu,
1308 WEditMenuItem *item)
1310 _Panel *panel = (_Panel*)delegate->data;
1311 WEditMenu *submenu;
1313 updateFrameTitle(panel, WGetEditMenuItemTitle(item), panel->currentType);
1315 submenu = WGetEditMenuSubmenu(menu, item);
1316 if (submenu) {
1317 WSetEditMenuTitle(submenu, WGetEditMenuItemTitle(item));
1322 static Bool
1323 shouldRemoveItem(struct WEditMenuDelegate *delegate, WEditMenu *menu,
1324 WEditMenuItem *item)
1326 _Panel *panel = (_Panel*)delegate->data;
1328 if (panel->dontAsk)
1329 return True;
1331 if (WGetEditMenuSubmenu(menu, item)) {
1332 int res;
1334 res = WMRunAlertPanel(WMWidgetScreen(menu), NULL,
1335 _("Remove Submenu"),
1336 _("Removing this item will destroy all items inside\n"
1337 "the submenu. Do you really want to do that?"),
1338 _("Yes"), _("No"),
1339 _("Yes, don't ask again."));
1340 switch (res) {
1341 case WAPRDefault:
1342 return True;
1343 case WAPRAlternate:
1344 return False;
1345 case WAPROther:
1346 panel->dontAsk = True;
1347 return True;
1350 return True;
1354 static void
1355 menuItemDeselected(WEditMenuDelegate *delegate, WEditMenu *menu,
1356 WEditMenuItem *item)
1358 _Panel *panel = (_Panel*)delegate->data;
1360 changeInfoType(panel, NULL, NoInfo);
1364 static void
1365 menuItemSelected(WEditMenuDelegate *delegate, WEditMenu *menu,
1366 WEditMenuItem *item)
1368 ItemData *data = WGetEditMenuItemData(item);
1369 _Panel *panel = (_Panel*)delegate->data;
1371 panel->currentItem = item;
1373 if (data) {
1374 changeInfoType(panel, WGetEditMenuItemTitle(item), data->type);
1376 switch (data->type) {
1377 case NoInfo:
1378 break;
1380 case ExecInfo:
1381 WMSetTextFieldText(panel->commandT, data->param.exec.command);
1382 WMSetTextFieldText(panel->shortT, data->param.exec.shortcut);
1383 break;
1385 case CommandInfo:
1386 WMSelectListItem(panel->icommandL,
1387 data->param.command.command);
1388 WMSetListPosition(panel->icommandL,
1389 data->param.command.command - 2);
1390 WMSetTextFieldText(panel->shortT, data->param.command.shortcut);
1392 switch (data->param.command.command) {
1393 case 3:
1394 case 4:
1395 WMSetButtonSelected(panel->quickB,
1396 data->param.command.parameter!=NULL);
1397 break;
1398 case 6:
1399 WMSetTextFieldText(panel->paramT,
1400 data->param.command.parameter);
1401 break;
1404 icommandLClicked(panel->icommandL, panel);
1405 break;
1407 case PipeInfo:
1408 WMSetTextFieldText(panel->pipeT, data->param.pipe.command);
1409 break;
1411 case ExternalInfo:
1412 WMSetTextFieldText(panel->pathT, data->param.external.path);
1413 break;
1415 case DirectoryInfo:
1416 WMSetTextFieldText(panel->dpathT, data->param.directory.directory);
1417 WMSetTextFieldText(panel->dcommandT, data->param.directory.command);
1418 WMSetButtonSelected(panel->dstripB, data->param.directory.stripExt);
1419 break;
1421 case WSMenuInfo:
1422 break;
1424 default:
1425 break;
1432 static WEditMenu*
1433 buildSubmenu(_Panel *panel, proplist_t pl)
1435 WMScreen *scr = WMWidgetScreen(panel->win);
1436 WEditMenu *menu;
1437 WEditMenuItem *item;
1438 char *title;
1439 proplist_t tp, bp;
1440 int i;
1442 tp = PLGetArrayElement(pl, 0);
1443 title = PLGetString(tp);
1445 menu = WCreateEditMenu(scr, title);
1447 for (i = 1; i < PLGetNumberOfElements(pl); i++) {
1448 proplist_t pi;
1450 pi = PLGetArrayElement(pl, i);
1452 tp = PLGetArrayElement(pi, 0);
1453 bp = PLGetArrayElement(pi, 1);
1455 title = PLGetString(tp);
1457 if (PLIsArray(bp)) { /* it's a submenu */
1458 WEditMenu *submenu;
1460 submenu = buildSubmenu(panel, pi);
1462 item = WAddMenuItemWithTitle(menu, title);
1464 WSetEditMenuSubmenu(menu, item, submenu);
1465 } else {
1466 ItemData *data;
1468 item = WAddMenuItemWithTitle(menu, title);
1470 data = parseCommand(pi);
1472 if (panel->markerPix[data->type])
1473 WSetEditMenuItemImage(item, panel->markerPix[data->type]);
1474 WSetEditMenuItemData(item, data, (WMCallback*)freeItemData);
1478 WSetEditMenuAcceptsDrop(menu, True);
1479 WSetEditMenuDelegate(menu, &menuDelegate);
1481 WMRealizeWidget(menu);
1483 return menu;
1488 static void
1489 buildMenuFromPL(_Panel *panel, proplist_t pl)
1491 panel->menu = buildSubmenu(panel, pl);
1496 static proplist_t
1497 getDefaultMenu(_Panel *panel)
1499 proplist_t menu, pmenu;
1500 char *menuPath, *gspath;
1502 gspath = wusergnusteppath();
1504 menuPath = wmalloc(strlen(gspath)+128);
1505 /* if there is a localized plmenu for the tongue put it's filename here */
1506 sprintf(menuPath, _("%s/Library/WindowMaker/plmenu"), gspath);
1508 menu = PLGetProplistWithPath(menuPath);
1509 if (!menu) {
1510 wwarning("%s:could not read property list menu", menuPath);
1512 if (strcmp("%s/Library/WindowMaker/plmenu",
1513 _("%s/Library/WindowMaker/plmenu"))!=0) {
1515 sprintf(menuPath, "%s/Library/WindowMaker/plmenu", gspath);
1516 menu = PLGetProplistWithPath(menuPath);
1517 wwarning("%s:could not read property list menu", menuPath);
1519 if (!menu) {
1520 char buffer[512];
1522 sprintf(buffer, _("Could not open default menu from '%s'"),
1523 menuPath);
1524 WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win,
1525 _("Error"), buffer, _("OK"), NULL, NULL);
1529 wfree(menuPath);
1531 if (menu) {
1532 pmenu = menu;
1533 } else {
1534 pmenu = NULL;
1537 return pmenu;
1541 static void
1542 showData(_Panel *panel)
1544 char *gspath;
1545 char *menuPath;
1546 proplist_t pmenu;
1548 gspath = wusergnusteppath();
1550 menuPath = wmalloc(strlen(gspath)+32);
1551 strcpy(menuPath, gspath);
1552 strcat(menuPath, "/Defaults/WMRootMenu");
1554 pmenu = PLGetProplistWithPath(menuPath);
1556 if (!pmenu || !PLIsArray(pmenu)) {
1557 int res;
1559 res = WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win,
1560 _("Warning"),
1561 _("The menu file format currently in use is not supported\n"
1562 "by this tool. Do you want to discard the current menu\n"
1563 "to use this tool?"),
1564 _("Yes, Discard and Update"),
1565 _("No, Keep Current Menu"), NULL);
1567 if (res == WAPRDefault) {
1568 pmenu = getDefaultMenu(panel);
1570 if (!pmenu) {
1571 pmenu = PLMakeArrayFromElements(PLMakeString("Applications"),
1572 NULL);
1574 } else {
1575 panel->dontSave = True;
1576 return;
1580 panel->menuPath = menuPath;
1582 buildMenuFromPL(panel, pmenu);
1584 PLRelease(pmenu);
1588 static Bool
1589 notblank(char *s)
1591 if (s) {
1592 while (*s++) {
1593 if (!isspace(*s))
1594 return True;
1597 return False;
1601 static proplist_t
1602 processData(char *title, ItemData *data)
1604 proplist_t item;
1605 char *s1;
1606 static char *pscut = NULL;
1607 static char *pomenu = NULL;
1608 int i;
1610 if (!pscut) {
1611 pscut = PLMakeString("SHORTCUT");
1612 pomenu = PLMakeString("OPEN_MENU");
1615 item = PLMakeArrayFromElements(PLMakeString(title), NULL);
1618 switch (data->type) {
1619 case ExecInfo:
1620 #if 1
1621 if (strpbrk(data->param.exec.command, "&$*|><?`=")) {
1622 s1 = "SHEXEC";
1623 } else {
1624 s1 = "EXEC";
1626 #else
1627 s1 = "SHEXEC";
1628 #endif
1630 if (notblank(data->param.exec.shortcut)) {
1631 PLAppendArrayElement(item, pscut);
1632 PLAppendArrayElement(item,
1633 PLMakeString(data->param.exec.shortcut));
1636 PLAppendArrayElement(item, PLMakeString(s1));
1637 PLAppendArrayElement(item, PLMakeString(data->param.exec.command));
1638 break;
1640 case CommandInfo:
1641 if (notblank(data->param.command.shortcut)) {
1642 PLAppendArrayElement(item, pscut);
1643 PLAppendArrayElement(item,
1644 PLMakeString(data->param.command.shortcut));
1647 i = data->param.command.command;
1649 PLAppendArrayElement(item, PLMakeString(commandNames[i]));
1651 switch (i) {
1652 case 3:
1653 case 4:
1654 if (data->param.command.parameter) {
1655 PLAppendArrayElement(item,
1656 PLMakeString(data->param.command.parameter));
1658 break;
1660 case 6: /* restart */
1661 if (data->param.command.parameter) {
1662 PLAppendArrayElement(item,
1663 PLMakeString(data->param.command.parameter));
1665 break;
1668 break;
1670 case PipeInfo:
1671 PLAppendArrayElement(item, pomenu);
1672 s1 = wstrconcat("| ", data->param.pipe.command);
1673 PLAppendArrayElement(item, PLMakeString(s1));
1674 wfree(s1);
1675 break;
1677 case ExternalInfo:
1678 PLAppendArrayElement(item, pomenu);
1679 PLAppendArrayElement(item, PLMakeString(data->param.external.path));
1680 break;
1682 case DirectoryInfo:
1684 int l;
1685 char *tmp;
1687 l = strlen(data->param.directory.directory);
1688 l += strlen(data->param.directory.command);
1689 l += 32;
1691 PLAppendArrayElement(item, pomenu);
1693 tmp = wmalloc(l);
1694 sprintf(tmp, "%s%s WITH %s",
1695 data->param.directory.stripExt ? "-noext " : "",
1696 data->param.directory.directory,
1697 data->param.directory.command);
1699 PLAppendArrayElement(item, PLMakeString(tmp));
1700 wfree(tmp);
1702 break;
1704 case WSMenuInfo:
1705 PLAppendArrayElement(item, PLMakeString("WORKSPACE_MENU"));
1706 break;
1708 default:
1709 assert(0);
1710 break;
1713 return item;
1717 static proplist_t
1718 processSubmenu(WEditMenu *menu)
1720 WEditMenuItem *item;
1721 proplist_t pmenu;
1722 proplist_t pl;
1723 char *s;
1724 int i;
1727 s = WGetEditMenuTitle(menu);
1728 pl = PLMakeString(s);
1730 pmenu = PLMakeArrayFromElements(pl, NULL);
1732 i = 0;
1733 while ((item = WGetEditMenuItem(menu, i++))) {
1734 WEditMenu *submenu;
1736 s = WGetEditMenuItemTitle(item);
1738 submenu = WGetEditMenuSubmenu(menu, item);
1739 if (submenu) {
1740 pl = processSubmenu(submenu);
1741 } else {
1742 pl = processData(s, WGetEditMenuItemData(item));
1745 PLAppendArrayElement(pmenu, pl);
1748 return pmenu;
1753 static proplist_t
1754 buildPLFromMenu(_Panel *panel)
1756 proplist_t menu;
1758 menu = processSubmenu(panel->menu);
1760 return menu;
1766 static void
1767 storeData(_Panel *panel)
1769 proplist_t menu;
1771 if (panel->dontSave)
1772 return;
1774 menu = buildPLFromMenu(panel);
1776 PLSetFilename(menu, PLMakeString(panel->menuPath));
1778 PLSave(menu, YES);
1780 PLRelease(menu);
1785 static void
1786 showMenus(_Panel *panel)
1788 WEditMenuUnhide(panel->menu);
1792 static void
1793 hideMenus(_Panel *panel)
1795 WEditMenuHide(panel->menu);
1801 Panel*
1802 InitMenu(WMScreen *scr, WMWindow *win)
1804 _Panel *panel;
1806 panel = wmalloc(sizeof(_Panel));
1807 memset(panel, 0, sizeof(_Panel));
1809 panel->sectionName = _("Applications Menu Definition");
1811 panel->description = _("Edit the menu for launching applications.");
1813 panel->win = win;
1815 panel->callbacks.createWidgets = createPanel;
1816 panel->callbacks.updateDomain = storeData;
1817 panel->callbacks.showPanel = showMenus;
1818 panel->callbacks.hidePanel = hideMenus;
1821 AddSection(panel, ICON_FILE);
1823 return panel;