Init the object variable for the registergroup so that
[cake.git] / workbench / system / Wanderer / Tools / Info / main.c
blob201dfe25d51762c5c93d85c74da3e319e012daed
1 /*
2 Copyright © 2003-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #define DEBUG 0
9 #include <aros/debug.h>
11 #include <proto/exec.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
14 #include <proto/workbench.h>
15 #include <proto/dos.h>
16 #include <proto/alib.h>
17 #include <proto/icon.h>
19 #include <dos/dos.h>
20 #include <dos/datetime.h>
21 #include <exec/memory.h>
22 #include <libraries/asl.h>
23 #include <libraries/commodities.h>
24 #include <libraries/mui.h>
25 #include <workbench/startup.h>
26 #include <workbench/workbench.h>
27 #include <workbench/icon.h>
28 #include <devices/inputevent.h>
30 #include <mui/TextEditor_mcc.h>
31 #include <zune/iconimage.h>
33 #include "locale.h"
35 #include <stdio.h>
37 #include <string.h>
39 #define RETURNID_SLEEP 1
40 #define RETURNID_WAKE 2
41 #define RETURNID_ABOUT 3
42 #define RETURNID_NEWKEY 4
43 #define RETURNID_DELKEY 5
44 #define RETURNID_LVACK 6
45 #define RETURNID_STRINGACK 7
46 #define RETURNID_SAVE 8
47 #define RETURNID_TOOLACK 9
48 #define RETURNID_STACKACK 10
49 #define RETURNID_COMMENTACK 11
50 #define RETURNID_VERSION 12
52 #define MAX_PATH_LEN 1024
53 #define MAX_TOOLTYPE_LINE 256
54 #define BUFFERSIZE 1024
56 #define USE_TEXTEDITOR 1
58 static Object *window, *commentspace, *filename_string, *stackspace, *savebutton;
59 #if USE_TEXTEDITOR
60 static Object *editor, *slider;
61 #else
62 static Object *list, *editor, *liststr;
63 #endif
65 BOOL file_altered = FALSE;
66 BOOL icon_altered = FALSE;
68 UBYTE **BuildToolTypes(UBYTE **src_ttypes)
70 #if USE_TEXTEDITOR
71 APTR pool = CreatePool(MEMF_CLEAR, 200, 200);
72 STRPTR contents, sp, *dst_ttypes;
73 ULONG lines = 1;
75 if (!pool) return NULL;
76 contents = (STRPTR)DoMethod(editor, MUIM_TextEditor_ExportText);
78 if (!contents || !contents[0])
80 DeletePool(pool);
81 return NULL;
84 sp = contents;
86 while((sp = strchr(sp, '\n')))
88 sp++;
89 lines++;
92 dst_ttypes = AllocPooled(pool, (lines + 3) * sizeof(STRPTR));
93 if (!dst_ttypes)
95 FreeVec(contents);
96 DeletePool(pool);
97 return NULL;
100 *dst_ttypes++ = (STRPTR)pool;
101 *dst_ttypes++ = (STRPTR)contents;
103 for(sp = contents, lines = 0; sp; lines++)
105 dst_ttypes[lines] = sp;
106 sp = strchr(sp, '\n');
107 if (sp)
109 *sp++ = '\0';
112 dst_ttypes[lines] = 0;
114 return dst_ttypes;
115 #else
116 APTR pool = CreatePool(MEMF_CLEAR, 200, 200);
117 Object *listobj = list;
118 WORD list_index = 0, num_ttypes = 0, alloc_ttypes = 10;
119 UBYTE **dst_ttypes;
121 if (!pool) return NULL;
123 dst_ttypes = AllocPooled(pool, (alloc_ttypes + 2) * sizeof(UBYTE *));
124 if (!dst_ttypes)
126 DeletePool(pool);
127 return NULL;
130 get(listobj, MUIA_List_Entries, &list_index);
131 while(num_ttypes<list_index)
133 STRPTR text = NULL;
134 DoMethod(listobj, MUIM_List_GetEntry, num_ttypes, (IPTR)&text);
135 if (num_ttypes >= alloc_ttypes)
137 UBYTE **new_dst_ttypes = AllocPooled(pool, (alloc_ttypes + 10 + 2) * sizeof(UBYTE *));
138 if (!new_dst_ttypes)
140 DeletePool(pool);
141 return NULL;
143 CopyMem(dst_ttypes + 1, new_dst_ttypes + 1, alloc_ttypes * sizeof(UBYTE *));
144 dst_ttypes = new_dst_ttypes;
145 alloc_ttypes += 10;
147 dst_ttypes[num_ttypes + 1] = AllocPooled(pool, strlen(text) + 1);
148 if (!dst_ttypes[num_ttypes + 1])
150 DeletePool(pool);
151 return NULL;
153 CopyMem(text, dst_ttypes[num_ttypes + 1], strlen(text) + 1);
154 D(bug("[WBInfo] tooltype #%ld %s\n", num_ttypes + 1, text));
155 num_ttypes++;
157 dst_ttypes[0] = (APTR)pool;
158 return dst_ttypes + 1;
159 #endif
162 void FreeToolTypes(UBYTE **ttypes)
164 #if USE_TEXTEDITOR
165 if (ttypes)
167 DeletePool((APTR)ttypes[-2]);
168 FreeVec((APTR)ttypes[-1]);
170 #else
171 if (ttypes)
173 DeletePool((APTR)ttypes[-1]);
175 #endif
178 void SaveIcon(struct DiskObject *icon, STRPTR name, BPTR cd)
180 STRPTR tool = NULL, stack = NULL;
181 BPTR restored_cd;
182 LONG ls;
183 UBYTE **ttypes = NULL, **old_ttypes = NULL;
185 restored_cd = CurrentDir(cd);
187 switch(icon->do_Type)
189 case WBPROJECT:
190 get(filename_string, MUIA_String_Contents, &tool);
191 icon->do_DefaultTool = tool;
192 break;
193 case WBTOOL:
194 get(stackspace, MUIA_String_Contents, &stack);
195 stcd_l(stack, &ls);
196 icon->do_StackSize = ls;
197 break;
200 old_ttypes = (UBYTE **)icon->do_ToolTypes;
201 ttypes = BuildToolTypes(old_ttypes);
202 icon->do_ToolTypes = ttypes;
204 PutIconTags(name, icon, TAG_DONE);
206 icon->do_ToolTypes = old_ttypes;
207 if (ttypes)
209 FreeToolTypes(ttypes);
211 CurrentDir(restored_cd);
212 icon_altered = FALSE;
215 void SaveFile(struct AnchorPath * ap, BPTR cd)
217 STRPTR text=NULL;
218 BPTR restored_cd;
219 restored_cd = CurrentDir(cd);
220 get(commentspace, MUIA_String_Contents, &text);
221 if (text)
222 SetComment(ap->ap_Buf, text);
223 CurrentDir(restored_cd);
224 file_altered = FALSE;
227 #if !USE_TEXTEDITOR
228 void ListToString(void)
230 STRPTR text = NULL;
231 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR) &text);
232 if (text)
234 set(liststr, MUIA_String_Contents, text);
235 nnset(liststr, MUIA_Disabled, FALSE);
236 set(window, MUIA_Window_ActiveObject, (IPTR)liststr);
240 void StringToKey(void)
242 STRPTR text = NULL;
243 STRPTR input = NULL;
245 icon_altered = TRUE;
247 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR) &text);
248 if (text)
250 get(liststr, MUIA_String_Contents, &input);
251 DoMethod(list, MUIM_List_InsertSingle, input, MUIV_List_Insert_Active);
252 set(list, MUIA_List_Active, MUIV_List_Active_Down);
253 DoMethod(list, MUIM_List_Remove, MUIV_List_Remove_Active);
254 nnset(liststr, MUIA_String_Contents, (IPTR) "");
255 nnset(liststr, MUIA_Disabled, TRUE);
256 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
260 void NewKey(void)
262 nnset(liststr, MUIA_String_Contents, "");
263 nnset(liststr, MUIA_Disabled, FALSE);
264 DoMethod(list, MUIM_List_InsertSingle, "", MUIV_List_Insert_Bottom);
265 nnset(list, MUIA_List_Active, MUIV_List_Active_Bottom);
266 set(window, MUIA_Window_ActiveObject, (IPTR) liststr);
269 void DelKey(void)
271 STRPTR text = NULL;
272 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&text);
274 if (text)
276 DoMethod(list, MUIM_List_Remove, MUIV_List_Remove_Active);
277 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&text);
278 if (!text)
280 nnset(liststr, MUIA_String_Contents, (IPTR) "");
281 nnset(liststr, MUIA_Disabled, TRUE);
282 ListToString();
283 } else {
284 ListToString();
288 #endif
290 static char * GetVersion(STRPTR name, BPTR cd)
292 D(bug("[WBINFO/Getversion] Name %s\n", name));
293 STRPTR commandline = NULL;
294 ULONG commandlineSize;
295 static TEXT result[100]; // must be static because we return its address
296 char *retval = result;
297 TEXT tmpfilename[40];
298 int nr = 0;
299 int i;
300 BPTR output = NULL;
301 BPTR restored_cd = (BPTR)-1;
303 if (name == NULL)
305 D(bug("[WBINFO/Getversion] Name is Null\n"));
306 goto exit;
309 memset(result, 0, sizeof(result));
310 result[0] = '?';
312 commandlineSize = strlen(name) + 20;
313 commandline = AllocVec(commandlineSize, MEMF_CLEAR);
314 if (commandline == NULL)
316 D(bug("[WBInfo/GetVersion] Can't allocate RAM for commandline\n"));
317 goto exit;
320 restored_cd = CurrentDir(cd);
322 //search for non-existing temp file name
325 nr++;
326 if (nr > 30)
328 D(bug("[WBINFO/Getversion] Can't find non-existing tmpfile"));
329 goto exit;
331 sprintf(tmpfilename, "t:tmp_version_%d", nr);
332 output = Open(tmpfilename, MODE_OLDFILE);
333 if (output)
335 Close(output);
337 } while (output != NULL);
339 D(bug("[WBInfo/Getversion] tmpfilename %s\n", tmpfilename));
340 output = Open(tmpfilename, MODE_NEWFILE);
341 if (output == NULL)
343 D(bug("[WBInfo/Getversion] Can't create tmpfile\n"));
344 goto exit;
347 // call c:version
348 sprintf(commandline, "c:version \"%s\" full", name);
349 D(bug("[WBInfo/GetVersion] Commandline %s\n", commandline));
350 if (SystemTags(commandline,
351 SYS_Asynch, FALSE,
352 SYS_Output, (IPTR) output,
353 //SYS_Error, (IPTR) NULL,
354 NP_StackSize, 16000,
355 TAG_DONE) != 0)
357 D(bug("[WBInfo/Getversion] SystemTags failed\n"));
358 goto exit;
361 // Seek didn't work for me on RAM-Disk, so we reopen the file
362 Close(output);
363 output = Open(tmpfilename, MODE_OLDFILE);
364 if (output == NULL)
366 D(bug("[WBInfo/GetVersion] Can't open tmpfile\n"));
367 goto exit;
369 // read result
370 if (Read(output, result, sizeof(result) - 1) == -1)
372 D(bug("[WBInfo/GetVersion] Can't read from tmpfile\n"));
373 goto exit;
375 D(bug("[WBInfo/GetVersion] Result %s\n", result));
377 // remove illegal chars (e.g. newline) from result
378 for (i = 0 ; result[i] != 0 ; i++)
380 if (result[i] < 32)
381 result[i] = ' ';
384 // set string pointer after program name
385 while (*retval != ' ')
386 retval++;
388 exit:
389 FreeVec(commandline);
390 if (output)
392 Close(output);
393 DeleteFile(tmpfilename);
395 if (restored_cd != (BPTR)-1)
396 CurrentDir(restored_cd);
398 return retval;
401 int main(int argc, char **argv)
403 Object *application, *group, *toolspace=NULL, *toollabel=NULL;
404 Object *registergroup=NULL, *infomenu=NULL, *protectmenu=NULL, *toolmenu=NULL;
405 Object *stacklabel=NULL, *drawerspace=NULL;
406 Object *sizespace=NULL, *typespace=NULL, *quit=NULL, *aboutmenu=NULL;
407 Object *datespace=NULL, *versionspace=NULL;
408 Object *cancelbutton=NULL;
409 #if !USE_TEXTEDITOR
410 Object *newkey=NULL, *delkey=NULL;
411 #endif
412 Object *readobject=NULL, *writeobject=NULL, *executeobject=NULL, *deleteobject=NULL;
413 Object *scriptobject=NULL, *pureobject=NULL, *archiveobject=NULL;
414 struct WBStartup *startup;
415 struct DiskObject *icon=NULL;
416 struct AnchorPath *ap=NULL;
417 struct DateStamp *ds=NULL;
418 struct DateTime dt;
419 IPTR dte;
420 STRPTR name=NULL, type=NULL;
421 BPTR cd, lock, icon_cd;
422 LONG returnid = 0;
423 ULONG protection;
424 char stack[16];
425 char deftool[MAX_PATH_LEN];
426 char comment[MAXCOMMENTLENGTH];
427 char size[10];
428 char date[LEN_DATSTRING];
429 char time[LEN_DATSTRING];
430 char dow[LEN_DATSTRING];
431 char datetime[2*LEN_DATSTRING];
432 UBYTE flags[8], lname[MAXFILENAMELENGTH];
434 char *pages[] = {_(MSG_INFORMATION),_(MSG_PROTECTION),_(MSG_TOOLTYPES),NULL};
435 char * typeNames[] =
437 NULL, /* not used */
438 _(MSG_DISK), /* 1 */
439 _(MSG_DRAWER), /* 2 */
440 _(MSG_TOOL), /* 3 */
441 _(MSG_PROJECT), /* 4 */
442 _(MSG_GARBAGE), /* 5 */
443 _(MSG_DEVICE), /* 6 */
444 _(MSG_KICK), /* 7 */
445 _(MSG_APPICON) /* 8 */
448 if (argc != 0)
450 /* start from wanderer only */
451 PrintFault(ERROR_FILE_NOT_OBJECT, argv[0]);
452 return RETURN_FAIL;
455 startup = (struct WBStartup *) argv;
457 if (startup->sm_NumArgs < 2)
459 /* need atleast 1 arg */
460 PrintFault(ERROR_REQUIRED_ARG_MISSING, argv[0]);
461 D(bug("[WBInfo] required arg missing\n"));
462 return RETURN_FAIL;
465 lock = startup->sm_ArgList[1].wa_Lock;
466 NameFromLock(lock, lname, MAXFILENAMELENGTH);
467 D(bug("[WBInfo] name from lock: %s\n",lname));
468 name = startup->sm_ArgList[1].wa_Name;
469 cd = CurrentDir(lock);
470 if (name == NULL)
472 /* directory not found*/
473 PrintFault(ERROR_DIR_NOT_FOUND, argv[0]);
474 D(bug("[WBInfo] dir not found\n"));
475 return RETURN_FAIL;
478 ap = AllocVec(sizeof(struct AnchorPath) + MAX_PATH_LEN, MEMF_CLEAR);
479 if (ap == NULL)
481 PrintFault(ERROR_NO_FREE_STORE, argv[0]);
482 D(bug("[WBInfo] no free store\n"));
483 return RETURN_FAIL;
486 ap->ap_Strlen = MAX_PATH_LEN;
488 if (0 != MatchFirst(name, ap))
490 D(bug("[WBInfo] pass to diskinfo\n"));
491 OpenWorkbenchObject(
492 "WANDERER:Tools/DiskInfo",
493 WBOPENA_ArgLock, (IPTR) startup->sm_ArgList[1].wa_Lock,
494 WBOPENA_ArgName, (IPTR) startup->sm_ArgList[1].wa_Name,
495 TAG_DONE);
496 FreeVec(ap);
497 return RETURN_OK;
500 ap->ap_BreakBits = SIGBREAKF_CTRL_C;
502 if (!(ap->ap_Flags & APF_DIDDIR))
504 D(bug("[WBInfo] scan file\n"));
505 /* fill comment */
506 sprintf(comment,"%s",ap->ap_Info.fib_Comment);
508 /* fill date and time */
509 ds = &ap->ap_Info.fib_Date;
510 DateStamp((struct DateStamp *)&dt);
511 CopyMem(ds, &dt.dat_Stamp, sizeof(struct DateStamp));
512 dt.dat_Format = FORMAT_DOS;
513 dt.dat_Flags = 0;
514 dt.dat_StrDay = dow;
515 dt.dat_StrDate = date;
516 dt.dat_StrTime = time;
517 dte = DateToStr(&dt);
518 sprintf(datetime, "%s %s", time, date);
520 /* fill size */
521 sprintf(size, "%d", ap->ap_Info.fib_Size);
523 /* fill protection */
524 protection = ap->ap_Info.fib_Protection;
526 /* Convert the protection bits to a boolean */
527 flags[0] = protection & FIBF_SCRIPT ? 1 : 0; /* s */
528 flags[1] = protection & FIBF_PURE ? 1 : 0; /* p */
529 flags[2] = protection & FIBF_ARCHIVE ? 1 : 0; /* a */
531 /* The following flags are high-active! */
532 flags[3] = protection & FIBF_READ ? 0 : 1; /* r */
533 flags[4] = protection & FIBF_WRITE ? 0 : 1; /* w */
534 flags[5] = protection & FIBF_EXECUTE ? 0 : 1; /* e */
535 flags[6] = protection & FIBF_DELETE ? 0 : 1; /* d */
536 flags[7] = 0x00; /* h */
539 /* read icon */
541 icon = GetIconTags(name,
542 ICONGETA_FailIfUnavailable, FALSE,
543 ICONGETA_IsDefaultIcon, FALSE,
544 TAG_DONE);
546 if (icon != NULL)
548 D(bug("[WBInfo] file has icon\n"));
549 type = (char *) typeNames[icon->do_Type];
550 D(bug("[WBInfo] icon type is: %s\n", type));
551 sprintf(stack, "%d", icon->do_StackSize);
552 if (icon->do_DefaultTool)
553 sprintf(deftool, "%s", icon->do_DefaultTool);
554 else
555 *deftool = '\0';
556 } else {
557 FreeVec(ap);
558 PrintFault(ERROR_OBJECT_WRONG_TYPE, argv[0]);
559 return RETURN_FAIL;
562 if (icon->do_Type == 2)
564 sizespace = (Object *)TextObject,
565 ButtonFrame,
566 MUIA_Background, MUII_TextBack,
567 MUIA_Text_PreParse, (IPTR) "\33r",
568 MUIA_Text_Contents, (IPTR) NULL,
569 MUIA_Text_Contents, (IPTR) "?",
570 MUIA_InputMode, MUIV_InputMode_RelVerify,
571 End;
573 else
575 sizespace = (Object *)TextObject,
576 TextFrame,
577 MUIA_Background, MUII_TextBack,
578 MUIA_Text_PreParse, (IPTR) "\33r",
579 MUIA_Text_Contents, (IPTR) size,
580 End;
583 application = (Object *)ApplicationObject,
584 MUIA_Application_Title, __(MSG_TITLE),
585 MUIA_Application_Version, (IPTR) "$VER: Info 0.3 ("ADATE") © AROS Dev Team",
586 MUIA_Application_Description, __(MSG_DESCRIPTION),
587 MUIA_Application_Base, (IPTR) "INFO",
588 MUIA_Application_Menustrip, (IPTR) MenuitemObject,
589 MUIA_Family_Child, (IPTR) MenuitemObject,
590 MUIA_Menuitem_Title, __(MSG_PROJECT),
591 MUIA_Family_Child, (IPTR)(infomenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
592 __(MSG_INFORMATION), MUIA_Menuitem_Shortcut, (IPTR) "I", End),
593 MUIA_Family_Child, (IPTR)(protectmenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
594 __(MSG_PROTECTION),MUIA_Menuitem_Shortcut, (IPTR) "P", End),
595 MUIA_Family_Child, (IPTR)(toolmenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
596 __(MSG_TOOLTYPES),MUIA_Menuitem_Shortcut, (IPTR) "T", End),
597 MUIA_Family_Child, (IPTR) MenuitemObject, MUIA_Menuitem_Title, ~0, End,
598 MUIA_Family_Child, (IPTR) (aboutmenu = (Object *)MenuitemObject, MUIA_Menuitem_Title,
599 __(MSG_ABOUT), (IPTR) MUIA_Menuitem_Shortcut, (IPTR) "?", End),
600 MUIA_Family_Child, (IPTR) MenuitemObject, MUIA_Menuitem_Title, ~0, End,
601 MUIA_Family_Child, (IPTR) (quit = (Object *)MenuitemObject, MUIA_Menuitem_Title,
602 __(MSG_QUIT), MUIA_Menuitem_Shortcut, (IPTR) "Q", End),
603 End,
604 End,
605 SubWindow, (IPTR) (window = (Object *)WindowObject,
606 MUIA_Window_Title, (IPTR) __(MSG_ICON),
607 MUIA_Window_ID, MAKE_ID('I','N','F','O'),
608 MUIA_Window_Activate, TRUE,
609 WindowContents, (IPTR) VGroup,
610 Child, (IPTR) HGroup,
611 Child, (IPTR) VGroup,
612 Child, (IPTR) IconImageObject,
613 MUIA_InputMode, MUIV_InputMode_Toggle,
614 MUIA_IconImage_File, (IPTR) name,
615 End,
616 End,
617 Child, (IPTR) VGroup,
618 Child, (IPTR) TextObject,
619 TextFrame,
620 MUIA_Background, MUII_TextBack,
621 MUIA_Text_PreParse, (IPTR) "\33l",
622 MUIA_Text_Contents, (IPTR) FilePart(name),
623 End,
624 End,
625 End,
626 Child, (IPTR) (registergroup = RegisterGroup(pages),
627 MUIA_CycleChain, 1,
628 Child, (IPTR) HGroup, /* hgroup information pannel */
629 Child, (IPTR) VGroup,
630 Child, (IPTR) HGroup,
631 Child, (IPTR) ColGroup(2),
632 Child, (IPTR) Label2(__(MSG_TYPE)),
633 Child, (IPTR) (typespace = (Object *)TextObject,
634 TextFrame,
635 MUIA_Background, MUII_TextBack,
636 MUIA_Text_PreParse, (IPTR) "\33r",
637 MUIA_Text_Contents, (IPTR) type,
638 End),
639 Child, (IPTR) Label2(__(MSG_DATE)),
640 Child, (IPTR) (datespace = (Object *)TextObject,
641 TextFrame,
642 MUIA_Background, MUII_TextBack,
643 MUIA_Text_PreParse, (IPTR) "\33r",
644 MUIA_Text_Contents, (IPTR) datetime,
645 End),
646 Child, (IPTR) Label2(__(MSG_VERSION)),
647 Child, (IPTR) (versionspace = (Object *)TextObject,
648 ButtonFrame,
649 MUIA_Background, MUII_TextBack,
650 MUIA_Text_PreParse, (IPTR) "\33r",
651 MUIA_Text_Contents, (IPTR) NULL,
652 MUIA_Text_Contents, (IPTR) "?",
653 MUIA_InputMode, MUIV_InputMode_RelVerify,
654 End),
655 Child, (IPTR) Label2(__(MSG_SIZE)),
656 Child, (IPTR) sizespace,
657 End,
658 End,
659 Child, (IPTR) HVSpace,
660 Child, (IPTR) (group = (Object *)HGroup,
661 End),
662 Child, (IPTR) HGroup,
663 Child, (IPTR) Label2(__(MSG_COMMENT)),
664 Child, (IPTR) (commentspace = (Object *)StringObject,
665 StringFrame,
666 MUIA_CycleChain, 1,
667 End),
668 End,
669 End,
670 End, /* end hgroup information pannel */
671 Child, (IPTR) HGroup, /* hgroup protections pannel */
672 Child, (IPTR) VGroup,
673 Child, (IPTR) ColGroup(2),
674 Child, (IPTR) HVSpace,
675 Child, (IPTR) ColGroup(2),
676 Child, (IPTR) Label2(_(MSG_READ)),
677 Child, (IPTR) (readobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
678 Child, (IPTR) Label2(_(MSG_WRITE)),
679 Child, (IPTR) (writeobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
680 Child, (IPTR) Label2(_(MSG_EXECUTE)),
681 Child, (IPTR) (executeobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
682 Child, (IPTR) Label2(_(MSG_DELETE)),
683 Child, (IPTR) (deleteobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
684 Child, (IPTR) Label2(_(MSG_SCRIPT)),
685 Child, (IPTR) (scriptobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
686 Child, (IPTR) Label2(_(MSG_PURE)),
687 Child, (IPTR) (pureobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
688 Child, (IPTR) Label2(_(MSG_ARCHIVED)),
689 Child, (IPTR) (archiveobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
690 End,
691 End,
692 End,
693 End, /* end hgroup protections pannel */
694 Child, (IPTR) HGroup, /* hgroup tooltypes pannel */
695 Child, (IPTR) VGroup,
696 Child, (IPTR) HGroup,
697 Child, (IPTR) VGroup,
698 GroupSpacing(0),
699 #if !USE_TEXTEDITOR
700 Child, (IPTR) ListviewObject,
701 MUIA_Listview_List, (IPTR) (list = ListObject,
702 InputListFrame,
703 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
704 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
705 MUIA_List_AutoVisible, TRUE,
706 End),
707 End,
708 Child, (IPTR) (liststr = StringObject,
709 MUIA_Disabled, TRUE,
710 StringFrame,
711 End),
712 #else
713 Child, (IPTR) HGroup,
714 GroupSpacing(0),
715 Child, (IPTR) (editor = MUI_NewObject(MUIC_TextEditor,
716 TAG_DONE)),
717 Child, (IPTR) (slider = (Object *)ScrollbarObject,
718 End),
719 End,
720 #endif
721 End,
722 End,
723 #if !USE_TEXTEDITOR
724 Child, (IPTR) HGroup,
725 MUIA_Group_SameSize, TRUE,
726 Child, (IPTR) (newkey = SimpleButton(__(MSG_NEW_KEY))),
727 Child, (IPTR) (delkey = SimpleButton(__(MSG_DELETE_KEY))),
728 End,
729 #endif
730 End,
731 End, /* end hgroup tooltypes pannel */
732 End),
733 Child, (IPTR) HGroup,
734 MUIA_Group_SameSize, TRUE,
735 Child, (IPTR) (savebutton =
736 ImageButton(_(MSG_SAVE),"THEME:Images/Gadgets/Prefs/Save")),
737 Child, (IPTR) (cancelbutton =
738 ImageButton(_(MSG_CANCEL),"THEME:Images/Gadgets/Prefs/Cancel")),
739 End,
740 End,
741 End),
742 End;
744 icon_cd = CurrentDir(cd);
746 if (application != NULL)
748 ULONG signals = 0;
750 #if !USE_TEXTEDITOR
751 set(liststr, MUIA_String_AttachedList, (IPTR)list);
752 #endif
754 // menu
755 DoMethod(aboutmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
756 (IPTR) application, 2,
757 MUIM_Application_ReturnID, RETURNID_ABOUT);
758 DoMethod(infomenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
759 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 0);
760 DoMethod(protectmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
761 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 1);
762 DoMethod(toolmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
763 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 2);
764 DoMethod(quit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
765 (IPTR) application, 2, MUIM_Application_ReturnID,
766 MUIV_Application_ReturnID_Quit);
768 DoMethod(cancelbutton, MUIM_Notify, MUIA_Pressed, FALSE,
769 (IPTR) application, 2,
770 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
771 DoMethod(savebutton, MUIM_Notify, MUIA_Pressed, FALSE,
772 (IPTR) application, 2,
773 MUIM_Application_ReturnID, RETURNID_SAVE);
774 DoMethod(application, MUIM_Notify, MUIA_Application_Sleep, FALSE,
775 (IPTR) application, 2,
776 MUIM_Application_ReturnID, RETURNID_WAKE);
777 DoMethod(application, MUIM_Notify, MUIA_Application_Sleep, TRUE,
778 (IPTR) application, 2,
779 MUIM_Application_ReturnID, RETURNID_SLEEP);
780 DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
781 (IPTR) application, 2, MUIM_Application_ReturnID,
782 MUIV_Application_ReturnID_Quit );
783 #if !USE_TEXTEDITOR
784 DoMethod(newkey, MUIM_Notify, MUIA_Pressed, FALSE,
785 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_NEWKEY);
786 DoMethod(delkey, MUIM_Notify, MUIA_Pressed, FALSE,
787 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_DELKEY);
788 DoMethod(list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
789 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_LVACK);
790 DoMethod(liststr, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
791 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_STRINGACK);
792 #endif
793 DoMethod(commentspace, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
794 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_COMMENTACK);
795 DoMethod(versionspace, MUIM_Notify, MUIA_Pressed, FALSE,
796 (IPTR) application, 2,
797 MUIM_Application_ReturnID, RETURNID_VERSION);
799 #if USE_TEXTEDITOR
800 set(editor, MUIA_TextEditor_Slider, slider);
802 if (icon->do_ToolTypes)
804 char *tt = NULL, *contents;
805 int i = 0;
806 ULONG len = 0;
808 while ((tt = icon->do_ToolTypes[i]) != NULL)
810 len += strlen(icon->do_ToolTypes[i]) + 1;
811 i++;
814 contents = AllocVec(len + 1, MEMF_ANY);
815 if (contents)
817 contents[0] = 0;
818 i = 0;
819 BOOL first = TRUE;
821 while ((icon->do_ToolTypes[i]) != NULL)
823 if ( ! first )
825 strcat(contents, "\n");
827 first = FALSE;
828 strcat(contents, icon->do_ToolTypes[i]);
830 i++;
833 set(editor, MUIA_TextEditor_Contents, contents);
834 FreeVec(contents);
837 #else
839 if (icon->do_ToolTypes)
841 char *tt = NULL;
842 int i = 0;
843 while ((tt = icon->do_ToolTypes[i]) != NULL)
845 DoMethod(list, MUIM_List_InsertSingle, tt, MUIV_List_Insert_Bottom);
846 i++;
849 #endif
851 switch(icon->do_Type)
853 case WBPROJECT:
854 toolspace = MUI_NewObject(MUIC_Popasl, ASLFR_DoSaveMode, TRUE,
855 MUIA_Popstring_String,
856 filename_string = MUI_MakeObject(MUIO_String, NULL, MAX_PATH_LEN),
857 MUIA_Popstring_Button, PopButton(MUII_PopFile), TAG_DONE);
858 toollabel = MUI_MakeObject(MUIO_Label, _(MSG_DEFTOOL), NULL);
859 if ((toolspace != NULL)&&(toollabel != NULL)&&(filename_string != NULL))
861 DoMethod(group, MUIM_Group_InitChange);
862 DoMethod(group, OM_ADDMEMBER, toollabel);
863 DoMethod(group, OM_ADDMEMBER, toolspace);
864 DoMethod(group, MUIM_Group_ExitChange);
866 set(filename_string, MUIA_String_Contents, deftool);
867 set(toolspace, MUIA_CycleChain, 1);
868 DoMethod(filename_string, MUIM_Notify,
869 MUIA_String_Acknowledge, MUIV_EveryTime,
870 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_TOOLACK);
872 break;
873 case WBTOOL:
874 stackspace = MUI_MakeObject(MUIO_String, NULL, 16);
875 stacklabel = MUI_MakeObject(MUIO_Label, _(MSG_STACK), NULL);
876 if ((stackspace != NULL)&&(stacklabel !=NULL))
878 DoMethod(group, MUIM_Group_InitChange);
879 DoMethod(group, OM_ADDMEMBER, stacklabel);
880 DoMethod(group, OM_ADDMEMBER, stackspace);
881 DoMethod(group, MUIM_Group_ExitChange);
882 SetAttrs(stackspace, MUIA_String_Contents, stack,
883 MUIA_CycleChain, 1,
884 MUIA_String_Accept, (IPTR)"0123456789",TAG_DONE);
885 DoMethod(stackspace, MUIM_Notify,
886 MUIA_String_Acknowledge, MUIV_EveryTime,
887 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_STACKACK);
889 break;
890 case WBDRAWER:
891 drawerspace = MUI_NewObject(MUIC_Rectangle, TAG_DONE);
892 if ((drawerspace != NULL))
894 DoMethod(group, MUIM_Group_InitChange);
895 DoMethod(group, OM_ADDMEMBER, drawerspace);
896 DoMethod(group, MUIM_Group_ExitChange);
898 break;
901 if (comment != NULL)
902 set(commentspace, MUIA_String_Contents, comment);
904 set(readobject, MUIA_Selected, flags[3]);
905 set(writeobject, MUIA_Selected, flags[4]);
906 set(executeobject, MUIA_Selected, flags[5]);
907 set(deleteobject, MUIA_Selected, flags[6]);
909 set(scriptobject, MUIA_Selected, flags[0]);
910 set(pureobject, MUIA_Selected, flags[1]);
911 set(archiveobject, MUIA_Selected, flags[2]);
913 SetAttrs(window, MUIA_Window_Open, TRUE, TAG_DONE);
915 while (returnid != MUIV_Application_ReturnID_Quit)
917 #ifdef DEBUG
918 if (returnid)
920 D(bug("[WBInfo] broker command received: %ld\n", returnid));
921 #endif
922 switch(returnid)
924 case RETURNID_SLEEP:
925 set(window, MUIA_Window_Open, FALSE);
926 set(window, MUIA_Window_Activate, TRUE);
927 break;
928 case RETURNID_WAKE:
929 set(window, MUIA_Window_Open, TRUE);
930 break;
931 case RETURNID_ABOUT:
932 if (MUI_RequestA(application,NULL,0,
933 _(MSG_ABOUT), _(MSG_OK), _(MSG_COPYRIGHT), NULL))
934 break;
935 #if !USE_TEXTEDITOR
936 case RETURNID_NEWKEY:
937 NewKey();
938 break;
939 case RETURNID_DELKEY:
940 DelKey();
941 icon_altered = TRUE;
942 break;
943 case RETURNID_LVACK:
944 ListToString();
945 break;
946 case RETURNID_STRINGACK:
947 StringToKey();
948 icon_altered = TRUE;
949 break;
950 #endif
951 case RETURNID_SAVE:
952 #if !USE_TEXTEDITOR
953 if (icon_altered)
954 #endif
955 SaveIcon(icon, name, lock);
956 if (file_altered)
957 SaveFile(ap, lock);
958 DoMethod(application, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
959 break;
960 case RETURNID_STACKACK:
961 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
962 icon_altered = TRUE;
963 break;
964 case RETURNID_TOOLACK:
965 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
966 icon_altered = TRUE;
967 break;
968 case RETURNID_COMMENTACK:
969 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
970 file_altered = TRUE;
971 break;
972 case RETURNID_VERSION:
973 set(versionspace, MUIA_Text_Contents, GetVersion(name, lock));
974 break;
976 #ifdef DEBUG
978 #endif
979 if (signals)
981 signals = Wait(signals | SIGBREAKF_CTRL_C);
982 if(signals & SIGBREAKF_CTRL_C) break;
985 returnid = ((LONG) DoMethod(application, MUIM_Application_NewInput, (IPTR) &signals));
987 SetAttrs(window, MUIA_Window_Open, FALSE, TAG_DONE);
988 MUI_DisposeObject(application);
989 } else {
990 PrintFault(ERROR_INVALID_RESIDENT_LIBRARY, argv[0]);
991 D(bug("[WBInfo: Couldn't create app\n"));
993 FreeDiskObject(icon);
994 FreeVec(ap);
995 return RETURN_OK;