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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/keysym.h>
27 #include <X11/cursorfont.h>
43 #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);
471 pad
= makeFactoryMenu(panel
->box
, 150);
472 WMMoveWidget(pad
, 10, 40);
474 putNewItem(panel
, pad
, ExecInfo
, _("Run Program"));
475 putNewItem(panel
, pad
, CommandInfo
, _("Internal Command"));
476 putNewSubmenu(pad
, _("Submenu"));
477 putNewItem(panel
, pad
, ExternalInfo
, _("External Submenu"));
478 putNewItem(panel
, pad
, PipeInfo
, _("Generated Submenu"));
479 putNewItem(panel
, pad
, DirectoryInfo
, _("Directory Contents"));
480 putNewItem(panel
, pad
, WSMenuInfo
, _("Workspace Menu"));
481 putNewItem(panel
, pad
, WWindowListInfo
, _("Window List Menu"));
483 panel
->itemPad
[0] = pad
;
491 sview
= WMCreateScrollView(panel
->box
);
492 WMResizeWidget(sview
, 150, 180);
493 WMMoveWidget(sview
, 10, 40);
494 WMSetScrollViewHasVerticalScroller(sview
, True
);
496 pad
= makeFactoryMenu(panel
->box
, 130);
498 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
500 data
= putNewItem(panel
, pad
, ExecInfo
, _("XTerm"));
501 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
503 data
= putNewItem(panel
, pad
, ExecInfo
, _("rxvt"));
504 data
->param
.exec
.command
= "rxvt";
506 data
= putNewItem(panel
, pad
, ExecInfo
, _("ETerm"));
507 data
->param
.exec
.command
= "eterm";
509 data
= putNewItem(panel
, pad
, ExecInfo
, _("Run..."));
510 data
->param
.exec
.command
= _("%A(Run,Type command to run)");
512 data
= putNewItem(panel
, pad
, ExecInfo
, _("Firefox"));
513 data
->param
.exec
.command
= "firefox";
515 data
= putNewItem(panel
, pad
, ExecInfo
, _("gimp"));
516 data
->param
.exec
.command
= "gimp";
518 data
= putNewItem(panel
, pad
, ExecInfo
, _("epic"));
519 data
->param
.exec
.command
= "xterm -e epic";
521 data
= putNewItem(panel
, pad
, ExecInfo
, _("ee"));
522 data
->param
.exec
.command
= "ee";
524 data
= putNewItem(panel
, pad
, ExecInfo
, _("xv"));
525 data
->param
.exec
.command
= "xv";
527 data
= putNewItem(panel
, pad
, ExecInfo
, _("Evince"));
528 data
->param
.exec
.command
= "evince";
530 data
= putNewItem(panel
, pad
, ExecInfo
, _("ghostview"));
531 data
->param
.exec
.command
= "gv";
533 data
= putNewItem(panel
, pad
, CommandInfo
, _("Exit Window Maker"));
534 data
->param
.command
.command
= 3;
538 panel
->itemPad
[1] = sview
;
542 WEditMenu
*pad
, *smenu
;
546 sview
= WMCreateScrollView(panel
->box
);
547 WMResizeWidget(sview
, 150, 180);
548 WMMoveWidget(sview
, 10, 40);
549 WMSetScrollViewHasVerticalScroller(sview
, True
);
551 pad
= makeFactoryMenu(panel
->box
, 130);
553 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
555 data
= putNewItem(panel
, pad
, ExternalInfo
, _("Debian Menu"));
556 data
->param
.pipe
.command
= "/etc/X11/WindowMaker/menu.hook";
558 data
= putNewItem(panel
, pad
, PipeInfo
, _("RedHat Menu"));
559 data
->param
.pipe
.command
= "wmconfig --output wmaker";
561 data
= putNewItem(panel
, pad
, PipeInfo
, _("Menu Conectiva"));
562 data
->param
.pipe
.command
= "wmconfig --output wmaker";
564 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Themes"));
565 data
->param
.directory
.command
= "setstyle";
566 data
->param
.directory
.directory
=
567 "/usr/share/WindowMaker/Themes /usr/local/share/WindowMaker/Themes $HOME/GNUstep/Library/WindowMaker/Themes";
568 data
->param
.directory
.stripExt
= 1;
570 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Bg Images (scale)"));
571 data
->param
.directory
.command
= "wmsetbg -u -s";
572 data
->param
.directory
.directory
=
573 "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
574 data
->param
.directory
.stripExt
= 1;
576 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Bg Images (tile)"));
577 data
->param
.directory
.command
= "wmsetbg -u -t";
578 data
->param
.directory
.directory
=
579 "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
580 data
->param
.directory
.stripExt
= 1;
582 smenu
= putNewSubmenu(pad
, _("Assorted XTerms"));
584 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Yellow on Blue"));
585 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg midnightblue -fg yellow";
587 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Black"));
588 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
590 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on White"));
591 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg white -fg black";
593 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on Beige"));
594 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#bbbb99' -fg black";
596 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Green"));
597 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#228822' -fg white";
599 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Olive"));
600 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#335533' -fg white";
602 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Blue on Blue"));
603 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#112244' -fg '#88aabb'";
605 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm BIG FONTS"));
606 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white -fn 10x20";
610 panel
->itemPad
[2] = sview
;
613 width
= FRAME_WIDTH
- 20 - 150 - 10 - 2;
615 panel
->optionsF
= WMCreateFrame(panel
->box
);
616 WMResizeWidget(panel
->optionsF
, width
, FRAME_HEIGHT
- 15);
617 WMMoveWidget(panel
->optionsF
, 10 + 150 + 10, 5);
623 panel
->commandF
= WMCreateFrame(panel
->optionsF
);
624 WMResizeWidget(panel
->commandF
, width
, 50);
625 WMMoveWidget(panel
->commandF
, 10, 20);
626 WMSetFrameTitle(panel
->commandF
, _("Program to Run"));
627 WMSetFrameTitlePosition(panel
->commandF
, WTPAtTop
);
629 panel
->commandT
= WMCreateTextField(panel
->commandF
);
630 WMResizeWidget(panel
->commandT
, width
- 95, 20);
631 WMMoveWidget(panel
->commandT
, 10, 20);
633 panel
->browseB
= WMCreateCommandButton(panel
->commandF
);
634 WMResizeWidget(panel
->browseB
, 70, 24);
635 WMMoveWidget(panel
->browseB
, width
- 80, 18);
636 WMSetButtonText(panel
->browseB
, _("Browse"));
637 WMSetButtonAction(panel
->browseB
, browseForFile
, panel
);
639 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->commandT
);
642 panel
->xtermC
= WMCreateSwitchButton(panel
->commandF
);
643 WMResizeWidget(panel
->xtermC
, width
- 20, 20);
644 WMMoveWidget(panel
->xtermC
, 10, 50);
645 WMSetButtonText(panel
->xtermC
, _("Run the program inside a Xterm"));
647 WMMapSubwidgets(panel
->commandF
);
651 panel
->pathF
= WMCreateFrame(panel
->optionsF
);
652 WMResizeWidget(panel
->pathF
, width
, 150);
653 WMMoveWidget(panel
->pathF
, 10, 40);
654 WMSetFrameTitle(panel
->pathF
, _("Path for Menu"));
656 panel
->pathT
= WMCreateTextField(panel
->pathF
);
657 WMResizeWidget(panel
->pathT
, width
- 20, 20);
658 WMMoveWidget(panel
->pathT
, 10, 20);
660 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->pathT
);
662 label
= WMCreateLabel(panel
->pathF
);
663 WMResizeWidget(label
, width
- 20, 80);
664 WMMoveWidget(label
, 10, 50);
665 WMSetLabelText(label
, _("Enter the path for a file containing a menu\n"
666 "or a list of directories with the programs you\n"
667 "want to have listed in the menu. Ex:\n"
668 "~/GNUstep/Library/WindowMaker/menu\n" "or\n" "/usr/X11R6/bin ~/xbin"));
670 WMMapSubwidgets(panel
->pathF
);
674 panel
->pipeF
= WMCreateFrame(panel
->optionsF
);
675 WMResizeWidget(panel
->pipeF
, width
, 155);
676 WMMoveWidget(panel
->pipeF
, 10, 30);
677 WMSetFrameTitle(panel
->pipeF
, _("Command"));
679 panel
->pipeT
= WMCreateTextField(panel
->pipeF
);
680 WMResizeWidget(panel
->pipeT
, width
- 20, 20);
681 WMMoveWidget(panel
->pipeT
, 10, 20);
683 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->pipeT
);
685 label
= WMCreateLabel(panel
->pipeF
);
686 WMResizeWidget(label
, width
- 20, 40);
687 WMMoveWidget(label
, 10, 50);
688 WMSetLabelText(label
, _("Enter a command that outputs a menu\n" "definition to stdout when invoked."));
690 panel
->pipeCacheB
= WMCreateSwitchButton(panel
->pipeF
);
691 WMResizeWidget(panel
->pipeCacheB
, width
- 20, 40);
692 WMMoveWidget(panel
->pipeCacheB
, 10, 110);
693 WMSetButtonText(panel
->pipeCacheB
, _("Cache menu contents after opening for\n" "the first time"));
695 WMMapSubwidgets(panel
->pipeF
);
699 panel
->dcommandF
= WMCreateFrame(panel
->optionsF
);
700 WMResizeWidget(panel
->dcommandF
, width
, 90);
701 WMMoveWidget(panel
->dcommandF
, 10, 25);
702 WMSetFrameTitle(panel
->dcommandF
, _("Command to Open Files"));
704 panel
->dcommandT
= WMCreateTextField(panel
->dcommandF
);
705 WMResizeWidget(panel
->dcommandT
, width
- 20, 20);
706 WMMoveWidget(panel
->dcommandT
, 10, 20);
708 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->dcommandT
);
710 label
= WMCreateLabel(panel
->dcommandF
);
711 WMResizeWidget(label
, width
- 20, 45);
712 WMMoveWidget(label
, 10, 40);
713 WMSetLabelText(label
, _("Enter the command you want to use to open the\n"
714 "files in the directories listed below."));
716 WMMapSubwidgets(panel
->dcommandF
);
718 panel
->dpathF
= WMCreateFrame(panel
->optionsF
);
719 WMResizeWidget(panel
->dpathF
, width
, 80);
720 WMMoveWidget(panel
->dpathF
, 10, 125);
721 WMSetFrameTitle(panel
->dpathF
, _("Directories with Files"));
723 panel
->dpathT
= WMCreateTextField(panel
->dpathF
);
724 WMResizeWidget(panel
->dpathT
, width
- 20, 20);
725 WMMoveWidget(panel
->dpathT
, 10, 20);
727 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->dpathT
);
729 panel
->dstripB
= WMCreateSwitchButton(panel
->dpathF
);
730 WMResizeWidget(panel
->dstripB
, width
- 20, 20);
731 WMMoveWidget(panel
->dstripB
, 10, 50);
732 WMSetButtonText(panel
->dstripB
, _("Strip extensions from file names"));
734 WMSetButtonAction(panel
->dstripB
, buttonClicked
, panel
);
736 WMMapSubwidgets(panel
->dpathF
);
740 panel
->shortF
= WMCreateFrame(panel
->optionsF
);
741 WMResizeWidget(panel
->shortF
, width
, 50);
742 WMMoveWidget(panel
->shortF
, 10, 160);
743 WMSetFrameTitle(panel
->shortF
, _("Keyboard Shortcut"));
745 panel
->shortT
= WMCreateTextField(panel
->shortF
);
746 WMResizeWidget(panel
->shortT
, width
- 20 - 150, 20);
747 WMMoveWidget(panel
->shortT
, 10, 20);
749 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->shortT
);
751 panel
->sgrabB
= WMCreateCommandButton(panel
->shortF
);
752 WMResizeWidget(panel
->sgrabB
, 70, 24);
753 WMMoveWidget(panel
->sgrabB
, width
- 80, 18);
754 WMSetButtonText(panel
->sgrabB
, _("Capture"));
755 WMSetButtonAction(panel
->sgrabB
, sgrabClicked
, panel
);
757 panel
->sclearB
= WMCreateCommandButton(panel
->shortF
);
758 WMResizeWidget(panel
->sclearB
, 70, 24);
759 WMMoveWidget(panel
->sclearB
, width
- 155, 18);
760 WMSetButtonText(panel
->sclearB
, _("Clear"));
761 WMSetButtonAction(panel
->sclearB
, sgrabClicked
, panel
);
763 WMMapSubwidgets(panel
->shortF
);
765 /* internal command */
767 panel
->icommandL
= WMCreateList(panel
->optionsF
);
768 WMResizeWidget(panel
->icommandL
, width
, 80);
769 WMMoveWidget(panel
->icommandL
, 10, 20);
771 WMSetListAction(panel
->icommandL
, icommandLClicked
, panel
);
773 WMAddNotificationObserver(dataChanged
, panel
, WMListSelectionDidChangeNotification
, panel
->icommandL
);
775 WMInsertListItem(panel
->icommandL
, 0, _("Arrange Icons"));
776 WMInsertListItem(panel
->icommandL
, 1, _("Hide All Windows Except For The Focused One"));
777 WMInsertListItem(panel
->icommandL
, 2, _("Show All Windows"));
779 WMInsertListItem(panel
->icommandL
, 3, _("Exit Window Maker"));
780 WMInsertListItem(panel
->icommandL
, 4, _("Exit X Session"));
781 WMInsertListItem(panel
->icommandL
, 5, _("Restart Window Maker"));
782 WMInsertListItem(panel
->icommandL
, 6, _("Start Another Window Manager : ("));
784 WMInsertListItem(panel
->icommandL
, 7, _("Save Current Session"));
785 WMInsertListItem(panel
->icommandL
, 8, _("Clear Saved Session"));
786 WMInsertListItem(panel
->icommandL
, 9, _("Refresh Screen"));
787 WMInsertListItem(panel
->icommandL
, 10, _("Open Info Panel"));
788 WMInsertListItem(panel
->icommandL
, 11, _("Open Copyright Panel"));
790 panel
->paramF
= WMCreateFrame(panel
->optionsF
);
791 WMResizeWidget(panel
->paramF
, width
, 50);
792 WMMoveWidget(panel
->paramF
, 10, 105);
793 WMSetFrameTitle(panel
->paramF
, _("Window Manager to Start"));
795 panel
->paramT
= WMCreateTextField(panel
->paramF
);
796 WMResizeWidget(panel
->paramT
, width
- 20, 20);
797 WMMoveWidget(panel
->paramT
, 10, 20);
799 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->paramT
);
801 WMMapSubwidgets(panel
->paramF
);
803 panel
->quickB
= WMCreateSwitchButton(panel
->optionsF
);
804 WMResizeWidget(panel
->quickB
, width
, 20);
805 WMMoveWidget(panel
->quickB
, 10, 120);
806 WMSetButtonText(panel
->quickB
, _("Do not confirm action."));
807 WMSetButtonAction(panel
->quickB
, buttonClicked
, panel
);
809 label
= WMCreateLabel(panel
->optionsF
);
810 WMResizeWidget(label
, width
+ 5, FRAME_HEIGHT
- 50);
811 WMMoveWidget(label
, 7, 20);
812 WMSetLabelText(label
,
813 _("Instructions:\n\n"
814 " - drag items from the left to the menu to add new items\n"
815 " - drag items out of the menu to remove items\n"
816 " - drag items in menu to change their position\n"
817 " - drag items with Control pressed to copy them\n"
818 " - double click in a menu item to change the label\n"
819 " - click on a menu item to change related information"));
822 WMRealizeWidget(panel
->box
);
823 WMMapSubwidgets(panel
->box
);
824 WMMapWidget(panel
->box
);
828 for (i
= 0; i
< 3; i
++)
829 WMUnmapWidget(panel
->itemPad
[i
]);
831 changedItemPad(panel
->typeP
, panel
);
833 panel
->sections
[NoInfo
][0] = label
;
835 panel
->sections
[ExecInfo
][0] = panel
->commandF
;
836 panel
->sections
[ExecInfo
][1] = panel
->shortF
;
838 panel
->sections
[CommandInfo
][0] = panel
->icommandL
;
839 panel
->sections
[CommandInfo
][1] = panel
->shortF
;
841 panel
->sections
[ExternalInfo
][0] = panel
->pathF
;
843 panel
->sections
[PipeInfo
][0] = panel
->pipeF
;
845 panel
->sections
[DirectoryInfo
][0] = panel
->dpathF
;
846 panel
->sections
[DirectoryInfo
][1] = panel
->dcommandF
;
848 panel
->currentType
= NoInfo
;
855 pos
= WMGetViewScreenPosition(WMWidgetView(panel
->box
));
858 pos
.x
+= FRAME_WIDTH
+ 20;
863 pos
.y
= WMAX(pos
.y
- 100, 0);
866 WEditMenuShowAt(panel
->menu
, pos
.x
, pos
.y
);
870 static void freeItemData(ItemData
* data
)
872 #define CFREE(d) if (d) wfree(d)
875 switch (data
->type
) {
877 CFREE(data
->param
.command
.parameter
);
878 CFREE(data
->param
.command
.shortcut
);
882 CFREE(data
->param
.exec
.command
);
883 CFREE(data
->param
.exec
.shortcut
);
887 CFREE(data
->param
.pipe
.command
);
891 CFREE(data
->param
.external
.path
);
895 CFREE(data
->param
.directory
.command
);
896 CFREE(data
->param
.directory
.directory
);
907 static ItemData
*parseCommand(WMPropList
* item
)
909 ItemData
*data
= NEW(ItemData
);
911 char *command
= NULL
;
912 char *parameter
= NULL
;
913 char *shortcut
= NULL
;
916 p
= WMGetFromPLArray(item
, i
++);
917 command
= WMGetFromPLString(p
);
918 if (strcmp(command
, "SHORTCUT") == 0) {
919 p
= WMGetFromPLArray(item
, i
++);
920 shortcut
= WMGetFromPLString(p
);
921 p
= WMGetFromPLArray(item
, i
++);
922 command
= WMGetFromPLString(p
);
924 p
= WMGetFromPLArray(item
, i
++);
926 parameter
= WMGetFromPLString(p
);
928 if (strcmp(command
, "EXEC") == 0 || strcmp(command
, "SHEXEC") == 0) {
930 data
->type
= ExecInfo
;
932 data
->param
.exec
.command
= wstrdup(parameter
);
934 data
->param
.exec
.shortcut
= wstrdup(shortcut
);
936 } else if (strcmp(command
, "OPEN_MENU") == 0) {
939 * dir menu, menu file
944 while (isspace(*p
) && *p
)
947 if (*(p
+ 1) == '|') {
949 data
->param
.pipe
.cached
= 0;
951 data
->param
.pipe
.cached
= 1;
953 data
->type
= PipeInfo
;
954 data
->param
.pipe
.command
= wtrimspace(p
+ 1);
960 s
= strstr(p
, "WITH");
967 data
->type
= DirectoryInfo
;
971 while (*s
&& isspace(*s
))
973 data
->param
.directory
.command
= wstrdup(s
);
975 wtokensplit(p
, &tokens
, &tokn
);
978 ctokens
= wmalloc(sizeof(char *) * tokn
);
980 for (i
= 0, j
= 0; i
< tokn
; i
++) {
981 if (strcmp(tokens
[i
], "-noext") == 0) {
982 data
->param
.directory
.stripExt
= 1;
984 ctokens
[j
++] = tokens
[i
];
987 data
->param
.directory
.directory
= wtokenjoin(ctokens
, j
);
990 wtokenfree(tokens
, tokn
);
992 data
->type
= ExternalInfo
;
993 data
->param
.external
.path
= p
;
996 } else if (strcmp(command
, "WORKSPACE_MENU") == 0) {
997 data
->type
= WSMenuInfo
;
998 } else if (strcmp(command
, "WINDOWS_MENU") == 0) {
999 data
->type
= WWindowListInfo
;
1003 if (strcmp(command
, "ARRANGE_ICONS") == 0) {
1005 } else if (strcmp(command
, "HIDE_OTHERS") == 0) {
1007 } else if (strcmp(command
, "SHOW_ALL") == 0) {
1009 } else if (strcmp(command
, "EXIT") == 0) {
1011 } else if (strcmp(command
, "SHUTDOWN") == 0) {
1013 } else if (strcmp(command
, "RESTART") == 0) {
1019 } else if (strcmp(command
, "SAVE_SESSION") == 0) {
1021 } else if (strcmp(command
, "CLEAR_SESSION") == 0) {
1023 } else if (strcmp(command
, "REFRESH") == 0) {
1025 } else if (strcmp(command
, "INFO_PANEL") == 0) {
1027 } else if (strcmp(command
, "LEGAL_PANEL") == 0) {
1030 wwarning(_("unknown command '%s' in menu"), command
);
1035 data
->type
= CommandInfo
;
1037 data
->param
.command
.command
= cmd
;
1039 data
->param
.command
.shortcut
= wstrdup(shortcut
);
1041 data
->param
.command
.parameter
= wstrdup(parameter
);
1047 static void updateFrameTitle(_Panel
* panel
, char *title
, InfoType type
)
1049 if (type
!= NoInfo
) {
1054 tmp
= wstrconcat(title
, _(": Execute Program"));
1058 tmp
= wstrconcat(title
, _(": Perform Internal Command"));
1062 tmp
= wstrconcat(title
, _(": Open a Submenu"));
1066 tmp
= wstrconcat(title
, _(": Program Generated Submenu"));
1070 tmp
= wstrconcat(title
, _(": Directory Contents Menu"));
1074 tmp
= wstrconcat(title
, _(": Open Workspaces Submenu"));
1077 case WWindowListInfo
:
1078 tmp
= wstrconcat(title
, _(": Open Window List Submenu"));
1085 WMSetFrameTitle(panel
->optionsF
, tmp
);
1088 WMSetFrameTitle(panel
->optionsF
, NULL
);
1092 static void changeInfoType(_Panel
* panel
, char *title
, InfoType type
)
1096 if (panel
->currentType
!= type
) {
1098 w
= panel
->sections
[panel
->currentType
];
1104 WMUnmapWidget(panel
->paramF
);
1105 WMUnmapWidget(panel
->quickB
);
1107 w
= panel
->sections
[type
];
1115 updateFrameTitle(panel
, title
, type
);
1117 panel
->currentType
= type
;
1120 static void updateMenuItem(_Panel
* panel
, WEditMenuItem
* item
, WMWidget
* changedWidget
)
1122 ItemData
*data
= WGetEditMenuItemData(item
);
1124 assert(data
!= NULL
);
1126 #define REPLACE(v, d) if (v) wfree(v); v = d
1128 switch (data
->type
) {
1130 if (changedWidget
== panel
->commandT
) {
1131 REPLACE(data
->param
.exec
.command
, WMGetTextFieldText(panel
->commandT
));
1133 if (changedWidget
== panel
->shortT
) {
1134 REPLACE(data
->param
.exec
.shortcut
, WMGetTextFieldText(panel
->shortT
));
1139 if (changedWidget
== panel
->icommandL
) {
1140 data
->param
.command
.command
= WMGetListSelectedItemRow(panel
->icommandL
);
1142 switch (data
->param
.command
.command
) {
1145 if (changedWidget
== panel
->quickB
) {
1146 REPLACE(data
->param
.command
.parameter
, WMGetButtonSelected(panel
->quickB
)
1147 ? wstrdup("QUICK") : NULL
);
1152 if (changedWidget
== panel
->paramT
) {
1153 REPLACE(data
->param
.command
.parameter
, WMGetTextFieldText(panel
->paramT
));
1157 if (changedWidget
== panel
->shortT
) {
1158 REPLACE(data
->param
.command
.shortcut
, WMGetTextFieldText(panel
->shortT
));
1164 if (changedWidget
== panel
->pipeT
) {
1165 REPLACE(data
->param
.pipe
.command
, WMGetTextFieldText(panel
->pipeT
));
1167 if (changedWidget
== panel
->pipeCacheB
) {
1168 data
->param
.pipe
.cached
= WMGetButtonSelected(panel
->pipeCacheB
);
1173 if (changedWidget
== panel
->pathT
) {
1174 REPLACE(data
->param
.external
.path
, WMGetTextFieldText(panel
->pathT
));
1179 if (changedWidget
== panel
->dpathT
) {
1180 REPLACE(data
->param
.directory
.directory
, WMGetTextFieldText(panel
->dpathT
));
1182 if (changedWidget
== panel
->dcommandT
) {
1183 REPLACE(data
->param
.directory
.command
, WMGetTextFieldText(panel
->dcommandT
));
1185 if (changedWidget
== panel
->dstripB
) {
1186 data
->param
.directory
.stripExt
= WMGetButtonSelected(panel
->dstripB
);
1199 menuItemCloned(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* origItem
, WEditMenuItem
* newItem
)
1201 ItemData
*data
= WGetEditMenuItemData(origItem
);
1207 #define DUP(s) (s) ? wstrdup(s) : NULL
1209 newData
= NEW(ItemData
);
1211 newData
->type
= data
->type
;
1213 switch (data
->type
) {
1215 newData
->param
.exec
.command
= DUP(data
->param
.exec
.command
);
1216 newData
->param
.exec
.shortcut
= DUP(data
->param
.exec
.shortcut
);
1220 newData
->param
.command
.command
= data
->param
.command
.command
;
1221 newData
->param
.command
.parameter
= DUP(data
->param
.command
.parameter
);
1222 newData
->param
.command
.shortcut
= DUP(data
->param
.command
.shortcut
);
1226 newData
->param
.pipe
.command
= DUP(data
->param
.pipe
.command
);
1227 newData
->param
.pipe
.cached
= data
->param
.pipe
.cached
;
1231 newData
->param
.external
.path
= DUP(data
->param
.external
.path
);
1235 newData
->param
.directory
.directory
= DUP(data
->param
.directory
.directory
);
1236 newData
->param
.directory
.command
= DUP(data
->param
.directory
.command
);
1237 newData
->param
.directory
.stripExt
= data
->param
.directory
.stripExt
;
1246 WSetEditMenuItemData(newItem
, newData
, (WMCallback
*) freeItemData
);
1249 static void menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1251 _Panel
*panel
= (_Panel
*) delegate
->data
;
1254 updateFrameTitle(panel
, WGetEditMenuItemTitle(item
), panel
->currentType
);
1256 submenu
= WGetEditMenuSubmenu(menu
, item
);
1258 WSetEditMenuTitle(submenu
, WGetEditMenuItemTitle(item
));
1262 static Bool
shouldRemoveItem(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1264 _Panel
*panel
= (_Panel
*) delegate
->data
;
1269 if (WGetEditMenuSubmenu(menu
, item
)) {
1272 res
= WMRunAlertPanel(WMWidgetScreen(menu
), NULL
,
1273 _("Remove Submenu"),
1274 _("Removing this item will destroy all items inside\n"
1275 "the submenu. Do you really want to do that?"),
1276 _("Yes"), _("No"), _("Yes, don't ask again."));
1283 panel
->dontAsk
= True
;
1290 static void menuItemDeselected(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1292 _Panel
*panel
= (_Panel
*) delegate
->data
;
1294 changeInfoType(panel
, NULL
, NoInfo
);
1297 static void menuItemSelected(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1299 ItemData
*data
= WGetEditMenuItemData(item
);
1300 _Panel
*panel
= (_Panel
*) delegate
->data
;
1302 panel
->currentItem
= item
;
1305 changeInfoType(panel
, WGetEditMenuItemTitle(item
), data
->type
);
1307 switch (data
->type
) {
1312 WMSetTextFieldText(panel
->commandT
, data
->param
.exec
.command
);
1313 WMSetTextFieldText(panel
->shortT
, data
->param
.exec
.shortcut
);
1317 WMSelectListItem(panel
->icommandL
, data
->param
.command
.command
);
1318 WMSetListPosition(panel
->icommandL
, data
->param
.command
.command
- 2);
1319 WMSetTextFieldText(panel
->shortT
, data
->param
.command
.shortcut
);
1321 switch (data
->param
.command
.command
) {
1324 WMSetButtonSelected(panel
->quickB
, data
->param
.command
.parameter
!= NULL
);
1327 WMSetTextFieldText(panel
->paramT
, data
->param
.command
.parameter
);
1331 icommandLClicked(panel
->icommandL
, panel
);
1335 WMSetTextFieldText(panel
->pipeT
, data
->param
.pipe
.command
);
1336 WMSetButtonSelected(panel
->pipeCacheB
, data
->param
.pipe
.cached
);
1340 WMSetTextFieldText(panel
->pathT
, data
->param
.external
.path
);
1344 WMSetTextFieldText(panel
->dpathT
, data
->param
.directory
.directory
);
1345 WMSetTextFieldText(panel
->dcommandT
, data
->param
.directory
.command
);
1346 WMSetButtonSelected(panel
->dstripB
, data
->param
.directory
.stripExt
);
1358 static WEditMenu
*buildSubmenu(_Panel
* panel
, WMPropList
* pl
)
1360 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1362 WEditMenuItem
*item
;
1364 WMPropList
*tp
, *bp
;
1367 tp
= WMGetFromPLArray(pl
, 0);
1368 title
= WMGetFromPLString(tp
);
1370 menu
= WCreateEditMenu(scr
, title
);
1372 for (i
= 1; i
< WMGetPropListItemCount(pl
); i
++) {
1375 pi
= WMGetFromPLArray(pl
, i
);
1377 tp
= WMGetFromPLArray(pi
, 0);
1378 bp
= WMGetFromPLArray(pi
, 1);
1380 title
= WMGetFromPLString(tp
);
1382 if (!bp
|| WMIsPLArray(bp
)) { /* it's a submenu */
1385 submenu
= buildSubmenu(panel
, pi
);
1387 item
= WAddMenuItemWithTitle(menu
, title
);
1389 WSetEditMenuSubmenu(menu
, item
, submenu
);
1393 data
= parseCommand(pi
);
1396 item
= WAddMenuItemWithTitle(menu
, title
);
1397 if (panel
->markerPix
[data
->type
])
1398 WSetEditMenuItemImage(item
, panel
->markerPix
[data
->type
]);
1399 WSetEditMenuItemData(item
, data
, (WMCallback
*) freeItemData
);
1401 char *buf
= wmalloc(1024);
1402 snprintf(buf
, 1024, _("Invalid menu command \"%s\" with label \"%s\" cleared"),
1403 WMGetFromPLString(WMGetFromPLArray(pi
, 1)),
1404 WMGetFromPLString(WMGetFromPLArray(pi
, 0)));
1405 WMRunAlertPanel(scr
, panel
->parent
, _("Warning"), buf
, _("OK"), NULL
, NULL
);
1412 WSetEditMenuAcceptsDrop(menu
, True
);
1413 WSetEditMenuDelegate(menu
, &menuDelegate
);
1415 WMRealizeWidget(menu
);
1420 static void buildMenuFromPL(_Panel
* panel
, WMPropList
* pl
)
1422 panel
->menu
= buildSubmenu(panel
, pl
);
1425 static WMPropList
*getDefaultMenu(_Panel
* panel
)
1428 char *menuPath
, *gspath
;
1430 gspath
= wstrdup(WMAKER_RESOURCE_PATH
);
1432 menuPath
= wmalloc(strlen(gspath
) + 128);
1433 sprintf(menuPath
, "%s/plmenu", gspath
);
1435 menu
= WMReadPropListFromFile(menuPath
);
1440 msg
= _("Could not open default menu from '%s'");
1441 buffer
= wmalloc(strlen(msg
) + strlen(menuPath
) + 10);
1442 sprintf(buffer
, msg
, menuPath
);
1443 WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1444 _("Error"), buffer
, _("OK"), NULL
, NULL
);
1454 static void showData(_Panel
* panel
)
1460 gspath
= wusergnusteppath();
1462 menuPath
= wmalloc(strlen(gspath
) + 32);
1463 strcpy(menuPath
, gspath
);
1464 strcat(menuPath
, "/Defaults/WMRootMenu");
1466 pmenu
= WMReadPropListFromFile(menuPath
);
1468 if (!pmenu
|| !WMIsPLArray(pmenu
)) {
1471 res
= WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1473 _("The menu file format currently in use is not supported\n"
1474 "by this tool. Do you want to discard the current menu\n"
1475 "to use this tool?"),
1476 _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL
);
1478 if (res
== WAPRDefault
) {
1479 pmenu
= getDefaultMenu(panel
);
1482 pmenu
= WMCreatePLArray(WMCreatePLString("Applications"), NULL
);
1485 panel
->dontSave
= True
;
1490 panel
->menuPath
= menuPath
;
1492 buildMenuFromPL(panel
, pmenu
);
1494 WMReleasePropList(pmenu
);
1497 static Bool
notblank(char *s
)
1508 static WMPropList
*processData(char *title
, ItemData
* data
)
1512 static WMPropList
*pscut
= NULL
;
1513 static WMPropList
*pomenu
= NULL
;
1520 pscut
= WMCreatePLString("SHORTCUT");
1521 pomenu
= WMCreatePLString("OPEN_MENU");
1524 item
= WMCreatePLArray(WMCreatePLString(title
), NULL
);
1526 switch (data
->type
) {
1528 if (data
->param
.exec
.command
== NULL
)
1531 if (strpbrk(data
->param
.exec
.command
, "&$*|><?`=;")) {
1540 if (notblank(data
->param
.exec
.shortcut
)) {
1541 WMAddToPLArray(item
, pscut
);
1542 WMAddToPLArray(item
, WMCreatePLString(data
->param
.exec
.shortcut
));
1545 WMAddToPLArray(item
, WMCreatePLString(s1
));
1546 WMAddToPLArray(item
, WMCreatePLString(data
->param
.exec
.command
));
1550 if (notblank(data
->param
.command
.shortcut
)) {
1551 WMAddToPLArray(item
, pscut
);
1552 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.shortcut
));
1555 i
= data
->param
.command
.command
;
1557 WMAddToPLArray(item
, WMCreatePLString(commandNames
[i
]));
1562 if (data
->param
.command
.parameter
) {
1563 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.parameter
));
1567 case 6: /* restart */
1568 if (data
->param
.command
.parameter
) {
1569 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.parameter
));
1577 if (!data
->param
.pipe
.command
)
1579 WMAddToPLArray(item
, pomenu
);
1580 if (data
->param
.pipe
.cached
)
1581 s1
= wstrconcat("| ", data
->param
.pipe
.command
);
1583 s1
= wstrconcat("|| ", data
->param
.pipe
.command
);
1584 WMAddToPLArray(item
, WMCreatePLString(s1
));
1589 if (!data
->param
.external
.path
)
1591 WMAddToPLArray(item
, pomenu
);
1592 WMAddToPLArray(item
, WMCreatePLString(data
->param
.external
.path
));
1596 if (!data
->param
.directory
.directory
|| !data
->param
.directory
.command
)
1602 l
= strlen(data
->param
.directory
.directory
);
1603 l
+= strlen(data
->param
.directory
.command
);
1606 WMAddToPLArray(item
, pomenu
);
1609 sprintf(tmp
, "%s%s WITH %s",
1610 data
->param
.directory
.stripExt
? "-noext " : "",
1611 data
->param
.directory
.directory
, data
->param
.directory
.command
);
1613 WMAddToPLArray(item
, WMCreatePLString(tmp
));
1619 WMAddToPLArray(item
, WMCreatePLString("WORKSPACE_MENU"));
1622 case WWindowListInfo
:
1623 WMAddToPLArray(item
, WMCreatePLString("WINDOWS_MENU"));
1634 static WMPropList
*processSubmenu(WEditMenu
* menu
)
1636 WEditMenuItem
*item
;
1642 s
= WGetEditMenuTitle(menu
);
1643 pl
= WMCreatePLString(s
);
1645 pmenu
= WMCreatePLArray(pl
, NULL
);
1648 while ((item
= WGetEditMenuItem(menu
, i
++))) {
1651 s
= WGetEditMenuItemTitle(item
);
1653 submenu
= WGetEditMenuSubmenu(menu
, item
);
1655 pl
= processSubmenu(submenu
);
1657 pl
= processData(s
, WGetEditMenuItemData(item
));
1663 WMAddToPLArray(pmenu
, pl
);
1669 static WMPropList
*buildPLFromMenu(_Panel
* panel
)
1673 menu
= processSubmenu(panel
->menu
);
1678 static void storeData(_Panel
* panel
)
1682 if (panel
->dontSave
)
1685 menu
= buildPLFromMenu(panel
);
1687 WMWritePropListToFile(menu
, panel
->menuPath
);
1689 WMReleasePropList(menu
);
1692 static void showMenus(_Panel
* panel
)
1695 WEditMenuUnhide(panel
->menu
);
1698 static void hideMenus(_Panel
* panel
)
1701 WEditMenuHide(panel
->menu
);
1704 Panel
*InitMenu(WMScreen
* scr
, WMWidget
* parent
)
1708 panel
= wmalloc(sizeof(_Panel
));
1709 memset(panel
, 0, sizeof(_Panel
));
1711 panel
->sectionName
= _("Applications Menu Definition");
1713 panel
->description
= _("Edit the menu for launching applications.");
1715 panel
->parent
= parent
;
1717 panel
->callbacks
.createWidgets
= createPanel
;
1718 panel
->callbacks
.updateDomain
= storeData
;
1719 panel
->callbacks
.showPanel
= showMenus
;
1720 panel
->callbacks
.hidePanel
= hideMenus
;
1722 AddSection(panel
, ICON_FILE
);