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.
27 #include <X11/keysym.h>
28 #include <X11/cursorfont.h>
45 #define MAX_SECTION_SIZE 4
47 typedef struct _Panel
{
53 CallbackRec callbacks
;
62 WMPixmap
*markerPix
[LastInfo
];
75 WMTextField
*commandT
; /* command to run */
77 WMButton
*xtermC
; /* inside xterm? */
88 WMButton
*plpipeCacheB
;
94 WMTextField
*dcommandT
;
110 Bool dontAsk
; /* whether to comfirm submenu remove */
115 /* about the currently selected item */
116 WEditMenuItem
*currentItem
;
117 InfoType currentType
;
118 WMWidget
*sections
[LastInfo
][MAX_SECTION_SIZE
];
148 static char *commandNames
[] = {
163 #define ICON_FILE "menus"
165 static void showData(_Panel
* panel
);
167 static void updateMenuItem(_Panel
* panel
, WEditMenuItem
* item
, WMWidget
* changedWidget
);
169 static void menuItemSelected(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
171 static void menuItemDeselected(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
173 static void menuItemCloned(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
,
174 WEditMenuItem
* origItem
, WEditMenuItem
* newItem
);
176 static void menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
178 static Bool
shouldRemoveItem(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
);
180 static void freeItemData(ItemData
* data
);
183 static WEditMenuDelegate menuDelegate
= {
192 static void dataChanged(void *self
, WMNotification
* notif
)
194 _Panel
*panel
= (_Panel
*) self
;
195 WEditMenuItem
*item
= panel
->currentItem
;
196 WMWidget
*w
= (WMWidget
*) WMGetNotificationObject(notif
);
198 updateMenuItem(panel
, item
, w
);
201 static void buttonClicked(WMWidget
* w
, void *data
)
203 _Panel
*panel
= (_Panel
*) data
;
204 WEditMenuItem
*item
= panel
->currentItem
;
206 updateMenuItem(panel
, item
, w
);
209 static void icommandLClicked(WMWidget
* w
, void *data
)
211 _Panel
*panel
= (_Panel
*) data
;
214 cmd
= WMGetListSelectedItemRow(w
);
215 if (cmd
== 3 || cmd
== 4) {
216 WMMapWidget(panel
->quickB
);
218 WMUnmapWidget(panel
->quickB
);
221 WMMapWidget(panel
->paramF
);
223 WMUnmapWidget(panel
->paramF
);
227 static void browseForFile(WMWidget
* self
, void *clientData
)
229 _Panel
*panel
= (_Panel
*) clientData
;
230 WMFilePanel
*filePanel
;
231 char *text
, *oldprog
, *newprog
;
233 filePanel
= WMGetOpenPanel(WMWidgetScreen(self
));
234 text
= WMGetTextFieldText(panel
->commandT
);
236 oldprog
= wtrimspace(text
);
239 if (oldprog
[0] == 0 || oldprog
[0] != '/') {
241 oldprog
= wstrdup("/");
244 while (*ptr
&& !isspace(*ptr
))
249 WMSetFilePanelCanChooseDirectories(filePanel
, False
);
251 if (WMRunModalFilePanelForDirectory(filePanel
, panel
->parent
, oldprog
, _("Select Program"), NULL
) == True
) {
252 newprog
= WMGetFilePanelFileName(filePanel
);
253 WMSetTextFieldText(panel
->commandT
, newprog
);
254 updateMenuItem(panel
, panel
->currentItem
, panel
->commandT
);
261 static void sgrabClicked(WMWidget
* w
, void *data
)
263 _Panel
*panel
= (_Panel
*) data
;
264 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->parent
));
267 if (w
== panel
->sclearB
) {
268 WMSetTextFieldText(panel
->shortT
, "");
269 updateMenuItem(panel
, panel
->currentItem
, panel
->shortT
);
273 if (!panel
->capturing
) {
274 panel
->capturing
= 1;
275 WMSetButtonText(w
, _("Cancel"));
276 XGrabKeyboard(dpy
, WMWidgetXID(panel
->parent
), True
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
277 shortcut
= capture_shortcut(dpy
, &panel
->capturing
, 0);
279 WMSetTextFieldText(panel
->shortT
, shortcut
);
280 updateMenuItem(panel
, panel
->currentItem
, panel
->shortT
);
284 panel
->capturing
= 0;
285 WMSetButtonText(w
, _("Capture"));
286 XUngrabKeyboard(dpy
, CurrentTime
);
289 static void changedItemPad(WMWidget
* w
, void *data
)
291 _Panel
*panel
= (_Panel
*) data
;
292 int padn
= WMGetPopUpButtonSelectedItem(w
);
294 WMUnmapWidget(panel
->itemPad
[panel
->currentPad
]);
295 WMMapWidget(panel
->itemPad
[padn
]);
297 panel
->currentPad
= padn
;
300 static WEditMenu
*putNewSubmenu(WEditMenu
* menu
, const char *title
)
305 item
= WAddMenuItemWithTitle(menu
, title
);
307 tmp
= WCreateEditMenu(WMWidgetScreen(menu
), title
);
308 WSetEditMenuAcceptsDrop(tmp
, True
);
309 WSetEditMenuDelegate(tmp
, &menuDelegate
);
310 WSetEditMenuSubmenu(menu
, item
, tmp
);
315 static ItemData
*putNewItem(_Panel
* panel
, WEditMenu
* menu
, int type
, const char *title
)
320 item
= WAddMenuItemWithTitle(menu
, title
);
322 data
= wmalloc(sizeof(ItemData
));
324 WSetEditMenuItemData(item
, data
, (WMCallback
*) freeItemData
);
325 WSetEditMenuItemImage(item
, panel
->markerPix
[type
]);
330 static WEditMenu
*makeFactoryMenu(WMWidget
* parent
, int width
)
334 pad
= WCreateEditMenuPad(parent
);
335 WMResizeWidget(pad
, width
, 10);
336 WSetEditMenuMinSize(pad
, wmksize(width
, 0));
337 WSetEditMenuMaxSize(pad
, wmksize(width
, 0));
338 WSetEditMenuSelectable(pad
, False
);
339 WSetEditMenuEditable(pad
, False
);
340 WSetEditMenuIsFactory(pad
, True
);
341 WSetEditMenuDelegate(pad
, &menuDelegate
);
346 static void createPanel(_Panel
* p
)
348 _Panel
*panel
= (_Panel
*) p
;
349 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
350 WMColor
*black
= WMBlackColor(scr
);
351 WMColor
*white
= WMWhiteColor(scr
);
352 WMColor
*gray
= WMGrayColor(scr
);
353 WMFont
*bold
= WMBoldSystemFontOfSize(scr
, 12);
354 WMFont
*font
= WMSystemFontOfSize(scr
, 12);
358 menuDelegate
.data
= panel
;
360 panel
->boldFont
= bold
;
361 panel
->normalFont
= font
;
363 panel
->black
= black
;
364 panel
->white
= white
;
369 Display
*dpy
= WMScreenDisplay(scr
);
373 pixm
= WMCreatePixmap(scr
, 7, 7, WMScreenDepth(scr
), True
);
375 pix
= WMGetPixmapXID(pixm
);
377 XDrawLine(dpy
, pix
, WMColorGC(black
), 0, 3, 6, 3);
378 XDrawLine(dpy
, pix
, WMColorGC(black
), 3, 0, 3, 6);
380 XDrawLine(dpy, pix, WMColorGC(black), 1, 0, 3, 3);
381 XDrawLine(dpy, pix, WMColorGC(black), 1, 6, 3, 3);
382 XDrawLine(dpy, pix, WMColorGC(black), 0, 0, 0, 6);
385 pix
= WMGetPixmapMaskXID(pixm
);
387 gc
= XCreateGC(dpy
, pix
, 0, NULL
);
389 XSetForeground(dpy
, gc
, 0);
390 XFillRectangle(dpy
, pix
, gc
, 0, 0, 7, 7);
392 XSetForeground(dpy
, gc
, 1);
393 XDrawLine(dpy
, pix
, gc
, 0, 3, 6, 3);
394 XDrawLine(dpy
, pix
, gc
, 3, 0, 3, 6);
396 panel
->markerPix
[ExternalInfo
] = pixm
;
397 panel
->markerPix
[PipeInfo
] = pixm
;
398 panel
->markerPix
[PLPipeInfo
] = pixm
;
399 panel
->markerPix
[DirectoryInfo
] = pixm
;
400 panel
->markerPix
[WSMenuInfo
] = pixm
;
401 panel
->markerPix
[WWindowListInfo
] = pixm
;
406 panel
->box
= WMCreateBox(panel
->parent
);
407 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
409 panel
->typeP
= WMCreatePopUpButton(panel
->box
);
410 WMResizeWidget(panel
->typeP
, 150, 20);
411 WMMoveWidget(panel
->typeP
, 10, 10);
413 WMAddPopUpButtonItem(panel
->typeP
, _("New Items"));
414 WMAddPopUpButtonItem(panel
->typeP
, _("Sample Commands"));
415 WMAddPopUpButtonItem(panel
->typeP
, _("Sample Submenus"));
417 WMSetPopUpButtonAction(panel
->typeP
, changedItemPad
, panel
);
419 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
424 pad
= makeFactoryMenu(panel
->box
, 150);
425 WMMoveWidget(pad
, 10, 40);
427 putNewItem(panel
, pad
, ExecInfo
, _("Run Program"));
428 putNewItem(panel
, pad
, CommandInfo
, _("Internal Command"));
429 putNewSubmenu(pad
, _("Submenu"));
430 putNewItem(panel
, pad
, ExternalInfo
, _("External Submenu"));
431 putNewItem(panel
, pad
, PipeInfo
, _("Generated Submenu"));
432 putNewItem(panel
, pad
, PLPipeInfo
, _("Generated PL Menu"));
433 putNewItem(panel
, pad
, DirectoryInfo
, _("Directory Contents"));
434 putNewItem(panel
, pad
, WSMenuInfo
, _("Workspace Menu"));
435 putNewItem(panel
, pad
, WWindowListInfo
, _("Window List Menu"));
437 panel
->itemPad
[0] = pad
;
445 sview
= WMCreateScrollView(panel
->box
);
446 WMResizeWidget(sview
, 150, 180);
447 WMMoveWidget(sview
, 10, 40);
448 WMSetScrollViewHasVerticalScroller(sview
, True
);
450 pad
= makeFactoryMenu(panel
->box
, 130);
452 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
454 data
= putNewItem(panel
, pad
, ExecInfo
, _("XTerm"));
455 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
457 data
= putNewItem(panel
, pad
, ExecInfo
, _("rxvt"));
458 data
->param
.exec
.command
= "rxvt";
460 data
= putNewItem(panel
, pad
, ExecInfo
, _("ETerm"));
461 data
->param
.exec
.command
= "eterm";
463 data
= putNewItem(panel
, pad
, ExecInfo
, _("Run..."));
464 data
->param
.exec
.command
= _("%A(Run,Type command to run)");
466 data
= putNewItem(panel
, pad
, ExecInfo
, _("Firefox"));
467 data
->param
.exec
.command
= "firefox";
469 data
= putNewItem(panel
, pad
, ExecInfo
, _("gimp"));
470 data
->param
.exec
.command
= "gimp";
472 data
= putNewItem(panel
, pad
, ExecInfo
, _("epic"));
473 data
->param
.exec
.command
= "xterm -e epic";
475 data
= putNewItem(panel
, pad
, ExecInfo
, _("ee"));
476 data
->param
.exec
.command
= "ee";
478 data
= putNewItem(panel
, pad
, ExecInfo
, _("xv"));
479 data
->param
.exec
.command
= "xv";
481 data
= putNewItem(panel
, pad
, ExecInfo
, _("Evince"));
482 data
->param
.exec
.command
= "evince";
484 data
= putNewItem(panel
, pad
, ExecInfo
, _("ghostview"));
485 data
->param
.exec
.command
= "gv";
487 data
= putNewItem(panel
, pad
, CommandInfo
, _("Exit Window Maker"));
488 data
->param
.command
.command
= 3;
492 panel
->itemPad
[1] = sview
;
496 WEditMenu
*pad
, *smenu
;
500 sview
= WMCreateScrollView(panel
->box
);
501 WMResizeWidget(sview
, 150, 180);
502 WMMoveWidget(sview
, 10, 40);
503 WMSetScrollViewHasVerticalScroller(sview
, True
);
505 pad
= makeFactoryMenu(panel
->box
, 130);
507 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
509 data
= putNewItem(panel
, pad
, ExternalInfo
, _("Debian Menu"));
510 data
->param
.pipe
.command
= "/etc/" GSUSER_SUBDIR
"/" DEFAULTS_SUBDIR
"/menu.hook";
512 data
= putNewItem(panel
, pad
, PipeInfo
, _("RedHat Menu"));
513 data
->param
.pipe
.command
= "wmconfig --output wmaker";
515 data
= putNewItem(panel
, pad
, PipeInfo
, _("Menu Conectiva"));
516 data
->param
.pipe
.command
= "wmconfig --output wmaker";
518 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Themes"));
519 data
->param
.directory
.command
= "setstyle";
520 data
->param
.directory
.directory
=
521 "/usr/share/" PACKAGE_TARNAME
"/Themes"
522 " /usr/local/share/" PACKAGE_TARNAME
"/Themes"
523 " $HOME/" GSUSER_SUBDIR
"/" USERDATA_SUBDIR
"/" PACKAGE_TARNAME
"/Themes";
524 data
->param
.directory
.stripExt
= 1;
526 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Bg Images (scale)"));
527 data
->param
.directory
.command
= "wmsetbg -u -s";
528 data
->param
.directory
.directory
=
529 "/opt/kde2/share/wallpapers"
530 " /usr/share/" PACKAGE_TARNAME
"/Backgrounds"
531 " $HOME/" GSUSER_SUBDIR
"/" USERDATA_SUBDIR
"/" PACKAGE_TARNAME
"/Backgrounds";
532 data
->param
.directory
.stripExt
= 1;
534 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Bg Images (tile)"));
535 data
->param
.directory
.command
= "wmsetbg -u -t";
536 data
->param
.directory
.directory
=
537 "/opt/kde2/share/wallpapers"
538 " /usr/share/" PACKAGE_TARNAME
"/Backgrounds"
539 " $HOME/" GSUSER_SUBDIR
"/" USERDATA_SUBDIR
"/" PACKAGE_TARNAME
"/Backgrounds";
540 data
->param
.directory
.stripExt
= 1;
542 smenu
= putNewSubmenu(pad
, _("Assorted XTerms"));
544 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Yellow on Blue"));
545 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg midnightblue -fg yellow";
547 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Black"));
548 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
550 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on White"));
551 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg white -fg black";
553 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on Beige"));
554 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#bbbb99' -fg black";
556 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Green"));
557 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#228822' -fg white";
559 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Olive"));
560 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#335533' -fg white";
562 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Blue on Blue"));
563 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#112244' -fg '#88aabb'";
565 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm BIG FONTS"));
566 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white -fn 10x20";
570 panel
->itemPad
[2] = sview
;
573 width
= FRAME_WIDTH
- 20 - 150 - 10 - 2;
575 panel
->optionsF
= WMCreateFrame(panel
->box
);
576 WMResizeWidget(panel
->optionsF
, width
, FRAME_HEIGHT
- 15);
577 WMMoveWidget(panel
->optionsF
, 10 + 150 + 10, 5);
583 panel
->commandF
= WMCreateFrame(panel
->optionsF
);
584 WMResizeWidget(panel
->commandF
, width
, 50);
585 WMMoveWidget(panel
->commandF
, 10, 20);
586 WMSetFrameTitle(panel
->commandF
, _("Program to Run"));
587 WMSetFrameTitlePosition(panel
->commandF
, WTPAtTop
);
589 panel
->commandT
= WMCreateTextField(panel
->commandF
);
590 WMResizeWidget(panel
->commandT
, width
- 95, 20);
591 WMMoveWidget(panel
->commandT
, 10, 20);
593 panel
->browseB
= WMCreateCommandButton(panel
->commandF
);
594 WMResizeWidget(panel
->browseB
, 70, 24);
595 WMMoveWidget(panel
->browseB
, width
- 80, 18);
596 WMSetButtonText(panel
->browseB
, _("Browse"));
597 WMSetButtonAction(panel
->browseB
, browseForFile
, panel
);
599 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->commandT
);
602 panel
->xtermC
= WMCreateSwitchButton(panel
->commandF
);
603 WMResizeWidget(panel
->xtermC
, width
- 20, 20);
604 WMMoveWidget(panel
->xtermC
, 10, 50);
605 WMSetButtonText(panel
->xtermC
, _("Run the program inside a Xterm"));
607 WMMapSubwidgets(panel
->commandF
);
611 panel
->pathF
= WMCreateFrame(panel
->optionsF
);
612 WMResizeWidget(panel
->pathF
, width
, 150);
613 WMMoveWidget(panel
->pathF
, 10, 40);
614 WMSetFrameTitle(panel
->pathF
, _("Path for Menu"));
616 panel
->pathT
= WMCreateTextField(panel
->pathF
);
617 WMResizeWidget(panel
->pathT
, width
- 20, 20);
618 WMMoveWidget(panel
->pathT
, 10, 20);
620 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->pathT
);
622 label
= WMCreateLabel(panel
->pathF
);
623 WMResizeWidget(label
, width
- 20, 90);
624 WMMoveWidget(label
, 10, 50);
625 WMSetLabelText(label
, _("Enter the path for a file containing a menu\n"
626 "or a list of directories with the programs you\n"
627 "want to have listed in the menu. Ex:\n"
628 "~/" GSUSER_SUBDIR
"/" USERDATA_SUBDIR
"/" PACKAGE_TARNAME
"/menu\n"
629 "or\n" "/usr/bin ~/xbin"));
631 WMMapSubwidgets(panel
->pathF
);
635 panel
->pipeF
= WMCreateFrame(panel
->optionsF
);
636 WMResizeWidget(panel
->pipeF
, width
, 155);
637 WMMoveWidget(panel
->pipeF
, 10, 30);
638 WMSetFrameTitle(panel
->pipeF
, _("Command"));
640 panel
->pipeT
= WMCreateTextField(panel
->pipeF
);
641 WMResizeWidget(panel
->pipeT
, width
- 20, 20);
642 WMMoveWidget(panel
->pipeT
, 10, 20);
644 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->pipeT
);
646 label
= WMCreateLabel(panel
->pipeF
);
647 WMResizeWidget(label
, width
- 20, 40);
648 WMMoveWidget(label
, 10, 50);
649 WMSetLabelText(label
, _("Enter a command that outputs a menu\n" "definition to stdout when invoked."));
651 panel
->pipeCacheB
= WMCreateSwitchButton(panel
->pipeF
);
652 WMResizeWidget(panel
->pipeCacheB
, width
- 20, 40);
653 WMMoveWidget(panel
->pipeCacheB
, 10, 110);
654 WMSetButtonText(panel
->pipeCacheB
, _("Cache menu contents after opening for\n" "the first time"));
656 WMMapSubwidgets(panel
->pipeF
);
660 panel
->plpipeF
= WMCreateFrame(panel
->optionsF
);
661 WMResizeWidget(panel
->plpipeF
, width
, 155);
662 WMMoveWidget(panel
->plpipeF
, 10, 30);
663 WMSetFrameTitle(panel
->plpipeF
, _("Command"));
665 panel
->plpipeT
= WMCreateTextField(panel
->plpipeF
);
666 WMResizeWidget(panel
->plpipeT
, width
- 20, 20);
667 WMMoveWidget(panel
->plpipeT
, 10, 20);
669 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->plpipeT
);
671 label
= WMCreateLabel(panel
->plpipeF
);
672 WMResizeWidget(label
, width
- 20, 40);
673 WMMoveWidget(label
, 10, 50);
674 WMSetLabelText(label
, _("Enter a command that outputs a proplist menu\n" "definition to stdout when invoked."));
676 panel
->plpipeCacheB
= WMCreateSwitchButton(panel
->plpipeF
);
677 WMResizeWidget(panel
->plpipeCacheB
, width
- 20, 40);
678 WMMoveWidget(panel
->plpipeCacheB
, 10, 110);
679 WMSetButtonText(panel
->plpipeCacheB
, _("Cache menu contents after opening for\n" "the first time"));
681 WMMapSubwidgets(panel
->plpipeF
);
685 panel
->dcommandF
= WMCreateFrame(panel
->optionsF
);
686 WMResizeWidget(panel
->dcommandF
, width
, 90);
687 WMMoveWidget(panel
->dcommandF
, 10, 25);
688 WMSetFrameTitle(panel
->dcommandF
, _("Command to Open Files"));
690 panel
->dcommandT
= WMCreateTextField(panel
->dcommandF
);
691 WMResizeWidget(panel
->dcommandT
, width
- 20, 20);
692 WMMoveWidget(panel
->dcommandT
, 10, 20);
694 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->dcommandT
);
696 label
= WMCreateLabel(panel
->dcommandF
);
697 WMResizeWidget(label
, width
- 20, 45);
698 WMMoveWidget(label
, 10, 40);
699 WMSetLabelText(label
, _("Enter the command you want to use to open the\n"
700 "files in the directories listed below."));
702 WMMapSubwidgets(panel
->dcommandF
);
704 panel
->dpathF
= WMCreateFrame(panel
->optionsF
);
705 WMResizeWidget(panel
->dpathF
, width
, 80);
706 WMMoveWidget(panel
->dpathF
, 10, 125);
707 WMSetFrameTitle(panel
->dpathF
, _("Directories with Files"));
709 panel
->dpathT
= WMCreateTextField(panel
->dpathF
);
710 WMResizeWidget(panel
->dpathT
, width
- 20, 20);
711 WMMoveWidget(panel
->dpathT
, 10, 20);
713 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->dpathT
);
715 panel
->dstripB
= WMCreateSwitchButton(panel
->dpathF
);
716 WMResizeWidget(panel
->dstripB
, width
- 20, 20);
717 WMMoveWidget(panel
->dstripB
, 10, 50);
718 WMSetButtonText(panel
->dstripB
, _("Strip extensions from file names"));
720 WMSetButtonAction(panel
->dstripB
, buttonClicked
, panel
);
722 WMMapSubwidgets(panel
->dpathF
);
726 panel
->shortF
= WMCreateFrame(panel
->optionsF
);
727 WMResizeWidget(panel
->shortF
, width
, 50);
728 WMMoveWidget(panel
->shortF
, 10, 160);
729 WMSetFrameTitle(panel
->shortF
, _("Keyboard Shortcut"));
731 panel
->shortT
= WMCreateTextField(panel
->shortF
);
732 WMResizeWidget(panel
->shortT
, width
- 20 - 150, 20);
733 WMMoveWidget(panel
->shortT
, 10, 20);
735 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->shortT
);
737 panel
->sgrabB
= WMCreateCommandButton(panel
->shortF
);
738 WMResizeWidget(panel
->sgrabB
, 70, 24);
739 WMMoveWidget(panel
->sgrabB
, width
- 80, 18);
740 WMSetButtonText(panel
->sgrabB
, _("Capture"));
741 WMSetButtonAction(panel
->sgrabB
, sgrabClicked
, panel
);
743 panel
->sclearB
= WMCreateCommandButton(panel
->shortF
);
744 WMResizeWidget(panel
->sclearB
, 70, 24);
745 WMMoveWidget(panel
->sclearB
, width
- 155, 18);
746 WMSetButtonText(panel
->sclearB
, _("Clear"));
747 WMSetButtonAction(panel
->sclearB
, sgrabClicked
, panel
);
749 WMMapSubwidgets(panel
->shortF
);
751 /* internal command */
753 panel
->icommandL
= WMCreateList(panel
->optionsF
);
754 WMResizeWidget(panel
->icommandL
, width
, 80);
755 WMMoveWidget(panel
->icommandL
, 10, 20);
757 WMSetListAction(panel
->icommandL
, icommandLClicked
, panel
);
759 WMAddNotificationObserver(dataChanged
, panel
, WMListSelectionDidChangeNotification
, panel
->icommandL
);
761 WMInsertListItem(panel
->icommandL
, 0, _("Arrange Icons"));
762 WMInsertListItem(panel
->icommandL
, 1, _("Hide All Windows Except For The Focused One"));
763 WMInsertListItem(panel
->icommandL
, 2, _("Show All Windows"));
765 WMInsertListItem(panel
->icommandL
, 3, _("Exit Window Maker"));
766 WMInsertListItem(panel
->icommandL
, 4, _("Exit X Session"));
767 WMInsertListItem(panel
->icommandL
, 5, _("Restart Window Maker"));
768 WMInsertListItem(panel
->icommandL
, 6, _("Start Another Window Manager : ("));
770 WMInsertListItem(panel
->icommandL
, 7, _("Save Current Session"));
771 WMInsertListItem(panel
->icommandL
, 8, _("Clear Saved Session"));
772 WMInsertListItem(panel
->icommandL
, 9, _("Refresh Screen"));
773 WMInsertListItem(panel
->icommandL
, 10, _("Open Info Panel"));
774 WMInsertListItem(panel
->icommandL
, 11, _("Open Copyright Panel"));
776 panel
->paramF
= WMCreateFrame(panel
->optionsF
);
777 WMResizeWidget(panel
->paramF
, width
, 50);
778 WMMoveWidget(panel
->paramF
, 10, 105);
779 WMSetFrameTitle(panel
->paramF
, _("Window Manager to Start"));
781 panel
->paramT
= WMCreateTextField(panel
->paramF
);
782 WMResizeWidget(panel
->paramT
, width
- 20, 20);
783 WMMoveWidget(panel
->paramT
, 10, 20);
785 WMAddNotificationObserver(dataChanged
, panel
, WMTextDidChangeNotification
, panel
->paramT
);
787 WMMapSubwidgets(panel
->paramF
);
789 panel
->quickB
= WMCreateSwitchButton(panel
->optionsF
);
790 WMResizeWidget(panel
->quickB
, width
, 20);
791 WMMoveWidget(panel
->quickB
, 10, 120);
792 WMSetButtonText(panel
->quickB
, _("Do not confirm action."));
793 WMSetButtonAction(panel
->quickB
, buttonClicked
, panel
);
795 label
= WMCreateLabel(panel
->optionsF
);
796 WMResizeWidget(label
, width
+ 5, FRAME_HEIGHT
- 50);
797 WMMoveWidget(label
, 7, 20);
798 WMSetLabelText(label
,
799 _("Instructions:\n\n"
800 " - drag items from the left to the menu to add new items\n"
801 " - drag items out of the menu to remove items\n"
802 " - drag items in menu to change their position\n"
803 " - drag items with Control pressed to copy them\n"
804 " - double click in a menu item to change the label\n"
805 " - click on a menu item to change related information"));
808 WMRealizeWidget(panel
->box
);
809 WMMapSubwidgets(panel
->box
);
810 WMMapWidget(panel
->box
);
814 for (i
= 0; i
< wlengthof(panel
->itemPad
); i
++)
815 WMUnmapWidget(panel
->itemPad
[i
]);
817 changedItemPad(panel
->typeP
, panel
);
819 panel
->sections
[NoInfo
][0] = label
;
821 panel
->sections
[ExecInfo
][0] = panel
->commandF
;
822 panel
->sections
[ExecInfo
][1] = panel
->shortF
;
824 panel
->sections
[CommandInfo
][0] = panel
->icommandL
;
825 panel
->sections
[CommandInfo
][1] = panel
->shortF
;
827 panel
->sections
[ExternalInfo
][0] = panel
->pathF
;
829 panel
->sections
[PipeInfo
][0] = panel
->pipeF
;
831 panel
->sections
[PLPipeInfo
][0] = panel
->plpipeF
;
833 panel
->sections
[DirectoryInfo
][0] = panel
->dpathF
;
834 panel
->sections
[DirectoryInfo
][1] = panel
->dcommandF
;
836 panel
->currentType
= NoInfo
;
843 pos
= WMGetViewScreenPosition(WMWidgetView(panel
->box
));
846 pos
.x
+= FRAME_WIDTH
+ 20;
851 pos
.y
= WMAX(pos
.y
- 100, 0);
854 WEditMenuShowAt(panel
->menu
, pos
.x
, pos
.y
);
858 static void freeItemData(ItemData
* data
)
860 #define CFREE(d) if (d) wfree(d)
863 switch (data
->type
) {
865 CFREE(data
->param
.command
.parameter
);
866 CFREE(data
->param
.command
.shortcut
);
870 CFREE(data
->param
.exec
.command
);
871 CFREE(data
->param
.exec
.shortcut
);
875 CFREE(data
->param
.pipe
.command
);
879 CFREE(data
->param
.pipe
.command
);
883 CFREE(data
->param
.external
.path
);
887 CFREE(data
->param
.directory
.command
);
888 CFREE(data
->param
.directory
.directory
);
899 static ItemData
*parseCommand(WMPropList
* item
)
901 ItemData
*data
= wmalloc(sizeof(ItemData
));
903 char *command
= NULL
;
904 char *parameter
= NULL
;
905 char *shortcut
= NULL
;
908 p
= WMGetFromPLArray(item
, i
++);
909 command
= WMGetFromPLString(p
);
910 if (strcmp(command
, "SHORTCUT") == 0) {
911 p
= WMGetFromPLArray(item
, i
++);
912 shortcut
= WMGetFromPLString(p
);
913 p
= WMGetFromPLArray(item
, i
++);
914 command
= WMGetFromPLString(p
);
916 p
= WMGetFromPLArray(item
, i
++);
918 parameter
= WMGetFromPLString(p
);
920 if (strcmp(command
, "EXEC") == 0 || strcmp(command
, "SHEXEC") == 0) {
922 data
->type
= ExecInfo
;
924 if (parameter
== NULL
) {
929 data
->param
.exec
.command
= wstrdup(parameter
);
931 data
->param
.exec
.shortcut
= wstrdup(shortcut
);
933 } else if (strcmp(command
, "OPEN_MENU") == 0) {
936 * dir menu, menu file
947 while (isspace(*p
) && *p
)
950 if (*(p
+ 1) == '|') {
952 data
->param
.pipe
.cached
= 0;
954 data
->param
.pipe
.cached
= 1;
956 data
->type
= PipeInfo
;
957 data
->param
.pipe
.command
= wtrimspace(p
+ 1);
963 s
= strstr(p
, "WITH");
970 data
->type
= DirectoryInfo
;
974 while (*s
&& isspace(*s
))
976 data
->param
.directory
.command
= wstrdup(s
);
978 wtokensplit(p
, &tokens
, &tokn
);
981 ctokens
= wmalloc(sizeof(char *) * tokn
);
983 for (i
= 0, j
= 0; i
< tokn
; i
++) {
984 if (strcmp(tokens
[i
], "-noext") == 0) {
985 data
->param
.directory
.stripExt
= 1;
987 ctokens
[j
++] = tokens
[i
];
990 data
->param
.directory
.directory
= wtokenjoin(ctokens
, j
);
993 wtokenfree(tokens
, tokn
);
995 data
->type
= ExternalInfo
;
996 data
->param
.external
.path
= p
;
999 } else if (strcmp(command
, "OPEN_PLMENU") == 0) {
1003 while (isspace(*p
) && *p
)
1006 if (*(p
+ 1) == '|') {
1008 data
->param
.pipe
.cached
= 0;
1010 data
->param
.pipe
.cached
= 1;
1012 data
->type
= PLPipeInfo
;
1013 data
->param
.pipe
.command
= wtrimspace(p
+ 1);
1015 } else if (strcmp(command
, "WORKSPACE_MENU") == 0) {
1016 data
->type
= WSMenuInfo
;
1017 } else if (strcmp(command
, "WINDOWS_MENU") == 0) {
1018 data
->type
= WWindowListInfo
;
1022 if (strcmp(command
, "ARRANGE_ICONS") == 0) {
1024 } else if (strcmp(command
, "HIDE_OTHERS") == 0) {
1026 } else if (strcmp(command
, "SHOW_ALL") == 0) {
1028 } else if (strcmp(command
, "EXIT") == 0) {
1030 } else if (strcmp(command
, "SHUTDOWN") == 0) {
1032 } else if (strcmp(command
, "RESTART") == 0) {
1038 } else if (strcmp(command
, "SAVE_SESSION") == 0) {
1040 } else if (strcmp(command
, "CLEAR_SESSION") == 0) {
1042 } else if (strcmp(command
, "REFRESH") == 0) {
1044 } else if (strcmp(command
, "INFO_PANEL") == 0) {
1046 } else if (strcmp(command
, "LEGAL_PANEL") == 0) {
1049 wwarning(_("unknown command '%s' in menu"), command
);
1054 data
->type
= CommandInfo
;
1056 data
->param
.command
.command
= cmd
;
1058 data
->param
.command
.shortcut
= wstrdup(shortcut
);
1060 data
->param
.command
.parameter
= wstrdup(parameter
);
1066 static void updateFrameTitle(_Panel
* panel
, const char *title
, InfoType type
)
1068 if (type
!= NoInfo
) {
1073 tmp
= wstrconcat(title
, _(": Execute Program"));
1077 tmp
= wstrconcat(title
, _(": Perform Internal Command"));
1081 tmp
= wstrconcat(title
, _(": Open a Submenu"));
1085 tmp
= wstrconcat(title
, _(": Program Generated Submenu"));
1089 tmp
= wstrconcat(title
, _(": Program Generated Proplist Submenu"));
1093 tmp
= wstrconcat(title
, _(": Directory Contents Menu"));
1097 tmp
= wstrconcat(title
, _(": Open Workspaces Submenu"));
1100 case WWindowListInfo
:
1101 tmp
= wstrconcat(title
, _(": Open Window List Submenu"));
1108 WMSetFrameTitle(panel
->optionsF
, tmp
);
1111 WMSetFrameTitle(panel
->optionsF
, NULL
);
1115 static void changeInfoType(_Panel
* panel
, const char *title
, InfoType type
)
1119 if (panel
->currentType
!= type
) {
1121 w
= panel
->sections
[panel
->currentType
];
1127 WMUnmapWidget(panel
->paramF
);
1128 WMUnmapWidget(panel
->quickB
);
1130 w
= panel
->sections
[type
];
1138 updateFrameTitle(panel
, title
, type
);
1140 panel
->currentType
= type
;
1143 static void updateMenuItem(_Panel
* panel
, WEditMenuItem
* item
, WMWidget
* changedWidget
)
1145 ItemData
*data
= WGetEditMenuItemData(item
);
1147 assert(data
!= NULL
);
1149 #define REPLACE(v, d) if (v) wfree(v); v = d
1151 switch (data
->type
) {
1153 if (changedWidget
== panel
->commandT
) {
1154 REPLACE(data
->param
.exec
.command
, WMGetTextFieldText(panel
->commandT
));
1156 if (changedWidget
== panel
->shortT
) {
1157 REPLACE(data
->param
.exec
.shortcut
, WMGetTextFieldText(panel
->shortT
));
1162 if (changedWidget
== panel
->icommandL
) {
1163 data
->param
.command
.command
= WMGetListSelectedItemRow(panel
->icommandL
);
1165 switch (data
->param
.command
.command
) {
1168 if (changedWidget
== panel
->quickB
) {
1169 REPLACE(data
->param
.command
.parameter
, WMGetButtonSelected(panel
->quickB
)
1170 ? wstrdup("QUICK") : NULL
);
1175 if (changedWidget
== panel
->paramT
) {
1176 REPLACE(data
->param
.command
.parameter
, WMGetTextFieldText(panel
->paramT
));
1180 if (changedWidget
== panel
->shortT
) {
1181 REPLACE(data
->param
.command
.shortcut
, WMGetTextFieldText(panel
->shortT
));
1187 if (changedWidget
== panel
->pipeT
) {
1188 REPLACE(data
->param
.pipe
.command
, WMGetTextFieldText(panel
->pipeT
));
1190 if (changedWidget
== panel
->pipeCacheB
) {
1191 data
->param
.pipe
.cached
= WMGetButtonSelected(panel
->pipeCacheB
);
1196 if (changedWidget
== panel
->plpipeT
) {
1197 REPLACE(data
->param
.pipe
.command
, WMGetTextFieldText(panel
->plpipeT
));
1199 if (changedWidget
== panel
->plpipeCacheB
) {
1200 data
->param
.pipe
.cached
= WMGetButtonSelected(panel
->plpipeCacheB
);
1205 if (changedWidget
== panel
->pathT
) {
1206 REPLACE(data
->param
.external
.path
, WMGetTextFieldText(panel
->pathT
));
1211 if (changedWidget
== panel
->dpathT
) {
1212 REPLACE(data
->param
.directory
.directory
, WMGetTextFieldText(panel
->dpathT
));
1214 if (changedWidget
== panel
->dcommandT
) {
1215 REPLACE(data
->param
.directory
.command
, WMGetTextFieldText(panel
->dcommandT
));
1217 if (changedWidget
== panel
->dstripB
) {
1218 data
->param
.directory
.stripExt
= WMGetButtonSelected(panel
->dstripB
);
1231 menuItemCloned(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* origItem
, WEditMenuItem
* newItem
)
1233 ItemData
*data
= WGetEditMenuItemData(origItem
);
1236 /* Parameter not used, but tell the compiler that it is ok */
1243 #define DUP(s) (s) ? wstrdup(s) : NULL
1245 newData
= wmalloc(sizeof(ItemData
));
1247 newData
->type
= data
->type
;
1249 switch (data
->type
) {
1251 newData
->param
.exec
.command
= DUP(data
->param
.exec
.command
);
1252 newData
->param
.exec
.shortcut
= DUP(data
->param
.exec
.shortcut
);
1256 newData
->param
.command
.command
= data
->param
.command
.command
;
1257 newData
->param
.command
.parameter
= DUP(data
->param
.command
.parameter
);
1258 newData
->param
.command
.shortcut
= DUP(data
->param
.command
.shortcut
);
1262 newData
->param
.pipe
.command
= DUP(data
->param
.pipe
.command
);
1263 newData
->param
.pipe
.cached
= data
->param
.pipe
.cached
;
1267 newData
->param
.pipe
.command
= DUP(data
->param
.pipe
.command
);
1268 newData
->param
.pipe
.cached
= data
->param
.pipe
.cached
;
1272 newData
->param
.external
.path
= DUP(data
->param
.external
.path
);
1276 newData
->param
.directory
.directory
= DUP(data
->param
.directory
.directory
);
1277 newData
->param
.directory
.command
= DUP(data
->param
.directory
.command
);
1278 newData
->param
.directory
.stripExt
= data
->param
.directory
.stripExt
;
1287 WSetEditMenuItemData(newItem
, newData
, (WMCallback
*) freeItemData
);
1290 static void menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1292 _Panel
*panel
= (_Panel
*) delegate
->data
;
1295 /* Parameter not used, but tell the compiler it is ok */
1298 updateFrameTitle(panel
, WGetEditMenuItemTitle(item
), panel
->currentType
);
1300 submenu
= WGetEditMenuSubmenu(item
);
1302 WSetEditMenuTitle(submenu
, WGetEditMenuItemTitle(item
));
1306 static Bool
shouldRemoveItem(struct WEditMenuDelegate
*delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1308 _Panel
*panel
= (_Panel
*) delegate
->data
;
1313 if (WGetEditMenuSubmenu(item
)) {
1316 res
= WMRunAlertPanel(WMWidgetScreen(menu
), NULL
,
1317 _("Remove Submenu"),
1318 _("Removing this item will destroy all items inside\n"
1319 "the submenu. Do you really want to do that?"),
1320 _("Yes"), _("No"), _("Yes, don't ask again"));
1327 panel
->dontAsk
= True
;
1334 static void menuItemDeselected(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1336 _Panel
*panel
= (_Panel
*) delegate
->data
;
1338 /* Parameter not used, but tell the compiler that it is ok */
1342 changeInfoType(panel
, NULL
, NoInfo
);
1345 static void menuItemSelected(WEditMenuDelegate
* delegate
, WEditMenu
* menu
, WEditMenuItem
* item
)
1347 ItemData
*data
= WGetEditMenuItemData(item
);
1348 _Panel
*panel
= (_Panel
*) delegate
->data
;
1350 /* Parameter not used, but tell the compiler that it is ok */
1353 panel
->currentItem
= item
;
1356 changeInfoType(panel
, WGetEditMenuItemTitle(item
), data
->type
);
1358 switch (data
->type
) {
1363 WMSetTextFieldText(panel
->commandT
, data
->param
.exec
.command
);
1364 WMSetTextFieldText(panel
->shortT
, data
->param
.exec
.shortcut
);
1368 WMSelectListItem(panel
->icommandL
, data
->param
.command
.command
);
1369 WMSetListPosition(panel
->icommandL
, data
->param
.command
.command
- 2);
1370 WMSetTextFieldText(panel
->shortT
, data
->param
.command
.shortcut
);
1372 switch (data
->param
.command
.command
) {
1375 WMSetButtonSelected(panel
->quickB
, data
->param
.command
.parameter
!= NULL
);
1378 WMSetTextFieldText(panel
->paramT
, data
->param
.command
.parameter
);
1382 icommandLClicked(panel
->icommandL
, panel
);
1386 WMSetTextFieldText(panel
->pipeT
, data
->param
.pipe
.command
);
1387 WMSetButtonSelected(panel
->pipeCacheB
, data
->param
.pipe
.cached
);
1391 WMSetTextFieldText(panel
->plpipeT
, data
->param
.pipe
.command
);
1392 WMSetButtonSelected(panel
->plpipeCacheB
, data
->param
.pipe
.cached
);
1396 WMSetTextFieldText(panel
->pathT
, data
->param
.external
.path
);
1400 WMSetTextFieldText(panel
->dpathT
, data
->param
.directory
.directory
);
1401 WMSetTextFieldText(panel
->dcommandT
, data
->param
.directory
.command
);
1402 WMSetButtonSelected(panel
->dstripB
, data
->param
.directory
.stripExt
);
1414 static WEditMenu
*buildSubmenu(_Panel
* panel
, WMPropList
* pl
)
1416 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
1418 WEditMenuItem
*item
;
1420 WMPropList
*tp
, *bp
;
1423 tp
= WMGetFromPLArray(pl
, 0);
1424 title
= WMGetFromPLString(tp
);
1426 menu
= WCreateEditMenu(scr
, title
);
1428 for (i
= 1; i
< WMGetPropListItemCount(pl
); i
++) {
1431 pi
= WMGetFromPLArray(pl
, i
);
1433 tp
= WMGetFromPLArray(pi
, 0);
1434 bp
= WMGetFromPLArray(pi
, 1);
1436 title
= WMGetFromPLString(tp
);
1438 if (!bp
|| WMIsPLArray(bp
)) { /* it's a submenu */
1441 submenu
= buildSubmenu(panel
, pi
);
1443 item
= WAddMenuItemWithTitle(menu
, title
);
1445 WSetEditMenuSubmenu(menu
, item
, submenu
);
1449 data
= parseCommand(pi
);
1452 item
= WAddMenuItemWithTitle(menu
, title
);
1453 if (panel
->markerPix
[data
->type
])
1454 WSetEditMenuItemImage(item
, panel
->markerPix
[data
->type
]);
1455 WSetEditMenuItemData(item
, data
, (WMCallback
*) freeItemData
);
1459 snprintf(buf
, sizeof(buf
), _("Invalid menu command \"%s\" with label \"%s\" cleared"),
1460 WMGetFromPLString(WMGetFromPLArray(pi
, 1)),
1461 WMGetFromPLString(WMGetFromPLArray(pi
, 0)));
1462 WMRunAlertPanel(scr
, panel
->parent
, _("Warning"), buf
, _("OK"), NULL
, NULL
);
1468 WSetEditMenuAcceptsDrop(menu
, True
);
1469 WSetEditMenuDelegate(menu
, &menuDelegate
);
1471 WMRealizeWidget(menu
);
1476 static void buildMenuFromPL(_Panel
* panel
, WMPropList
* pl
)
1478 panel
->menu
= buildSubmenu(panel
, pl
);
1481 static WMPropList
*getDefaultMenu(_Panel
* panel
)
1484 static const char menuPath
[] = WMAKER_RESOURCE_PATH
"/plmenu";
1486 menu
= WMReadPropListFromFile(menuPath
);
1490 msg
= _("Could not open default menu from '%s'");
1491 buffer
= wmalloc(strlen(msg
) + strlen(menuPath
) + 10);
1492 sprintf(buffer
, msg
, menuPath
);
1493 WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1494 _("Error"), buffer
, _("OK"), NULL
, NULL
);
1501 static void showData(_Panel
* panel
)
1503 char *menuPath
, *labelText
;
1507 menuPath
= wdefaultspathfordomain("WMRootMenu");
1509 pmenu
= WMReadPropListFromFile(menuPath
);
1511 /* check if WMRootMenu references another file, and if so,
1512 if that file is in proplist format */
1513 while (WMIsPLString(pmenu
)) {
1516 path
= wexpandpath(WMGetFromPLString(pmenu
));
1518 if (access(path
, F_OK
) < 0) {
1519 char *old_path
= path
;
1521 path
= wfindfile(DEF_CONFIG_PATHS
, path
);
1525 /* TODO: if needed, concatenate locale suffix to path.
1526 See getLocalizedMenuFile() in src/rootmenu.c. */
1531 if (access(path
, W_OK
) < 0) {
1532 snprintf(buf
, sizeof(buf
),
1533 _("The menu file \"%s\" referenced by "
1534 "WMRootMenu is read-only.\n"
1535 "You cannot use WPrefs to modify it."),
1537 WMRunAlertPanel(WMWidgetScreen(panel
->parent
),
1540 _("OK"), NULL
, NULL
);
1541 panel
->dontSave
= True
;
1546 pmenu
= WMReadPropListFromFile(path
);
1550 if (!pmenu
|| !WMIsPLArray(pmenu
)) {
1553 res
= WMRunAlertPanel(WMWidgetScreen(panel
->parent
), panel
->parent
,
1555 _("The menu file format currently in use is not supported\n"
1556 "by this tool. Do you want to discard the current menu\n"
1557 "to use this tool?"),
1558 _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL
);
1560 if (res
== WAPRDefault
) {
1561 pmenu
= getDefaultMenu(panel
);
1564 pmenu
= WMCreatePLArray(WMCreatePLString("Applications"), NULL
);
1567 panel
->dontSave
= True
;
1572 panel
->menuPath
= menuPath
;
1574 snprintf(buf
, sizeof(buf
),
1575 _("\n\nWhen saved, the menu will be written to the file\n\"%s\"."),
1577 labelText
= WMGetLabelText(panel
->sections
[NoInfo
][0]);
1578 labelText
= wstrconcat(labelText
, buf
);
1579 WMSetLabelText(panel
->sections
[NoInfo
][0], labelText
);
1582 buildMenuFromPL(panel
, pmenu
);
1584 WMReleasePropList(pmenu
);
1587 static Bool
notblank(const char *s
)
1598 static WMPropList
*processData(const char *title
, ItemData
* data
)
1602 static WMPropList
*pscut
= NULL
;
1603 static WMPropList
*pomenu
= NULL
;
1604 static WMPropList
*poplmenu
= NULL
;
1611 pscut
= WMCreatePLString("SHORTCUT");
1612 pomenu
= WMCreatePLString("OPEN_MENU");
1613 poplmenu
= WMCreatePLString("OPEN_PLMENU");
1616 item
= WMCreatePLArray(WMCreatePLString(title
), NULL
);
1618 switch (data
->type
) {
1620 if (data
->param
.exec
.command
== NULL
)
1623 if (strpbrk(data
->param
.exec
.command
, "&$*|><?`=;")) {
1629 if (notblank(data
->param
.exec
.shortcut
)) {
1630 WMAddToPLArray(item
, pscut
);
1631 WMAddToPLArray(item
, WMCreatePLString(data
->param
.exec
.shortcut
));
1634 WMAddToPLArray(item
, WMCreatePLString(s1
));
1635 WMAddToPLArray(item
, WMCreatePLString(data
->param
.exec
.command
));
1639 if (notblank(data
->param
.command
.shortcut
)) {
1640 WMAddToPLArray(item
, pscut
);
1641 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.shortcut
));
1644 i
= data
->param
.command
.command
;
1646 WMAddToPLArray(item
, WMCreatePLString(commandNames
[i
]));
1651 if (data
->param
.command
.parameter
) {
1652 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.parameter
));
1656 case 6: /* restart */
1657 if (data
->param
.command
.parameter
) {
1658 WMAddToPLArray(item
, WMCreatePLString(data
->param
.command
.parameter
));
1667 if (!data
->param
.pipe
.command
)
1669 if (data
->type
== PLPipeInfo
)
1670 WMAddToPLArray(item
, poplmenu
);
1672 WMAddToPLArray(item
, pomenu
);
1674 if (data
->param
.pipe
.cached
)
1675 s1
= wstrconcat("| ", data
->param
.pipe
.command
);
1677 s1
= wstrconcat("|| ", data
->param
.pipe
.command
);
1678 WMAddToPLArray(item
, WMCreatePLString(s1
));
1683 if (!data
->param
.external
.path
)
1685 WMAddToPLArray(item
, pomenu
);
1686 WMAddToPLArray(item
, WMCreatePLString(data
->param
.external
.path
));
1694 if (!data
->param
.directory
.directory
|| !data
->param
.directory
.command
)
1697 l
= strlen(data
->param
.directory
.directory
);
1698 l
+= strlen(data
->param
.directory
.command
);
1701 WMAddToPLArray(item
, pomenu
);
1704 sprintf(tmp
, "%s%s WITH %s",
1705 data
->param
.directory
.stripExt
? "-noext " : "",
1706 data
->param
.directory
.directory
, data
->param
.directory
.command
);
1708 WMAddToPLArray(item
, WMCreatePLString(tmp
));
1714 WMAddToPLArray(item
, WMCreatePLString("WORKSPACE_MENU"));
1717 case WWindowListInfo
:
1718 WMAddToPLArray(item
, WMCreatePLString("WINDOWS_MENU"));
1729 WMReleasePropList(item
);
1733 static WMPropList
*processSubmenu(WEditMenu
* menu
)
1735 WEditMenuItem
*item
;
1741 s
= WGetEditMenuTitle(menu
);
1742 pl
= WMCreatePLString(s
);
1744 pmenu
= WMCreatePLArray(pl
, NULL
);
1747 while ((item
= WGetEditMenuItem(menu
, i
++))) {
1750 s
= WGetEditMenuItemTitle(item
);
1752 submenu
= WGetEditMenuSubmenu(item
);
1754 pl
= processSubmenu(submenu
);
1756 pl
= processData(s
, WGetEditMenuItemData(item
));
1762 WMAddToPLArray(pmenu
, pl
);
1768 static WMPropList
*buildPLFromMenu(_Panel
* panel
)
1772 menu
= processSubmenu(panel
->menu
);
1777 static void storeData(_Panel
* panel
)
1781 if (panel
->dontSave
)
1784 menu
= buildPLFromMenu(panel
);
1786 WMWritePropListToFile(menu
, panel
->menuPath
);
1788 WMReleasePropList(menu
);
1791 static void showMenus(_Panel
* panel
)
1794 WEditMenuUnhide(panel
->menu
);
1797 static void hideMenus(_Panel
* panel
)
1800 WEditMenuHide(panel
->menu
);
1803 Panel
*InitMenu(WMWidget
*parent
)
1807 panel
= wmalloc(sizeof(_Panel
));
1809 panel
->sectionName
= _("Applications Menu Definition");
1811 panel
->description
= _("Edit the menu for launching applications.");
1813 panel
->parent
= parent
;
1815 panel
->callbacks
.createWidgets
= createPanel
;
1816 panel
->callbacks
.updateDomain
= storeData
;
1817 panel
->callbacks
.showPanel
= showMenus
;
1818 panel
->callbacks
.hidePanel
= hideMenus
;
1820 AddSection(panel
, ICON_FILE
);