Fix for stupid Solaris (maybe other Sysv systems too).
[wmaker-crm.git] / WPrefs.app / Menu.c
blob1cd793142c4abbc76760e6102d3c53b44138f898
1 /* Menu.c- menu definition
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998 Alfredo K. Kojima
6 *
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,
20 * USA.
24 #include "WPrefs.h"
25 #include <assert.h>
26 #include <ctype.h>
28 #include <X11/keysym.h>
30 typedef struct _Panel {
31 WMFrame *frame;
32 char *sectionName;
34 char *description;
36 CallbackRec callbacks;
37 WMWindow *win;
39 WMPopUpButton *cmd1P;
40 WMPopUpButton *cmd2P;
42 WMTextField *tit1T;
43 WMTextField *tit2T;
45 WMBrowser *browser;
47 WMFrame *labF;
48 WMTextField *labT;
50 WMFrame *cmdF;
51 WMPopUpButton *cmdP;
53 WMButton *noconfirmB;
55 WMFrame *proF;
56 WMTextField *proT;
57 WMLabel *infoL;
59 WMFrame *pathF;
60 WMTextField *pathT;
61 WMLabel *pathL;
63 WMFrame *shoF;
64 WMTextField *shoT;
65 WMButton *shoB;
67 WMButton *guruB;
69 /**/
70 proplist_t menu;
71 proplist_t editedItem;
73 proplist_t itemClipboard; /* for copy/paste */
75 char capturing; /* shortcut capture */
76 char unsaved; /* if there are unsaved changes */
77 char dontSave;
78 char scrolledBrowser;
79 } _Panel;
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 */
93 enum {
94 CAddCommand = 0,
95 CAddSubmenu = 1,
96 CAddExternal = 2,
97 CAddWorkspace = 3,
98 CRemove = 4,
99 CCut = 5,
100 CCopy = 6,
101 CPaste = 7
105 enum {
106 CpExec = 0,
107 CpShExec = 1,
108 CpArrange = 2,
109 CpHide = 3,
110 CpShow = 4,
111 CpExit = 5,
112 CpShutdown = 6,
113 CpRestart = 7,
114 CpRestartWM = 8,
115 CpSaveSession = 9,
116 CpClearSession = 10,
117 CpRefresh = 11,
118 CpInfo = 12,
119 CpLegal = 13
122 enum {
123 TNothing,
124 TExec,
125 TShExec,
126 TSimpleCommand,
127 TRestart,
128 TRestartWM,
129 TExit,
130 TExternalMenu,
131 TWSMenu
136 static void showData(_Panel *panel);
138 static void fillBrowser(WMBrowserDelegate *self, WMBrowser *bPtr, int column,
139 WMList *list);
141 static void scrolledBrowser(WMBrowserDelegate *self, WMBrowser *sender);
143 static WMBrowserDelegate browserDelegate = {
144 NULL, /* data */
145 fillBrowser, /* createRowsForColumn */
146 NULL, /* titleOfColumn */
147 scrolledBrowser, /* didScroll */
148 NULL /* willScroll */
152 static Bool
153 isMenu(proplist_t item)
155 if (PLGetNumberOfElements(item)==1)
156 return True;
158 return PLIsArray(PLGetArrayElement(item, 1));
162 static void
163 splitOpenMenuParameter(char *str, char **dirs, char **prog)
165 char *p;
167 if (!(p = strstr(str, " WITH "))) {
168 *dirs = wstrdup(str);
169 *prog = NULL;
170 } else {
171 int i, j;
173 i = strlen(str);
174 j = strlen(p);
175 *dirs = wmalloc(i-j+1);
176 strncpy(*dirs, str, i-j+1);
177 (*dirs)[i-j] = 0;
179 p += 6;
180 while (isspace(*p)) p++;
181 if (*p!=0) {
182 *prog = wmalloc(j);
183 strcpy(*prog, p);
184 } else {
185 *prog = NULL;
191 static void
192 changeItemTitle(proplist_t item, char *title)
194 proplist_t tmp;
196 tmp = PLGetArrayElement(item, 0);
197 PLRelease(tmp);
198 PLRemoveArrayElement(item, 0);
199 PLInsertArrayElement(item, title?PLMakeString(title):PLMakeString(""), 0);
203 static void
204 removeParameter(proplist_t item)
206 proplist_t tmp;
207 int index;
209 if (strcmp(PLGetString(PLGetArrayElement(item, 1)), "SHORTCUT")==0) {
210 index = 4;
211 } else {
212 index = 2;
214 tmp = PLGetArrayElement(item, index);
215 PLRemoveArrayElement(item, index);
216 if (tmp)
217 PLRelease(tmp);
221 static void
222 changeItemParameter(proplist_t item, char *param)
224 proplist_t tmp;
225 int index;
227 if (strcmp(PLGetString(PLGetArrayElement(item, 1)), "SHORTCUT")==0) {
228 index = 4;
229 } else {
230 index = 2;
232 tmp = PLGetArrayElement(item, index);
233 PLRemoveArrayElement(item, index);
234 PLRelease(tmp);
235 tmp = param?PLMakeString(param):PLMakeString("");
236 PLInsertArrayElement(item, tmp, index);
240 static void
241 changeItemShortcut(proplist_t item, char *shortcut)
243 proplist_t tmp;
245 if (strcmp(PLGetString(PLGetArrayElement(item, 1)), "SHORTCUT")==0) {
246 if (shortcut) {
247 tmp = PLGetArrayElement(item, 2);
248 PLRemoveArrayElement(item, 2);
249 PLRelease(tmp);
250 PLInsertArrayElement(item, PLMakeString(shortcut), 2);
251 } else {
252 /* remove SHORTCUT keyword */
253 tmp = PLGetArrayElement(item, 1);
254 PLRemoveArrayElement(item, 1);
255 PLRelease(tmp);
256 /* remove the shortcut */
257 tmp = PLGetArrayElement(item, 1);
258 PLRemoveArrayElement(item, 1);
259 PLRelease(tmp);
261 } else {
262 if (shortcut) {
263 PLInsertArrayElement(item, PLMakeString("SHORTCUT"), 1);
264 PLInsertArrayElement(item, PLMakeString(shortcut), 2);
265 } else {
266 /* do nothing */
272 static void
273 changeItemCommand(proplist_t item, char *command)
275 proplist_t tmp;
277 tmp = PLGetArrayElement(item, 1);
278 if (strcmp(PLGetString(tmp), "SHORTCUT")==0) {
279 PLRelease(tmp);
280 PLRemoveArrayElement(item, 3);
281 PLInsertArrayElement(item, PLMakeString(command), 3);
282 } else {
283 PLRelease(tmp);
284 PLRemoveArrayElement(item, 1);
285 PLInsertArrayElement(item, PLMakeString(command), 1);
290 static char*
291 getItemTitle(proplist_t item)
293 return PLGetString(PLGetArrayElement(item, 0));
297 static char*
298 getItemParameter(proplist_t item)
300 proplist_t tmp;
302 tmp = PLGetArrayElement(item, 1);
303 if (strcmp(PLGetString(tmp), "SHORTCUT")==0) {
304 tmp = PLGetArrayElement(item, 4);
305 return tmp ? PLGetString(tmp) : NULL;
306 } else {
307 tmp = PLGetArrayElement(item, 2);
308 return tmp ? PLGetString(tmp) : NULL;
314 static char*
315 getItemShortcut(proplist_t item)
317 proplist_t tmp;
319 tmp = PLGetArrayElement(item, 1);
320 if (strcmp(PLGetString(tmp), "SHORTCUT")==0) {
321 return PLGetString(PLGetArrayElement(item, 2));
322 } else {
323 return NULL;
329 static char*
330 getItemCommand(proplist_t item)
332 proplist_t tmp;
333 char *str;
335 tmp = PLGetArrayElement(item, 1);
336 if (!tmp)
337 return "";
338 if (strcmp(PLGetString(tmp), "SHORTCUT")==0) {
339 str = PLGetString(PLGetArrayElement(item,3));
340 } else {
341 str = PLGetString(tmp);
343 return str;
348 static proplist_t
349 getSubmenuInColumn(_Panel *panel, int column)
351 proplist_t parent;
352 proplist_t submenu;
353 WMList *list;
354 int r;
356 if (column == 0) {
357 return panel->menu;
359 if (column >= WMGetBrowserNumberOfColumns(panel->browser))
360 return NULL;
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);
373 return submenu;
377 static void
378 updateForItemType(_Panel *panel, int type)
380 if (type==TNothing) {
381 WMUnmapWidget(panel->labF);
382 } else {
383 WMMapWidget(panel->labF);
385 if (type==TExternalMenu || type==TNothing) {
386 WMUnmapWidget(panel->cmdF);
387 } else {
388 WMMapWidget(panel->cmdF);
390 if (type==TNothing || type==TWSMenu || type==TExternalMenu) {
391 WMUnmapWidget(panel->shoF);
392 } else {
393 WMMapWidget(panel->shoF);
395 if (type==TExec || type == TShExec || type==TRestart
396 || type==TExternalMenu) {
397 WMMapWidget(panel->proF);
398 } else {
399 WMUnmapWidget(panel->proF);
401 if (type==TExternalMenu) {
402 WMMapWidget(panel->pathF);
403 } else {
404 WMUnmapWidget(panel->pathF);
406 if (type==TExit) {
407 WMMapWidget(panel->noconfirmB);
408 } else {
409 WMUnmapWidget(panel->noconfirmB);
411 if (type==TWSMenu) {
412 WMMapWidget(panel->infoL);
413 } else {
414 WMUnmapWidget(panel->infoL);
416 if (type==TExternalMenu) {
417 WMMapWidget(panel->guruB);
418 } else {
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"));
427 } else {
428 WMSetFrameTitle(panel->proF, _("Program to Run"));
433 proplist_t
434 getItemOfSelectedEntry(WMBrowser *bPtr)
436 proplist_t item;
437 proplist_t menu;
438 int i;
440 i = WMGetBrowserSelectedColumn(bPtr);
441 menu = getSubmenuInColumn((_Panel*)WMGetHangedData(bPtr), i);
443 i = WMGetBrowserSelectedRowInColumn(bPtr, i);
444 item = PLGetArrayElement(menu, i+1);
446 return item;
450 static void
451 performCommand(WMWidget *w, void *data)
453 _Panel *panel = (_Panel*)data;
454 WMPopUpButton *pop = (WMPopUpButton*)w;
455 proplist_t menuItem = NULL;
456 proplist_t menu;
457 int column;
458 int row;
459 static int cmdIndex=0;
460 char *title = NULL;
461 Bool removed = False;
463 column = WMGetBrowserFirstVisibleColumn(panel->browser);
464 if (pop == panel->cmd2P) {
465 column++;
468 if (column >= WMGetBrowserNumberOfColumns(panel->browser))
469 return;
471 menu = getSubmenuInColumn(panel, column);
473 row = WMGetBrowserSelectedRowInColumn(panel->browser, column);
475 switch (WMGetPopUpButtonSelectedItem(pop)) {
476 case CAddCommand:
477 title = wmalloc(strlen(_("New Command %i"))+6);
478 sprintf(title, _("New Command %i"), cmdIndex++);
479 menuItem = PLMakeArrayFromElements(PLMakeString(title),
480 PLMakeString("EXEC"),
481 PLMakeString(""),
482 NULL);
483 break;
484 case CAddSubmenu:
485 title = wstrdup(_("New Submenu"));
486 menuItem = PLMakeArrayFromElements(PLMakeString(title),
487 NULL);
488 break;
489 case CAddExternal:
490 title = wstrdup(_("External Menu"));
491 menuItem = PLMakeArrayFromElements(PLMakeString(title),
492 PLMakeString("OPEN_MENU"),
493 PLMakeString(""),
494 NULL);
495 break;
496 case CAddWorkspace:
497 title = wstrdup(_("Workspaces"));
498 menuItem = PLMakeArrayFromElements(PLMakeString(title),
499 PLMakeString("WORKSPACE_MENU"),
500 NULL);
501 WMSetPopUpButtonItemEnabled(panel->cmd1P, CAddWorkspace, False);
502 WMSetPopUpButtonItemEnabled(panel->cmd2P, CAddWorkspace, False);
503 break;
504 case CRemove:
505 if (row < 0)
506 return;
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);
515 PLRelease(menuItem);
516 updateForItemType(panel, TNothing);
517 panel->editedItem = NULL;
518 panel->unsaved = 1;
520 if (pop == panel->cmd1P && !panel->scrolledBrowser) {
521 WMSetTextFieldText(panel->tit2T, NULL);
524 removed = True;
525 return;
526 case CCut:
527 if (row < 0)
528 return;
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);
545 panel->unsaved = 1;
546 removed = True;
547 return;
548 case CCopy:
549 if (row < 0)
550 return;
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)
561 return;
562 panel->itemClipboard = PLDeepCopy(menuItem);
564 WMSetPopUpButtonItemEnabled(panel->cmd1P, CPaste, True);
565 WMSetPopUpButtonItemEnabled(panel->cmd2P, CPaste, True);
566 return;
567 case CPaste:
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);
573 break;
576 if (row>=0) row++;
577 WMInsertBrowserItem(panel->browser, column, row, title, isMenu(menuItem));
578 if (row<0)
579 PLAppendArrayElement(menu, menuItem);
580 else
581 PLInsertArrayElement(menu, menuItem, row+1);
582 free(title);
583 panel->unsaved = 1;
585 if (removed) {
586 if (pop == panel->cmd1P) {
587 WMSetTextFieldText(panel->tit2T, NULL);
593 static void
594 browserClick(WMWidget *w, void *data)
596 _Panel *panel = (_Panel*)data;
597 proplist_t item;
598 char *command;
600 /* stop shortcut capture */
601 panel->capturing = 0;
603 item = getItemOfSelectedEntry(panel->browser);
605 panel->editedItem = item;
607 /* set title */
608 WMSetTextFieldText(panel->labT, getItemTitle(item));
610 if (isMenu(item)) {
611 updateForItemType(panel, TNothing);
613 WMSetPopUpButtonEnabled(panel->cmd2P, True);
614 return;
615 } else {
616 int column = WMGetBrowserSelectedColumn(panel->browser);
618 if (column == WMGetBrowserNumberOfColumns(panel->browser)-1
619 && column > 0)
620 WMSetPopUpButtonEnabled(panel->cmd2P, True);
621 else
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) {
635 char *p, *c;
637 splitOpenMenuParameter(getItemParameter(item), &p, &c);
638 WMSetTextFieldText(panel->pathT, p);
639 WMSetTextFieldText(panel->proT, c);
640 if (p)
641 free(p);
642 if (c)
643 free(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);
668 } else {
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);
692 static void
693 fillBrowser(WMBrowserDelegate *self, WMBrowser *bPtr, int column, WMList *list)
695 _Panel *panel = (_Panel*)WMGetHangedData(bPtr);
696 proplist_t menuItem;
697 proplist_t menuList = NULL;
698 int i;
701 menuList = getSubmenuInColumn(panel, column);
702 assert(menuList != NULL);
704 if (column > WMGetBrowserFirstVisibleColumn(bPtr)) {
705 WMSetTextFieldText(panel->tit2T, getItemTitle(menuList));
706 } else {
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),
713 isMenu(menuItem));
720 static void
721 changedItem(void *observerData, WMNotification *notification)
723 _Panel *panel = (_Panel*)observerData;
724 WMTextField *t = (WMTextField*)WMGetNotificationObject(notification);
725 proplist_t item = panel->editedItem;
726 WMList *list;
727 WMListItem *litem;
728 char *command;
729 char *str;
732 if (!item)
733 return;
735 panel->unsaved = 1;
736 if (!isMenu(item)) {
737 command = getItemCommand(item);
739 if (t == panel->shoT) {
740 str = WMGetTextFieldText(t);
741 if (strlen(str)==0) {
742 free(str);
743 str = NULL;
745 changeItemShortcut(item, str);
746 if (str)
747 free(str);
748 } else if (t == panel->labT) {
749 int column;
751 str = WMGetTextFieldText(t);
752 if (!str)
753 str = wstrdup("");
754 changeItemTitle(item, str);
755 column = WMGetBrowserSelectedColumn(panel->browser);
756 list = WMGetBrowserListInColumn(panel->browser, column);
757 litem = WMGetListSelectedItem(list);
759 free(litem->text);
760 litem->text = str;
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);
771 free(str);
773 } else if (strcmp(command, "OPEN_MENU")==0) {
774 char *text;
775 char *str2;
777 str = WMGetTextFieldText(panel->pathT);
778 str2 = WMGetTextFieldText(panel->proT);
779 text = wmalloc(strlen(str)+strlen(str2)+16);
780 strcpy(text, str);
781 free(str);
782 if (strlen(str2)>0) {
783 strcat(text, " WITH ");
784 strcat(text, str2);
786 free(str2);
787 changeItemParameter(item, text);
788 free(text);
794 static void
795 changedTitle(void *observerData, WMNotification *notification)
797 _Panel *panel = (_Panel*)observerData;
798 WMTextField *t = (WMTextField*)WMGetNotificationObject(notification);
799 proplist_t menu;
800 WMList *list;
801 int column;
802 char *txt;
804 column = WMGetBrowserFirstVisibleColumn(panel->browser);
805 if (panel->tit2T == t)
806 column++;
808 menu = getSubmenuInColumn(panel, column);
809 if (!menu)
810 return;
812 txt = WMGetTextFieldText(t);
813 changeItemTitle(menu, txt);
815 if (column > 0) {
816 WMListItem *litem;
818 list = WMGetBrowserListInColumn(panel->browser, column-1);
819 litem = WMGetListSelectedItem(list);
821 free(litem->text);
822 litem->text = txt;
824 WMRedisplayWidget(list);
825 } else {
826 free(txt);
828 panel->unsaved = 1;
832 static void
833 changedCommand(WMWidget *w, void *data)
835 _Panel *panel = (_Panel*)data;
836 int i;
837 char *tmp;
839 panel->unsaved = 1;
840 i = WMGetPopUpButtonSelectedItem(panel->cmdP);
841 changeItemParameter(panel->editedItem, "");
842 switch (i) {
843 case CpExec:
844 if (strcmp(getItemCommand(panel->editedItem), "EXEC")!=0) {
845 changeItemCommand(panel->editedItem, "EXEC");
846 tmp = WMGetTextFieldText(panel->proT);
847 changeItemParameter(panel->editedItem, tmp);
848 free(tmp);
849 updateForItemType(panel, TExec);
851 break;
852 case CpShExec:
853 if (strcmp(getItemCommand(panel->editedItem), "SHEXEC")!=0) {
854 changeItemCommand(panel->editedItem, "SHEXEC");
855 tmp = WMGetTextFieldText(panel->proT);
856 changeItemParameter(panel->editedItem, tmp);
857 free(tmp);
858 updateForItemType(panel, TShExec);
860 break;
861 case CpArrange:
862 if (strcmp(getItemCommand(panel->editedItem), "ARRANGE_ICONS")!=0) {
863 changeItemCommand(panel->editedItem, "ARRANGE_ICONS");
864 updateForItemType(panel, TSimpleCommand);
866 break;
867 case CpHide:
868 if (strcmp(getItemCommand(panel->editedItem), "HIDE_OTHERS")!=0) {
869 changeItemCommand(panel->editedItem, "HIDE_OTHERS");
870 updateForItemType(panel, TSimpleCommand);
872 break;
873 case CpShow:
874 if (strcmp(getItemCommand(panel->editedItem), "SHOW_ALL")!=0) {
875 changeItemCommand(panel->editedItem, "SHOW_ALL");
876 updateForItemType(panel, TSimpleCommand);
878 break;
879 case CpExit:
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");
886 else
887 changeItemParameter(panel->editedItem, "");
888 break;
889 case CpShutdown:
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");
896 else
897 changeItemParameter(panel->editedItem, "");
898 break;
899 case CpRestartWM:
900 changeItemCommand(panel->editedItem, "RESTARTW");
901 updateForItemType(panel, TRestartWM);
902 break;
903 case CpRestart:
904 changeItemCommand(panel->editedItem, "RESTART");
905 updateForItemType(panel, TRestart);
906 tmp = WMGetTextFieldText(panel->proT);
907 changeItemParameter(panel->editedItem, tmp);
908 free(tmp);
909 break;
910 case CpSaveSession:
911 if (strcmp(getItemCommand(panel->editedItem), "SAVE_SESSION")!=0) {
912 changeItemCommand(panel->editedItem, "SAVE_SESSION");
913 updateForItemType(panel, TSimpleCommand);
915 break;
916 case CpClearSession:
917 if (strcmp(getItemCommand(panel->editedItem), "CLEAR_SESSION")!=0) {
918 changeItemCommand(panel->editedItem, "CLEAR_SESSION");
919 updateForItemType(panel, TSimpleCommand);
921 break;
922 case CpRefresh:
923 if (strcmp(getItemCommand(panel->editedItem), "REFRESH")!=0) {
924 changeItemCommand(panel->editedItem, "REFRESH");
925 updateForItemType(panel, TSimpleCommand);
927 break;
928 case CpInfo:
929 if (strcmp(getItemCommand(panel->editedItem), "INFO_PANEL")!=0) {
930 changeItemCommand(panel->editedItem, "INFO_PANEL");
931 updateForItemType(panel, TSimpleCommand);
933 break;
934 case CpLegal:
935 if (strcmp(getItemCommand(panel->editedItem), "LEGAL_PANEL")!=0) {
936 changeItemCommand(panel->editedItem, "LEGAL_PANEL");
937 updateForItemType(panel, TSimpleCommand);
939 break;
947 static char*
948 captureShortcut(Display *dpy, _Panel *panel)
950 XEvent ev;
951 KeySym ksym;
952 char buffer[64];
953 char *key = NULL;
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;
963 break;
966 WMHandleEvent(&ev);
969 if (!key)
970 return NULL;
972 buffer[0] = 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+");
995 strcat(buffer, key);
997 return wstrdup(buffer);
1001 static void
1002 captureClick(WMWidget *w, void *data)
1004 _Panel *panel = (_Panel*)data;
1005 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
1006 char *shortcut;
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);
1014 if (shortcut) {
1015 WMSetTextFieldText(panel->shoT, shortcut);
1016 changeItemShortcut(panel->editedItem, shortcut);
1017 panel->unsaved = 1;
1019 free(shortcut);
1021 panel->capturing = 0;
1022 WMSetButtonText(w, _("Capture"));
1023 XUngrabKeyboard(dpy, CurrentTime);
1028 static void
1029 scrolledBrowser(WMBrowserDelegate *self, WMBrowser *sender)
1031 _Panel *panel = (_Panel*)self->data;
1032 int column;
1033 proplist_t item;
1035 column = WMGetBrowserFirstVisibleColumn(sender);
1037 item = getSubmenuInColumn(panel, column);
1038 WMSetTextFieldText(panel->tit1T, getItemTitle(item));
1040 item = getSubmenuInColumn(panel, column + 1);
1041 if (item) {
1042 WMSetTextFieldText(panel->tit2T, getItemTitle(item));
1044 panel->scrolledBrowser = 1;
1048 static void
1049 confirmClicked(WMWidget *w, void *data)
1051 _Panel *panel = (_Panel*)data;
1053 if (WMGetButtonSelected(panel->noconfirmB)) {
1054 changeItemParameter(panel->editedItem, "QUICK");
1055 } else {
1056 changeItemParameter(panel->editedItem, "");
1058 panel->unsaved = 1;
1063 static void
1064 openGuru(WMWidget *w, void *data)
1066 _Panel *panel = (_Panel*)data;
1067 char *def;
1068 char *path, *cmd;
1070 def = OpenMenuGuru(GetWindow(panel));
1071 if (def) {
1072 changeItemParameter(panel->editedItem, def);
1073 splitOpenMenuParameter(def, &path, &cmd);
1074 free(def);
1075 WMSetTextFieldText(panel->pathT, path);
1076 if (path)
1077 free(path);
1079 WMSetTextFieldText(panel->proT, cmd);
1080 if (cmd)
1081 free(cmd);
1082 panel->unsaved = 1;
1087 static void
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,
1131 panel->tit1T);
1133 panel->tit2T = WMCreateTextField(panel->frame);
1134 WMResizeWidget(panel->tit2T, 144, 20);
1135 WMMoveWidget(panel->tit2T, 164, 40);
1136 WMAddNotificationObserver(changedTitle, panel, WMTextDidChangeNotification,
1137 panel->tit2T);
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);
1151 /**/
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,
1162 panel->labT);
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,
1214 panel->pathT);
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,
1227 panel->proT);
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,
1240 panel->shoT);
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);
1259 showData(panel);
1265 static proplist_t
1266 preProcessMenu(proplist_t menu, int *hasWSMenu)
1268 proplist_t pmenu;
1269 proplist_t item;
1270 int i;
1272 pmenu = PLDeepCopy(menu);
1273 if (PLGetNumberOfElements(pmenu)==1) {
1274 return pmenu;
1276 for (i=1; i<PLGetNumberOfElements(pmenu); i++) {
1277 item = PLGetArrayElement(pmenu, i);
1278 if (isMenu(item)) {
1279 PLInsertArrayElement(pmenu, preProcessMenu(item, hasWSMenu), i);
1280 PLRemoveArrayElement(pmenu, i+1);
1281 PLRelease(item);
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(""));
1288 } else {
1289 if (PLGetNumberOfElements(item) == 2) {
1290 changeItemCommand(item, "RESTARTW");
1291 PLAppendArrayElement(item, PLMakeString(""));
1294 } else {
1295 if (strcmp(getItemCommand(item),"WORKSPACE_MENU")==0)
1296 *hasWSMenu = 1;
1297 if (getItemShortcut(item)) {
1298 if (PLGetNumberOfElements(item) == 4)
1299 PLAppendArrayElement(item, PLMakeString(""));
1300 } else {
1301 if (PLGetNumberOfElements(item) == 2)
1302 PLAppendArrayElement(item, PLMakeString(""));
1307 return pmenu;
1312 static proplist_t
1313 postProcessMenu(proplist_t menu)
1315 proplist_t pmenu;
1316 proplist_t item;
1317 int i;
1318 int count;
1320 pmenu = PLDeepCopy(menu);
1321 if (PLGetNumberOfElements(pmenu)==1) {
1322 return pmenu;
1324 count = PLGetNumberOfElements(pmenu);
1325 for (i=1; i<count; i++) {
1326 char *cmd;
1327 item = PLGetArrayElement(pmenu, i);
1328 if (isMenu(item)) {
1329 PLInsertArrayElement(pmenu, postProcessMenu(item), i);
1330 PLRemoveArrayElement(pmenu, i+1);
1331 PLRelease(item);
1332 } else {
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) {
1339 /* do nothing */
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);
1345 } else {
1346 removeParameter(item);
1351 return pmenu;
1355 static proplist_t
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);
1368 if (!menu) {
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);
1378 if (!menu) {
1379 char buffer[512];
1381 sprintf(buffer, _("Could not open default menu from '%s'"),
1382 menuPath);
1383 WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win,
1384 _("Error"), buffer, _("OK"), NULL, NULL);
1388 free(menuPath);
1390 if (menu) {
1391 pmenu = preProcessMenu(menu, hasWSMenu);
1392 PLRelease(menu);
1393 } else {
1394 pmenu = NULL;
1397 return pmenu;
1401 static void
1402 showData(_Panel *panel)
1404 char *gspath;
1405 char *menuPath;
1406 proplist_t menu, pmenu, plPath;
1407 int hasWSMenu = 0;
1409 gspath = wusergnusteppath();
1411 menuPath = wmalloc(strlen(gspath)+32);
1412 strcpy(menuPath, gspath);
1413 strcat(menuPath, "/Defaults/WMRootMenu");
1415 menu = PLGetProplistWithPath(menuPath);
1416 pmenu = NULL;
1418 if (!menu || !PLIsArray(menu)) {
1419 if (AskMenuCopy(panel->win)) {
1420 panel->dontSave = 0;
1421 panel->unsaved = 1;
1423 pmenu = getDefaultMenu(panel, &hasWSMenu);
1424 } else {
1425 WMSetPopUpButtonEnabled(panel->cmd1P, False);
1426 WMSetPopUpButtonEnabled(panel->cmd2P, False);
1427 panel->dontSave = 1;
1429 if (!pmenu) {
1430 pmenu = PLMakeArrayFromElements(PLMakeString("Applications"),
1431 NULL);
1433 } else {
1434 pmenu = preProcessMenu(menu, &hasWSMenu);
1436 plPath = PLMakeString(menuPath);
1437 free(menuPath);
1438 PLSetFilename(pmenu, plPath);
1439 PLRelease(plPath);
1441 if (menu)
1442 PLRelease(menu);
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);
1454 if (hasWSMenu) {
1455 WMSetPopUpButtonItemEnabled(panel->cmd1P, CAddWorkspace, False);
1456 WMSetPopUpButtonItemEnabled(panel->cmd2P, CAddWorkspace, False);
1458 WMLoadBrowserColumnZero(panel->browser);
1460 updateForItemType(panel, TNothing);
1464 static void
1465 storeData(_Panel *panel)
1467 proplist_t menu;
1469 if (!panel->unsaved || panel->dontSave)
1470 return;
1471 panel->unsaved = 0;
1473 menu = postProcessMenu(panel->menu);
1475 PLSetFilename(menu, PLGetFilename(panel->menu));
1477 PLSave(menu, YES);
1479 PLRelease(menu);
1483 Panel*
1484 InitMenu(WMScreen *scr, WMWindow *win)
1486 _Panel *panel;
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.");
1495 panel->win = win;
1497 panel->callbacks.createWidgets = createPanel;
1498 panel->callbacks.updateDomain = storeData;
1500 AddSection(panel, ICON_FILE);
1502 return panel;