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 " - double click in a menu item to change the label\n"
854 " - click on a menu item to change related information"));
857 WMRealizeWidget(panel
->frame
);
858 WMMapSubwidgets(panel
->frame
);
859 WMMapWidget(panel
->frame
);
864 for (i
= 0; i
< 3; i
++)
865 WMUnmapWidget(panel
->itemPad
[i
]);
867 changedItemPad(panel
->typeP
, panel
);
869 panel
->sections
[NoInfo
][0] = label
;
871 panel
->sections
[ExecInfo
][0] = panel
->commandF
;
872 panel
->sections
[ExecInfo
][1] = panel
->shortF
;
874 panel
->sections
[CommandInfo
][0] = panel
->icommandL
;
875 panel
->sections
[CommandInfo
][1] = panel
->shortF
;
877 panel
->sections
[ExternalInfo
][0] = panel
->pathF
;
879 panel
->sections
[PipeInfo
][0] = panel
->pipeF
;
881 panel
->sections
[DirectoryInfo
][0] = panel
->dpathF
;
882 panel
->sections
[DirectoryInfo
][1] = panel
->dcommandF
;
884 panel
->currentType
= NoInfo
;
891 pos
= WMGetViewScreenPosition(WMWidgetView(panel
->frame
));
894 pos
.x
+= FRAME_WIDTH
+ 20;
899 pos
.y
= WMAX(pos
.y
- 100, 0);
901 WEditMenuShowAt(panel
->menu
, pos
.x
, pos
.y
);
909 freeItemData(ItemData
*data
)
911 #define CFREE(d) if (d) wfree(d)
914 switch (data
->type
) {
916 CFREE(data
->param
.command
.parameter
);
917 CFREE(data
->param
.command
.shortcut
);
921 CFREE(data
->param
.exec
.command
);
922 CFREE(data
->param
.exec
.shortcut
);
926 CFREE(data
->param
.pipe
.command
);
930 CFREE(data
->param
.external
.path
);
934 CFREE(data
->param
.directory
.command
);
935 CFREE(data
->param
.directory
.directory
);
948 parseCommand(proplist_t item
)
950 ItemData
*data
= NEW(ItemData
);
952 char *command
= NULL
;
953 char *parameter
= NULL
;
954 char *shortcut
= NULL
;
958 p
= PLGetArrayElement(item
, i
++);
959 command
= PLGetString(p
);
960 if (strcmp(command
, "SHORTCUT") == 0) {
961 p
= PLGetArrayElement(item
, i
++);
962 shortcut
= PLGetString(p
);
963 p
= PLGetArrayElement(item
, i
++);
964 command
= PLGetString(p
);
966 p
= PLGetArrayElement(item
, i
++);
968 parameter
= PLGetString(p
);
970 if (strcmp(command
, "EXEC") == 0 || strcmp(command
, "SHEXEC") == 0) {
972 data
->type
= ExecInfo
;
974 data
->param
.exec
.command
= wstrdup(parameter
);
976 data
->param
.exec
.shortcut
= wstrdup(shortcut
);
978 } else if (strcmp(command
, "OPEN_MENU") == 0) {
981 * dir menu, menu file
983 * |pipe (TODO: ||pipe)
986 while (isspace(*p
) && *p
) p
++;
988 data
->type
= PipeInfo
;
989 data
->param
.pipe
.command
= wtrimspace(p
+1);
995 s
= strstr(p
, "WITH");
1002 data
->type
= DirectoryInfo
;
1006 while (*s
&& isspace(*s
)) s
++;
1007 data
->param
.directory
.command
= wstrdup(s
);
1009 wtokensplit(p
, &tokens
, &tokn
);
1012 ctokens
= wmalloc(sizeof(char*)*tokn
);
1014 for (i
= 0, j
= 0; i
< tokn
; i
++) {
1015 if (strcmp(tokens
[i
], "-noext") == 0) {
1017 data
->param
.directory
.stripExt
= 1;
1019 ctokens
[j
++] = tokens
[i
];
1022 data
->param
.directory
.directory
= wtokenjoin(ctokens
, j
);
1025 wtokenfree(tokens
, tokn
);
1027 data
->type
= ExternalInfo
;
1028 data
->param
.external
.path
= p
;
1031 } else if (strcmp(command
, "WORKSPACE_MENU") == 0) {
1032 data
->type
= WSMenuInfo
;
1036 if (strcmp(command
, "ARRANGE_ICONS") == 0) {
1038 } else if (strcmp(command
, "HIDE_OTHERS") == 0) {
1040 } else if (strcmp(command
, "SHOW_ALL") == 0) {
1042 } else if (strcmp(command
, "EXIT") == 0) {
1044 } else if (strcmp(command
, "SHUTDOWN") == 0) {
1046 } else if (strcmp(command
, "RESTART") == 0) {
1052 } else if (strcmp(command
, "SAVE_SESSION") == 0) {
1054 } else if (strcmp(command
, "CLEAR_SESSION") == 0) {
1056 } else if (strcmp(command
, "REFRESH") == 0) {
1058 } else if (strcmp(command
, "INFO_PANEL") == 0) {
1060 } else if (strcmp(command
, "LEGAL_PANEL") == 0) {
1063 wwarning(_("unknown command '%s' in menu"), command
);
1067 data
->type
= CommandInfo
;
1069 data
->param
.command
.command
= cmd
;
1071 data
->param
.command
.shortcut
= wstrdup(shortcut
);
1073 data
->param
.command
.parameter
= wstrdup(parameter
);
1088 updateFrameTitle(_Panel
*panel
, char *title
, InfoType type
)
1090 if (type
!= NoInfo
) {
1095 tmp
= wstrconcat(title
, _(": Execute Program"));
1099 tmp
= wstrconcat(title
, _(": Perform Internal Command"));
1103 tmp
= wstrconcat(title
, _(": Open a Submenu"));
1107 tmp
= wstrconcat(title
, _(": Program Generated Submenu"));
1111 tmp
= wstrconcat(title
, _(": Directory Contents Menu"));
1115 tmp
= wstrconcat(title
, _(": Open Workspaces Submenu"));
1122 WMSetFrameTitle(panel
->optionsF
, tmp
);
1125 WMSetFrameTitle(panel
->optionsF
, NULL
);
1132 changeInfoType(_Panel
*panel
, char *title
, InfoType type
)
1136 if (panel
->currentType
!= type
) {
1138 w
= panel
->sections
[panel
->currentType
];
1144 WMUnmapWidget(panel
->paramF
);
1145 WMUnmapWidget(panel
->quickB
);
1148 w
= panel
->sections
[type
];
1156 updateFrameTitle(panel
, title
, type
);
1158 panel
->currentType
= type
;
1165 updateMenuItem(_Panel
*panel
, WEditMenuItem
*item
, WMWidget
*changedWidget
)
1167 ItemData
*data
= WGetEditMenuItemData(item
);
1169 assert(data
!= NULL
);
1171 #define REPLACE(v, d) if (v) wfree(v); v = d
1173 switch (data
->type
) {
1175 if (changedWidget
== panel
->commandT
) {
1176 REPLACE(data
->param
.exec
.command
,
1177 WMGetTextFieldText(panel
->commandT
));
1179 if (changedWidget
== panel
->shortT
) {
1180 REPLACE(data
->param
.exec
.shortcut
,
1181 WMGetTextFieldText(panel
->shortT
));
1186 if (changedWidget
== panel
->icommandL
) {
1187 data
->param
.command
.command
=
1188 WMGetListSelectedItemRow(panel
->icommandL
);
1190 switch (data
->param
.command
.command
) {
1193 if (changedWidget
== panel
->quickB
) {
1194 REPLACE(data
->param
.command
.parameter
,
1195 WMGetButtonSelected(panel
->quickB
)
1196 ? wstrdup("QUICK") : NULL
);
1201 if (changedWidget
== panel
->paramT
) {
1202 REPLACE(data
->param
.command
.parameter
,
1203 WMGetTextFieldText(panel
->paramT
));
1207 if (changedWidget
== panel
->shortT
) {
1208 REPLACE(data
->param
.command
.shortcut
,
1209 WMGetTextFieldText(panel
->shortT
));
1216 if (changedWidget
== panel
->pipeT
) {
1217 REPLACE(data
->param
.pipe
.command
,
1218 WMGetTextFieldText(panel
->pipeT
));
1223 if (changedWidget
== panel
->pathT
) {
1224 REPLACE(data
->param
.external
.path
,
1225 WMGetTextFieldText(panel
->pathT
));
1230 if (changedWidget
== panel
->dpathT
) {
1231 REPLACE(data
->param
.directory
.directory
,
1232 WMGetTextFieldText(panel
->dpathT
));
1234 if (changedWidget
== panel
->dcommandT
) {
1235 REPLACE(data
->param
.directory
.command
,
1236 WMGetTextFieldText(panel
->dcommandT
));
1238 if (changedWidget
== panel
->dstripB
) {
1239 data
->param
.directory
.stripExt
=
1240 WMGetButtonSelected(panel
->dstripB
);
1255 menuItemCloned(WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1256 WEditMenuItem
*origItem
, WEditMenuItem
*newItem
)
1258 ItemData
*data
= WGetEditMenuItemData(origItem
);
1264 #define DUP(s) (s) ? wstrdup(s) : NULL
1266 newData
= NEW(ItemData
);
1268 newData
->type
= data
->type
;
1270 switch (data
->type
) {
1272 newData
->param
.exec
.command
= DUP(data
->param
.exec
.command
);
1273 newData
->param
.exec
.shortcut
= DUP(data
->param
.exec
.shortcut
);
1277 newData
->param
.command
.command
= data
->param
.command
.command
;
1278 newData
->param
.command
.parameter
= DUP(data
->param
.command
.parameter
);
1279 newData
->param
.command
.shortcut
= DUP(data
->param
.command
.shortcut
);
1283 newData
->param
.pipe
.command
= DUP(data
->param
.pipe
.command
);
1287 newData
->param
.external
.path
= DUP(data
->param
.external
.path
);
1291 newData
->param
.directory
.directory
= DUP(data
->param
.directory
.directory
);
1292 newData
->param
.directory
.command
= DUP(data
->param
.directory
.command
);
1293 newData
->param
.directory
.stripExt
= data
->param
.directory
.stripExt
;
1302 WSetEditMenuItemData(newItem
, newData
, (WMCallback
*)freeItemData
);
1307 menuItemEdited(struct WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1308 WEditMenuItem
*item
)
1310 _Panel
*panel
= (_Panel
*)delegate
->data
;
1313 updateFrameTitle(panel
, WGetEditMenuItemTitle(item
), panel
->currentType
);
1315 submenu
= WGetEditMenuSubmenu(menu
, item
);
1317 WSetEditMenuTitle(submenu
, WGetEditMenuItemTitle(item
));
1323 shouldRemoveItem(struct WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1324 WEditMenuItem
*item
)
1326 _Panel
*panel
= (_Panel
*)delegate
->data
;
1331 if (WGetEditMenuSubmenu(menu
, item
)) {
1334 res
= WMRunAlertPanel(WMWidgetScreen(menu
), NULL
,
1335 _("Remove Submenu"),
1336 _("Removing this item will destroy all items inside\n"
1337 "the submenu. Do you really want to do that?"),
1339 _("Yes, don't ask again."));
1346 panel
->dontAsk
= True
;
1355 menuItemDeselected(WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1356 WEditMenuItem
*item
)
1358 _Panel
*panel
= (_Panel
*)delegate
->data
;
1360 changeInfoType(panel
, NULL
, NoInfo
);
1365 menuItemSelected(WEditMenuDelegate
*delegate
, WEditMenu
*menu
,
1366 WEditMenuItem
*item
)
1368 ItemData
*data
= WGetEditMenuItemData(item
);
1369 _Panel
*panel
= (_Panel
*)delegate
->data
;
1371 panel
->currentItem
= item
;
1374 changeInfoType(panel
, WGetEditMenuItemTitle(item
), data
->type
);
1376 switch (data
->type
) {
1381 WMSetTextFieldText(panel
->commandT
, data
->param
.exec
.command
);
1382 WMSetTextFieldText(panel
->shortT
, data
->param
.exec
.shortcut
);
1386 WMSelectListItem(panel
->icommandL
,
1387 data
->param
.command
.command
);
1388 WMSetListPosition(panel
->icommandL
,
1389 data
->param
.command
.command
- 2);
1390 WMSetTextFieldText(panel
->shortT
, data
->param
.command
.shortcut
);
1392 switch (data
->param
.command
.command
) {
1395 WMSetButtonSelected(panel
->quickB
,
1396 data
->param
.command
.parameter
!=NULL
);
1399 WMSetTextFieldText(panel
->paramT
,
1400 data
->param
.command
.parameter
);
1404 icommandLClicked(panel
->icommandL
, panel
);
1408 WMSetTextFieldText(panel
->pipeT
, data
->param
.pipe
.command
);
1412 WMSetTextFieldText(panel
->pathT
, data
->param
.external
.path
);
1416 WMSetTextFieldText(panel
->dpathT
, data
->param
.directory
.directory
);
1417 WMSetTextFieldText(panel
->dcommandT
, data
->param
.directory
.command
);
1418 WMSetButtonSelected(panel
->dstripB
, data
->param
.directory
.stripExt
);
1433 buildSubmenu(_Panel
*panel
, proplist_t pl
)
1435 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
1437 WEditMenuItem
*item
;
1442 tp
= PLGetArrayElement(pl
, 0);
1443 title
= PLGetString(tp
);
1445 menu
= WCreateEditMenu(scr
, title
);
1447 for (i
= 1; i
< PLGetNumberOfElements(pl
); i
++) {
1450 pi
= PLGetArrayElement(pl
, i
);
1452 tp
= PLGetArrayElement(pi
, 0);
1453 bp
= PLGetArrayElement(pi
, 1);
1455 title
= PLGetString(tp
);
1457 if (PLIsArray(bp
)) { /* it's a submenu */
1460 submenu
= buildSubmenu(panel
, pi
);
1462 item
= WAddMenuItemWithTitle(menu
, title
);
1464 WSetEditMenuSubmenu(menu
, item
, submenu
);
1468 item
= WAddMenuItemWithTitle(menu
, title
);
1470 data
= parseCommand(pi
);
1472 if (panel
->markerPix
[data
->type
])
1473 WSetEditMenuItemImage(item
, panel
->markerPix
[data
->type
]);
1474 WSetEditMenuItemData(item
, data
, (WMCallback
*)freeItemData
);
1478 WSetEditMenuAcceptsDrop(menu
, True
);
1479 WSetEditMenuDelegate(menu
, &menuDelegate
);
1481 WMRealizeWidget(menu
);
1489 buildMenuFromPL(_Panel
*panel
, proplist_t pl
)
1491 panel
->menu
= buildSubmenu(panel
, pl
);
1497 getDefaultMenu(_Panel
*panel
)
1499 proplist_t menu
, pmenu
;
1500 char *menuPath
, *gspath
;
1502 gspath
= wusergnusteppath();
1504 menuPath
= wmalloc(strlen(gspath
)+128);
1505 /* if there is a localized plmenu for the tongue put it's filename here */
1506 sprintf(menuPath
, _("%s/Library/WindowMaker/plmenu"), gspath
);
1508 menu
= PLGetProplistWithPath(menuPath
);
1510 wwarning("%s:could not read property list menu", menuPath
);
1512 if (strcmp("%s/Library/WindowMaker/plmenu",
1513 _("%s/Library/WindowMaker/plmenu"))!=0) {
1515 sprintf(menuPath
, "%s/Library/WindowMaker/plmenu", gspath
);
1516 menu
= PLGetProplistWithPath(menuPath
);
1517 wwarning("%s:could not read property list menu", menuPath
);
1522 sprintf(buffer
, _("Could not open default menu from '%s'"),
1524 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
1525 _("Error"), buffer
, _("OK"), NULL
, NULL
);
1542 showData(_Panel
*panel
)
1548 gspath
= wusergnusteppath();
1550 menuPath
= wmalloc(strlen(gspath
)+32);
1551 strcpy(menuPath
, gspath
);
1552 strcat(menuPath
, "/Defaults/WMRootMenu");
1554 pmenu
= PLGetProplistWithPath(menuPath
);
1556 if (!pmenu
|| !PLIsArray(pmenu
)) {
1559 res
= WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
1561 _("The menu file format currently in use is not supported\n"
1562 "by this tool. Do you want to discard the current menu\n"
1563 "to use this tool?"),
1564 _("Yes, Discard and Update"),
1565 _("No, Keep Current Menu"), NULL
);
1567 if (res
== WAPRDefault
) {
1568 pmenu
= getDefaultMenu(panel
);
1571 pmenu
= PLMakeArrayFromElements(PLMakeString("Applications"),
1575 panel
->dontSave
= True
;
1580 panel
->menuPath
= menuPath
;
1582 buildMenuFromPL(panel
, pmenu
);
1602 processData(char *title
, ItemData
*data
)
1606 static char *pscut
= NULL
;
1607 static char *pomenu
= NULL
;
1611 pscut
= PLMakeString("SHORTCUT");
1612 pomenu
= PLMakeString("OPEN_MENU");
1615 item
= PLMakeArrayFromElements(PLMakeString(title
), NULL
);
1618 switch (data
->type
) {
1621 if (strpbrk(data
->param
.exec
.command
, "&$*|><?`=")) {
1630 if (notblank(data
->param
.exec
.shortcut
)) {
1631 PLAppendArrayElement(item
, pscut
);
1632 PLAppendArrayElement(item
,
1633 PLMakeString(data
->param
.exec
.shortcut
));
1636 PLAppendArrayElement(item
, PLMakeString(s1
));
1637 PLAppendArrayElement(item
, PLMakeString(data
->param
.exec
.command
));
1641 if (notblank(data
->param
.command
.shortcut
)) {
1642 PLAppendArrayElement(item
, pscut
);
1643 PLAppendArrayElement(item
,
1644 PLMakeString(data
->param
.command
.shortcut
));
1647 i
= data
->param
.command
.command
;
1649 PLAppendArrayElement(item
, PLMakeString(commandNames
[i
]));
1654 if (data
->param
.command
.parameter
) {
1655 PLAppendArrayElement(item
,
1656 PLMakeString(data
->param
.command
.parameter
));
1660 case 6: /* restart */
1661 if (data
->param
.command
.parameter
) {
1662 PLAppendArrayElement(item
,
1663 PLMakeString(data
->param
.command
.parameter
));
1671 PLAppendArrayElement(item
, pomenu
);
1672 s1
= wstrconcat("| ", data
->param
.pipe
.command
);
1673 PLAppendArrayElement(item
, PLMakeString(s1
));
1678 PLAppendArrayElement(item
, pomenu
);
1679 PLAppendArrayElement(item
, PLMakeString(data
->param
.external
.path
));
1687 l
= strlen(data
->param
.directory
.directory
);
1688 l
+= strlen(data
->param
.directory
.command
);
1691 PLAppendArrayElement(item
, pomenu
);
1694 sprintf(tmp
, "%s%s WITH %s",
1695 data
->param
.directory
.stripExt
? "-noext " : "",
1696 data
->param
.directory
.directory
,
1697 data
->param
.directory
.command
);
1699 PLAppendArrayElement(item
, PLMakeString(tmp
));
1705 PLAppendArrayElement(item
, PLMakeString("WORKSPACE_MENU"));
1718 processSubmenu(WEditMenu
*menu
)
1720 WEditMenuItem
*item
;
1727 s
= WGetEditMenuTitle(menu
);
1728 pl
= PLMakeString(s
);
1730 pmenu
= PLMakeArrayFromElements(pl
, NULL
);
1733 while ((item
= WGetEditMenuItem(menu
, i
++))) {
1736 s
= WGetEditMenuItemTitle(item
);
1738 submenu
= WGetEditMenuSubmenu(menu
, item
);
1740 pl
= processSubmenu(submenu
);
1742 pl
= processData(s
, WGetEditMenuItemData(item
));
1745 PLAppendArrayElement(pmenu
, pl
);
1754 buildPLFromMenu(_Panel
*panel
)
1758 menu
= processSubmenu(panel
->menu
);
1767 storeData(_Panel
*panel
)
1771 if (panel
->dontSave
)
1774 menu
= buildPLFromMenu(panel
);
1776 PLSetFilename(menu
, PLMakeString(panel
->menuPath
));
1786 showMenus(_Panel
*panel
)
1788 WEditMenuUnhide(panel
->menu
);
1793 hideMenus(_Panel
*panel
)
1795 WEditMenuHide(panel
->menu
);
1802 InitMenu(WMScreen
*scr
, WMWindow
*win
)
1806 panel
= wmalloc(sizeof(_Panel
));
1807 memset(panel
, 0, sizeof(_Panel
));
1809 panel
->sectionName
= _("Applications Menu Definition");
1811 panel
->description
= _("Edit the menu for launching applications.");
1815 panel
->callbacks
.createWidgets
= createPanel
;
1816 panel
->callbacks
.updateDomain
= storeData
;
1817 panel
->callbacks
.showPanel
= showMenus
;
1818 panel
->callbacks
.hidePanel
= hideMenus
;
1821 AddSection(panel
, ICON_FILE
);