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
);
581 list
= WMGetBrowserListInColumn(panel
->browser
, 0);
582 for (i
= 0; i
< WMGetListNumberOfRows(list
); i
++) {
583 WMListItem
*item
=WMGetListItem(list
, i
);
585 printf("%i empty\n", i
);
592 WMInsertBrowserItem(panel
->browser
, column
, row
, title
, isMenu(menuItem
));
594 PLAppendArrayElement(menu
, menuItem
);
596 PLInsertArrayElement(menu
, menuItem
, row
+1);
603 if (pop
== panel
->cmd1P
) {
604 WMSetTextFieldText(panel
->tit2T
, NULL
);
611 browserClick(WMWidget
*w
, void *data
)
613 _Panel
*panel
= (_Panel
*)data
;
617 /* stop shortcut capture */
618 panel
->capturing
= 0;
620 item
= getItemOfSelectedEntry(panel
->browser
);
622 panel
->editedItem
= item
;
625 WMSetTextFieldText(panel
->labT
, getItemTitle(item
));
628 updateForItemType(panel
, TNothing
);
630 WMSetPopUpButtonEnabled(panel
->cmd2P
, True
);
633 int column
= WMGetBrowserSelectedColumn(panel
->browser
);
635 if (column
== WMGetBrowserNumberOfColumns(panel
->browser
)-1
637 WMSetPopUpButtonEnabled(panel
->cmd2P
, True
);
639 WMSetPopUpButtonEnabled(panel
->cmd2P
, False
);
641 if (column
==WMGetBrowserFirstVisibleColumn(panel
->browser
)) {
642 /* second column is empty, because selected item is not a submenu */
643 WMSetTextFieldText(panel
->tit2T
, NULL
);
647 command
= getItemCommand(item
);
649 WMSetTextFieldText(panel
->shoT
, getItemShortcut(item
));
651 if (strcmp(command
, "OPEN_MENU")==0) {
654 splitOpenMenuParameter(getItemParameter(item
), &p
, &c
);
655 WMSetTextFieldText(panel
->pathT
, p
);
656 WMSetTextFieldText(panel
->proT
, c
);
661 updateForItemType(panel
, TExternalMenu
);
662 } else if (strcmp(command
, "EXEC")==0) {
663 WMSetTextFieldText(panel
->proT
, getItemParameter(item
));
664 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpExec
);
665 updateForItemType(panel
, TExec
);
666 } else if (strcmp(command
, "SHEXEC")==0) {
667 WMSetTextFieldText(panel
->proT
, getItemParameter(item
));
668 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpShExec
);
669 updateForItemType(panel
, TShExec
);
670 } else if (strcmp(command
, "WORKSPACE_MENU")==0) {
671 updateForItemType(panel
, TWSMenu
);
672 } else if (strcmp(command
, "EXIT")==0) {
673 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpExit
);
674 updateForItemType(panel
, TExit
);
675 } else if (strcmp(command
, "SHUTDOWN")==0) {
676 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpShutdown
);
677 updateForItemType(panel
, TExit
);
678 } else if (strcmp(command
, "RESTARTW")==0) {
679 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpRestartWM
);
680 updateForItemType(panel
, TRestartWM
);
681 } else if (strcmp(command
, "RESTART")==0) {
682 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpRestart
);
683 WMSetTextFieldText(panel
->proT
, getItemParameter(item
));
684 updateForItemType(panel
, TRestart
);
686 /* simple commands */
687 if (strcmp(command
, "ARRANGE_ICONS")==0)
688 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpArrange
);
689 else if (strcmp(command
, "HIDE_OTHERS")==0)
690 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpHide
);
691 else if (strcmp(command
, "SHOW_ALL")==0)
692 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpShow
);
693 else if (strcmp(command
, "SAVE_SESSION")==0)
694 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpSaveSession
);
695 else if (strcmp(command
, "CLEAR_SESSION")==0)
696 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpClearSession
);
697 else if (strcmp(command
, "REFRESH")==0)
698 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpRefresh
);
699 else if (strcmp(command
, "INFO_PANEL")==0)
700 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpInfo
);
701 else if (strcmp(command
, "LEGAL_PANEL")==0)
702 WMSetPopUpButtonSelectedItem(panel
->cmdP
, CpLegal
);
703 updateForItemType(panel
, TSimpleCommand
);
710 fillBrowser(WMBrowserDelegate
*self
, WMBrowser
*bPtr
, int column
, WMList
*list
)
712 _Panel
*panel
= (_Panel
*)WMGetHangedData(bPtr
);
714 proplist_t menuList
= NULL
;
718 menuList
= getSubmenuInColumn(panel
, column
);
719 assert(menuList
!= NULL
);
721 if (column
> WMGetBrowserFirstVisibleColumn(bPtr
)) {
722 WMSetTextFieldText(panel
->tit2T
, getItemTitle(menuList
));
724 WMSetTextFieldText(panel
->tit1T
, getItemTitle(menuList
));
727 for (i
=1; i
<PLGetNumberOfElements(menuList
); i
++) {
728 menuItem
= PLGetArrayElement(menuList
, i
);
729 WMInsertBrowserItem(bPtr
, column
, -1, getItemTitle(menuItem
),
738 changedItem(void *observerData
, WMNotification
*notification
)
740 _Panel
*panel
= (_Panel
*)observerData
;
741 WMTextField
*t
= (WMTextField
*)WMGetNotificationObject(notification
);
742 proplist_t item
= panel
->editedItem
;
754 command
= getItemCommand(item
);
756 if (t
== panel
->shoT
) {
757 str
= WMGetTextFieldText(t
);
758 if (strlen(str
)==0) {
762 changeItemShortcut(item
, str
);
765 } else if (t
== panel
->labT
) {
768 str
= WMGetTextFieldText(t
);
771 changeItemTitle(item
, str
);
772 column
= WMGetBrowserSelectedColumn(panel
->browser
);
773 list
= WMGetBrowserListInColumn(panel
->browser
, column
);
774 litem
= WMGetListSelectedItem(list
);
779 WMRedisplayWidget(list
);
780 } else if (strcmp(command
, "EXEC")==0
781 || strcmp(command
, "SHEXEC")==0
782 || strcmp(command
, "RESTART")==0) {
783 if (t
== panel
->proT
) {
784 str
= WMGetTextFieldText(t
);
786 changeItemParameter(item
, str
);
790 } else if (strcmp(command
, "OPEN_MENU")==0) {
794 str
= WMGetTextFieldText(panel
->pathT
);
795 str2
= WMGetTextFieldText(panel
->proT
);
796 text
= wmalloc(strlen(str
)+strlen(str2
)+16);
799 if (strlen(str2
)>0) {
800 strcat(text
, " WITH ");
804 changeItemParameter(item
, text
);
812 changedTitle(void *observerData
, WMNotification
*notification
)
814 _Panel
*panel
= (_Panel
*)observerData
;
815 WMTextField
*t
= (WMTextField
*)WMGetNotificationObject(notification
);
821 column
= WMGetBrowserFirstVisibleColumn(panel
->browser
);
822 if (panel
->tit2T
== t
)
825 menu
= getSubmenuInColumn(panel
, column
);
829 txt
= WMGetTextFieldText(t
);
830 changeItemTitle(menu
, txt
);
835 list
= WMGetBrowserListInColumn(panel
->browser
, column
-1);
836 litem
= WMGetListSelectedItem(list
);
841 WMRedisplayWidget(list
);
850 changedCommand(WMWidget
*w
, void *data
)
852 _Panel
*panel
= (_Panel
*)data
;
857 i
= WMGetPopUpButtonSelectedItem(panel
->cmdP
);
858 changeItemParameter(panel
->editedItem
, "");
861 if (strcmp(getItemCommand(panel
->editedItem
), "EXEC")!=0) {
862 changeItemCommand(panel
->editedItem
, "EXEC");
863 tmp
= WMGetTextFieldText(panel
->proT
);
864 changeItemParameter(panel
->editedItem
, tmp
);
866 updateForItemType(panel
, TExec
);
870 if (strcmp(getItemCommand(panel
->editedItem
), "SHEXEC")!=0) {
871 changeItemCommand(panel
->editedItem
, "SHEXEC");
872 tmp
= WMGetTextFieldText(panel
->proT
);
873 changeItemParameter(panel
->editedItem
, tmp
);
875 updateForItemType(panel
, TShExec
);
879 if (strcmp(getItemCommand(panel
->editedItem
), "ARRANGE_ICONS")!=0) {
880 changeItemCommand(panel
->editedItem
, "ARRANGE_ICONS");
881 updateForItemType(panel
, TSimpleCommand
);
885 if (strcmp(getItemCommand(panel
->editedItem
), "HIDE_OTHERS")!=0) {
886 changeItemCommand(panel
->editedItem
, "HIDE_OTHERS");
887 updateForItemType(panel
, TSimpleCommand
);
891 if (strcmp(getItemCommand(panel
->editedItem
), "SHOW_ALL")!=0) {
892 changeItemCommand(panel
->editedItem
, "SHOW_ALL");
893 updateForItemType(panel
, TSimpleCommand
);
897 if (strcmp(getItemCommand(panel
->editedItem
), "EXIT")!=0) {
898 changeItemCommand(panel
->editedItem
, "EXIT");
899 updateForItemType(panel
, TExit
);
901 if (WMGetButtonSelected(panel
->noconfirmB
))
902 changeItemParameter(panel
->editedItem
, "QUICK");
904 changeItemParameter(panel
->editedItem
, "");
907 if (strcmp(getItemCommand(panel
->editedItem
), "SHUTDOWN")!=0) {
908 changeItemCommand(panel
->editedItem
, "SHUTDOWN");
909 updateForItemType(panel
, TExit
);
911 if (WMGetButtonSelected(panel
->noconfirmB
))
912 changeItemParameter(panel
->editedItem
, "QUICK");
914 changeItemParameter(panel
->editedItem
, "");
917 changeItemCommand(panel
->editedItem
, "RESTARTW");
918 updateForItemType(panel
, TRestartWM
);
921 changeItemCommand(panel
->editedItem
, "RESTART");
922 updateForItemType(panel
, TRestart
);
923 tmp
= WMGetTextFieldText(panel
->proT
);
924 changeItemParameter(panel
->editedItem
, tmp
);
928 if (strcmp(getItemCommand(panel
->editedItem
), "SAVE_SESSION")!=0) {
929 changeItemCommand(panel
->editedItem
, "SAVE_SESSION");
930 updateForItemType(panel
, TSimpleCommand
);
934 if (strcmp(getItemCommand(panel
->editedItem
), "CLEAR_SESSION")!=0) {
935 changeItemCommand(panel
->editedItem
, "CLEAR_SESSION");
936 updateForItemType(panel
, TSimpleCommand
);
940 if (strcmp(getItemCommand(panel
->editedItem
), "REFRESH")!=0) {
941 changeItemCommand(panel
->editedItem
, "REFRESH");
942 updateForItemType(panel
, TSimpleCommand
);
946 if (strcmp(getItemCommand(panel
->editedItem
), "INFO_PANEL")!=0) {
947 changeItemCommand(panel
->editedItem
, "INFO_PANEL");
948 updateForItemType(panel
, TSimpleCommand
);
952 if (strcmp(getItemCommand(panel
->editedItem
), "LEGAL_PANEL")!=0) {
953 changeItemCommand(panel
->editedItem
, "LEGAL_PANEL");
954 updateForItemType(panel
, TSimpleCommand
);
965 captureShortcut(Display
*dpy
, _Panel
*panel
)
972 while (panel
->capturing
) {
973 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
974 WMNextEvent(dpy
, &ev
);
975 if (ev
.type
==KeyPress
&& ev
.xkey
.keycode
!=0) {
976 ksym
= XKeycodeToKeysym(dpy
, ev
.xkey
.keycode
, 0);
977 if (!IsModifierKey(ksym
)) {
978 key
=XKeysymToString(ksym
);
979 panel
->capturing
= 0;
991 if (ev
.xkey
.state
& ControlMask
) {
992 strcat(buffer
, "Control+");
994 if (ev
.xkey
.state
& ShiftMask
) {
995 strcat(buffer
, "Shift+");
997 if (ev
.xkey
.state
& Mod1Mask
) {
998 strcat(buffer
, "Mod1+");
1000 if (ev
.xkey
.state
& Mod2Mask
) {
1001 strcat(buffer
, "Mod2+");
1003 if (ev
.xkey
.state
& Mod3Mask
) {
1004 strcat(buffer
, "Mod3+");
1006 if (ev
.xkey
.state
& Mod4Mask
) {
1007 strcat(buffer
, "Mod4+");
1009 if (ev
.xkey
.state
& Mod5Mask
) {
1010 strcat(buffer
, "Mod5+");
1012 strcat(buffer
, key
);
1014 return wstrdup(buffer
);
1019 captureClick(WMWidget
*w
, void *data
)
1021 _Panel
*panel
= (_Panel
*)data
;
1022 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->win
));
1025 if (!panel
->capturing
) {
1026 panel
->capturing
= 1;
1027 WMSetButtonText(w
, _("Cancel"));
1028 XGrabKeyboard(dpy
, WMWidgetXID(panel
->win
), True
, GrabModeAsync
,
1029 GrabModeAsync
, CurrentTime
);
1030 shortcut
= captureShortcut(dpy
, panel
);
1032 WMSetTextFieldText(panel
->shoT
, shortcut
);
1033 changeItemShortcut(panel
->editedItem
, shortcut
);
1038 panel
->capturing
= 0;
1039 WMSetButtonText(w
, _("Capture"));
1040 XUngrabKeyboard(dpy
, CurrentTime
);
1046 scrolledBrowser(WMBrowserDelegate
*self
, WMBrowser
*sender
)
1048 _Panel
*panel
= (_Panel
*)self
->data
;
1052 column
= WMGetBrowserFirstVisibleColumn(sender
);
1054 item
= getSubmenuInColumn(panel
, column
);
1055 WMSetTextFieldText(panel
->tit1T
, getItemTitle(item
));
1057 item
= getSubmenuInColumn(panel
, column
+ 1);
1059 WMSetTextFieldText(panel
->tit2T
, getItemTitle(item
));
1061 panel
->scrolledBrowser
= 1;
1066 confirmClicked(WMWidget
*w
, void *data
)
1068 _Panel
*panel
= (_Panel
*)data
;
1070 if (WMGetButtonSelected(panel
->noconfirmB
)) {
1071 changeItemParameter(panel
->editedItem
, "QUICK");
1073 changeItemParameter(panel
->editedItem
, "");
1081 openGuru(WMWidget
*w
, void *data
)
1083 _Panel
*panel
= (_Panel
*)data
;
1087 def
= OpenMenuGuru(GetWindow(panel
));
1089 changeItemParameter(panel
->editedItem
, def
);
1090 splitOpenMenuParameter(def
, &path
, &cmd
);
1092 WMSetTextFieldText(panel
->pathT
, path
);
1096 WMSetTextFieldText(panel
->proT
, cmd
);
1105 createPanel(_Panel
*p
)
1107 _Panel
*panel
= (_Panel
*)p
;
1110 panel
->frame
= WMCreateFrame(panel
->win
);
1111 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
1112 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
1114 panel
->cmd1P
= WMCreatePopUpButton(panel
->frame
);
1115 WMSetPopUpButtonAction(panel
->cmd1P
, performCommand
, panel
);
1116 WMResizeWidget(panel
->cmd1P
, 144, 20);
1117 WMMoveWidget(panel
->cmd1P
, 15, 15);
1118 WMSetPopUpButtonPullsDown(panel
->cmd1P
, True
);
1119 WMSetPopUpButtonText(panel
->cmd1P
, _("Commands"));
1120 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add Command"));
1121 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add Submenu"));
1122 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add External Menu"));
1123 WMAddPopUpButtonItem(panel
->cmd1P
, _("Add Workspace Menu"));
1124 WMAddPopUpButtonItem(panel
->cmd1P
, _("Remove Item"));
1125 WMAddPopUpButtonItem(panel
->cmd1P
, _("Cut Item"));
1126 WMAddPopUpButtonItem(panel
->cmd1P
, _("Copy Item"));
1127 WMAddPopUpButtonItem(panel
->cmd1P
, _("Paste Item"));
1129 panel
->cmd2P
= WMCreatePopUpButton(panel
->frame
);
1130 WMSetPopUpButtonAction(panel
->cmd2P
, performCommand
, panel
);
1131 WMResizeWidget(panel
->cmd2P
, 144, 20);
1132 WMMoveWidget(panel
->cmd2P
, 164, 15);
1133 WMSetPopUpButtonPullsDown(panel
->cmd2P
, True
);
1134 WMSetPopUpButtonText(panel
->cmd2P
, _("Commands"));
1135 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add Command"));
1136 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add Submenu"));
1137 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add External Menu"));
1138 WMAddPopUpButtonItem(panel
->cmd2P
, _("Add Workspace Menu"));
1139 WMAddPopUpButtonItem(panel
->cmd2P
, _("Remove Item"));
1140 WMAddPopUpButtonItem(panel
->cmd2P
, _("Cut Item"));
1141 WMAddPopUpButtonItem(panel
->cmd2P
, _("Copy Item"));
1142 WMAddPopUpButtonItem(panel
->cmd2P
, _("Paste Item"));
1144 panel
->tit1T
= WMCreateTextField(panel
->frame
);
1145 WMResizeWidget(panel
->tit1T
, 144, 20);
1146 WMMoveWidget(panel
->tit1T
, 15, 40);
1147 WMAddNotificationObserver(changedTitle
, panel
, WMTextDidChangeNotification
,
1150 panel
->tit2T
= WMCreateTextField(panel
->frame
);
1151 WMResizeWidget(panel
->tit2T
, 144, 20);
1152 WMMoveWidget(panel
->tit2T
, 164, 40);
1153 WMAddNotificationObserver(changedTitle
, panel
, WMTextDidChangeNotification
,
1156 panel
->browser
= WMCreateBrowser(panel
->frame
);
1157 WMSetBrowserTitled(panel
->browser
, False
);
1158 WMResizeWidget(panel
->browser
, 295, 160);
1159 WMMoveWidget(panel
->browser
, 15, 65);
1161 browserDelegate
.data
= panel
;
1163 WMSetBrowserDelegate(panel
->browser
, &browserDelegate
);
1164 WMHangData(panel
->browser
, panel
);
1165 WMSetBrowserPathSeparator(panel
->browser
, "\r");
1166 WMSetBrowserAction(panel
->browser
, browserClick
, panel
);
1170 panel
->labF
= WMCreateFrame(panel
->frame
);
1171 WMResizeWidget(panel
->labF
, 190, 50);
1172 WMMoveWidget(panel
->labF
, 320, 10);
1173 WMSetFrameTitle(panel
->labF
, _("Label"));
1175 panel
->labT
= WMCreateTextField(panel
->labF
);
1176 WMResizeWidget(panel
->labT
, 170, 20);
1177 WMMoveWidget(panel
->labT
, 10, 20);
1178 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1181 WMMapSubwidgets(panel
->labF
);
1183 panel
->cmdF
= WMCreateFrame(panel
->frame
);
1184 WMResizeWidget(panel
->cmdF
, 190, 50);
1185 WMMoveWidget(panel
->cmdF
, 320, 65);
1186 WMSetFrameTitle(panel
->cmdF
, _("Command"));
1188 panel
->cmdP
= WMCreatePopUpButton(panel
->cmdF
);
1189 WMResizeWidget(panel
->cmdP
, 170, 20);
1190 WMMoveWidget(panel
->cmdP
, 10, 20);
1191 WMAddPopUpButtonItem(panel
->cmdP
, _("Run Program"));
1192 WMAddPopUpButtonItem(panel
->cmdP
, _("Execute Shell Command"));
1193 WMAddPopUpButtonItem(panel
->cmdP
, _("Arrange Icons"));
1194 WMAddPopUpButtonItem(panel
->cmdP
, _("Hide Others"));
1195 WMAddPopUpButtonItem(panel
->cmdP
, _("Show All Windows"));
1196 WMAddPopUpButtonItem(panel
->cmdP
, _("Exit WindowMaker"));
1197 WMAddPopUpButtonItem(panel
->cmdP
, _("Exit X Session"));
1198 WMAddPopUpButtonItem(panel
->cmdP
, _("Start Window Manager"));
1199 WMAddPopUpButtonItem(panel
->cmdP
, _("Restart WindowMaker"));
1200 WMAddPopUpButtonItem(panel
->cmdP
, _("Save Session"));
1201 WMAddPopUpButtonItem(panel
->cmdP
, _("Clear Session"));
1202 WMAddPopUpButtonItem(panel
->cmdP
, _("Refresh Screen"));
1203 WMAddPopUpButtonItem(panel
->cmdP
, _("Info Panel"));
1204 WMAddPopUpButtonItem(panel
->cmdP
, _("Legal Panel"));
1205 WMSetPopUpButtonAction(panel
->cmdP
, changedCommand
, panel
);
1207 WMMapSubwidgets(panel
->cmdF
);
1209 panel
->infoL
= WMCreateLabel(panel
->frame
);
1210 WMResizeWidget(panel
->infoL
, 190, 50);
1211 WMMoveWidget(panel
->infoL
, 320, 65);
1212 WMSetLabelText(panel
->infoL
, _("Open workspace menu"));
1213 WMSetLabelRelief(panel
->infoL
, WRGroove
);
1214 WMSetLabelTextAlignment(panel
->infoL
, WACenter
);
1216 panel
->noconfirmB
= WMCreateSwitchButton(panel
->frame
);
1217 WMResizeWidget(panel
->noconfirmB
, 190, 50);
1218 WMMoveWidget(panel
->noconfirmB
, 320, 120);
1219 WMSetButtonText(panel
->noconfirmB
, _("No confirmation panel"));
1220 WMSetButtonAction(panel
->noconfirmB
, confirmClicked
, panel
);
1222 panel
->pathF
= WMCreateFrame(panel
->frame
);
1223 WMResizeWidget(panel
->pathF
, 190, 50);
1224 WMMoveWidget(panel
->pathF
, 320, 65);
1225 WMSetFrameTitle(panel
->pathF
, _("Menu Path/Directory List"));
1227 panel
->pathT
= WMCreateTextField(panel
->pathF
);
1228 WMResizeWidget(panel
->pathT
, 170, 20);
1229 WMMoveWidget(panel
->pathT
, 10, 20);
1230 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1233 WMMapSubwidgets(panel
->pathF
);
1235 panel
->proF
= WMCreateFrame(panel
->frame
);
1236 WMResizeWidget(panel
->proF
, 190, 50);
1237 WMMoveWidget(panel
->proF
, 320, 120);
1238 WMSetFrameTitle(panel
->proF
, _("Program to Run"));
1240 panel
->proT
= WMCreateTextField(panel
->proF
);
1241 WMResizeWidget(panel
->proT
, 170, 20);
1242 WMMoveWidget(panel
->proT
, 10, 20);
1243 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1246 WMMapSubwidgets(panel
->proF
);
1248 panel
->shoF
= WMCreateFrame(panel
->frame
);
1249 WMResizeWidget(panel
->shoF
, 190, 50);
1250 WMMoveWidget(panel
->shoF
, 320, 175);
1251 WMSetFrameTitle(panel
->shoF
, _("Shortcut"));
1253 panel
->shoT
= WMCreateTextField(panel
->shoF
);
1254 WMResizeWidget(panel
->shoT
, 95, 20);
1255 WMMoveWidget(panel
->shoT
, 10, 20);
1256 WMAddNotificationObserver(changedItem
, panel
, WMTextDidChangeNotification
,
1259 panel
->shoB
= WMCreateCommandButton(panel
->shoF
);
1260 WMResizeWidget(panel
->shoB
, 70, 24);
1261 WMMoveWidget(panel
->shoB
, 110, 18);
1262 WMSetButtonText(panel
->shoB
, _("Capture"));
1263 WMSetButtonAction(panel
->shoB
, captureClick
, panel
);
1265 WMMapSubwidgets(panel
->shoF
);
1267 panel
->guruB
= WMCreateCommandButton(panel
->frame
);
1268 WMResizeWidget(panel
->guruB
, 180, 24);
1269 WMMoveWidget(panel
->guruB
, 325, 190);
1270 WMSetButtonText(panel
->guruB
, _("Ask help to the Guru"));
1271 WMSetButtonAction(panel
->guruB
, openGuru
, panel
);
1273 WMRealizeWidget(panel
->frame
);
1274 WMMapSubwidgets(panel
->frame
);
1283 preProcessMenu(proplist_t menu
, int *hasWSMenu
)
1289 pmenu
= PLDeepCopy(menu
);
1290 if (PLGetNumberOfElements(pmenu
)==1) {
1293 for (i
=1; i
<PLGetNumberOfElements(pmenu
); i
++) {
1294 item
= PLGetArrayElement(pmenu
, i
);
1296 PLInsertArrayElement(pmenu
, preProcessMenu(item
, hasWSMenu
), i
);
1297 PLRemoveArrayElement(pmenu
, i
+1);
1299 } else if (strcmp(getItemCommand(item
), "RESTART")==0) {
1300 if (getItemShortcut(item
)) {
1301 if (PLGetNumberOfElements(item
) == 4) {
1302 changeItemCommand(item
, "RESTARTW");
1303 PLAppendArrayElement(item
, PLMakeString(""));
1306 if (PLGetNumberOfElements(item
) == 2) {
1307 changeItemCommand(item
, "RESTARTW");
1308 PLAppendArrayElement(item
, PLMakeString(""));
1312 if (strcmp(getItemCommand(item
),"WORKSPACE_MENU")==0)
1314 if (getItemShortcut(item
)) {
1315 if (PLGetNumberOfElements(item
) == 4)
1316 PLAppendArrayElement(item
, PLMakeString(""));
1318 if (PLGetNumberOfElements(item
) == 2)
1319 PLAppendArrayElement(item
, PLMakeString(""));
1330 postProcessMenu(proplist_t menu
)
1337 pmenu
= PLDeepCopy(menu
);
1338 if (PLGetNumberOfElements(pmenu
)==1) {
1341 count
= PLGetNumberOfElements(pmenu
);
1342 for (i
=1; i
<count
; i
++) {
1344 item
= PLGetArrayElement(pmenu
, i
);
1346 PLInsertArrayElement(pmenu
, postProcessMenu(item
), i
);
1347 PLRemoveArrayElement(pmenu
, i
+1);
1350 cmd
= getItemCommand(item
);
1351 if (strcmp(cmd
, "RESTARTW")==0) {
1352 changeItemCommand(item
, "RESTART");
1353 removeParameter(item
);
1354 } else if (strcmp(cmd
, "EXEC")==0 || strcmp(cmd
, "SHEXEC")==0 ||
1355 strcmp(cmd
, "OPEN_MENU")==0) {
1357 } else if (strcmp(cmd
, "RESTART")==0 || strcmp(cmd
, "SHUTDOWN")==0
1358 || strcmp(cmd
, "EXIT")==0) {
1359 char *tmp
= getItemParameter(item
);
1360 if (tmp
&& strlen(tmp
)==0)
1361 removeParameter(item
);
1363 removeParameter(item
);
1373 getDefaultMenu(_Panel
*panel
, int *hasWSMenu
)
1375 proplist_t menu
, pmenu
;
1376 char *menuPath
, *gspath
;
1378 gspath
= wusergnusteppath();
1380 menuPath
= wmalloc(strlen(gspath
)+128);
1381 /* if there is a localized plmenu for the tongue put it's filename here */
1382 sprintf(menuPath
, _("%s/Library/WindowMaker/plmenu"), gspath
);
1384 menu
= PLGetProplistWithPath(menuPath
);
1386 wwarning("%s:could not read property list menu", menuPath
);
1388 if (strcmp("%s/Library/WindowMaker/plmenu",
1389 _("%s/Library/WindowMaker/plmenu"))!=0) {
1391 sprintf(menuPath
, "%s/Library/WindowMaker/plmenu", gspath
);
1392 menu
= PLGetProplistWithPath(menuPath
);
1393 wwarning("%s:could not read property list menu", menuPath
);
1398 sprintf(buffer
, _("Could not open default menu from '%s'"),
1400 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
1401 _("Error"), buffer
, _("OK"), NULL
, NULL
);
1408 pmenu
= preProcessMenu(menu
, hasWSMenu
);
1419 showData(_Panel
*panel
)
1423 proplist_t menu
, pmenu
, plPath
;
1426 gspath
= wusergnusteppath();
1428 menuPath
= wmalloc(strlen(gspath
)+32);
1429 strcpy(menuPath
, gspath
);
1430 strcat(menuPath
, "/Defaults/WMRootMenu");
1432 menu
= PLGetProplistWithPath(menuPath
);
1435 if (!menu
|| !PLIsArray(menu
)) {
1436 if (AskMenuCopy(panel
->win
)) {
1437 panel
->dontSave
= 0;
1440 pmenu
= getDefaultMenu(panel
, &hasWSMenu
);
1442 WMSetPopUpButtonEnabled(panel
->cmd1P
, False
);
1443 WMSetPopUpButtonEnabled(panel
->cmd2P
, False
);
1444 panel
->dontSave
= 1;
1447 pmenu
= PLMakeArrayFromElements(PLMakeString("Applications"),
1451 pmenu
= preProcessMenu(menu
, &hasWSMenu
);
1453 plPath
= PLMakeString(menuPath
);
1455 PLSetFilename(pmenu
, plPath
);
1461 if (panel
->itemClipboard
) {
1462 PLRelease(panel
->itemClipboard
);
1463 panel
->itemClipboard
= NULL
;
1465 panel
->menu
= pmenu
;
1466 panel
->editedItem
= NULL
;
1467 panel
->capturing
= 0;
1469 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CPaste
, False
);
1470 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CPaste
, False
);
1472 WMSetPopUpButtonItemEnabled(panel
->cmd1P
, CAddWorkspace
, False
);
1473 WMSetPopUpButtonItemEnabled(panel
->cmd2P
, CAddWorkspace
, False
);
1475 WMLoadBrowserColumnZero(panel
->browser
);
1477 updateForItemType(panel
, TNothing
);
1482 storeData(_Panel
*panel
)
1486 if (!panel
->unsaved
|| panel
->dontSave
)
1490 menu
= postProcessMenu(panel
->menu
);
1492 PLSetFilename(menu
, PLGetFilename(panel
->menu
));
1501 InitMenu(WMScreen
*scr
, WMWindow
*win
)
1505 panel
= wmalloc(sizeof(_Panel
));
1506 memset(panel
, 0, sizeof(_Panel
));
1508 panel
->sectionName
= _("Applications Menu Definition");
1510 panel
->description
= _("Edit the menu for launching applications.");
1514 panel
->callbacks
.createWidgets
= createPanel
;
1515 panel
->callbacks
.updateDomain
= storeData
;
1517 AddSection(panel
, ICON_FILE
);