1 /* MenuGuru.c- OPEN_MENU definition "guru" assistant
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,
29 typedef struct _MenuGuru
{
82 while (isspace(*p
)) p
++;
85 while (isspace(p
[i
]) && i
>0) {
95 showPart(MenuGuru
*panel
, int part
)
97 WMUnmapSubwidgets(panel
->win
);
98 WMMapWidget(panel
->nextB
);
99 WMMapWidget(panel
->backB
);
100 WMMapWidget(panel
->cancelB
);
102 WMSetButtonEnabled(panel
->backB
, part
!=GSelectType
);
106 WMSetWindowTitle(panel
->win
, _("Menu Guru - Select Type"));
107 WMMapWidget(panel
->typetopL
);
108 WMMapWidget(panel
->typedB
);
109 WMMapWidget(panel
->typepB
);
110 WMMapWidget(panel
->typefB
);
111 WMSetButtonText(panel
->nextB
, _("Next"));
114 WMSetWindowTitle(panel
->win
, _("Menu Guru - Select Menu File"));
115 WMMapWidget(panel
->pathtopL
);
116 WMMapWidget(panel
->pathT
);
117 /* WMMapWidget(panel->pathB);*/
118 WMMapWidget(panel
->pathbotL
);
119 WMSetButtonText(panel
->nextB
, _("OK"));
122 WMSetWindowTitle(panel
->win
, _("Menu Guru - Select Pipe Command"));
123 WMMapWidget(panel
->pipetopL
);
124 WMMapWidget(panel
->pipeT
);
125 WMMapWidget(panel
->pipebotL
);
126 WMSetButtonText(panel
->nextB
, _("OK"));
129 WMSetWindowTitle(panel
->win
, _("Menu Guru - Select Directories"));
130 WMMapWidget(panel
->dirtopL
);
131 WMMapWidget(panel
->dirT
);
132 WMMapWidget(panel
->dirbotL
);
133 WMSetButtonText(panel
->nextB
, _("Next"));
136 WMSetWindowTitle(panel
->win
, _("Menu Guru - Select Command"));
137 WMMapWidget(panel
->progtopL
);
138 WMMapWidget(panel
->progT
);
139 WMMapWidget(panel
->progbotL
);
140 WMSetButtonText(panel
->nextB
, _("OK"));
143 panel
->section
= part
;
148 clickNext(WMWidget
*w
, void *data
)
150 MenuGuru
*panel
= (MenuGuru
*)data
;
153 switch (panel
->section
) {
155 if (WMGetButtonSelected(panel
->typefB
)) {
156 showPart(panel
, GSelectFile
);
157 } else if (WMGetButtonSelected(panel
->typepB
)) {
158 showPart(panel
, GSelectPipe
);
160 showPart(panel
, GSelectPaths
);
164 tmp
= WMGetTextFieldText(panel
->pathT
);
165 p
= trimstr(tmp
); free(tmp
);
175 tmp
= WMGetTextFieldText(panel
->dirT
);
176 p
= trimstr(tmp
); free(tmp
);
182 showPart(panel
, GSelectProgram
);
185 tmp
= WMGetTextFieldText(panel
->pipeT
);
186 p
= trimstr(tmp
); free(tmp
);
207 clickBack(WMWidget
*w
, void *data
)
209 MenuGuru
*panel
= (MenuGuru
*)data
;
212 switch (panel
->section
) {
214 newSection
= GSelectType
;
217 newSection
= GSelectType
;
220 newSection
= GSelectType
;
223 newSection
= GSelectPaths
;
226 newSection
= panel
->section
;
228 showPart(panel
, newSection
);
234 closeWindow(WMWidget
*w
, void *data
)
236 MenuGuru
*panel
= (MenuGuru
*)data
;
243 createPanel(WMWindow
*mainWindow
, MenuGuru
*panel
)
245 panel
->win
= WMCreatePanelForWindow(mainWindow
, "menuGuru");
246 WMResizeWidget(panel
->win
, 370, 220);
248 panel
->nextB
= WMCreateCommandButton(panel
->win
);
249 WMResizeWidget(panel
->nextB
, 80, 24);
250 WMMoveWidget(panel
->nextB
, 280, 185);
251 WMSetButtonText(panel
->nextB
, _("Next"));
252 WMSetButtonAction(panel
->nextB
, clickNext
, panel
);
254 panel
->backB
= WMCreateCommandButton(panel
->win
);
255 WMResizeWidget(panel
->backB
, 80, 24);
256 WMMoveWidget(panel
->backB
, 195, 185);
257 WMSetButtonText(panel
->backB
, _("Back"));
258 WMSetButtonAction(panel
->backB
, clickBack
, panel
);
260 panel
->cancelB
= WMCreateCommandButton(panel
->win
);
261 WMResizeWidget(panel
->cancelB
, 80, 24);
262 WMMoveWidget(panel
->cancelB
, 110, 185);
263 WMSetButtonText(panel
->cancelB
, _("Cancel"));
264 WMSetButtonAction(panel
->cancelB
, closeWindow
, panel
);
268 panel
->typetopL
= WMCreateLabel(panel
->win
);
269 WMResizeWidget(panel
->typetopL
, 350, 45);
270 WMMoveWidget(panel
->typetopL
, 10, 10);
271 WMSetLabelText(panel
->typetopL
, _("This process will help you create a "
272 "submenu which definition is located in another file "
273 "or is created dynamically.\nWhat do you want to use as the "
274 "contents of the submenu?"));
276 panel
->typefB
= WMCreateRadioButton(panel
->win
);
277 WMResizeWidget(panel
->typefB
, 330, 35);
278 WMMoveWidget(panel
->typefB
, 20, 65);
279 WMSetButtonText(panel
->typefB
, _("A file containing the menu definition "
280 "in the plain text (non-property list) menu format."));
282 panel
->typepB
= WMCreateRadioButton(panel
->win
);
283 WMResizeWidget(panel
->typepB
, 330, 35);
284 WMMoveWidget(panel
->typepB
, 20, 105);
285 WMSetButtonText(panel
->typepB
, _("The menu definition generated by a "
286 "script/program read through a pipe."));
288 panel
->typedB
= WMCreateRadioButton(panel
->win
);
289 WMResizeWidget(panel
->typedB
, 330, 35);
290 WMMoveWidget(panel
->typedB
, 20, 140);
291 WMSetButtonText(panel
->typedB
, _("The files in one or more directories."));
293 WMGroupButtons(panel
->typefB
, panel
->typepB
);
294 WMGroupButtons(panel
->typefB
, panel
->typedB
);
296 WMPerformButtonClick(panel
->typefB
);
300 panel
->pathtopL
= WMCreateLabel(panel
->win
);
301 WMResizeWidget(panel
->pathtopL
, 330, 20);
302 WMMoveWidget(panel
->pathtopL
, 20, 25);
303 WMSetLabelText(panel
->pathtopL
, _("Type the path for the menu file:"));
305 panel
->pathT
= WMCreateTextField(panel
->win
);
306 WMResizeWidget(panel
->pathT
, 330, 20);
307 WMMoveWidget(panel
->pathT
, 20, 50);
309 panel->pathB = WMCreateCommandButton(panel->win);
310 WMResizeWidget(panel->pathB, 70, 24);
311 WMMoveWidget(panel->pathB, 275, 75);
312 WMSetButtonText(panel->pathB, _("Browse"));
315 panel
->pathbotL
= WMCreateLabel(panel
->win
);
316 WMResizeWidget(panel
->pathbotL
, 330, 80);
317 WMMoveWidget(panel
->pathbotL
, 20, 100);
318 WMSetLabelText(panel
->pathbotL
, _("The menu file must contain a menu "
319 "in the plain text menu file format. This format is "
320 "described in the menu files included with WindowMaker, "
321 "probably at ~/GNUstep/Library/WindowMaker/menu"));
325 panel
->pipetopL
= WMCreateLabel(panel
->win
);
326 WMResizeWidget(panel
->pipetopL
, 330, 32);
327 WMMoveWidget(panel
->pipetopL
, 20, 20);
328 WMSetLabelText(panel
->pipetopL
, _("Type the command that will generate "
329 "the menu definition:"));
331 panel
->pipeT
= WMCreateTextField(panel
->win
);
332 WMResizeWidget(panel
->pipeT
, 330, 20);
333 WMMoveWidget(panel
->pipeT
, 20, 55);
335 panel
->pipebotL
= WMCreateLabel(panel
->win
);
336 WMResizeWidget(panel
->pipebotL
, 330, 80);
337 WMMoveWidget(panel
->pipebotL
, 20, 85);
338 WMSetLabelText(panel
->pipebotL
, _("The command supplied must generate and "
339 "output a valid menu definition to stdout. This definition "
340 "should be in the plain text menu file format, described "
341 "in the menu files included with WindowMaker, usually "
342 "at ~/GNUstep/Library/WindowMaker/menu"));
347 panel
->dirtopL
= WMCreateLabel(panel
->win
);
348 WMResizeWidget(panel
->dirtopL
, 330, 32);
349 WMMoveWidget(panel
->dirtopL
, 20, 20);
350 WMSetLabelText(panel
->dirtopL
, _("Type the path for the directory. You "
351 "can type more than one path by separating them with "
354 panel
->dirT
= WMCreateTextField(panel
->win
);
355 WMResizeWidget(panel
->dirT
, 330, 20);
356 WMMoveWidget(panel
->dirT
, 20, 55);
358 panel
->dirbotL
= WMCreateLabel(panel
->win
);
359 WMResizeWidget(panel
->dirbotL
, 330, 80);
360 WMMoveWidget(panel
->dirbotL
, 20, 85);
361 WMSetLabelText(panel
->dirbotL
, _("The menu generated will have an item "
362 "for each file in the directory. The directories can "
363 "contain program executables or data files (such as "
369 panel
->dirtopL
= WMCreateLabel(panel
->win
);
370 WMResizeWidget(panel
->dirtopL
, 330, 32);
371 WMMoveWidget(panel
->dirtopL
, 20, 20);
372 WMSetLabelText(panel
->dirtopL
, _("Type the path for the directory. You "
373 "can type more than one path by separating them with "
376 panel
->dirT
= WMCreateTextField(panel
->win
);
377 WMResizeWidget(panel
->dirT
, 330, 20);
378 WMMoveWidget(panel
->dirT
, 20, 55);
380 panel
->dirbotL
= WMCreateLabel(panel
->win
);
381 WMResizeWidget(panel
->dirbotL
, 330, 80);
382 WMMoveWidget(panel
->dirbotL
, 20, 85);
383 WMSetLabelText(panel
->dirbotL
, _("The menu generated will have an item "
384 "for each file in the directory. The directories can "
385 "contain program executables or data files (such as "
391 panel
->dirtopL
= WMCreateLabel(panel
->win
);
392 WMResizeWidget(panel
->dirtopL
, 330, 32);
393 WMMoveWidget(panel
->dirtopL
, 20, 20);
394 WMSetLabelText(panel
->dirtopL
, _("Type the path for the directory. You "
395 "can type more than one path by separating them with "
398 panel
->dirT
= WMCreateTextField(panel
->win
);
399 WMResizeWidget(panel
->dirT
, 330, 20);
400 WMMoveWidget(panel
->dirT
, 20, 60);
402 panel
->dirbotL
= WMCreateLabel(panel
->win
);
403 WMResizeWidget(panel
->dirbotL
, 330, 80);
404 WMMoveWidget(panel
->dirbotL
, 20, 85);
405 WMSetLabelText(panel
->dirbotL
, _("The menu generated will have an item "
406 "for each file in the directory. The directories can "
407 "contain program executables or data files (such as "
412 panel
->progtopL
= WMCreateLabel(panel
->win
);
413 WMResizeWidget(panel
->progtopL
, 330, 48);
414 WMMoveWidget(panel
->progtopL
, 20, 10);
415 WMSetLabelText(panel
->progtopL
, _("If the directory contain data files, "
416 "type the command used to open these files. Otherwise, "
417 "leave it in blank."));
419 panel
->progT
= WMCreateTextField(panel
->win
);
420 WMResizeWidget(panel
->progT
, 330, 20);
421 WMMoveWidget(panel
->progT
, 20, 60);
423 panel
->progbotL
= WMCreateLabel(panel
->win
);
424 WMResizeWidget(panel
->progbotL
, 330, 72);
425 WMMoveWidget(panel
->progbotL
, 20, 90);
426 WMSetLabelText(panel
->progbotL
, _("Each file in the directory will have "
427 "an item and they will be opened with the supplied command."
428 "For example, if the directory contains image files and "
429 "the command is \"xv -root\", each file in the directory "
430 "will have a menu item like \"xv -root imagefile\"."));
432 WMRealizeWidget(panel
->win
);
438 OpenMenuGuru(WMWindow
*mainWindow
)
440 WMScreen
*scr
= WMWidgetScreen(mainWindow
);
442 char *text
, *p
, *dirs
;
444 createPanel(mainWindow
, &panel
);
445 WMSetWindowCloseAction(panel
.win
, closeWindow
, &panel
);
447 showPart(&panel
, GSelectType
);
449 WMMapWidget(panel
.win
);
455 WMNextEvent(WMScreenDisplay(scr
), &ev
);
461 switch (panel
.section
) {
463 text
= WMGetTextFieldText(panel
.pathT
);
466 text
= WMGetTextFieldText(panel
.pipeT
);
467 p
= trimstr(text
); free(text
);
469 text
= wmalloc(strlen(p
)+4);
478 dirs
= WMGetTextFieldText(panel
.dirT
);
479 text
= WMGetTextFieldText(panel
.progT
);
480 p
= trimstr(text
); free(text
);
485 text
= wmalloc(strlen(dirs
)+16+strlen(p
));
486 sprintf(text
, "%s WITH %s", dirs
, p
);
494 WMDestroyWidget(panel
.win
);