1 /* Menu.c- menu definition
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 2000-2003 Alfredo K. Kojima
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,
27 #include <X11/keysym.h>
28 #include <X11/cursorfont.h>
44 #define MAX_SECTION_SIZE 4
46 typedef struct _Panel
{
52 CallbackRec callbacks
;
61 WMPixmap
*markerPix
[LastInfo
];
74 WMTextField
*commandT
; /* command to run */
76 WMButton
*xtermC
; /* inside xterm? */
89 WMTextField
*dcommandT
;
105 Bool dontAsk
; /* whether to comfirm submenu remove */
110 /* about the currently selected item */
111 WEditMenuItem
*currentItem
;
112 InfoType currentType
;
113 WMWidget
*sections
[LastInfo
][MAX_SECTION_SIZE
];
143 static char *commandNames
[] = {
158 #define NEW(type) memset(wmalloc(sizeof(type)), 0, sizeof(type))
160 #define ICON_FILE "menus"
162 static void showData(_Panel
* panel
);
164 static void updateMenuItem(_Panel
* panel
, WEditMenuItem
* item
, WMWidget
* changedWidget
);
166 static void menuItemSelected(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
168 static void menuItemDeselected(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
170 static void menuItemCloned(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
,
171 WEditMenuItem
* origItem
, WEditMenuItem
* newItem
);
173 static void menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
175 static Bool
shouldRemoveItem(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
177 static void freeItemData(ItemData
* data
);
179 static WEditMenuDelegate menuDelegate
= {
188 static void dataChanged(void *self
, WMNotification
* notif
)
190 _Panel
*panel
= (_Panel
*) self
;
191 WEditMenuItem
*item
= panel
->currentItem
;
192 WMWidget
*w
= (WMWidget
*) WMGetNotificationObject(notif
);
194 updateMenuItem(panel
, item
, w
);
197 static void buttonClicked(WMWidget
* w
, void *data
)
199 _Panel
*panel
= (_Panel
*) data
;
200 WEditMenuItem
*item
= panel
->currentItem
;
202 updateMenuItem(panel
, item
, w
);
205 static void icommandLClicked(WMWidget
* w
, void *data
)
207 _Panel
*panel
= (_Panel
*) data
;
210 cmd
= WMGetListSelectedItemRow(w
);
211 if (cmd
== 3 || cmd
== 4) {
212 WMMapWidget(panel
->quickB
);
214 WMUnmapWidget(panel
->quickB
);
217 WMMapWidget(panel
->paramF
);
219 WMUnmapWidget(panel
->paramF
);
223 static void browseForFile(WMWidget
* self
, void *clientData
)
225 _Panel
*panel
= (_Panel
*) clientData
;
226 WMFilePanel
*filePanel
;
227 char *text
, *oldprog
, *newprog
;
229 filePanel
= WMGetOpenPanel(WMWidgetScreen(self
));
230 text
= WMGetTextFieldText(panel
->commandT
);
232 oldprog
= wtrimspace(text
);
235 if (oldprog
[0] == 0 || oldprog
[0] != '/') {
237 oldprog
= wstrdup("/");
240 while (*ptr
&& !isspace(*ptr
))
245 WMSetFilePanelCanChooseDirectories(filePanel
, False
);
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
);
257 static char *captureShortcut(Display
* dpy
, _Panel
* panel
)
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;
283 if (ev
.xkey
.state
& ControlMask
) {
284 strcat(buffer
, "Control+");
286 if (ev
.xkey
.state
& ShiftMask
) {
287 strcat(buffer
, "Shift+");
289 if (ev
.xkey
.state
& Mod1Mask
) {
290 strcat(buffer
, "Mod1+");
292 if (ev
.xkey
.state
& Mod2Mask
) {
293 strcat(buffer
, "Mod2+");
295 if (ev
.xkey
.state
& Mod3Mask
) {
296 strcat(buffer
, "Mod3+");
298 if (ev
.xkey
.state
& Mod4Mask
) {
299 strcat(buffer
, "Mod4+");
301 if (ev
.xkey
.state
& Mod5Mask
) {
302 strcat(buffer
, "Mod5+");
306 return wstrdup(buffer
);
309 static void sgrabClicked(WMWidget
* w
, void *data
)
311 _Panel
*panel
= (_Panel
*) data
;
312 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->parent
));
315 if (w
== panel
->sclearB
) {
316 WMSetTextFieldText(panel
->shortT
, "");
317 updateMenuItem(panel
, panel
->currentItem
, panel
->shortT
);
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
);
327 WMSetTextFieldText(panel
->shortT
, shortcut
);
328 updateMenuItem(panel
, panel
->currentItem
, panel
->shortT
);
332 panel
->capturing
= 0;
333 WMSetButtonText(w
, _("Capture"));
334 XUngrabKeyboard(dpy
, CurrentTime
);
337 static void changedItemPad(WMWidget
* w
, void *data
)
339 _Panel
*panel
= (_Panel
*) data
;
340 int padn
= WMGetPopUpButtonSelectedItem(w
);
342 WMUnmapWidget(panel
->itemPad
[panel
->currentPad
]);
343 WMMapWidget(panel
->itemPad
[padn
]);
345 panel
->currentPad
= padn
;
348 static WEditMenu
*putNewSubmenu(WEditMenu
* menu
, char *title
)
353 item
= WAddMenuItemWithTitle(menu
, title
);
355 tmp
= WCreateEditMenu(WMWidgetScreen(menu
), title
);
356 WSetEditMenuAcceptsDrop(tmp
, True
);
357 WSetEditMenuDelegate(tmp
, &menuDelegate
);
358 WSetEditMenuSubmenu(menu
, item
, tmp
);
363 static ItemData
*putNewItem(_Panel
* panel
, WEditMenu
* menu
, int type
, char *title
)
368 item
= WAddMenuItemWithTitle(menu
, title
);
370 data
= NEW(ItemData
);
372 WSetEditMenuItemData(item
, data
, (WMCallback
*) freeItemData
);
373 WSetEditMenuItemImage(item
, panel
->markerPix
[type
]);
378 static WEditMenu
*makeFactoryMenu(WMWidget
* parent
, int width
)
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
);
394 static void createPanel(_Panel
* p
)
396 _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);
406 menuDelegate
.data
= panel
;
408 panel
->boldFont
= bold
;
409 panel
->normalFont
= font
;
411 panel
->black
= black
;
412 panel
->white
= white
;
417 Display
*dpy
= WMScreenDisplay(scr
);
421 pixm
= WMCreatePixmap(scr
, 7, 7, WMScreenDepth(scr
), True
);
423 pix
= WMGetPixmapXID(pixm
);
425 XDrawLine(dpy
, pix
, WMColorGC(black
), 0, 3, 6, 3);
426 XDrawLine(dpy
, pix
, WMColorGC(black
), 3, 0, 3, 6);
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);
433 pix
= WMGetPixmapMaskXID(pixm
);
435 gc
= XCreateGC(dpy
, pix
, 0, NULL
);
437 XSetForeground(dpy
, gc
, 0);
438 XFillRectangle(dpy
, pix
, gc
, 0, 0, 7, 7);
440 XSetForeground(dpy
, gc
, 1);
441 XDrawLine(dpy
, pix
, gc
, 0, 3, 6, 3);
442 XDrawLine(dpy
, pix
, gc
, 3, 0, 3, 6);
444 panel
->markerPix
[ExternalInfo
] = pixm
;
445 panel
->markerPix
[PipeInfo
] = pixm
;
446 panel
->markerPix
[DirectoryInfo
] = pixm
;
447 panel
->markerPix
[WSMenuInfo
] = pixm
;
448 panel
->markerPix
[WWindowListInfo
] = pixm
;
453 panel
->box
= WMCreateBox(panel
->parent
);
454 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
456 panel
->typeP
= WMCreatePopUpButton(panel
->box
);
457 WMResizeWidget(panel
->typeP
, 150, 20);
458 WMMoveWidget(panel
->typeP
, 10, 10);
460 WMAddPopUpButtonItem(panel
->typeP
, _("New Items"));
461 WMAddPopUpButtonItem(panel
->typeP
, _("Sample Commands"));
462 WMAddPopUpButtonItem(panel
->typeP
, _("Sample Submenus"));
464 WMSetPopUpButtonAction(panel
->typeP
, changedItemPad
, panel
);
466 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
473 pad
= makeFactoryMenu(panel
->box
, 150);
474 WMMoveWidget(pad
, 10, 40);
476 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"));
485 panel
->itemPad
[0] = pad
;
493 sview
= WMCreateScrollView(panel
->box
);
494 WMResizeWidget(sview
, 150, 180);
495 WMMoveWidget(sview
, 10, 40);
496 WMSetScrollViewHasVerticalScroller(sview
, True
);
498 pad
= makeFactoryMenu(panel
->box
, 130);
500 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
502 data
= putNewItem(panel
, pad
, ExecInfo
, _("XTerm"));
503 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
505 data
= putNewItem(panel
, pad
, ExecInfo
, _("rxvt"));
506 data
->param
.exec
.command
= "rxvt";
508 data
= putNewItem(panel
, pad
, ExecInfo
, _("ETerm"));
509 data
->param
.exec
.command
= "eterm";
511 data
= putNewItem(panel
, pad
, ExecInfo
, _("Run..."));
512 data
->param
.exec
.command
= _("%a(Run,Type command to run)");
514 data
= putNewItem(panel
, pad
, ExecInfo
, _("Netscape"));
515 data
->param
.exec
.command
= "netscape";
517 data
= putNewItem(panel
, pad
, ExecInfo
, _("gimp"));
518 data
->param
.exec
.command
= "gimp";
520 data
= putNewItem(panel
, pad
, ExecInfo
, _("epic"));
521 data
->param
.exec
.command
= "xterm -e epic";
523 data
= putNewItem(panel
, pad
, ExecInfo
, _("ee"));
524 data
->param
.exec
.command
= "ee";
526 data
= putNewItem(panel
, pad
, ExecInfo
, _("xv"));
527 data
->param
.exec
.command
= "xv";
529 data
= putNewItem(panel
, pad
, ExecInfo
, _("Acrobat Reader"));
530 data
->param
.exec
.command
= "acroread || /usr/local/Acrobat4/bin/acroread";
532 data
= putNewItem(panel
, pad
, ExecInfo
, _("ghostview"));
533 data
->param
.exec
.command
= "gv";
535 data
= putNewItem(panel
, pad
, CommandInfo
, _("Exit Window Maker"));
536 data
->param
.command
.command
= 3;
540 panel
->itemPad
[1] = sview
;
544 WEditMenu
*pad
, *smenu
;
548 sview
= WMCreateScrollView(panel
->box
);
549 WMResizeWidget(sview
, 150, 180);
550 WMMoveWidget(sview
, 10, 40);
551 WMSetScrollViewHasVerticalScroller(sview
, True
);
553 pad
= makeFactoryMenu(panel
->box
, 130);
555 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
557 data
= putNewItem(panel
, pad
, ExternalInfo
, _("Debian Menu"));
558 data
->param
.pipe
.command
= "/etc/X11/WindowMaker/menu.hook";
560 data
= putNewItem(panel
, pad
, PipeInfo
, _("RedHat Menu"));
561 data
->param
.pipe
.command
= "wmconfig --output wmaker";
563 data
= putNewItem(panel
, pad
, PipeInfo
, _("Menu Conectiva"));
564 data
->param
.pipe
.command
= "wmconfig --output wmaker";
566 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;
572 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;
578 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;
584 smenu
= putNewSubmenu(pad
, _("Assorted XTerms"));
586 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Yellow on Blue"));
587 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg midnightblue -fg yellow";
589 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Black"));
590 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
592 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on White"));
593 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg white -fg black";
595 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on Beige"));
596 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#bbbb99' -fg black";
598 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Green"));
599 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#228822' -fg white";
601 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Olive"));
602 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#335533' -fg white";
604 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Blue on Blue"));
605 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#112244' -fg '#88aabb'";
607 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm BIG FONTS"));
608 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white -fn 10x20";
612 panel
->itemPad
[2] = sview
;
615 width
= FRAME_WIDTH
- 20 - 150 - 10 - 2;
617 panel
->optionsF
= WMCreateFrame(panel
->box
);
618 WMResizeWidget(panel
->optionsF
, width
, FRAME_HEIGHT
- 15);
619 WMMoveWidget(panel
->optionsF
, 10 + 150 + 10, 5);
625 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
);
631 panel
->commandT
= WMCreateTextField(panel
->commandF
);
632 WMResizeWidget(panel
->commandT
, width
- 95, 20);
633 WMMoveWidget(panel
->commandT
, 10, 20);
635 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
);
641 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->commandT
);
644 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"));
649 WMMapSubwidgets(panel
->commandF
);
653 panel
->pathF
= WMCreateFrame(panel
->optionsF
);
654 WMResizeWidget(panel
->pathF
, width
, 150);
655 WMMoveWidget(panel
->pathF
, 10, 40);
656 WMSetFrameTitle(panel
->pathF
, _("Path for Menu"));
658 panel
->pathT
= WMCreateTextField(panel
->pathF
);
659 WMResizeWidget(panel
->pathT
, width
- 20, 20);
660 WMMoveWidget(panel
->pathT
, 10, 20);
662 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->pathT
);
664 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"));
672 WMMapSubwidgets(panel
->pathF
);
676 panel
->pipeF
= WMCreateFrame(panel
->optionsF
);
677 WMResizeWidget(panel
->pipeF
, width
, 155);
678 WMMoveWidget(panel
->pipeF
, 10, 30);
679 WMSetFrameTitle(panel
->pipeF
, _("Command"));
681 panel
->pipeT
= WMCreateTextField(panel
->pipeF
);
682 WMResizeWidget(panel
->pipeT
, width
- 20, 20);
683 WMMoveWidget(panel
->pipeT
, 10, 20);
685 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->pipeT
);
687 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."));
692 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"));
697 WMMapSubwidgets(panel
->pipeF
);
701 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"));
706 panel
->dcommandT
= WMCreateTextField(panel
->dcommandF
);
707 WMResizeWidget(panel
->dcommandT
, width
- 20, 20);
708 WMMoveWidget(panel
->dcommandT
, 10, 20);
710 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->dcommandT
);
712 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."));
718 WMMapSubwidgets(panel
->dcommandF
);
720 panel
->dpathF
= WMCreateFrame(panel
->optionsF
);
721 WMResizeWidget(panel
->dpathF
, width
, 80);
722 WMMoveWidget(panel
->dpathF
, 10, 125);
723 WMSetFrameTitle(panel
->dpathF
, _("Directories with Files"));
725 panel
->dpathT
= WMCreateTextField(panel
->dpathF
);
726 WMResizeWidget(panel
->dpathT
, width
- 20, 20);
727 WMMoveWidget(panel
->dpathT
, 10, 20);
729 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->dpathT
);
731 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"));
736 WMSetButtonAction(panel
->dstripB
, buttonClicked
, panel
);
738 WMMapSubwidgets(panel
->dpathF
);
742 panel
->shortF
= WMCreateFrame(panel
->optionsF
);
743 WMResizeWidget(panel
->shortF
, width
, 50);
744 WMMoveWidget(panel
->shortF
, 10, 160);
745 WMSetFrameTitle(panel
->shortF
, _("Keyboard Shortcut"));
747 panel
->shortT
= WMCreateTextField(panel
->shortF
);
748 WMResizeWidget(panel
->shortT
, width
- 20 - 150, 20);
749 WMMoveWidget(panel
->shortT
, 10, 20);
751 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->shortT
);
753 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
);
759 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
);
765 WMMapSubwidgets(panel
->shortF
);
767 /* internal command */
769 panel
->icommandL
= WMCreateList(panel
->optionsF
);
770 WMResizeWidget(panel
->icommandL
, width
, 80);
771 WMMoveWidget(panel
->icommandL
, 10, 20);
773 WMSetListAction(panel
->icommandL
, icommandLClicked
, panel
);
775 WMAddNotificationObserver(dataChanged
, panel
, WMListSelectionDidChangeNotification
, panel
->icommandL
);
777 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"));
781 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 : ("));
786 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"));
792 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"));
797 panel
->paramT
= WMCreateTextField(panel
->paramF
);
798 WMResizeWidget(panel
->paramT
, width
- 20, 20);
799 WMMoveWidget(panel
->paramT
, 10, 20);
801 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->paramT
);
803 WMMapSubwidgets(panel
->paramF
);
805 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
);
811 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"));
824 WMRealizeWidget(panel
->box
);
825 WMMapSubwidgets(panel
->box
);
826 WMMapWidget(panel
->box
);
830 for (i
= 0; i
< 3; i
++)
831 WMUnmapWidget(panel
->itemPad
[i
]);
833 changedItemPad(panel
->typeP
, panel
);
835 panel
->sections
[NoInfo
][0] = label
;
837 panel
->sections
[ExecInfo
][0] = panel
->commandF
;
838 panel
->sections
[ExecInfo
][1] = panel
->shortF
;
840 panel
->sections
[CommandInfo
][0] = panel
->icommandL
;
841 panel
->sections
[CommandInfo
][1] = panel
->shortF
;
843 panel
->sections
[ExternalInfo
][0] = panel
->pathF
;
845 panel
->sections
[PipeInfo
][0] = panel
->pipeF
;
847 panel
->sections
[DirectoryInfo
][0] = panel
->dpathF
;
848 panel
->sections
[DirectoryInfo
][1] = panel
->dcommandF
;
850 panel
->currentType
= NoInfo
;
857 pos
= WMGetViewScreenPosition(WMWidgetView(panel
->box
));
860 pos
.x
+= FRAME_WIDTH
+ 20;
865 pos
.y
= WMAX(pos
.y
- 100, 0);
868 WEditMenuShowAt(panel
->menu
, pos
.x
, pos
.y
);
872 static void freeItemData(ItemData
* data
)
874 #define CFREE(d) if (d) wfree(d)
877 switch (data
->type
) {
879 CFREE(data
->param
.command
.parameter
);
880 CFREE(data
->param
.command
.shortcut
);
884 CFREE(data
->param
.exec
.command
);
885 CFREE(data
->param
.exec
.shortcut
);
889 CFREE(data
->param
.pipe
.command
);
893 CFREE(data
->param
.external
.path
);
897 CFREE(data
->param
.directory
.command
);
898 CFREE(data
->param
.directory
.directory
);
909 static ItemData
*parseCommand(WMPropList
* item
)
911 ItemData
*data
= NEW(ItemData
);
913 char *command
= NULL
;
914 char *parameter
= NULL
;
915 char *shortcut
= NULL
;
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
);
926 p
= WMGetFromPLArray(item
, i
++);
928 parameter
= WMGetFromPLString(p
);
930 if (strcmp(command
, "EXEC") == 0 || strcmp(command
, "SHEXEC") == 0) {
932 data
->type
= ExecInfo
;
934 data
->param
.exec
.command
= wstrdup(parameter
);
936 data
->param
.exec
.shortcut
= wstrdup(shortcut
);
938 } else if (strcmp(command
, "OPEN_MENU") == 0) {
941 * dir menu, menu file
946 while (isspace(*p
) && *p
)
949 if (*(p
+ 1) == '|') {
951 data
->param
.pipe
.cached
= 0;
953 data
->param
.pipe
.cached
= 1;
955 data
->type
= PipeInfo
;
956 data
->param
.pipe
.command
= wtrimspace(p
+ 1);
962 s
= strstr(p
, "WITH");
969 data
->type
= DirectoryInfo
;
973 while (*s
&& isspace(*s
))
975 data
->param
.directory
.command
= wstrdup(s
);
977 wtokensplit(p
, &tokens
, &tokn
);
980 ctokens
= wmalloc(sizeof(char *) * tokn
);
982 for (i
= 0, j
= 0; i
< tokn
; i
++) {
983 if (strcmp(tokens
[i
], "-noext") == 0) {
984 data
->param
.directory
.stripExt
= 1;
986 ctokens
[j
++] = tokens
[i
];
989 data
->param
.directory
.directory
= wtokenjoin(ctokens
, j
);
992 wtokenfree(tokens
, tokn
);
994 data
->type
= ExternalInfo
;
995 data
->param
.external
.path
= p
;
998 } else if (strcmp(command
, "WORKSPACE_MENU") == 0) {
999 data
->type
= WSMenuInfo
;
1000 } else if (strcmp(command
, "WINDOWS_MENU") == 0) {
1001 data
->type
= WWindowListInfo
;
1005 if (strcmp(command
, "ARRANGE_ICONS") == 0) {
1007 } else if (strcmp(command
, "HIDE_OTHERS") == 0) {
1009 } else if (strcmp(command
, "SHOW_ALL") == 0) {
1011 } else if (strcmp(command
, "EXIT") == 0) {
1013 } else if (strcmp(command
, "SHUTDOWN") == 0) {
1015 } else if (strcmp(command
, "RESTART") == 0) {
1021 } else if (strcmp(command
, "SAVE_SESSION") == 0) {
1023 } else if (strcmp(command
, "CLEAR_SESSION") == 0) {
1025 } else if (strcmp(command
, "REFRESH") == 0) {
1027 } else if (strcmp(command
, "INFO_PANEL") == 0) {
1029 } else if (strcmp(command
, "LEGAL_PANEL") == 0) {
1032 wwarning(_("unknown command '%s' in menu"), command
);
1036 data
->type
= CommandInfo
;
1038 data
->param
.command
.command
= cmd
;
1040 data
->param
.command
.shortcut
= wstrdup(shortcut
);
1042 data
->param
.command
.parameter
= wstrdup(parameter
);
1053 static void updateFrameTitle(_Panel
* panel
, char *title
, InfoType type
)
1055 if (type
!= NoInfo
) {
1060 tmp
= wstrconcat(title
, _(": Execute Program"));
1064 tmp
= wstrconcat(title
, _(": Perform Internal Command"));
1068 tmp
= wstrconcat(title
, _(": Open a Submenu"));
1072 tmp
= wstrconcat(title
, _(": Program Generated Submenu"));
1076 tmp
= wstrconcat(title
, _(": Directory Contents Menu"));
1080 tmp
= wstrconcat(title
, _(": Open Workspaces Submenu"));
1083 case WWindowListInfo
:
1084 tmp
= wstrconcat(title
, _(": Open Window List Submenu"));
1091 WMSetFrameTitle(panel
->optionsF
, tmp
);
1094 WMSetFrameTitle(panel
->optionsF
, NULL
);
1098 static void changeInfoType(_Panel
* panel
, char *title
, InfoType type
)
1102 if (panel
->currentType
!= type
) {
1104 w
= panel
->sections
[panel
->currentType
];
1110 WMUnmapWidget(panel
->paramF
);
1111 WMUnmapWidget(panel
->quickB
);
1113 w
= panel
->sections
[type
];
1121 updateFrameTitle(panel
, title
, type
);
1123 panel
->currentType
= type
;
1126 static void updateMenuItem(_Panel
* panel
, WEditMenuItem
* item
, WMWidget
* changedWidget
)
1128 ItemData
*data
= WGetEditMenuItemData(item
);
1130 assert(data
!= NULL
);
1132 #define REPLACE(v, d) if (v) wfree(v); v = d
1134 switch (data
->type
) {
1136 if (changedWidget
== panel
->commandT
) {
1137 REPLACE(data
->param
.exec
.command
, WMGetTextFieldText(panel
->commandT
));
1139 if (changedWidget
== panel
->shortT
) {
1140 REPLACE(data
->param
.exec
.shortcut
, WMGetTextFieldText(panel
->shortT
));
1145 if (changedWidget
== panel
->icommandL
) {
1146 data
->param
.command
.command
= WMGetListSelectedItemRow(panel
->icommandL
);
1148 switch (data
->param
.command
.command
) {
1151 if (changedWidget
== panel
->quickB
) {
1152 REPLACE(data
->param
.command
.parameter
, WMGetButtonSelected(panel
->quickB
)
1153 ? wstrdup("QUICK") : NULL
);
1158 if (changedWidget
== panel
->paramT
) {
1159 REPLACE(data
->param
.command
.parameter
, WMGetTextFieldText(panel
->paramT
));
1163 if (changedWidget
== panel
->shortT
) {
1164 REPLACE(data
->param
.command
.shortcut
, WMGetTextFieldText(panel
->shortT
));
1170 if (changedWidget
== panel
->pipeT
) {
1171 REPLACE(data
->param
.pipe
.command
, WMGetTextFieldText(panel
->pipeT
));
1173 if (changedWidget
== panel
->pipeCacheB
) {
1174 data
->param
.pipe
.cached
= WMGetButtonSelected(panel
->pipeCacheB
);
1179 if (changedWidget
== panel
->pathT
) {
1180 REPLACE(data
->param
.external
.path
, WMGetTextFieldText(panel
->pathT
));
1185 if (changedWidget
== panel
->dpathT
) {
1186 REPLACE(data
->param
.directory
.directory
, WMGetTextFieldText(panel
->dpathT
));
1188 if (changedWidget
== panel
->dcommandT
) {
1189 REPLACE(data
->param
.directory
.command
, WMGetTextFieldText(panel
->dcommandT
));
1191 if (changedWidget
== panel
->dstripB
) {
1192 data
->param
.directory
.stripExt
= WMGetButtonSelected(panel
->dstripB
);
1205 menuItemCloned(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* origItem
, WEditMenuItem
* newItem
)
1207 ItemData
*data
= WGetEditMenuItemData(origItem
);
1213 #define DUP(s) (s) ? wstrdup(s) : NULL
1215 newData
= NEW(ItemData
);
1217 newData
->type
= data
->type
;
1219 switch (data
->type
) {
1221 newData
->param
.exec
.command
= DUP(data
->param
.exec
.command
);
1222 newData
->param
.exec
.shortcut
= DUP(data
->param
.exec
.shortcut
);
1226 newData
->param
.command
.command
= data
->param
.command
.command
;
1227 newData
->param
.command
.parameter
= DUP(data
->param
.command
.parameter
);
1228 newData
->param
.command
.shortcut
= DUP(data
->param
.command
.shortcut
);
1232 newData
->param
.pipe
.command
= DUP(data
->param
.pipe
.command
);
1233 newData
->param
.pipe
.cached
= data
->param
.pipe
.cached
;
1237 newData
->param
.external
.path
= DUP(data
->param
.external
.path
);
1241 newData
->param
.directory
.directory
= DUP(data
->param
.directory
.directory
);
1242 newData
->param
.directory
.command
= DUP(data
->param
.directory
.command
);
1243 newData
->param
.directory
.stripExt
= data
->param
.directory
.stripExt
;
1252 WSetEditMenuItemData(newItem
, newData
, (WMCallback
*) freeItemData
);
1255 static void menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1257 _Panel
*panel
= (_Panel
*) delegate
->data
;
1260 updateFrameTitle(panel
, WGetEditMenuItemTitle(item
), panel
->currentType
);
1262 submenu
= WGetEditMenuSubmenu(menu
, item
);
1264 WSetEditMenuTitle(submenu
, WGetEditMenuItemTitle(item
));
1268 static Bool
shouldRemoveItem(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1270 _Panel
*panel
= (_Panel
*) delegate
->data
;
1275 if (WGetEditMenuSubmenu(menu
, item
)) {
1278 res
= WMRunAlertPanel(WMWidgetScreen(menu
), NULL
,
1279 _("Remove Submenu"),
1280 _("Removing this item will destroy all items inside\n"
1281 "the submenu. Do you really want to do that?"),
1282 _("Yes"), _("No"), _("Yes, don't ask again."));
1289 panel
->dontAsk
= True
;
1296 static void menuItemDeselected(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1298 _Panel
*panel
= (_Panel
*) delegate
->data
;
1300 changeInfoType(panel
, NULL
, NoInfo
);
1303 static void menuItemSelected(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1305 ItemData
*data
= WGetEditMenuItemData(item
);
1306 _Panel
*panel
= (_Panel
*) delegate
->data
;
1308 panel
->currentItem
= item
;
1311 changeInfoType(panel
, WGetEditMenuItemTitle(item
), data
->type
);
1313 switch (data
->type
) {
1318 WMSetTextFieldText(panel
->commandT
, data
->param
.exec
.command
);
1319 WMSetTextFieldText(panel
->shortT
, data
->param
.exec
.shortcut
);
1323 WMSelectListItem(panel
->icommandL
, data
->param
.command
.command
);
1324 WMSetListPosition(panel
->icommandL
, data
->param
.command
.command
- 2);
1325 WMSetTextFieldText(panel
->shortT
, data
->param
.command
.shortcut
);
1327 switch (data
->param
.command
.command
) {
1330 WMSetButtonSelected(panel
->quickB
, data
->param
.command
.parameter
!= NULL
);
1333 WMSetTextFieldText(panel
->paramT
, data
->param
.command
.parameter
);
1337 icommandLClicked(panel
->icommandL
, panel
);
1341 WMSetTextFieldText(panel
->pipeT
, data
->param
.pipe
.command
);
1342 WMSetButtonSelected(panel
->pipeCacheB
, data
->param
.pipe
.cached
);
1346 WMSetTextFieldText(panel
->pathT
, data
->param
.external
.path
);
1350 WMSetTextFieldText(panel
->dpathT
, data
->param
.directory
.directory
);
1351 WMSetTextFieldText(panel
->dcommandT
, data
->param
.directory
.command
);
1352 WMSetButtonSelected(panel
->dstripB
, data
->param
.directory
.stripExt
);
1364 static WEditMenu
*buildSubmenu(_Panel
* panel
, WMPropList
* pl
)
1366 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1368 WEditMenuItem
*item
;
1370 WMPropList
*tp
, *bp
;
1373 tp
= WMGetFromPLArray(pl
, 0);
1374 title
= WMGetFromPLString(tp
);
1376 menu
= WCreateEditMenu(scr
, title
);
1378 for (i
= 1; i
< WMGetPropListItemCount(pl
); i
++) {
1381 pi
= WMGetFromPLArray(pl
, i
);
1383 tp
= WMGetFromPLArray(pi
, 0);
1384 bp
= WMGetFromPLArray(pi
, 1);
1386 title
= WMGetFromPLString(tp
);
1388 if (!bp
|| WMIsPLArray(bp
)) { /* it's a submenu */
1391 submenu
= buildSubmenu(panel
, pi
);
1393 item
= WAddMenuItemWithTitle(menu
, title
);
1395 WSetEditMenuSubmenu(menu
, item
, submenu
);
1399 item
= WAddMenuItemWithTitle(menu
, title
);
1401 data
= parseCommand(pi
);
1403 if (panel
->markerPix
[data
->type
])
1404 WSetEditMenuItemImage(item
, panel
->markerPix
[data
->type
]);
1405 WSetEditMenuItemData(item
, data
, (WMCallback
*) freeItemData
);
1409 WSetEditMenuAcceptsDrop(menu
, True
);
1410 WSetEditMenuDelegate(menu
, &menuDelegate
);
1412 WMRealizeWidget(menu
);
1417 static void buildMenuFromPL(_Panel
* panel
, WMPropList
* pl
)
1419 panel
->menu
= buildSubmenu(panel
, pl
);
1422 static WMPropList
*getDefaultMenu(_Panel
* panel
)
1425 char *menuPath
, *gspath
;
1427 gspath
= wusergnusteppath();
1429 menuPath
= wmalloc(strlen(gspath
) + 128);
1430 sprintf(menuPath
, "%s/Library/WindowMaker/plmenu", gspath
);
1432 menu
= WMReadPropListFromFile(menuPath
);
1437 msg
= _("Could not open default menu from '%s'");
1438 buffer
= wmalloc(strlen(msg
) + strlen(menuPath
) + 10);
1439 sprintf(buffer
, msg
, menuPath
);
1440 WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1441 _("Error"), buffer
, _("OK"), NULL
, NULL
);
1450 static void showData(_Panel
* panel
)
1456 gspath
= wusergnusteppath();
1458 menuPath
= wmalloc(strlen(gspath
) + 32);
1459 strcpy(menuPath
, gspath
);
1460 strcat(menuPath
, "/Defaults/WMRootMenu");
1462 pmenu
= WMReadPropListFromFile(menuPath
);
1464 if (!pmenu
|| !WMIsPLArray(pmenu
)) {
1467 res
= WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1469 _("The menu file format currently in use is not supported\n"
1470 "by this tool. Do you want to discard the current menu\n"
1471 "to use this tool?"),
1472 _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL
);
1474 if (res
== WAPRDefault
) {
1475 pmenu
= getDefaultMenu(panel
);
1478 pmenu
= WMCreatePLArray(WMCreatePLString("Applications"), NULL
);
1481 panel
->dontSave
= True
;
1486 panel
->menuPath
= menuPath
;
1488 buildMenuFromPL(panel
, pmenu
);
1490 WMReleasePropList(pmenu
);
1493 static Bool
notblank(char *s
)
1504 static WMPropList
*processData(char *title
, ItemData
* data
)
1508 static WMPropList
*pscut
= NULL
;
1509 static WMPropList
*pomenu
= NULL
;
1513 pscut
= WMCreatePLString("SHORTCUT");
1514 pomenu
= WMCreatePLString("OPEN_MENU");
1517 item
= WMCreatePLArray(WMCreatePLString(title
), NULL
);
1519 switch (data
->type
) {
1521 if (data
->param
.exec
.command
== NULL
)
1524 if (strpbrk(data
->param
.exec
.command
, "&$*|><?`=;")) {
1533 if (notblank(data
->param
.exec
.shortcut
)) {
1534 WMAddToPLArray(item
, pscut
);
1535 WMAddToPLArray(item
, WMCreatePLString(data
->param
.exec
.shortcut
));
1538 WMAddToPLArray(item
, WMCreatePLString(s1
));
1539 WMAddToPLArray(item
, WMCreatePLString(data
->param
.exec
.command
));
1543 if (notblank(data
->param
.command
.shortcut
)) {
1544 WMAddToPLArray(item
, pscut
);
1545 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.shortcut
));
1548 i
= data
->param
.command
.command
;
1550 WMAddToPLArray(item
, WMCreatePLString(commandNames
[i
]));
1555 if (data
->param
.command
.parameter
) {
1556 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.parameter
));
1560 case 6: /* restart */
1561 if (data
->param
.command
.parameter
) {
1562 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.parameter
));
1570 if (!data
->param
.pipe
.command
)
1572 WMAddToPLArray(item
, pomenu
);
1573 if (data
->param
.pipe
.cached
)
1574 s1
= wstrconcat("| ", data
->param
.pipe
.command
);
1576 s1
= wstrconcat("|| ", data
->param
.pipe
.command
);
1577 WMAddToPLArray(item
, WMCreatePLString(s1
));
1582 if (!data
->param
.external
.path
)
1584 WMAddToPLArray(item
, pomenu
);
1585 WMAddToPLArray(item
, WMCreatePLString(data
->param
.external
.path
));
1589 if (!data
->param
.directory
.directory
|| !data
->param
.directory
.command
)
1595 l
= strlen(data
->param
.directory
.directory
);
1596 l
+= strlen(data
->param
.directory
.command
);
1599 WMAddToPLArray(item
, pomenu
);
1602 sprintf(tmp
, "%s%s WITH %s",
1603 data
->param
.directory
.stripExt
? "-noext " : "",
1604 data
->param
.directory
.directory
, data
->param
.directory
.command
);
1606 WMAddToPLArray(item
, WMCreatePLString(tmp
));
1612 WMAddToPLArray(item
, WMCreatePLString("WORKSPACE_MENU"));
1615 case WWindowListInfo
:
1616 WMAddToPLArray(item
, WMCreatePLString("WINDOWS_MENU"));
1627 static WMPropList
*processSubmenu(WEditMenu
* menu
)
1629 WEditMenuItem
*item
;
1635 s
= WGetEditMenuTitle(menu
);
1636 pl
= WMCreatePLString(s
);
1638 pmenu
= WMCreatePLArray(pl
, NULL
);
1641 while ((item
= WGetEditMenuItem(menu
, i
++))) {
1644 s
= WGetEditMenuItemTitle(item
);
1646 submenu
= WGetEditMenuSubmenu(menu
, item
);
1648 pl
= processSubmenu(submenu
);
1650 pl
= processData(s
, WGetEditMenuItemData(item
));
1656 WMAddToPLArray(pmenu
, pl
);
1662 static WMPropList
*buildPLFromMenu(_Panel
* panel
)
1666 menu
= processSubmenu(panel
->menu
);
1671 static void storeData(_Panel
* panel
)
1675 if (panel
->dontSave
)
1678 menu
= buildPLFromMenu(panel
);
1680 WMWritePropListToFile(menu
, panel
->menuPath
, True
);
1682 WMReleasePropList(menu
);
1685 static void showMenus(_Panel
* panel
)
1688 WEditMenuUnhide(panel
->menu
);
1691 static void hideMenus(_Panel
* panel
)
1694 WEditMenuHide(panel
->menu
);
1697 Panel
*InitMenu(WMScreen
* scr
, WMWidget
* parent
)
1701 panel
= wmalloc(sizeof(_Panel
));
1702 memset(panel
, 0, sizeof(_Panel
));
1704 panel
->sectionName
= _("Applications Menu Definition");
1706 panel
->description
= _("Edit the menu for launching applications.");
1708 panel
->parent
= parent
;
1710 panel
->callbacks
.createWidgets
= createPanel
;
1711 panel
->callbacks
.updateDomain
= storeData
;
1712 panel
->callbacks
.showPanel
= showMenus
;
1713 panel
->callbacks
.hidePanel
= hideMenus
;
1715 AddSection(panel
, ICON_FILE
);