1 /* Menu.c- menu definition
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 2000 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,
28 #include <X11/keysym.h>
29 #include <X11/cursorfont.h>
46 #define MAX_SECTION_SIZE 4
48 typedef struct _Panel
{
54 CallbackRec callbacks
;
64 WMPixmap
*markerPix
[LastInfo
];
77 WMTextField
*commandT
; /* command to run */
78 WMButton
*xtermC
; /* inside xterm? */
90 WMTextField
*dcommandT
;
106 Bool dontAsk
; /* whether to comfirm submenu remove */
112 /* about the currently selected item */
113 WEditMenuItem
*currentItem
;
114 InfoType currentType
;
115 WMWidget
*sections
[LastInfo
][MAX_SECTION_SIZE
];
147 static char *commandNames
[] = {
164 #define NEW(type) memset(wmalloc(sizeof(type)), 0, sizeof(type))
167 #define ICON_FILE "menus"
171 static void showData(_Panel
*panel
);
174 static void updateMenuItem(_Panel
*panel
, WEditMenuItem
*item
,
175 WMWidget
*changedWidget
);
177 static void menuItemSelected(struct WEditMenuDelegate
*delegate
,
178 WEditMenu
*menu
, WEditMenuItem
*item
);
180 static void menuItemDeselected(struct WEditMenuDelegate
*delegate
,
181 WEditMenu
*menu
, WEditMenuItem
*item
);
183 static void menuItemCloned(struct WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
184 WEditMenuItem
*origItem
, WEditMenuItem
*newItem
);
186 static void menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
187 WEditMenuItem
*item
);
189 static Bool
shouldRemoveItem(struct WEditMenuDelegate
*delegate
,
190 WEditMenu
*menu
, WEditMenuItem
*item
);
193 static void freeItemData(ItemData
*data
);
197 static WEditMenuDelegate menuDelegate
= {
208 dataChanged(void *self
, WMNotification
*notif
)
210 _Panel
*panel
= (_Panel
*)self
;
211 WEditMenuItem
*item
= panel
->currentItem
;
212 WMWidget
*w
= (WMWidget
*)WMGetNotificationObject(notif
);
214 updateMenuItem(panel
, item
, w
);
219 buttonClicked(WMWidget
*w
, void *data
)
221 _Panel
*panel
= (_Panel
*)data
;
222 WEditMenuItem
*item
= panel
->currentItem
;
224 updateMenuItem(panel
, item
, w
);
229 icommandLClicked(WMWidget
*w
, void *data
)
231 _Panel
*panel
= (_Panel
*)data
;
234 cmd
= WMGetListSelectedItemRow(w
);
235 if (cmd
== 3 || cmd
== 4) {
236 WMMapWidget(panel
->quickB
);
238 WMUnmapWidget(panel
->quickB
);
241 WMMapWidget(panel
->paramF
);
243 WMUnmapWidget(panel
->paramF
);
256 captureShortcut(Display
*dpy
, _Panel
*panel
)
263 while (panel
->capturing
) {
264 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
265 WMNextEvent(dpy
, &ev
);
266 if (ev
.type
==KeyPress
&& ev
.xkey
.keycode
!=0) {
267 ksym
= XKeycodeToKeysym(dpy
, ev
.xkey
.keycode
, 0);
268 if (!IsModifierKey(ksym
)) {
269 key
=XKeysymToString(ksym
);
270 panel
->capturing
= 0;
282 if (ev
.xkey
.state
& ControlMask
) {
283 strcat(buffer
, "Control+");
285 if (ev
.xkey
.state
& ShiftMask
) {
286 strcat(buffer
, "Shift+");
288 if (ev
.xkey
.state
& Mod1Mask
) {
289 strcat(buffer
, "Mod1+");
291 if (ev
.xkey
.state
& Mod2Mask
) {
292 strcat(buffer
, "Mod2+");
294 if (ev
.xkey
.state
& Mod3Mask
) {
295 strcat(buffer
, "Mod3+");
297 if (ev
.xkey
.state
& Mod4Mask
) {
298 strcat(buffer
, "Mod4+");
300 if (ev
.xkey
.state
& Mod5Mask
) {
301 strcat(buffer
, "Mod5+");
305 return wstrdup(buffer
);
311 sgrabClicked(WMWidget
*w
, void *data
)
313 _Panel
*panel
= (_Panel
*)data
;
314 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->win
));
318 if (w
== panel
->sclearB
) {
319 WMSetTextFieldText(panel
->shortT
, "");
320 updateMenuItem(panel
, panel
->currentItem
, panel
->shortT
);
324 if (!panel
->capturing
) {
325 panel
->capturing
= 1;
326 WMSetButtonText(w
, _("Cancel"));
327 XGrabKeyboard(dpy
, WMWidgetXID(panel
->win
), True
, GrabModeAsync
,
328 GrabModeAsync
, CurrentTime
);
329 shortcut
= captureShortcut(dpy
, panel
);
331 WMSetTextFieldText(panel
->shortT
, shortcut
);
332 updateMenuItem(panel
, panel
->currentItem
, panel
->shortT
);
336 panel
->capturing
= 0;
337 WMSetButtonText(w
, _("Capture"));
338 XUngrabKeyboard(dpy
, CurrentTime
);
343 changedItemPad(WMWidget
*w
, void *data
)
345 _Panel
*panel
= (_Panel
*)data
;
346 int padn
= WMGetPopUpButtonSelectedItem(w
);
348 WMUnmapWidget(panel
->itemPad
[panel
->currentPad
]);
349 WMMapWidget(panel
->itemPad
[padn
]);
351 panel
->currentPad
= padn
;
356 putNewSubmenu(WEditMenu
*menu
, char *title
)
361 item
= WAddMenuItemWithTitle(menu
, title
);
363 tmp
= WCreateEditMenu(WMWidgetScreen(menu
), title
);
364 WSetEditMenuAcceptsDrop(tmp
, True
);
365 WSetEditMenuDelegate(tmp
, &menuDelegate
);
366 WSetEditMenuSubmenu(menu
, item
, tmp
);
373 putNewItem(_Panel
*panel
, WEditMenu
*menu
, int type
, char *title
)
378 item
= WAddMenuItemWithTitle(menu
, title
);
380 data
= NEW(ItemData
);
382 WSetEditMenuItemData(item
, data
, (WMCallback
*)freeItemData
);
383 WSetEditMenuItemImage(item
, panel
->markerPix
[type
]);
390 makeFactoryMenu(WMWidget
*parent
, int width
)
394 pad
= WCreateEditMenuPad(parent
);
395 WMResizeWidget(pad
, width
, 10);
396 WSetEditMenuMinSize(pad
, wmksize(width
, 0));
397 WSetEditMenuMaxSize(pad
, wmksize(width
, 0));
398 WSetEditMenuSelectable(pad
, False
);
399 WSetEditMenuEditable(pad
, False
);
400 WSetEditMenuIsFactory(pad
, True
);
401 WSetEditMenuDelegate(pad
, &menuDelegate
);
408 createPanel(_Panel
*p
)
410 _Panel
*panel
= (_Panel
*)p
;
411 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
412 WMColor
*black
= WMBlackColor(scr
);
413 WMColor
*white
= WMWhiteColor(scr
);
414 WMColor
*gray
= WMGrayColor(scr
);
415 WMFont
*bold
= WMBoldSystemFontOfSize(scr
, 12);
416 WMFont
*font
= WMSystemFontOfSize(scr
, 12);
421 menuDelegate
.data
= panel
;
424 panel
->boldFont
= bold
;
425 panel
->normalFont
= font
;
427 panel
->black
= black
;
428 panel
->white
= white
;
433 Display
*dpy
= WMScreenDisplay(scr
);
437 pixm
= WMCreatePixmap(scr
, 7, 7, WMScreenDepth(scr
), True
);
439 pix
= WMGetPixmapXID(pixm
);
441 XDrawLine(dpy
, pix
, WMColorGC(black
), 0, 3, 6, 3);
442 XDrawLine(dpy
, pix
, WMColorGC(black
), 3, 0, 3, 6);
444 XDrawLine(dpy, pix, WMColorGC(black), 1, 0, 3, 3);
445 XDrawLine(dpy, pix, WMColorGC(black), 1, 6, 3, 3);
446 XDrawLine(dpy, pix, WMColorGC(black), 0, 0, 0, 6);
449 pix
= WMGetPixmapMaskXID(pixm
);
451 gc
= XCreateGC(dpy
, pix
, 0, NULL
);
453 XSetForeground(dpy
, gc
, 0);
454 XFillRectangle(dpy
, pix
, gc
, 0, 0, 7, 7);
456 XSetForeground(dpy
, gc
, 1);
457 XDrawLine(dpy
, pix
, gc
, 0, 3, 6, 3);
458 XDrawLine(dpy
, pix
, gc
, 3, 0, 3, 6);
460 panel
->markerPix
[ExternalInfo
] = pixm
;
461 panel
->markerPix
[PipeInfo
] = pixm
;
462 panel
->markerPix
[DirectoryInfo
] = pixm
;
463 panel
->markerPix
[WSMenuInfo
] = pixm
;
469 panel
->frame
= WMCreateFrame(panel
->win
);
470 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
471 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
473 panel
->typeP
= WMCreatePopUpButton(panel
->frame
);
474 WMResizeWidget(panel
->typeP
, 150, 20);
475 WMMoveWidget(panel
->typeP
, 10, 10);
477 WMAddPopUpButtonItem(panel
->typeP
, _("New Items"));
478 WMAddPopUpButtonItem(panel
->typeP
, _("Sample Commands"));
479 WMAddPopUpButtonItem(panel
->typeP
, _("Sample Submenus"));
481 WMSetPopUpButtonAction(panel
->typeP
, changedItemPad
, panel
);
483 WMSetPopUpButtonSelectedItem(panel
->typeP
, 0);
490 pad
= makeFactoryMenu(panel
->frame
, 150);
491 WMMoveWidget(pad
, 10, 40);
493 data
= putNewItem(panel
, pad
, ExecInfo
, "Run Program");
494 data
= putNewItem(panel
, pad
, CommandInfo
, "Internal Command");
495 smenu
= putNewSubmenu(pad
, "Submenu");
496 data
= putNewItem(panel
, pad
, ExternalInfo
, "External Submenu");
497 data
= putNewItem(panel
, pad
, PipeInfo
, "Generated Submenu");
498 data
= putNewItem(panel
, pad
, DirectoryInfo
, "Directory Contents");
499 data
= putNewItem(panel
, pad
, WSMenuInfo
, "Workspace Menu");
501 panel
->itemPad
[0] = pad
;
509 sview
= WMCreateScrollView(panel
->frame
);
510 WMResizeWidget(sview
, 150, 180);
511 WMMoveWidget(sview
, 10, 40);
512 WMSetScrollViewHasVerticalScroller(sview
, True
);
514 pad
= makeFactoryMenu(panel
->frame
, 130);
516 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
518 data
= putNewItem(panel
, pad
, ExecInfo
, _("XTerm"));
519 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
521 data
= putNewItem(panel
, pad
, ExecInfo
, _("rxvt"));
522 data
->param
.exec
.command
= "rxvt";
524 data
= putNewItem(panel
, pad
, ExecInfo
, _("ETerm"));
525 data
->param
.exec
.command
= "eterm";
527 data
= putNewItem(panel
, pad
, ExecInfo
, _("Run..."));
528 data
->param
.exec
.command
= "%a(Run,Type command to run)";
530 data
= putNewItem(panel
, pad
, ExecInfo
, _("Netscape"));
531 data
->param
.exec
.command
= "netscape";
533 data
= putNewItem(panel
, pad
, ExecInfo
, _("gimp"));
534 data
->param
.exec
.command
= "gimp";
536 data
= putNewItem(panel
, pad
, ExecInfo
, _("epic"));
537 data
->param
.exec
.command
= "xterm -e epic";
539 data
= putNewItem(panel
, pad
, ExecInfo
, _("ee"));
540 data
->param
.exec
.command
= "ee";
542 data
= putNewItem(panel
, pad
, ExecInfo
, _("xv"));
543 data
->param
.exec
.command
= "xv";
545 data
= putNewItem(panel
, pad
, ExecInfo
, _("Acrobat Reader"));
546 data
->param
.exec
.command
= "acroread || /usr/local/Acrobat4/bin/acroread";
548 data
= putNewItem(panel
, pad
, ExecInfo
, _("ghostview"));
549 data
->param
.exec
.command
= "gv";
551 data
= putNewItem(panel
, pad
, CommandInfo
, _("Exit Window Maker"));
552 data
->param
.command
.command
= 3;
556 panel
->itemPad
[1] = sview
;
561 WEditMenu
*pad
, *smenu
;
565 sview
= WMCreateScrollView(panel
->frame
);
566 WMResizeWidget(sview
, 150, 180);
567 WMMoveWidget(sview
, 10, 40);
568 WMSetScrollViewHasVerticalScroller(sview
, True
);
570 pad
= makeFactoryMenu(panel
->frame
, 130);
572 WMSetScrollViewContentView(sview
, WMWidgetView(pad
));
574 data
= putNewItem(panel
, pad
, ExternalInfo
, _("Debian Menu"));
575 data
->param
.pipe
.command
= "/etc/X11/WindowMaker/menu.hook";
577 data
= putNewItem(panel
, pad
, PipeInfo
, _("RedHat Menu"));
578 data
->param
.pipe
.command
= "wmconfig --output wmaker";
580 data
= putNewItem(panel
, pad
, PipeInfo
, _("Menu Conectiva"));
581 data
->param
.pipe
.command
= "wmconfig --output wmaker";
583 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Themes"));
584 data
->param
.directory
.command
= "setstyle";
585 data
->param
.directory
.directory
= "/usr/share/WindowMaker/Themes /usr/local/share/WindowMaker/Themes $HOME/GNUstep/Library/WindowMaker/Themes";
586 data
->param
.directory
.stripExt
= 1;
588 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Bg Images (scale)"));
589 data
->param
.directory
.command
= "wmsetbg -u -s";
590 data
->param
.directory
.directory
= "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
591 data
->param
.directory
.stripExt
= 1;
593 data
= putNewItem(panel
, pad
, DirectoryInfo
, _("Bg Images (tile)"));
594 data
->param
.directory
.command
= "wmsetbg -u -t";
595 data
->param
.directory
.directory
= "/opt/kde2/share/wallpapers /usr/share/WindowMaker/Backgrounds $HOME/GNUstep/Library/WindowMaker/Backgrounds";
596 data
->param
.directory
.stripExt
= 1;
598 smenu
= putNewSubmenu(pad
, _("Assorted XTerms"));
600 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Yellow on Blue"));
601 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg midnightblue -fg yellow";
603 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Black"));
604 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white";
606 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on White"));
607 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg white -fg black";
609 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Black on Beige"));
610 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#bbbb99' -fg black";
612 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Green"));
613 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#228822' -fg white";
615 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm White on Olive"));
616 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#335533' -fg white";
618 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm Blue on Blue"));
619 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg '#112244' -fg '#88aabb'";
621 data
= putNewItem(panel
, smenu
, ExecInfo
, _("XTerm BIG FONTS"));
622 data
->param
.exec
.command
= "xterm -sb -sl 2000 -bg black -fg white -fn 10x20";
626 panel
->itemPad
[2] = sview
;
630 width
= FRAME_WIDTH
- 20 - 150 - 10;
632 panel
->optionsF
= WMCreateFrame(panel
->frame
);
633 WMResizeWidget(panel
->optionsF
, width
, FRAME_HEIGHT
- 15);
634 WMMoveWidget(panel
->optionsF
, 10 + 150 + 10, 5);
640 panel
->commandF
= WMCreateFrame(panel
->optionsF
);
641 WMResizeWidget(panel
->commandF
, width
, 50);
642 WMMoveWidget(panel
->commandF
, 10, 20);
643 WMSetFrameTitle(panel
->commandF
, _("Program to Run"));
645 panel
->commandT
= WMCreateTextField(panel
->commandF
);
646 WMResizeWidget(panel
->commandT
, width
- 20, 20);
647 WMMoveWidget(panel
->commandT
, 10, 20);
649 WMAddNotificationObserver(dataChanged
, panel
,
650 WMTextDidChangeNotification
,
654 panel
->xtermC
= WMCreateSwitchButton(panel
->commandF
);
655 WMResizeWidget(panel
->xtermC
, width
- 20, 20);
656 WMMoveWidget(panel
->xtermC
, 10, 50);
657 WMSetButtonText(panel
->xtermC
, _("Run the program inside a Xterm"));
659 WMMapSubwidgets(panel
->commandF
);
664 panel
->pathF
= WMCreateFrame(panel
->optionsF
);
665 WMResizeWidget(panel
->pathF
, width
, 150);
666 WMMoveWidget(panel
->pathF
, 10, 40);
667 WMSetFrameTitle(panel
->pathF
, _("Path for Menu"));
669 panel
->pathT
= WMCreateTextField(panel
->pathF
);
670 WMResizeWidget(panel
->pathT
, width
- 20, 20);
671 WMMoveWidget(panel
->pathT
, 10, 20);
673 WMAddNotificationObserver(dataChanged
, panel
,
674 WMTextDidChangeNotification
,
677 label
= WMCreateLabel(panel
->pathF
);
678 WMResizeWidget(label
, width
- 20, 80);
679 WMMoveWidget(label
, 10, 50);
680 WMSetLabelText(label
, _("Enter the path for a file containing a menu\n"
681 "or a list of directories with the programs you\n"
682 "want to have listed in the menu. Ex:\n"
683 "~/GNUstep/Library/WindowMaker/menu\n"
685 "/usr/X11R6/bin ~/xbin"));
687 WMMapSubwidgets(panel
->pathF
);
692 panel
->pipeF
= WMCreateFrame(panel
->optionsF
);
693 WMResizeWidget(panel
->pipeF
, width
, 100);
694 WMMoveWidget(panel
->pipeF
, 10, 50);
695 WMSetFrameTitle(panel
->pipeF
, _("Command"));
697 panel
->pipeT
= WMCreateTextField(panel
->pipeF
);
698 WMResizeWidget(panel
->pipeT
, width
- 20, 20);
699 WMMoveWidget(panel
->pipeT
, 10, 20);
701 WMAddNotificationObserver(dataChanged
, panel
,
702 WMTextDidChangeNotification
,
706 label
= WMCreateLabel(panel
->pipeF
);
707 WMResizeWidget(label
, width
- 20, 40);
708 WMMoveWidget(label
, 10, 50);
709 WMSetLabelText(label
, _("Enter a command that outputs a menu\n"
710 "definition to stdout when invoked."));
712 WMMapSubwidgets(panel
->pipeF
);
717 panel
->dcommandF
= WMCreateFrame(panel
->optionsF
);
718 WMResizeWidget(panel
->dcommandF
, width
, 90);
719 WMMoveWidget(panel
->dcommandF
, 10, 25);
720 WMSetFrameTitle(panel
->dcommandF
, _("Command to Open Files"));
722 panel
->dcommandT
= WMCreateTextField(panel
->dcommandF
);
723 WMResizeWidget(panel
->dcommandT
, width
- 20, 20);
724 WMMoveWidget(panel
->dcommandT
, 10, 20);
726 WMAddNotificationObserver(dataChanged
, panel
,
727 WMTextDidChangeNotification
,
731 label
= WMCreateLabel(panel
->dcommandF
);
732 WMResizeWidget(label
, width
- 20, 45);
733 WMMoveWidget(label
, 10, 40);
734 WMSetLabelText(label
, _("Enter the command you want to use to open the\n"
735 "files in the directories listed below."));
737 WMMapSubwidgets(panel
->dcommandF
);
740 panel
->dpathF
= WMCreateFrame(panel
->optionsF
);
741 WMResizeWidget(panel
->dpathF
, width
, 80);
742 WMMoveWidget(panel
->dpathF
, 10, 125);
743 WMSetFrameTitle(panel
->dpathF
, _("Directories with Files"));
745 panel
->dpathT
= WMCreateTextField(panel
->dpathF
);
746 WMResizeWidget(panel
->dpathT
, width
- 20, 20);
747 WMMoveWidget(panel
->dpathT
, 10, 20);
749 WMAddNotificationObserver(dataChanged
, panel
,
750 WMTextDidChangeNotification
,
753 panel
->dstripB
= WMCreateSwitchButton(panel
->dpathF
);
754 WMResizeWidget(panel
->dstripB
, width
- 20, 20);
755 WMMoveWidget(panel
->dstripB
, 10, 50);
756 WMSetButtonText(panel
->dstripB
, _("Strip extensions from file names"));
758 WMSetButtonAction(panel
->dstripB
, buttonClicked
, panel
);
760 WMMapSubwidgets(panel
->dpathF
);
765 panel
->shortF
= WMCreateFrame(panel
->optionsF
);
766 WMResizeWidget(panel
->shortF
, width
, 50);
767 WMMoveWidget(panel
->shortF
, 10, 160);
768 WMSetFrameTitle(panel
->shortF
, _("Keyboard Shortcut"));
770 panel
->shortT
= WMCreateTextField(panel
->shortF
);
771 WMResizeWidget(panel
->shortT
, width
- 20 - 170, 20);
772 WMMoveWidget(panel
->shortT
, 10, 20);
774 WMAddNotificationObserver(dataChanged
, panel
,
775 WMTextDidChangeNotification
,
778 panel
->sgrabB
= WMCreateCommandButton(panel
->shortF
);
779 WMResizeWidget(panel
->sgrabB
, 80, 24);
780 WMMoveWidget(panel
->sgrabB
, width
- 90, 18);
781 WMSetButtonText(panel
->sgrabB
, _("Capture"));
782 WMSetButtonAction(panel
->sgrabB
, sgrabClicked
, panel
);
784 panel
->sclearB
= WMCreateCommandButton(panel
->shortF
);
785 WMResizeWidget(panel
->sclearB
, 80, 24);
786 WMMoveWidget(panel
->sclearB
, width
- 175, 18);
787 WMSetButtonText(panel
->sclearB
, _("Clear"));
788 WMSetButtonAction(panel
->sclearB
, sgrabClicked
, panel
);
790 WMMapSubwidgets(panel
->shortF
);
792 /* internal command */
794 panel
->icommandL
= WMCreateList(panel
->optionsF
);
795 WMResizeWidget(panel
->icommandL
, width
, 80);
796 WMMoveWidget(panel
->icommandL
, 10, 20);
798 WMSetListAction(panel
->icommandL
, icommandLClicked
, panel
);
800 WMAddNotificationObserver(dataChanged
, panel
,
801 WMListSelectionDidChangeNotification
,
804 WMInsertListItem(panel
->icommandL
, 0, _("Arrange Icons"));
805 WMInsertListItem(panel
->icommandL
, 1, _("Hide All Windows Except For The Focused One"));
806 WMInsertListItem(panel
->icommandL
, 2, _("Show All Windows"));
808 WMInsertListItem(panel
->icommandL
, 3, _("Exit Window Maker"));
809 WMInsertListItem(panel
->icommandL
, 4, _("Exit X Session"));
810 WMInsertListItem(panel
->icommandL
, 5, _("Restart Window Maker"));
811 WMInsertListItem(panel
->icommandL
, 6, _("Start Another Window Manager : ("));
813 WMInsertListItem(panel
->icommandL
, 7, _("Save Current Session"));
814 WMInsertListItem(panel
->icommandL
, 8, _("Clear Saved Session"));
815 WMInsertListItem(panel
->icommandL
, 9, _("Refresh Screen"));
816 WMInsertListItem(panel
->icommandL
, 10, _("Open Info Panel"));
817 WMInsertListItem(panel
->icommandL
, 11, _("Open Copyright Panel"));
820 panel
->paramF
= WMCreateFrame(panel
->optionsF
);
821 WMResizeWidget(panel
->paramF
, width
, 50);
822 WMMoveWidget(panel
->paramF
, 10, 105);
823 WMSetFrameTitle(panel
->paramF
, _("Window Manager to Start"));
825 panel
->paramT
= WMCreateTextField(panel
->paramF
);
826 WMResizeWidget(panel
->paramT
, width
- 20, 20);
827 WMMoveWidget(panel
->paramT
, 10, 20);
829 WMAddNotificationObserver(dataChanged
, panel
,
830 WMTextDidChangeNotification
,
833 WMMapSubwidgets(panel
->paramF
);
836 panel
->quickB
= WMCreateSwitchButton(panel
->optionsF
);
837 WMResizeWidget(panel
->quickB
, width
, 20);
838 WMMoveWidget(panel
->quickB
, 10, 120);
839 WMSetButtonText(panel
->quickB
, _("Do not confirm action."));
840 WMSetButtonAction(panel
->quickB
, buttonClicked
, panel
);
845 label
= WMCreateLabel(panel
->optionsF
);
846 WMResizeWidget(label
, width
- 20, FRAME_HEIGHT
- 50);
847 WMMoveWidget(label
, 10, 20);
848 WMSetLabelText(label
,
849 _("Instructions:\n\n"
850 " - drag items from the left to the menu to add new items\n"
851 " - drag items out of the menu to remove items\n"
852 " - drag items in menu to change their position\n"
853 " - drag items with Control pressed to copy them\n"
854 " - double click in a menu item to change the label\n"
855 " - click on a menu item to change related information"));
858 WMRealizeWidget(panel
->frame
);
859 WMMapSubwidgets(panel
->frame
);
860 WMMapWidget(panel
->frame
);
865 for (i
= 0; i
< 3; i
++)
866 WMUnmapWidget(panel
->itemPad
[i
]);
868 changedItemPad(panel
->typeP
, panel
);
870 panel
->sections
[NoInfo
][0] = label
;
872 panel
->sections
[ExecInfo
][0] = panel
->commandF
;
873 panel
->sections
[ExecInfo
][1] = panel
->shortF
;
875 panel
->sections
[CommandInfo
][0] = panel
->icommandL
;
876 panel
->sections
[CommandInfo
][1] = panel
->shortF
;
878 panel
->sections
[ExternalInfo
][0] = panel
->pathF
;
880 panel
->sections
[PipeInfo
][0] = panel
->pipeF
;
882 panel
->sections
[DirectoryInfo
][0] = panel
->dpathF
;
883 panel
->sections
[DirectoryInfo
][1] = panel
->dcommandF
;
885 panel
->currentType
= NoInfo
;
892 pos
= WMGetViewScreenPosition(WMWidgetView(panel
->frame
));
895 pos
.x
+= FRAME_WIDTH
+ 20;
900 pos
.y
= WMAX(pos
.y
- 100, 0);
902 WEditMenuShowAt(panel
->menu
, pos
.x
, pos
.y
);
910 freeItemData(ItemData
*data
)
912 #define CFREE(d) if (d) wfree(d)
915 switch (data
->type
) {
917 CFREE(data
->param
.command
.parameter
);
918 CFREE(data
->param
.command
.shortcut
);
922 CFREE(data
->param
.exec
.command
);
923 CFREE(data
->param
.exec
.shortcut
);
927 CFREE(data
->param
.pipe
.command
);
931 CFREE(data
->param
.external
.path
);
935 CFREE(data
->param
.directory
.command
);
936 CFREE(data
->param
.directory
.directory
);
949 parseCommand(proplist_t item
)
951 ItemData
*data
= NEW(ItemData
);
953 char *command
= NULL
;
954 char *parameter
= NULL
;
955 char *shortcut
= NULL
;
959 p
= PLGetArrayElement(item
, i
++);
960 command
= PLGetString(p
);
961 if (strcmp(command
, "SHORTCUT") == 0) {
962 p
= PLGetArrayElement(item
, i
++);
963 shortcut
= PLGetString(p
);
964 p
= PLGetArrayElement(item
, i
++);
965 command
= PLGetString(p
);
967 p
= PLGetArrayElement(item
, i
++);
969 parameter
= PLGetString(p
);
971 if (strcmp(command
, "EXEC") == 0 || strcmp(command
, "SHEXEC") == 0) {
973 data
->type
= ExecInfo
;
975 data
->param
.exec
.command
= wstrdup(parameter
);
977 data
->param
.exec
.shortcut
= wstrdup(shortcut
);
979 } else if (strcmp(command
, "OPEN_MENU") == 0) {
982 * dir menu, menu file
984 * |pipe (TODO: ||pipe)
987 while (isspace(*p
) && *p
) p
++;
989 data
->type
= PipeInfo
;
990 data
->param
.pipe
.command
= wtrimspace(p
+1);
996 s
= strstr(p
, "WITH");
1003 data
->type
= DirectoryInfo
;
1007 while (*s
&& isspace(*s
)) s
++;
1008 data
->param
.directory
.command
= wstrdup(s
);
1010 wtokensplit(p
, &tokens
, &tokn
);
1013 ctokens
= wmalloc(sizeof(char*)*tokn
);
1015 for (i
= 0, j
= 0; i
< tokn
; i
++) {
1016 if (strcmp(tokens
[i
], "-noext") == 0) {
1018 data
->param
.directory
.stripExt
= 1;
1020 ctokens
[j
++] = tokens
[i
];
1023 data
->param
.directory
.directory
= wtokenjoin(ctokens
, j
);
1026 wtokenfree(tokens
, tokn
);
1028 data
->type
= ExternalInfo
;
1029 data
->param
.external
.path
= p
;
1032 } else if (strcmp(command
, "WORKSPACE_MENU") == 0) {
1033 data
->type
= WSMenuInfo
;
1037 if (strcmp(command
, "ARRANGE_ICONS") == 0) {
1039 } else if (strcmp(command
, "HIDE_OTHERS") == 0) {
1041 } else if (strcmp(command
, "SHOW_ALL") == 0) {
1043 } else if (strcmp(command
, "EXIT") == 0) {
1045 } else if (strcmp(command
, "SHUTDOWN") == 0) {
1047 } else if (strcmp(command
, "RESTART") == 0) {
1053 } else if (strcmp(command
, "SAVE_SESSION") == 0) {
1055 } else if (strcmp(command
, "CLEAR_SESSION") == 0) {
1057 } else if (strcmp(command
, "REFRESH") == 0) {
1059 } else if (strcmp(command
, "INFO_PANEL") == 0) {
1061 } else if (strcmp(command
, "LEGAL_PANEL") == 0) {
1064 wwarning(_("unknown command '%s' in menu"), command
);
1068 data
->type
= CommandInfo
;
1070 data
->param
.command
.command
= cmd
;
1072 data
->param
.command
.shortcut
= wstrdup(shortcut
);
1074 data
->param
.command
.parameter
= wstrdup(parameter
);
1089 updateFrameTitle(_Panel
*panel
, char *title
, InfoType type
)
1091 if (type
!= NoInfo
) {
1096 tmp
= wstrconcat(title
, _(": Execute Program"));
1100 tmp
= wstrconcat(title
, _(": Perform Internal Command"));
1104 tmp
= wstrconcat(title
, _(": Open a Submenu"));
1108 tmp
= wstrconcat(title
, _(": Program Generated Submenu"));
1112 tmp
= wstrconcat(title
, _(": Directory Contents Menu"));
1116 tmp
= wstrconcat(title
, _(": Open Workspaces Submenu"));
1123 WMSetFrameTitle(panel
->optionsF
, tmp
);
1126 WMSetFrameTitle(panel
->optionsF
, NULL
);
1133 changeInfoType(_Panel
*panel
, char *title
, InfoType type
)
1137 if (panel
->currentType
!= type
) {
1139 w
= panel
->sections
[panel
->currentType
];
1145 WMUnmapWidget(panel
->paramF
);
1146 WMUnmapWidget(panel
->quickB
);
1149 w
= panel
->sections
[type
];
1157 updateFrameTitle(panel
, title
, type
);
1159 panel
->currentType
= type
;
1166 updateMenuItem(_Panel
*panel
, WEditMenuItem
*item
, WMWidget
*changedWidget
)
1168 ItemData
*data
= WGetEditMenuItemData(item
);
1170 assert(data
!= NULL
);
1172 #define REPLACE(v, d) if (v) wfree(v); v = d
1174 switch (data
->type
) {
1176 if (changedWidget
== panel
->commandT
) {
1177 REPLACE(data
->param
.exec
.command
,
1178 WMGetTextFieldText(panel
->commandT
));
1180 if (changedWidget
== panel
->shortT
) {
1181 REPLACE(data
->param
.exec
.shortcut
,
1182 WMGetTextFieldText(panel
->shortT
));
1187 if (changedWidget
== panel
->icommandL
) {
1188 data
->param
.command
.command
=
1189 WMGetListSelectedItemRow(panel
->icommandL
);
1191 switch (data
->param
.command
.command
) {
1194 if (changedWidget
== panel
->quickB
) {
1195 REPLACE(data
->param
.command
.parameter
,
1196 WMGetButtonSelected(panel
->quickB
)
1197 ? wstrdup("QUICK") : NULL
);
1202 if (changedWidget
== panel
->paramT
) {
1203 REPLACE(data
->param
.command
.parameter
,
1204 WMGetTextFieldText(panel
->paramT
));
1208 if (changedWidget
== panel
->shortT
) {
1209 REPLACE(data
->param
.command
.shortcut
,
1210 WMGetTextFieldText(panel
->shortT
));
1217 if (changedWidget
== panel
->pipeT
) {
1218 REPLACE(data
->param
.pipe
.command
,
1219 WMGetTextFieldText(panel
->pipeT
));
1224 if (changedWidget
== panel
->pathT
) {
1225 REPLACE(data
->param
.external
.path
,
1226 WMGetTextFieldText(panel
->pathT
));
1231 if (changedWidget
== panel
->dpathT
) {
1232 REPLACE(data
->param
.directory
.directory
,
1233 WMGetTextFieldText(panel
->dpathT
));
1235 if (changedWidget
== panel
->dcommandT
) {
1236 REPLACE(data
->param
.directory
.command
,
1237 WMGetTextFieldText(panel
->dcommandT
));
1239 if (changedWidget
== panel
->dstripB
) {
1240 data
->param
.directory
.stripExt
=
1241 WMGetButtonSelected(panel
->dstripB
);
1256 menuItemCloned(WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1257 WEditMenuItem
*origItem
, WEditMenuItem
*newItem
)
1259 ItemData
*data
= WGetEditMenuItemData(origItem
);
1265 #define DUP(s) (s) ? wstrdup(s) : NULL
1267 newData
= NEW(ItemData
);
1269 newData
->type
= data
->type
;
1271 switch (data
->type
) {
1273 newData
->param
.exec
.command
= DUP(data
->param
.exec
.command
);
1274 newData
->param
.exec
.shortcut
= DUP(data
->param
.exec
.shortcut
);
1278 newData
->param
.command
.command
= data
->param
.command
.command
;
1279 newData
->param
.command
.parameter
= DUP(data
->param
.command
.parameter
);
1280 newData
->param
.command
.shortcut
= DUP(data
->param
.command
.shortcut
);
1284 newData
->param
.pipe
.command
= DUP(data
->param
.pipe
.command
);
1288 newData
->param
.external
.path
= DUP(data
->param
.external
.path
);
1292 newData
->param
.directory
.directory
= DUP(data
->param
.directory
.directory
);
1293 newData
->param
.directory
.command
= DUP(data
->param
.directory
.command
);
1294 newData
->param
.directory
.stripExt
= data
->param
.directory
.stripExt
;
1303 WSetEditMenuItemData(newItem
, newData
, (WMCallback
*)freeItemData
);
1308 menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1309 WEditMenuItem
*item
)
1311 _Panel
*panel
= (_Panel
*)delegate
->data
;
1314 updateFrameTitle(panel
, WGetEditMenuItemTitle(item
), panel
->currentType
);
1316 submenu
= WGetEditMenuSubmenu(menu
, item
);
1318 WSetEditMenuTitle(submenu
, WGetEditMenuItemTitle(item
));
1324 shouldRemoveItem(struct WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1325 WEditMenuItem
*item
)
1327 _Panel
*panel
= (_Panel
*)delegate
->data
;
1332 if (WGetEditMenuSubmenu(menu
, item
)) {
1335 res
= WMRunAlertPanel(WMWidgetScreen(menu
), NULL
,
1336 _("Remove Submenu"),
1337 _("Removing this item will destroy all items inside\n"
1338 "the submenu. Do you really want to do that?"),
1340 _("Yes, don't ask again."));
1347 panel
->dontAsk
= True
;
1356 menuItemDeselected(WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1357 WEditMenuItem
*item
)
1359 _Panel
*panel
= (_Panel
*)delegate
->data
;
1361 changeInfoType(panel
, NULL
, NoInfo
);
1366 menuItemSelected(WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1367 WEditMenuItem
*item
)
1369 ItemData
*data
= WGetEditMenuItemData(item
);
1370 _Panel
*panel
= (_Panel
*)delegate
->data
;
1372 panel
->currentItem
= item
;
1375 changeInfoType(panel
, WGetEditMenuItemTitle(item
), data
->type
);
1377 switch (data
->type
) {
1382 WMSetTextFieldText(panel
->commandT
, data
->param
.exec
.command
);
1383 WMSetTextFieldText(panel
->shortT
, data
->param
.exec
.shortcut
);
1387 WMSelectListItem(panel
->icommandL
,
1388 data
->param
.command
.command
);
1389 WMSetListPosition(panel
->icommandL
,
1390 data
->param
.command
.command
- 2);
1391 WMSetTextFieldText(panel
->shortT
, data
->param
.command
.shortcut
);
1393 switch (data
->param
.command
.command
) {
1396 WMSetButtonSelected(panel
->quickB
,
1397 data
->param
.command
.parameter
!=NULL
);
1400 WMSetTextFieldText(panel
->paramT
,
1401 data
->param
.command
.parameter
);
1405 icommandLClicked(panel
->icommandL
, panel
);
1409 WMSetTextFieldText(panel
->pipeT
, data
->param
.pipe
.command
);
1413 WMSetTextFieldText(panel
->pathT
, data
->param
.external
.path
);
1417 WMSetTextFieldText(panel
->dpathT
, data
->param
.directory
.directory
);
1418 WMSetTextFieldText(panel
->dcommandT
, data
->param
.directory
.command
);
1419 WMSetButtonSelected(panel
->dstripB
, data
->param
.directory
.stripExt
);
1434 buildSubmenu(_Panel
*panel
, proplist_t pl
)
1436 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1438 WEditMenuItem
*item
;
1443 tp
= PLGetArrayElement(pl
, 0);
1444 title
= PLGetString(tp
);
1446 menu
= WCreateEditMenu(scr
, title
);
1448 for (i
= 1; i
< PLGetNumberOfElements(pl
); i
++) {
1451 pi
= PLGetArrayElement(pl
, i
);
1453 tp
= PLGetArrayElement(pi
, 0);
1454 bp
= PLGetArrayElement(pi
, 1);
1456 title
= PLGetString(tp
);
1458 if (PLIsArray(bp
)) { /* it's a submenu */
1461 submenu
= buildSubmenu(panel
, pi
);
1463 item
= WAddMenuItemWithTitle(menu
, title
);
1465 WSetEditMenuSubmenu(menu
, item
, submenu
);
1469 item
= WAddMenuItemWithTitle(menu
, title
);
1471 data
= parseCommand(pi
);
1473 if (panel
->markerPix
[data
->type
])
1474 WSetEditMenuItemImage(item
, panel
->markerPix
[data
->type
]);
1475 WSetEditMenuItemData(item
, data
, (WMCallback
*)freeItemData
);
1479 WSetEditMenuAcceptsDrop(menu
, True
);
1480 WSetEditMenuDelegate(menu
, &menuDelegate
);
1482 WMRealizeWidget(menu
);
1490 buildMenuFromPL(_Panel
*panel
, proplist_t pl
)
1492 panel
->menu
= buildSubmenu(panel
, pl
);
1498 getDefaultMenu(_Panel
*panel
)
1500 proplist_t menu
, pmenu
;
1501 char *menuPath
, *gspath
;
1503 gspath
= wusergnusteppath();
1505 menuPath
= wmalloc(strlen(gspath
)+128);
1506 /* if there is a localized plmenu for the tongue put it's filename here */
1507 sprintf(menuPath
, _("%s/Library/WindowMaker/plmenu"), gspath
);
1509 menu
= PLGetProplistWithPath(menuPath
);
1511 wwarning("%s:could not read property list menu", menuPath
);
1513 if (strcmp("%s/Library/WindowMaker/plmenu",
1514 _("%s/Library/WindowMaker/plmenu"))!=0) {
1516 sprintf(menuPath
, "%s/Library/WindowMaker/plmenu", gspath
);
1517 menu
= PLGetProplistWithPath(menuPath
);
1518 wwarning("%s:could not read property list menu", menuPath
);
1523 sprintf(buffer
, _("Could not open default menu from '%s'"),
1525 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
1526 _("Error"), buffer
, _("OK"), NULL
, NULL
);
1543 showData(_Panel
*panel
)
1549 gspath
= wusergnusteppath();
1551 menuPath
= wmalloc(strlen(gspath
)+32);
1552 strcpy(menuPath
, gspath
);
1553 strcat(menuPath
, "/Defaults/WMRootMenu");
1555 pmenu
= PLGetProplistWithPath(menuPath
);
1557 if (!pmenu
|| !PLIsArray(pmenu
)) {
1560 res
= WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
1562 _("The menu file format currently in use is not supported\n"
1563 "by this tool. Do you want to discard the current menu\n"
1564 "to use this tool?"),
1565 _("Yes, Discard and Update"),
1566 _("No, Keep Current Menu"), NULL
);
1568 if (res
== WAPRDefault
) {
1569 pmenu
= getDefaultMenu(panel
);
1572 pmenu
= PLMakeArrayFromElements(PLMakeString("Applications"),
1576 panel
->dontSave
= True
;
1581 panel
->menuPath
= menuPath
;
1583 buildMenuFromPL(panel
, pmenu
);
1603 processData(char *title
, ItemData
*data
)
1607 static char *pscut
= NULL
;
1608 static char *pomenu
= NULL
;
1612 pscut
= PLMakeString("SHORTCUT");
1613 pomenu
= PLMakeString("OPEN_MENU");
1616 item
= PLMakeArrayFromElements(PLMakeString(title
), NULL
);
1619 switch (data
->type
) {
1622 if (strpbrk(data
->param
.exec
.command
, "&$*|><?`=")) {
1631 if (notblank(data
->param
.exec
.shortcut
)) {
1632 PLAppendArrayElement(item
, pscut
);
1633 PLAppendArrayElement(item
,
1634 PLMakeString(data
->param
.exec
.shortcut
));
1637 PLAppendArrayElement(item
, PLMakeString(s1
));
1638 PLAppendArrayElement(item
, PLMakeString(data
->param
.exec
.command
));
1642 if (notblank(data
->param
.command
.shortcut
)) {
1643 PLAppendArrayElement(item
, pscut
);
1644 PLAppendArrayElement(item
,
1645 PLMakeString(data
->param
.command
.shortcut
));
1648 i
= data
->param
.command
.command
;
1650 PLAppendArrayElement(item
, PLMakeString(commandNames
[i
]));
1655 if (data
->param
.command
.parameter
) {
1656 PLAppendArrayElement(item
,
1657 PLMakeString(data
->param
.command
.parameter
));
1661 case 6: /* restart */
1662 if (data
->param
.command
.parameter
) {
1663 PLAppendArrayElement(item
,
1664 PLMakeString(data
->param
.command
.parameter
));
1672 PLAppendArrayElement(item
, pomenu
);
1673 s1
= wstrconcat("| ", data
->param
.pipe
.command
);
1674 PLAppendArrayElement(item
, PLMakeString(s1
));
1679 PLAppendArrayElement(item
, pomenu
);
1680 PLAppendArrayElement(item
, PLMakeString(data
->param
.external
.path
));
1688 l
= strlen(data
->param
.directory
.directory
);
1689 l
+= strlen(data
->param
.directory
.command
);
1692 PLAppendArrayElement(item
, pomenu
);
1695 sprintf(tmp
, "%s%s WITH %s",
1696 data
->param
.directory
.stripExt
? "-noext " : "",
1697 data
->param
.directory
.directory
,
1698 data
->param
.directory
.command
);
1700 PLAppendArrayElement(item
, PLMakeString(tmp
));
1706 PLAppendArrayElement(item
, PLMakeString("WORKSPACE_MENU"));
1719 processSubmenu(WEditMenu
*menu
)
1721 WEditMenuItem
*item
;
1728 s
= WGetEditMenuTitle(menu
);
1729 pl
= PLMakeString(s
);
1731 pmenu
= PLMakeArrayFromElements(pl
, NULL
);
1734 while ((item
= WGetEditMenuItem(menu
, i
++))) {
1737 s
= WGetEditMenuItemTitle(item
);
1739 submenu
= WGetEditMenuSubmenu(menu
, item
);
1741 pl
= processSubmenu(submenu
);
1743 pl
= processData(s
, WGetEditMenuItemData(item
));
1746 PLAppendArrayElement(pmenu
, pl
);
1755 buildPLFromMenu(_Panel
*panel
)
1759 menu
= processSubmenu(panel
->menu
);
1768 storeData(_Panel
*panel
)
1772 if (panel
->dontSave
)
1775 menu
= buildPLFromMenu(panel
);
1777 PLSetFilename(menu
, PLMakeString(panel
->menuPath
));
1787 showMenus(_Panel
*panel
)
1789 WEditMenuUnhide(panel
->menu
);
1794 hideMenus(_Panel
*panel
)
1796 WEditMenuHide(panel
->menu
);
1803 InitMenu(WMScreen
*scr
, WMWindow
*win
)
1807 panel
= wmalloc(sizeof(_Panel
));
1808 memset(panel
, 0, sizeof(_Panel
));
1810 panel
->sectionName
= _("Applications Menu Definition");
1812 panel
->description
= _("Edit the menu for launching applications.");
1816 panel
->callbacks
.createWidgets
= createPanel
;
1817 panel
->callbacks
.updateDomain
= storeData
;
1818 panel
->callbacks
.showPanel
= showMenus
;
1819 panel
->callbacks
.hidePanel
= hideMenus
;
1822 AddSection(panel
, ICON_FILE
);