1 /* Menu.c- menu definition
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998 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>
30 typedef struct _Panel
{
36 CallbackRec callbacks
;
71 proplist_t editedItem
;
73 proplist_t itemClipboard
; /* for copy/paste */
75 char capturing
; /* shortcut capture */
76 char unsaved
; /* if there are unsaved changes */
83 #define ICON_FILE "menus"
87 extern char *OpenMenuGuru(WMWindow
*mainWindow
);
89 extern Bool
AskMenuCopy(WMWindow
*wwin
);
92 /* must match the indexes of the commands popup */
136 static void showData(_Panel
*panel
);
138 static void fillBrowser(WMBrowserDelegate
*self
, WMBrowser
*bPtr
, int column
,
141 static void scrolledBrowser(WMBrowserDelegate
*self
, WMBrowser
*sender
);
143 static WMBrowserDelegate browserDelegate
= {
145 fillBrowser
, /* createRowsForColumn */
146 NULL
, /* titleOfColumn */
147 scrolledBrowser
, /* didScroll */
148 NULL
/* willScroll */
153 isMenu(proplist_t item
)
155 if (PLGetNumberOfElements(item
)==1)
158 return PLIsArray(PLGetArrayElement(item
, 1));
163 splitOpenMenuParameter(char *str
, char **dirs
, char **prog
)
167 if (!(p
= strstr(str
, " WITH "))) {
168 *dirs
= wstrdup(str
);
175 *dirs
= wmalloc(i
-j
+1);
176 strncpy(*dirs
, str
, i
-j
+1);
180 while (isspace(*p
)) p
++;
192 changeItemTitle(proplist_t item
, char *title
)
196 tmp
= PLGetArrayElement(item
, 0);
198 PLRemoveArrayElement(item
, 0);
199 PLInsertArrayElement(item
, title
?PLMakeString(title
):PLMakeString(""), 0);
204 removeParameter(proplist_t item
)
209 if (strcmp(PLGetString(PLGetArrayElement(item
, 1)), "SHORTCUT")==0) {
214 tmp
= PLGetArrayElement(item
, index
);
215 PLRemoveArrayElement(item
, index
);
222 changeItemParameter(proplist_t item
, char *param
)
227 if (strcmp(PLGetString(PLGetArrayElement(item
, 1)), "SHORTCUT")==0) {
232 tmp
= PLGetArrayElement(item
, index
);
233 PLRemoveArrayElement(item
, index
);
235 tmp
= param
?PLMakeString(param
):PLMakeString("");
236 PLInsertArrayElement(item
, tmp
, index
);
241 changeItemShortcut(proplist_t item
, char *shortcut
)
245 if (strcmp(PLGetString(PLGetArrayElement(item
, 1)), "SHORTCUT")==0) {
247 tmp
= PLGetArrayElement(item
, 2);
248 PLRemoveArrayElement(item
, 2);
250 PLInsertArrayElement(item
, PLMakeString(shortcut
), 2);
252 /* remove SHORTCUT keyword */
253 tmp
= PLGetArrayElement(item
, 1);
254 PLRemoveArrayElement(item
, 1);
256 /* remove the shortcut */
257 tmp
= PLGetArrayElement(item
, 1);
258 PLRemoveArrayElement(item
, 1);
263 PLInsertArrayElement(item
, PLMakeString("SHORTCUT"), 1);
264 PLInsertArrayElement(item
, PLMakeString(shortcut
), 2);
273 changeItemCommand(proplist_t item
, char *command
)
277 tmp
= PLGetArrayElement(item
, 1);
278 if (strcmp(PLGetString(tmp
), "SHORTCUT")==0) {
280 PLRemoveArrayElement(item
, 3);
281 PLInsertArrayElement(item
, PLMakeString(command
), 3);
284 PLRemoveArrayElement(item
, 1);
285 PLInsertArrayElement(item
, PLMakeString(command
), 1);
291 getItemTitle(proplist_t item
)
293 return PLGetString(PLGetArrayElement(item
, 0));
298 getItemParameter(proplist_t item
)
302 tmp
= PLGetArrayElement(item
, 1);
303 if (strcmp(PLGetString(tmp
), "SHORTCUT")==0) {
304 tmp
= PLGetArrayElement(item
, 4);
305 return tmp
? PLGetString(tmp
) : NULL
;
307 tmp
= PLGetArrayElement(item
, 2);
308 return tmp
? PLGetString(tmp
) : NULL
;
315 getItemShortcut(proplist_t item
)
319 tmp
= PLGetArrayElement(item
, 1);
320 if (strcmp(PLGetString(tmp
), "SHORTCUT")==0) {
321 return PLGetString(PLGetArrayElement(item
, 2));
330 getItemCommand(proplist_t item
)
335 tmp
= PLGetArrayElement(item
, 1);
338 if (strcmp(PLGetString(tmp
), "SHORTCUT")==0) {
339 str
= PLGetString(PLGetArrayElement(item
,3));
341 str
= PLGetString(tmp
);
349 getSubmenuInColumn(_Panel
*panel
, int column
)
359 if (column
>= WMGetBrowserNumberOfColumns(panel
->browser
))
362 list
= WMGetBrowserListInColumn(panel
->browser
, column
- 1);
363 assert(list
!= NULL
);
365 r
= WMGetListSelectedItemRow(list
);
367 parent
= getSubmenuInColumn(panel
, column
- 1);
369 assert(parent
!= NULL
);
371 submenu
= PLGetArrayElement(parent
, r
+ 1);
378 updateForItemType(_Panel
*panel
, int type
)
380 if (type
==TNothing
) {
381 WMUnmapWidget(panel
->labF
);
383 WMMapWidget(panel
->labF
);
385 if (type
==TExternalMenu
|| type
==TNothing
) {
386 WMUnmapWidget(panel
->cmdF
);
388 WMMapWidget(panel
->cmdF
);
390 if (type
==TNothing
|| type
==TWSMenu
|| type
==TExternalMenu
) {
391 WMUnmapWidget(panel
->shoF
);
393 WMMapWidget(panel
->shoF
);
395 if (type
==TExec
|| type
== TShExec
|| type
==TRestart
396 || type
==TExternalMenu
) {
397 WMMapWidget(panel
->proF
);
399 WMUnmapWidget(panel
->proF
);
401 if (type
==TExternalMenu
) {
402 WMMapWidget(panel
->pathF
);
404 WMUnmapWidget(panel
->pathF
);
407 WMMapWidget(panel
->noconfirmB
);
409 WMUnmapWidget(panel
->noconfirmB
);
412 WMMapWidget(panel
->infoL
);
414 WMUnmapWidget(panel
->infoL
);
416 if (type
==TExternalMenu
) {
417 WMMapWidget(panel
->guruB
);
419 WMUnmapWidget(panel
->guruB
);
421 if (type
== TRestart
) {
422 WMSetFrameTitle(panel
->proF
, _("Window Manager"));
423 } else if (type
== TExternalMenu
) {
424 WMSetFrameTitle(panel
->proF
, _("Program to Open Files"));
425 } else if (type
== TShExec
) {
426 WMSetFrameTitle(panel
->proF
, _("Command to Execute"));
428 WMSetFrameTitle(panel
->proF
, _("Program to Run"));
434 getItemOfSelectedEntry(WMBrowser
*bPtr
)
440 i
= WMGetBrowserSelectedColumn(bPtr
);
441 menu
= getSubmenuInColumn((_Panel
*)WMGetHangedData(bPtr
), i
);
443 i
= WMGetBrowserSelectedRowInColumn(bPtr
, i
);
444 item
= PLGetArrayElement(menu
, i
+1);
451 performCommand(WMWidget
*w
, void *data
)
453 _Panel
*panel
= (_Panel
*)data
;
454 WMPopUpButton
*pop
= (WMPopUpButton
*)w
;
455 proplist_t menuItem
= NULL
;
459 static int cmdIndex
=0;
461 Bool removed
= False
;
463 column
= WMGetBrowserFirstVisibleColumn(panel
->browser
);
464 if (pop
== panel
->cmd2P
) {
468 if (column
>= WMGetBrowserNumberOfColumns(panel
->browser
))
471 menu
= getSubmenuInColumn(panel
, column
);
473 row
= WMGetBrowserSelectedRowInColumn(panel
->browser
, column
);
475 switch (WMGetPopUpButtonSelectedItem(pop
)) {
477 title
= wmalloc(strlen(_("New Command %i"))+6);
478 sprintf(title
, _("New Command %i"), cmdIndex
++);
479 menuItem
= PLMakeArrayFromElements(PLMakeString(title
),
480 PLMakeString("EXEC"),
485 title
= wstrdup(_("New Submenu"));
486 menuItem
= PLMakeArrayFromElements(PLMakeString(title
),
490 title
= wstrdup(_("External Menu"));
491 menuItem
= PLMakeArrayFromElements(PLMakeString(title
),
492 PLMakeString("OPEN_MENU"),
497 title
= wstrdup(_("Workspaces"));
498 menuItem
= PLMakeArrayFromElements(PLMakeString(title
),
499 PLMakeString("WORKSPACE_MENU"),
501 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CAddWorkspace
, False
);
502 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CAddWorkspace
, False
);
507 panel
->scrolledBrowser
= 0;
508 WMRemoveBrowserItem(panel
->browser
, column
, row
);
509 menuItem
= PLGetArrayElement(menu
, row
+1);
510 if (strcmp(getItemCommand(menuItem
), "WORKSPACE_MENU")==0) {
511 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CAddWorkspace
, True
);
512 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CAddWorkspace
, True
);
514 PLRemoveArrayElement(menu
, row
+1);
516 updateForItemType(panel
, TNothing
);
517 panel
->editedItem
= NULL
;
520 if (pop
== panel
->cmd1P
&& !panel
->scrolledBrowser
) {
521 WMSetTextFieldText(panel
->tit2T
, NULL
);
529 if (panel
->itemClipboard
530 && strcmp(getItemCommand(panel
->itemClipboard
), "WORKSPACE_MENU")==0){
531 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CAddWorkspace
, True
);
532 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CAddWorkspace
, True
);
534 if (panel
->itemClipboard
)
535 PLRelease(panel
->itemClipboard
);
536 WMRemoveBrowserItem(panel
->browser
, column
, row
);
537 menuItem
= PLGetArrayElement(menu
, row
+1);
538 PLRemoveArrayElement(menu
, row
+1);
539 updateForItemType(panel
, TNothing
);
541 panel
->itemClipboard
= menuItem
;
543 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CPaste
, True
);
544 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CPaste
, True
);
551 if (panel
->itemClipboard
552 && strcmp(getItemCommand(panel
->itemClipboard
), "WORKSPACE_MENU")==0){
553 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CAddWorkspace
, True
);
554 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CAddWorkspace
, True
);
556 if (panel
->itemClipboard
)
557 PLRelease(panel
->itemClipboard
);
558 panel
->itemClipboard
= NULL
;
559 menuItem
= PLGetArrayElement(menu
, row
+1);
560 if (strcmp(getItemCommand(menuItem
), "WORKSPACE_MENU")==0)
562 panel
->itemClipboard
= PLDeepCopy(menuItem
);
564 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CPaste
, True
);
565 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CPaste
, True
);
568 menuItem
= panel
->itemClipboard
;
569 title
= wstrdup(getItemTitle(menuItem
));
570 panel
->itemClipboard
= NULL
;
571 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CPaste
, False
);
572 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CPaste
, False
);
577 WMInsertBrowserItem(panel
->browser
, column
, row
, title
, isMenu(menuItem
));
579 PLAppendArrayElement(menu
, menuItem
);
581 PLInsertArrayElement(menu
, menuItem
, row
+1);
586 if (pop
== panel
->cmd1P
) {
587 WMSetTextFieldText(panel
->tit2T
, NULL
);
594 browserClick(WMWidget
*w
, void *data
)
596 _Panel
*panel
= (_Panel
*)data
;
600 /* stop shortcut capture */
601 panel
->capturing
= 0;
603 item
= getItemOfSelectedEntry(panel
->browser
);
605 panel
->editedItem
= item
;
608 WMSetTextFieldText(panel
->labT
, getItemTitle(item
));
611 updateForItemType(panel
, TNothing
);
613 WMSetPopUpButtonEnabled(panel
->cmd2P
, True
);
616 int column
= WMGetBrowserSelectedColumn(panel
->browser
);
618 if (column
== WMGetBrowserNumberOfColumns(panel
->browser
)-1
620 WMSetPopUpButtonEnabled(panel
->cmd2P
, True
);
622 WMSetPopUpButtonEnabled(panel
->cmd2P
, False
);
624 if (column
==WMGetBrowserFirstVisibleColumn(panel
->browser
)) {
625 /* second column is empty, because selected item is not a submenu */
626 WMSetTextFieldText(panel
->tit2T
, NULL
);
630 command
= getItemCommand(item
);
632 WMSetTextFieldText(panel
->shoT
, getItemShortcut(item
));
634 if (strcmp(command
, "OPEN_MENU")==0) {
637 splitOpenMenuParameter(getItemParameter(item
), &p
, &c
);
638 WMSetTextFieldText(panel
->pathT
, p
);
639 WMSetTextFieldText(panel
->proT
, c
);
644 updateForItemType(panel
, TExternalMenu
);
645 } else if (strcmp(command
, "EXEC")==0) {
646 WMSetTextFieldText(panel
->proT
, getItemParameter(item
));
647 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpExec
);
648 updateForItemType(panel
, TExec
);
649 } else if (strcmp(command
, "SHEXEC")==0) {
650 WMSetTextFieldText(panel
->proT
, getItemParameter(item
));
651 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpShExec
);
652 updateForItemType(panel
, TShExec
);
653 } else if (strcmp(command
, "WORKSPACE_MENU")==0) {
654 updateForItemType(panel
, TWSMenu
);
655 } else if (strcmp(command
, "EXIT")==0) {
656 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpExit
);
657 updateForItemType(panel
, TExit
);
658 } else if (strcmp(command
, "SHUTDOWN")==0) {
659 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpShutdown
);
660 updateForItemType(panel
, TExit
);
661 } else if (strcmp(command
, "RESTARTW")==0) {
662 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpRestartWM
);
663 updateForItemType(panel
, TRestartWM
);
664 } else if (strcmp(command
, "RESTART")==0) {
665 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpRestart
);
666 WMSetTextFieldText(panel
->proT
, getItemParameter(item
));
667 updateForItemType(panel
, TRestart
);
669 /* simple commands */
670 if (strcmp(command
, "ARRANGE_ICONS")==0)
671 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpArrange
);
672 else if (strcmp(command
, "HIDE_OTHERS")==0)
673 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpHide
);
674 else if (strcmp(command
, "SHOW_ALL")==0)
675 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpShow
);
676 else if (strcmp(command
, "SAVE_SESSION")==0)
677 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpSaveSession
);
678 else if (strcmp(command
, "CLEAR_SESSION")==0)
679 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpClearSession
);
680 else if (strcmp(command
, "REFRESH")==0)
681 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpRefresh
);
682 else if (strcmp(command
, "INFO_PANEL")==0)
683 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpInfo
);
684 else if (strcmp(command
, "LEGAL_PANEL")==0)
685 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpLegal
);
686 updateForItemType(panel
, TSimpleCommand
);
693 fillBrowser(WMBrowserDelegate
*self
, WMBrowser
*bPtr
, int column
, WMList
*list
)
695 _Panel
*panel
= (_Panel
*)WMGetHangedData(bPtr
);
697 proplist_t menuList
= NULL
;
701 menuList
= getSubmenuInColumn(panel
, column
);
702 assert(menuList
!= NULL
);
704 if (column
> WMGetBrowserFirstVisibleColumn(bPtr
)) {
705 WMSetTextFieldText(panel
->tit2T
, getItemTitle(menuList
));
707 WMSetTextFieldText(panel
->tit1T
, getItemTitle(menuList
));
710 for (i
=1; i
<PLGetNumberOfElements(menuList
); i
++) {
711 menuItem
= PLGetArrayElement(menuList
, i
);
712 WMInsertBrowserItem(bPtr
, column
, -1, getItemTitle(menuItem
),
721 changedItem(void *observerData
, WMNotification
*notification
)
723 _Panel
*panel
= (_Panel
*)observerData
;
724 WMTextField
*t
= (WMTextField
*)WMGetNotificationObject(notification
);
725 proplist_t item
= panel
->editedItem
;
737 command
= getItemCommand(item
);
739 if (t
== panel
->shoT
) {
740 str
= WMGetTextFieldText(t
);
741 if (strlen(str
)==0) {
745 changeItemShortcut(item
, str
);
748 } else if (t
== panel
->labT
) {
751 str
= WMGetTextFieldText(t
);
754 changeItemTitle(item
, str
);
755 column
= WMGetBrowserSelectedColumn(panel
->browser
);
756 list
= WMGetBrowserListInColumn(panel
->browser
, column
);
757 litem
= WMGetListSelectedItem(list
);
762 WMRedisplayWidget(list
);
763 } else if (strcmp(command
, "EXEC")==0
764 || strcmp(command
, "SHEXEC")==0
765 || strcmp(command
, "RESTART")==0) {
766 if (t
== panel
->proT
) {
767 str
= WMGetTextFieldText(t
);
769 changeItemParameter(item
, str
);
773 } else if (strcmp(command
, "OPEN_MENU")==0) {
777 str
= WMGetTextFieldText(panel
->pathT
);
778 str2
= WMGetTextFieldText(panel
->proT
);
779 text
= wmalloc(strlen(str
)+strlen(str2
)+16);
782 if (strlen(str2
)>0) {
783 strcat(text
, " WITH ");
787 changeItemParameter(item
, text
);
795 changedTitle(void *observerData
, WMNotification
*notification
)
797 _Panel
*panel
= (_Panel
*)observerData
;
798 WMTextField
*t
= (WMTextField
*)WMGetNotificationObject(notification
);
804 column
= WMGetBrowserFirstVisibleColumn(panel
->browser
);
805 if (panel
->tit2T
== t
)
808 menu
= getSubmenuInColumn(panel
, column
);
812 txt
= WMGetTextFieldText(t
);
813 changeItemTitle(menu
, txt
);
818 list
= WMGetBrowserListInColumn(panel
->browser
, column
-1);
819 litem
= WMGetListSelectedItem(list
);
824 WMRedisplayWidget(list
);
833 changedCommand(WMWidget
*w
, void *data
)
835 _Panel
*panel
= (_Panel
*)data
;
840 i
= WMGetPopUpButtonSelectedItem(panel
->cmdP
);
841 changeItemParameter(panel
->editedItem
, "");
844 if (strcmp(getItemCommand(panel
->editedItem
), "EXEC")!=0) {
845 changeItemCommand(panel
->editedItem
, "EXEC");
846 tmp
= WMGetTextFieldText(panel
->proT
);
847 changeItemParameter(panel
->editedItem
, tmp
);
849 updateForItemType(panel
, TExec
);
853 if (strcmp(getItemCommand(panel
->editedItem
), "SHEXEC")!=0) {
854 changeItemCommand(panel
->editedItem
, "SHEXEC");
855 tmp
= WMGetTextFieldText(panel
->proT
);
856 changeItemParameter(panel
->editedItem
, tmp
);
858 updateForItemType(panel
, TShExec
);
862 if (strcmp(getItemCommand(panel
->editedItem
), "ARRANGE_ICONS")!=0) {
863 changeItemCommand(panel
->editedItem
, "ARRANGE_ICONS");
864 updateForItemType(panel
, TSimpleCommand
);
868 if (strcmp(getItemCommand(panel
->editedItem
), "HIDE_OTHERS")!=0) {
869 changeItemCommand(panel
->editedItem
, "HIDE_OTHERS");
870 updateForItemType(panel
, TSimpleCommand
);
874 if (strcmp(getItemCommand(panel
->editedItem
), "SHOW_ALL")!=0) {
875 changeItemCommand(panel
->editedItem
, "SHOW_ALL");
876 updateForItemType(panel
, TSimpleCommand
);
880 if (strcmp(getItemCommand(panel
->editedItem
), "EXIT")!=0) {
881 changeItemCommand(panel
->editedItem
, "EXIT");
882 updateForItemType(panel
, TExit
);
884 if (WMGetButtonSelected(panel
->noconfirmB
))
885 changeItemParameter(panel
->editedItem
, "QUICK");
887 changeItemParameter(panel
->editedItem
, "");
890 if (strcmp(getItemCommand(panel
->editedItem
), "SHUTDOWN")!=0) {
891 changeItemCommand(panel
->editedItem
, "SHUTDOWN");
892 updateForItemType(panel
, TExit
);
894 if (WMGetButtonSelected(panel
->noconfirmB
))
895 changeItemParameter(panel
->editedItem
, "QUICK");
897 changeItemParameter(panel
->editedItem
, "");
900 changeItemCommand(panel
->editedItem
, "RESTARTW");
901 updateForItemType(panel
, TRestartWM
);
904 changeItemCommand(panel
->editedItem
, "RESTART");
905 updateForItemType(panel
, TRestart
);
906 tmp
= WMGetTextFieldText(panel
->proT
);
907 changeItemParameter(panel
->editedItem
, tmp
);
911 if (strcmp(getItemCommand(panel
->editedItem
), "SAVE_SESSION")!=0) {
912 changeItemCommand(panel
->editedItem
, "SAVE_SESSION");
913 updateForItemType(panel
, TSimpleCommand
);
917 if (strcmp(getItemCommand(panel
->editedItem
), "CLEAR_SESSION")!=0) {
918 changeItemCommand(panel
->editedItem
, "CLEAR_SESSION");
919 updateForItemType(panel
, TSimpleCommand
);
923 if (strcmp(getItemCommand(panel
->editedItem
), "REFRESH")!=0) {
924 changeItemCommand(panel
->editedItem
, "REFRESH");
925 updateForItemType(panel
, TSimpleCommand
);
929 if (strcmp(getItemCommand(panel
->editedItem
), "INFO_PANEL")!=0) {
930 changeItemCommand(panel
->editedItem
, "INFO_PANEL");
931 updateForItemType(panel
, TSimpleCommand
);
935 if (strcmp(getItemCommand(panel
->editedItem
), "LEGAL_PANEL")!=0) {
936 changeItemCommand(panel
->editedItem
, "LEGAL_PANEL");
937 updateForItemType(panel
, TSimpleCommand
);
948 captureShortcut(Display
*dpy
, _Panel
*panel
)
955 while (panel
->capturing
) {
956 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
957 WMNextEvent(dpy
, &ev
);
958 if (ev
.type
==KeyPress
&& ev
.xkey
.keycode
!=0) {
959 ksym
= XKeycodeToKeysym(dpy
, ev
.xkey
.keycode
, 0);
960 if (!IsModifierKey(ksym
)) {
961 key
=XKeysymToString(ksym
);
962 panel
->capturing
= 0;
974 if (ev
.xkey
.state
& ControlMask
) {
975 strcat(buffer
, "Control+");
977 if (ev
.xkey
.state
& ShiftMask
) {
978 strcat(buffer
, "Shift+");
980 if (ev
.xkey
.state
& Mod1Mask
) {
981 strcat(buffer
, "Mod1+");
983 if (ev
.xkey
.state
& Mod2Mask
) {
984 strcat(buffer
, "Mod2+");
986 if (ev
.xkey
.state
& Mod3Mask
) {
987 strcat(buffer
, "Mod3+");
989 if (ev
.xkey
.state
& Mod4Mask
) {
990 strcat(buffer
, "Mod4+");
992 if (ev
.xkey
.state
& Mod5Mask
) {
993 strcat(buffer
, "Mod5+");
997 return wstrdup(buffer
);
1002 captureClick(WMWidget
*w
, void *data
)
1004 _Panel
*panel
= (_Panel
*)data
;
1005 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->win
));
1008 if (!panel
->capturing
) {
1009 panel
->capturing
= 1;
1010 WMSetButtonText(w
, _("Cancel"));
1011 XGrabKeyboard(dpy
, WMWidgetXID(panel
->win
), True
, GrabModeAsync
,
1012 GrabModeAsync
, CurrentTime
);
1013 shortcut
= captureShortcut(dpy
, panel
);
1015 WMSetTextFieldText(panel
->shoT
, shortcut
);
1016 changeItemShortcut(panel
->editedItem
, shortcut
);
1021 panel
->capturing
= 0;
1022 WMSetButtonText(w
, _("Capture"));
1023 XUngrabKeyboard(dpy
, CurrentTime
);
1029 scrolledBrowser(WMBrowserDelegate
*self
, WMBrowser
*sender
)
1031 _Panel
*panel
= (_Panel
*)self
->data
;
1035 column
= WMGetBrowserFirstVisibleColumn(sender
);
1037 item
= getSubmenuInColumn(panel
, column
);
1038 WMSetTextFieldText(panel
->tit1T
, getItemTitle(item
));
1040 item
= getSubmenuInColumn(panel
, column
+ 1);
1042 WMSetTextFieldText(panel
->tit2T
, getItemTitle(item
));
1044 panel
->scrolledBrowser
= 1;
1049 confirmClicked(WMWidget
*w
, void *data
)
1051 _Panel
*panel
= (_Panel
*)data
;
1053 if (WMGetButtonSelected(panel
->noconfirmB
)) {
1054 changeItemParameter(panel
->editedItem
, "QUICK");
1056 changeItemParameter(panel
->editedItem
, "");
1064 openGuru(WMWidget
*w
, void *data
)
1066 _Panel
*panel
= (_Panel
*)data
;
1070 def
= OpenMenuGuru(GetWindow(panel
));
1072 changeItemParameter(panel
->editedItem
, def
);
1073 splitOpenMenuParameter(def
, &path
, &cmd
);
1075 WMSetTextFieldText(panel
->pathT
, path
);
1079 WMSetTextFieldText(panel
->proT
, cmd
);
1088 createPanel(_Panel
*p
)
1090 _Panel
*panel
= (_Panel
*)p
;
1093 panel
->frame
= WMCreateFrame(panel
->win
);
1094 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1095 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1097 panel
->cmd1P
= WMCreatePopUpButton(panel
->frame
);
1098 WMSetPopUpButtonAction(panel
->cmd1P
, performCommand
, panel
);
1099 WMResizeWidget(panel
->cmd1P
, 144, 20);
1100 WMMoveWidget(panel
->cmd1P
, 15, 15);
1101 WMSetPopUpButtonPullsDown(panel
->cmd1P
, True
);
1102 WMSetPopUpButtonText(panel
->cmd1P
, _("Commands"));
1103 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add Command"));
1104 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add Submenu"));
1105 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add External Menu"));
1106 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add Workspace Menu"));
1107 WMAddPopUpButtonItem(panel
->cmd1P
, _("Remove Item"));
1108 WMAddPopUpButtonItem(panel
->cmd1P
, _("Cut Item"));
1109 WMAddPopUpButtonItem(panel
->cmd1P
, _("Copy Item"));
1110 WMAddPopUpButtonItem(panel
->cmd1P
, _("Paste Item"));
1112 panel
->cmd2P
= WMCreatePopUpButton(panel
->frame
);
1113 WMSetPopUpButtonAction(panel
->cmd2P
, performCommand
, panel
);
1114 WMResizeWidget(panel
->cmd2P
, 144, 20);
1115 WMMoveWidget(panel
->cmd2P
, 164, 15);
1116 WMSetPopUpButtonPullsDown(panel
->cmd2P
, True
);
1117 WMSetPopUpButtonText(panel
->cmd2P
, _("Commands"));
1118 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add Command"));
1119 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add Submenu"));
1120 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add External Menu"));
1121 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add Workspace Menu"));
1122 WMAddPopUpButtonItem(panel
->cmd2P
, _("Remove Item"));
1123 WMAddPopUpButtonItem(panel
->cmd2P
, _("Cut Item"));
1124 WMAddPopUpButtonItem(panel
->cmd2P
, _("Copy Item"));
1125 WMAddPopUpButtonItem(panel
->cmd2P
, _("Paste Item"));
1127 panel
->tit1T
= WMCreateTextField(panel
->frame
);
1128 WMResizeWidget(panel
->tit1T
, 144, 20);
1129 WMMoveWidget(panel
->tit1T
, 15, 40);
1130 WMAddNotificationObserver(changedTitle
, panel
, WMTextDidChangeNotification
,
1133 panel
->tit2T
= WMCreateTextField(panel
->frame
);
1134 WMResizeWidget(panel
->tit2T
, 144, 20);
1135 WMMoveWidget(panel
->tit2T
, 164, 40);
1136 WMAddNotificationObserver(changedTitle
, panel
, WMTextDidChangeNotification
,
1139 panel
->browser
= WMCreateBrowser(panel
->frame
);
1140 WMSetBrowserTitled(panel
->browser
, False
);
1141 WMResizeWidget(panel
->browser
, 295, 160);
1142 WMMoveWidget(panel
->browser
, 15, 65);
1144 browserDelegate
.data
= panel
;
1146 WMSetBrowserDelegate(panel
->browser
, &browserDelegate
);
1147 WMHangData(panel
->browser
, panel
);
1148 WMSetBrowserPathSeparator(panel
->browser
, "\r");
1149 WMSetBrowserAction(panel
->browser
, browserClick
, panel
);
1153 panel
->labF
= WMCreateFrame(panel
->frame
);
1154 WMResizeWidget(panel
->labF
, 190, 50);
1155 WMMoveWidget(panel
->labF
, 320, 10);
1156 WMSetFrameTitle(panel
->labF
, _("Label"));
1158 panel
->labT
= WMCreateTextField(panel
->labF
);
1159 WMResizeWidget(panel
->labT
, 170, 20);
1160 WMMoveWidget(panel
->labT
, 10, 20);
1161 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1164 WMMapSubwidgets(panel
->labF
);
1166 panel
->cmdF
= WMCreateFrame(panel
->frame
);
1167 WMResizeWidget(panel
->cmdF
, 190, 50);
1168 WMMoveWidget(panel
->cmdF
, 320, 65);
1169 WMSetFrameTitle(panel
->cmdF
, _("Command"));
1171 panel
->cmdP
= WMCreatePopUpButton(panel
->cmdF
);
1172 WMResizeWidget(panel
->cmdP
, 170, 20);
1173 WMMoveWidget(panel
->cmdP
, 10, 20);
1174 WMAddPopUpButtonItem(panel
->cmdP
, _("Run Program"));
1175 WMAddPopUpButtonItem(panel
->cmdP
, _("Execute Shell Command"));
1176 WMAddPopUpButtonItem(panel
->cmdP
, _("Arrange Icons"));
1177 WMAddPopUpButtonItem(panel
->cmdP
, _("Hide Others"));
1178 WMAddPopUpButtonItem(panel
->cmdP
, _("Show All Windows"));
1179 WMAddPopUpButtonItem(panel
->cmdP
, _("Exit WindowMaker"));
1180 WMAddPopUpButtonItem(panel
->cmdP
, _("Exit X Session"));
1181 WMAddPopUpButtonItem(panel
->cmdP
, _("Start Window Manager"));
1182 WMAddPopUpButtonItem(panel
->cmdP
, _("Restart WindowMaker"));
1183 WMAddPopUpButtonItem(panel
->cmdP
, _("Save Session"));
1184 WMAddPopUpButtonItem(panel
->cmdP
, _("Clear Session"));
1185 WMAddPopUpButtonItem(panel
->cmdP
, _("Refresh Screen"));
1186 WMAddPopUpButtonItem(panel
->cmdP
, _("Info Panel"));
1187 WMAddPopUpButtonItem(panel
->cmdP
, _("Legal Panel"));
1188 WMSetPopUpButtonAction(panel
->cmdP
, changedCommand
, panel
);
1190 WMMapSubwidgets(panel
->cmdF
);
1192 panel
->infoL
= WMCreateLabel(panel
->frame
);
1193 WMResizeWidget(panel
->infoL
, 190, 50);
1194 WMMoveWidget(panel
->infoL
, 320, 65);
1195 WMSetLabelText(panel
->infoL
, _("Open workspace menu"));
1196 WMSetLabelRelief(panel
->infoL
, WRGroove
);
1197 WMSetLabelTextAlignment(panel
->infoL
, WACenter
);
1199 panel
->noconfirmB
= WMCreateSwitchButton(panel
->frame
);
1200 WMResizeWidget(panel
->noconfirmB
, 190, 50);
1201 WMMoveWidget(panel
->noconfirmB
, 320, 120);
1202 WMSetButtonText(panel
->noconfirmB
, _("No confirmation panel"));
1203 WMSetButtonAction(panel
->noconfirmB
, confirmClicked
, panel
);
1205 panel
->pathF
= WMCreateFrame(panel
->frame
);
1206 WMResizeWidget(panel
->pathF
, 190, 50);
1207 WMMoveWidget(panel
->pathF
, 320, 65);
1208 WMSetFrameTitle(panel
->pathF
, _("Menu Path/Directory List"));
1210 panel
->pathT
= WMCreateTextField(panel
->pathF
);
1211 WMResizeWidget(panel
->pathT
, 170, 20);
1212 WMMoveWidget(panel
->pathT
, 10, 20);
1213 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1216 WMMapSubwidgets(panel
->pathF
);
1218 panel
->proF
= WMCreateFrame(panel
->frame
);
1219 WMResizeWidget(panel
->proF
, 190, 50);
1220 WMMoveWidget(panel
->proF
, 320, 120);
1221 WMSetFrameTitle(panel
->proF
, _("Program to Run"));
1223 panel
->proT
= WMCreateTextField(panel
->proF
);
1224 WMResizeWidget(panel
->proT
, 170, 20);
1225 WMMoveWidget(panel
->proT
, 10, 20);
1226 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1229 WMMapSubwidgets(panel
->proF
);
1231 panel
->shoF
= WMCreateFrame(panel
->frame
);
1232 WMResizeWidget(panel
->shoF
, 190, 50);
1233 WMMoveWidget(panel
->shoF
, 320, 175);
1234 WMSetFrameTitle(panel
->shoF
, _("Shortcut"));
1236 panel
->shoT
= WMCreateTextField(panel
->shoF
);
1237 WMResizeWidget(panel
->shoT
, 95, 20);
1238 WMMoveWidget(panel
->shoT
, 10, 20);
1239 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1242 panel
->shoB
= WMCreateCommandButton(panel
->shoF
);
1243 WMResizeWidget(panel
->shoB
, 70, 24);
1244 WMMoveWidget(panel
->shoB
, 110, 18);
1245 WMSetButtonText(panel
->shoB
, _("Capture"));
1246 WMSetButtonAction(panel
->shoB
, captureClick
, panel
);
1248 WMMapSubwidgets(panel
->shoF
);
1250 panel
->guruB
= WMCreateCommandButton(panel
->frame
);
1251 WMResizeWidget(panel
->guruB
, 180, 24);
1252 WMMoveWidget(panel
->guruB
, 325, 190);
1253 WMSetButtonText(panel
->guruB
, _("Ask help to the Guru"));
1254 WMSetButtonAction(panel
->guruB
, openGuru
, panel
);
1256 WMRealizeWidget(panel
->frame
);
1257 WMMapSubwidgets(panel
->frame
);
1266 preProcessMenu(proplist_t menu
, int *hasWSMenu
)
1272 pmenu
= PLDeepCopy(menu
);
1273 if (PLGetNumberOfElements(pmenu
)==1) {
1276 for (i
=1; i
<PLGetNumberOfElements(pmenu
); i
++) {
1277 item
= PLGetArrayElement(pmenu
, i
);
1279 PLInsertArrayElement(pmenu
, preProcessMenu(item
, hasWSMenu
), i
);
1280 PLRemoveArrayElement(pmenu
, i
+1);
1282 } else if (strcmp(getItemCommand(item
), "RESTART")==0) {
1283 if (getItemShortcut(item
)) {
1284 if (PLGetNumberOfElements(item
) == 4) {
1285 changeItemCommand(item
, "RESTARTW");
1286 PLAppendArrayElement(item
, PLMakeString(""));
1289 if (PLGetNumberOfElements(item
) == 2) {
1290 changeItemCommand(item
, "RESTARTW");
1291 PLAppendArrayElement(item
, PLMakeString(""));
1295 if (strcmp(getItemCommand(item
),"WORKSPACE_MENU")==0)
1297 if (getItemShortcut(item
)) {
1298 if (PLGetNumberOfElements(item
) == 4)
1299 PLAppendArrayElement(item
, PLMakeString(""));
1301 if (PLGetNumberOfElements(item
) == 2)
1302 PLAppendArrayElement(item
, PLMakeString(""));
1313 postProcessMenu(proplist_t menu
)
1320 pmenu
= PLDeepCopy(menu
);
1321 if (PLGetNumberOfElements(pmenu
)==1) {
1324 count
= PLGetNumberOfElements(pmenu
);
1325 for (i
=1; i
<count
; i
++) {
1327 item
= PLGetArrayElement(pmenu
, i
);
1329 PLInsertArrayElement(pmenu
, postProcessMenu(item
), i
);
1330 PLRemoveArrayElement(pmenu
, i
+1);
1333 cmd
= getItemCommand(item
);
1334 if (strcmp(cmd
, "RESTARTW")==0) {
1335 changeItemCommand(item
, "RESTART");
1336 removeParameter(item
);
1337 } else if (strcmp(cmd
, "EXEC")==0 || strcmp(cmd
, "SHEXEC")==0 ||
1338 strcmp(cmd
, "OPEN_MENU")==0) {
1340 } else if (strcmp(cmd
, "RESTART")==0 || strcmp(cmd
, "SHUTDOWN")==0
1341 || strcmp(cmd
, "EXIT")==0) {
1342 char *tmp
= getItemParameter(item
);
1343 if (tmp
&& strlen(tmp
)==0)
1344 removeParameter(item
);
1346 removeParameter(item
);
1356 getDefaultMenu(_Panel
*panel
, int *hasWSMenu
)
1358 proplist_t menu
, pmenu
;
1359 char *menuPath
, *gspath
;
1361 gspath
= wusergnusteppath();
1363 menuPath
= wmalloc(strlen(gspath
)+128);
1364 /* if there is a localized plmenu for the tongue put it's filename here */
1365 sprintf(menuPath
, _("%s/Library/WindowMaker/plmenu"), gspath
);
1367 menu
= PLGetProplistWithPath(menuPath
);
1369 wwarning("%s:could not read property list menu", menuPath
);
1371 if (strcmp("%s/Library/WindowMaker/plmenu",
1372 _("%s/Library/WindowMaker/plmenu"))!=0) {
1374 sprintf(menuPath
, "%s/Library/WindowMaker/plmenu", gspath
);
1375 menu
= PLGetProplistWithPath(menuPath
);
1376 wwarning("%s:could not read property list menu", menuPath
);
1381 sprintf(buffer
, _("Could not open default menu from '%s'"),
1383 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
1384 _("Error"), buffer
, _("OK"), NULL
, NULL
);
1391 pmenu
= preProcessMenu(menu
, hasWSMenu
);
1402 showData(_Panel
*panel
)
1406 proplist_t menu
, pmenu
, plPath
;
1409 gspath
= wusergnusteppath();
1411 menuPath
= wmalloc(strlen(gspath
)+32);
1412 strcpy(menuPath
, gspath
);
1413 strcat(menuPath
, "/Defaults/WMRootMenu");
1415 menu
= PLGetProplistWithPath(menuPath
);
1418 if (!menu
|| !PLIsArray(menu
)) {
1419 if (AskMenuCopy(panel
->win
)) {
1420 panel
->dontSave
= 0;
1423 pmenu
= getDefaultMenu(panel
, &hasWSMenu
);
1425 WMSetPopUpButtonEnabled(panel
->cmd1P
, False
);
1426 WMSetPopUpButtonEnabled(panel
->cmd2P
, False
);
1427 panel
->dontSave
= 1;
1430 pmenu
= PLMakeArrayFromElements(PLMakeString("Applications"),
1434 pmenu
= preProcessMenu(menu
, &hasWSMenu
);
1436 plPath
= PLMakeString(menuPath
);
1438 PLSetFilename(pmenu
, plPath
);
1444 if (panel
->itemClipboard
) {
1445 PLRelease(panel
->itemClipboard
);
1446 panel
->itemClipboard
= NULL
;
1448 panel
->menu
= pmenu
;
1449 panel
->editedItem
= NULL
;
1450 panel
->capturing
= 0;
1452 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CPaste
, False
);
1453 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CPaste
, False
);
1455 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CAddWorkspace
, False
);
1456 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CAddWorkspace
, False
);
1458 WMLoadBrowserColumnZero(panel
->browser
);
1460 updateForItemType(panel
, TNothing
);
1465 storeData(_Panel
*panel
)
1469 if (!panel
->unsaved
|| panel
->dontSave
)
1473 menu
= postProcessMenu(panel
->menu
);
1475 PLSetFilename(menu
, PLGetFilename(panel
->menu
));
1484 InitMenu(WMScreen
*scr
, WMWindow
*win
)
1488 panel
= wmalloc(sizeof(_Panel
));
1489 memset(panel
, 0, sizeof(_Panel
));
1491 panel
->sectionName
= _("Applications Menu Definition");
1493 panel
->description
= _("Edit the menu for launching applications.");
1497 panel
->callbacks
.createWidgets
= createPanel
;
1498 panel
->callbacks
.updateDomain
= storeData
;
1500 AddSection(panel
, ICON_FILE
);