add casts to zune macros to silence some warnings
[tangerine.git] / workbench / system / Wanderer / Tools / Info / main.c
blobbd9978a896785ba9fb67d386fa4178e8376f4a3a
1 /*
2 Copyright © 2003, 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 VERSION "$VER: Info 0.1 ("ADATE") © AROS Dev Team"
54 #define MAX_PATH_LEN 1024
55 #define MAX_TOOLTYPE_LINE 256
56 #define BUFFERSIZE 1024
58 #define USE_TEXTEDITOR 1
60 static Object *window, *commentspace, *filename_string, *stackspace, *savebutton;
61 #if USE_TEXTEDITOR
62 static Object *editor, *slider;
63 #else
64 static Object *list, *editor, *liststr;
65 #endif
67 BOOL file_altered = FALSE;
68 BOOL icon_altered = FALSE;
70 UBYTE **BuildToolTypes(UBYTE **src_ttypes)
72 #if USE_TEXTEDITOR
73 APTR pool = CreatePool(MEMF_CLEAR, 200, 200);
74 STRPTR contents, sp, *dst_ttypes;
75 ULONG lines = 1;
77 if (!pool) return NULL;
78 contents = (STRPTR)DoMethod(editor, MUIM_TextEditor_ExportText);
80 if (!contents || !contents[0])
82 DeletePool(pool);
83 return NULL;
86 sp = contents;
88 while((sp = strchr(sp, '\n')))
90 sp++;
91 lines++;
94 dst_ttypes = AllocPooled(pool, (lines + 3) * sizeof(STRPTR));
95 if (!dst_ttypes)
97 FreeVec(contents);
98 DeletePool(pool);
99 return NULL;
102 *dst_ttypes++ = (STRPTR)pool;
103 *dst_ttypes++ = (STRPTR)contents;
105 for(sp = contents, lines = 0; sp; lines++)
107 dst_ttypes[lines] = sp;
108 sp = strchr(sp, '\n');
109 if (sp)
111 *sp++ = '\0';
113 else
115 dst_ttypes[lines] = 0;
118 dst_ttypes[lines] = 0;
120 return dst_ttypes;
121 #else
122 APTR pool = CreatePool(MEMF_CLEAR, 200, 200);
123 Object *listobj = list;
124 WORD list_index = 0, num_ttypes = 0, alloc_ttypes = 10;
125 UBYTE **dst_ttypes;
127 if (!pool) return NULL;
129 dst_ttypes = AllocPooled(pool, (alloc_ttypes + 2) * sizeof(UBYTE *));
130 if (!dst_ttypes)
132 DeletePool(pool);
133 return NULL;
136 get(listobj, MUIA_List_Entries, &list_index);
137 while(num_ttypes<list_index)
139 STRPTR text = NULL;
140 DoMethod(listobj, MUIM_List_GetEntry, num_ttypes, (IPTR)&text);
141 if (num_ttypes >= alloc_ttypes)
143 UBYTE **new_dst_ttypes = AllocPooled(pool, (alloc_ttypes + 10 + 2) * sizeof(UBYTE *));
144 if (!new_dst_ttypes)
146 DeletePool(pool);
147 return NULL;
149 CopyMem(dst_ttypes + 1, new_dst_ttypes + 1, alloc_ttypes * sizeof(UBYTE *));
150 dst_ttypes = new_dst_ttypes;
151 alloc_ttypes += 10;
153 dst_ttypes[num_ttypes + 1] = AllocPooled(pool, strlen(text) + 1);
154 if (!dst_ttypes[num_ttypes + 1])
156 DeletePool(pool);
157 return NULL;
159 CopyMem(text, dst_ttypes[num_ttypes + 1], strlen(text) + 1);
160 D(bug("[WBInfo] tooltype #%ld %s\n", num_ttypes + 1, text));
161 num_ttypes++;
163 dst_ttypes[0] = (APTR)pool;
164 return dst_ttypes + 1;
165 #endif
168 void FreeToolTypes(UBYTE **ttypes)
170 #if USE_TEXTEDITOR
171 if (ttypes)
173 DeletePool((APTR)ttypes[-2]);
174 FreeVec((APTR)ttypes[-1]);
176 #else
177 if (ttypes)
179 DeletePool((APTR)ttypes[-1]);
181 #endif
184 void SaveIcon(struct DiskObject *icon, STRPTR name, BPTR cd)
186 STRPTR tool = NULL, stack = NULL;
187 BPTR restored_cd;
188 LONG ls;
189 UBYTE **ttypes = NULL, **old_ttypes = NULL;
191 restored_cd = CurrentDir(cd);
193 switch(icon->do_Type)
195 case WBPROJECT:
196 get(filename_string, MUIA_String_Contents, &tool);
197 icon->do_DefaultTool = tool;
198 break;
199 case WBTOOL:
200 get(stackspace, MUIA_String_Contents, &stack);
201 stcd_l(stack, &ls);
202 icon->do_StackSize = ls;
203 break;
206 old_ttypes = (UBYTE **)icon->do_ToolTypes;
207 if ((ttypes = BuildToolTypes(old_ttypes)))
209 icon->do_ToolTypes = ttypes;
211 PutIconTags(name, icon, TAG_DONE);
212 if (ttypes)
214 icon->do_ToolTypes = old_ttypes;
215 FreeToolTypes(ttypes);
217 CurrentDir(restored_cd);
218 icon_altered = FALSE;
221 void SaveFile(struct AnchorPath * ap, BPTR cd)
223 STRPTR text=NULL;
224 BPTR restored_cd;
225 restored_cd = CurrentDir(cd);
226 get(commentspace, MUIA_String_Contents, &text);
227 if (text)
228 SetComment(ap->ap_Buf, text);
229 CurrentDir(restored_cd);
230 file_altered = FALSE;
233 #if !USE_TEXTEDITOR
234 void ListToString(void)
236 STRPTR text = NULL;
237 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR) &text);
238 if (text)
240 set(liststr, MUIA_String_Contents, text);
241 nnset(liststr, MUIA_Disabled, FALSE);
242 set(window, MUIA_Window_ActiveObject, (IPTR)liststr);
246 void StringToKey(void)
248 STRPTR text = NULL;
249 STRPTR input = NULL;
251 icon_altered = TRUE;
253 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR) &text);
254 if (text)
256 get(liststr, MUIA_String_Contents, &input);
257 DoMethod(list, MUIM_List_InsertSingle, input, MUIV_List_Insert_Active);
258 set(list, MUIA_List_Active, MUIV_List_Active_Down);
259 DoMethod(list, MUIM_List_Remove, MUIV_List_Remove_Active);
260 nnset(liststr, MUIA_String_Contents, (IPTR) "");
261 nnset(liststr, MUIA_Disabled, TRUE);
262 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
266 void NewKey(void)
268 nnset(liststr, MUIA_String_Contents, "");
269 nnset(liststr, MUIA_Disabled, FALSE);
270 DoMethod(list, MUIM_List_InsertSingle, "", MUIV_List_Insert_Bottom);
271 nnset(list, MUIA_List_Active, MUIV_List_Active_Bottom);
272 set(window, MUIA_Window_ActiveObject, (IPTR) liststr);
275 void DelKey(void)
277 STRPTR text = NULL;
278 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&text);
280 if (text)
282 DoMethod(list, MUIM_List_Remove, MUIV_List_Remove_Active);
283 DoMethod(list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&text);
284 if (!text)
286 nnset(liststr, MUIA_String_Contents, (IPTR) "");
287 nnset(liststr, MUIA_Disabled, TRUE);
288 ListToString();
289 } else {
290 ListToString();
294 #endif
296 static char * GetVersion(STRPTR name, BPTR cd)
298 D(bug("[WBINFO/Getversion] Name %s\n", name));
299 STRPTR commandline = NULL;
300 ULONG commandlineSize;
301 static TEXT result[100]; // must be static because we return its address
302 char *retval = result;
303 TEXT tmpfilename[40];
304 int nr = 0;
305 int i;
306 BPTR output = NULL;
307 BPTR restored_cd = (BPTR)-1;
309 if (name == NULL)
311 D(bug("[WBINFO/Getversion] Name is Null\n"));
312 goto exit;
315 memset(result, 0, sizeof(result));
316 result[0] = '?';
318 commandlineSize = strlen(name) + 20;
319 commandline = AllocVec(commandlineSize, MEMF_CLEAR);
320 if (commandline == NULL)
322 D(bug("[WBInfo/GetVersion] Can't allocate RAM for commandline\n"));
323 goto exit;
326 restored_cd = CurrentDir(cd);
328 //search for non-existing temp file name
331 nr++;
332 if (nr > 30)
334 D(bug("[WBINFO/Getversion] Can't find non-existing tmpfile"));
335 goto exit;
337 sprintf(tmpfilename, "t:tmp_version_%d", nr);
338 output = Open(tmpfilename, MODE_OLDFILE);
339 if (output)
341 Close(output);
343 } while (output != NULL);
345 D(bug("[WBInfo/Getversion] tmpfilename %s\n", tmpfilename));
346 output = Open(tmpfilename, MODE_NEWFILE);
347 if (output == NULL)
349 D(bug("[WBInfo/Getversion] Can't create tmpfile\n"));
350 goto exit;
353 // call c:version
354 sprintf(commandline, "c:version \"%s\" full", name);
355 D(bug("[WBInfo/GetVersion] Commandline %s\n", commandline));
356 if (SystemTags(commandline,
357 SYS_Asynch, FALSE,
358 SYS_Output, (IPTR) output,
359 //SYS_Error, (IPTR) NULL,
360 NP_StackSize, 16000,
361 TAG_DONE) != 0)
363 D(bug("[WBInfo/Getversion] SystemTags failed\n"));
364 goto exit;
367 // Seek didn't work for me on RAM-Disk, so we reopen the file
368 Close(output);
369 output = Open(tmpfilename, MODE_OLDFILE);
370 if (output == NULL)
372 D(bug("[WBInfo/GetVersion] Can't open tmpfile\n"));
373 goto exit;
375 // read result
376 if (Read(output, result, sizeof(result) - 1) == -1)
378 D(bug("[WBInfo/GetVersion] Can't read from tmpfile\n"));
379 goto exit;
381 D(bug("[WBInfo/GetVersion] Result %s\n", result));
383 // remove illegal chars (e.g. newline) from result
384 for (i = 0 ; result[i] != 0 ; i++)
386 if (result[i] < 32)
387 result[i] = ' ';
390 // set string pointer after program name
391 while (*retval != ' ')
392 retval++;
394 exit:
395 FreeVec(commandline);
396 if (output)
398 Close(output);
399 DeleteFile(tmpfilename);
401 if (restored_cd != (BPTR)-1)
402 CurrentDir(restored_cd);
404 return retval;
407 int main(int argc, char **argv)
409 Object *application, *group, *toolspace=NULL, *toollabel=NULL;
410 Object *registergroup=NULL, *infomenu=NULL, *protectmenu=NULL, *toolmenu=NULL;
411 Object *stacklabel=NULL, *drawerspace=NULL;
412 Object *sizespace=NULL, *typespace=NULL, *quit=NULL, *aboutmenu=NULL;
413 Object *datespace=NULL, *versionspace=NULL;
414 Object *cancelbutton=NULL;
415 #if !USE_TEXTEDITOR
416 Object *newkey=NULL, *delkey=NULL;
417 #endif
418 Object *readobject=NULL, *writeobject=NULL, *executeobject=NULL, *deleteobject=NULL;
419 Object *scriptobject=NULL, *pureobject=NULL, *archiveobject=NULL;
420 struct WBStartup *startup;
421 struct DiskObject *icon=NULL;
422 struct AnchorPath *ap=NULL;
423 struct DateStamp *ds=NULL;
424 struct DateTime dt;
425 IPTR dte;
426 STRPTR name=NULL, type=NULL;
427 BPTR cd, lock, icon_cd;
428 LONG returnid = 0;
429 ULONG protection;
430 char stack[16];
431 char deftool[MAX_PATH_LEN] ;
432 char comment[MAXCOMMENTLENGTH];
433 char size[10];
434 char date[LEN_DATSTRING];
435 char time[LEN_DATSTRING];
436 char dow[LEN_DATSTRING];
437 char datetime[2*LEN_DATSTRING];
438 UBYTE flags[8], lname[MAXFILENAMELENGTH];
440 char *pages[] = {_(MSG_INFORMATION),_(MSG_PROTECTION),_(MSG_TOOLTYPES),NULL};
441 char * typeNames[] =
443 NULL, /* not used */
444 _(MSG_DISK), /* 1 */
445 _(MSG_DRAWER), /* 2 */
446 _(MSG_TOOL), /* 3 */
447 _(MSG_PROJECT), /* 4 */
448 _(MSG_GARBAGE), /* 5 */
449 _(MSG_DEVICE), /* 6 */
450 _(MSG_KICK), /* 7 */
451 _(MSG_APPICON) /* 8 */
454 if (argc != 0)
456 /* start from wanderer only */
457 PrintFault(ERROR_FILE_NOT_OBJECT, argv[0]);
458 return RETURN_FAIL;
461 startup = (struct WBStartup *) argv;
463 if (startup->sm_NumArgs < 2)
465 /* need atleast 1 arg */
466 PrintFault(ERROR_REQUIRED_ARG_MISSING, argv[0]);
467 D(bug("[WBInfo] required arg missing\n"));
468 return RETURN_FAIL;
471 lock = startup->sm_ArgList[1].wa_Lock;
472 NameFromLock(lock, lname, MAXFILENAMELENGTH);
473 D(bug("[WBInfo] name from lock: %s\n",lname));
474 name = startup->sm_ArgList[1].wa_Name;
475 cd = CurrentDir(lock);
476 if (name == NULL)
478 /* directory not found*/
479 PrintFault(ERROR_DIR_NOT_FOUND, argv[0]);
480 D(bug("[WBInfo] dir not found\n"));
481 return RETURN_FAIL;
484 ap = AllocVec(sizeof(struct AnchorPath) + MAX_PATH_LEN, MEMF_CLEAR);
485 if (ap == NULL)
487 PrintFault(ERROR_NO_FREE_STORE, argv[0]);
488 D(bug("[WBInfo] no free store\n"));
489 return RETURN_FAIL;
492 ap->ap_Strlen = MAX_PATH_LEN;
494 if (0 != MatchFirst(name, ap))
496 D(bug("[WBInfo] pass to diskinfo\n"));
497 OpenWorkbenchObject(
498 "WANDERER:Tools/DiskInfo",
499 WBOPENA_ArgLock, (IPTR) startup->sm_ArgList[1].wa_Lock,
500 WBOPENA_ArgName, (IPTR) startup->sm_ArgList[1].wa_Name,
501 TAG_DONE);
502 FreeVec(ap);
503 return RETURN_OK;
506 ap->ap_BreakBits = SIGBREAKF_CTRL_C;
508 if (!(ap->ap_Flags & APF_DIDDIR))
510 D(bug("[WBInfo] scan file\n"));
511 /* fill comment */
512 sprintf(comment,"%s",ap->ap_Info.fib_Comment);
514 /* fill date and time */
515 ds = &ap->ap_Info.fib_Date;
516 DateStamp((struct DateStamp *)&dt);
517 CopyMem(ds, &dt.dat_Stamp, sizeof(struct DateStamp));
518 dt.dat_Format = FORMAT_DOS;
519 dt.dat_Flags = 0;
520 dt.dat_StrDay = dow;
521 dt.dat_StrDate = date;
522 dt.dat_StrTime = time;
523 dte = DateToStr(&dt);
524 sprintf(datetime, "%s %s", time, date);
526 /* fill size */
527 sprintf(size, "%ld", ap->ap_Info.fib_Size);
529 /* fill protection */
530 protection = ap->ap_Info.fib_Protection;
532 /* Convert the protection bits to a boolean */
533 flags[0] = protection & FIBF_SCRIPT ? 1 : 0; /* s */
534 flags[1] = protection & FIBF_PURE ? 1 : 0; /* p */
535 flags[2] = protection & FIBF_ARCHIVE ? 1 : 0; /* a */
537 /* The following flags are high-active! */
538 flags[3] = protection & FIBF_READ ? 0 : 1; /* r */
539 flags[4] = protection & FIBF_WRITE ? 0 : 1; /* w */
540 flags[5] = protection & FIBF_EXECUTE ? 0 : 1; /* e */
541 flags[6] = protection & FIBF_DELETE ? 0 : 1; /* d */
542 flags[7] = 0x00; /* h */
545 /* read icon */
547 icon = GetIconTags(name,
548 ICONGETA_FailIfUnavailable, FALSE,
549 ICONGETA_IsDefaultIcon, FALSE,
550 TAG_DONE);
552 if (icon != NULL)
554 D(bug("[WBInfo] file has icon\n"));
555 type = (char *) typeNames[icon->do_Type];
556 D(bug("[WBInfo] icon type is: %s\n", type));
557 sprintf(stack, "%ld", icon->do_StackSize);
558 if (icon->do_DefaultTool) sprintf(deftool, "%s", icon->do_DefaultTool);
559 } else {
560 FreeVec(ap);
561 PrintFault(ERROR_OBJECT_WRONG_TYPE, argv[0]);
562 return RETURN_FAIL;
565 application = ApplicationObject,
566 MUIA_Application_Title, __(MSG_TITLE),
567 MUIA_Application_Version, (IPTR) "$VER: Info 0.2 ("ADATE") © AROS Dev Team",
568 MUIA_Application_Description, __(MSG_DESCRIPTION),
569 MUIA_Application_Base, (IPTR) "INFO",
570 MUIA_Application_Menustrip, (IPTR) MenuitemObject,
571 MUIA_Family_Child, (IPTR) MenuitemObject,
572 MUIA_Menuitem_Title, __(MSG_PROJECT),
573 MUIA_Family_Child, (IPTR)(infomenu = MenuitemObject, MUIA_Menuitem_Title,
574 __(MSG_INFORMATION), MUIA_Menuitem_Shortcut, (IPTR) "I", End),
575 MUIA_Family_Child, (IPTR)(protectmenu = MenuitemObject, MUIA_Menuitem_Title,
576 __(MSG_PROTECTION),MUIA_Menuitem_Shortcut, (IPTR) "P", End),
577 MUIA_Family_Child, (IPTR)(toolmenu = MenuitemObject, MUIA_Menuitem_Title,
578 __(MSG_TOOLTYPES),MUIA_Menuitem_Shortcut, (IPTR) "T", End),
579 MUIA_Family_Child, (IPTR) MenuitemObject, MUIA_Menuitem_Title, ~0, End,
580 MUIA_Family_Child, (IPTR) (aboutmenu = MenuitemObject, MUIA_Menuitem_Title,
581 __(MSG_ABOUT), (IPTR) MUIA_Menuitem_Shortcut, (IPTR) "?", End),
582 MUIA_Family_Child, (IPTR) MenuitemObject, MUIA_Menuitem_Title, ~0, End,
583 MUIA_Family_Child, (IPTR) (quit = MenuitemObject, MUIA_Menuitem_Title,
584 __(MSG_QUIT), MUIA_Menuitem_Shortcut, (IPTR) "Q", End),
585 End,
586 End,
587 SubWindow, (IPTR) (window = WindowObject,
588 MUIA_Window_Title, (IPTR) __(MSG_ICON),
589 MUIA_Window_ID, MAKE_ID('I','N','F','O'),
590 MUIA_Window_Activate, TRUE,
591 WindowContents, (IPTR) VGroup,
592 Child, (IPTR) HGroup,
593 Child, (IPTR) VGroup,
594 Child, (IPTR) IconImageObject,
595 MUIA_InputMode, MUIV_InputMode_Toggle,
596 MUIA_IconImage_File, (IPTR) name,
597 End,
598 End,
599 Child, (IPTR) VGroup,
600 Child, (IPTR) TextObject,
601 TextFrame,
602 MUIA_Background, MUII_TextBack,
603 MUIA_Text_PreParse, (IPTR) "\33l",
604 MUIA_Text_Contents, (IPTR) FilePart(name),
605 End,
606 End,
607 End,
608 Child, (IPTR) RegisterGroup(pages),
609 MUIA_CycleChain, 1,
610 Child, (IPTR) HGroup, /* hgroup information pannel */
611 Child, (IPTR) VGroup,
612 Child, (IPTR) HGroup,
613 Child, (IPTR) ColGroup(2),
614 Child, (IPTR) Label2(__(MSG_SIZE)),
615 Child, (IPTR) (sizespace = TextObject,
616 TextFrame,
617 MUIA_Background, MUII_TextBack,
618 MUIA_Text_PreParse, (IPTR) "\33r",
619 MUIA_Text_Contents, (IPTR) size,
620 End),
621 Child, (IPTR) Label2(__(MSG_DATE)),
622 Child, (IPTR) (datespace = TextObject,
623 TextFrame,
624 MUIA_Background, MUII_TextBack,
625 MUIA_Text_PreParse, (IPTR) "\33r",
626 MUIA_Text_Contents, (IPTR) datetime,
627 End),
628 Child, (IPTR) Label2(__(MSG_TYPE)),
629 Child, (IPTR) (typespace = TextObject,
630 TextFrame,
631 MUIA_Background, MUII_TextBack,
632 MUIA_Text_PreParse, (IPTR) "\33r",
633 MUIA_Text_Contents, (IPTR) type,
634 End),
635 Child, (IPTR) Label2(__(MSG_VERSION)),
636 Child, (IPTR) (versionspace = TextObject,
637 ButtonFrame,
638 MUIA_Background, MUII_TextBack,
639 MUIA_Text_PreParse, (IPTR) "\33r",
640 MUIA_Text_Contents, (IPTR) NULL,
641 MUIA_Text_Contents, (IPTR) "?",
642 MUIA_InputMode, MUIV_InputMode_RelVerify,
643 End),
644 End,
645 End,
646 Child, (IPTR) HVSpace,
647 Child, (IPTR) (group = HGroup,
648 End),
649 Child, (IPTR) HGroup,
650 Child, (IPTR) Label2(__(MSG_COMMENT)),
651 Child, (IPTR) (commentspace = StringObject,
652 StringFrame,
653 MUIA_CycleChain, 1,
654 End),
655 End,
656 End,
657 End, /* end hgroup information pannel */
658 Child, (IPTR) HGroup, /* hgroup protections pannel */
659 Child, (IPTR) VGroup,
660 Child, (IPTR) ColGroup(2),
661 Child, (IPTR) HVSpace,
662 Child, (IPTR) ColGroup(2),
663 Child, (IPTR) Label2(_(MSG_READ)),
664 Child, (IPTR) (readobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
665 Child, (IPTR) Label2(_(MSG_WRITE)),
666 Child, (IPTR) (writeobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
667 Child, (IPTR) Label2(_(MSG_EXECUTE)),
668 Child, (IPTR) (executeobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
669 Child, (IPTR) Label2(_(MSG_DELETE)),
670 Child, (IPTR) (deleteobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
671 Child, (IPTR) Label2(_(MSG_SCRIPT)),
672 Child, (IPTR) (scriptobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
673 Child, (IPTR) Label2(_(MSG_PURE)),
674 Child, (IPTR) (pureobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
675 Child, (IPTR) Label2(_(MSG_ARCHIVED)),
676 Child, (IPTR) (archiveobject = MUI_MakeObject(MUIO_Checkmark,NULL)),
677 End,
678 End,
679 End,
680 End, /* end hgroup protections pannel */
681 Child, (IPTR) HGroup, /* hgroup tooltypes pannel */
682 Child, (IPTR) VGroup,
683 Child, (IPTR) HGroup,
684 Child, (IPTR) VGroup,
685 GroupSpacing(0),
686 #if !USE_TEXTEDITOR
687 Child, (IPTR) ListviewObject,
688 MUIA_Listview_List, (IPTR) (list = ListObject,
689 InputListFrame,
690 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
691 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
692 MUIA_List_AutoVisible, TRUE,
693 End),
694 End,
695 Child, (IPTR) (liststr = StringObject,
696 MUIA_Disabled, TRUE,
697 StringFrame,
698 End),
699 #else
700 Child, (IPTR) HGroup,
701 GroupSpacing(0),
702 Child, (IPTR) (editor = MUI_NewObject(MUIC_TextEditor,
703 TAG_DONE)),
704 Child, (IPTR) (slider = ScrollbarObject,
705 End),
706 End,
707 #endif
708 End,
709 End,
710 #if !USE_TEXTEDITOR
711 Child, (IPTR) HGroup,
712 MUIA_Group_SameSize, TRUE,
713 Child, (IPTR) (newkey = SimpleButton(__(MSG_NEW_KEY))),
714 Child, (IPTR) (delkey = SimpleButton(__(MSG_DELETE_KEY))),
715 End,
716 #endif
717 End,
718 End, /* end hgroup tooltypes pannel */
719 End,
720 Child, (IPTR) HGroup,
721 MUIA_Group_SameSize, TRUE,
722 Child, (IPTR) (savebutton =
723 ImageButton(_(MSG_SAVE),"THEME:Images/Gadgets/Prefs/Save")),
724 Child, (IPTR) (cancelbutton =
725 ImageButton(_(MSG_CANCEL),"THEME:Images/Gadgets/Prefs/Cancel")),
726 End,
727 End,
728 End),
729 End;
731 icon_cd = CurrentDir(cd);
733 if (application != NULL)
735 ULONG signals = 0;
737 #if !USE_TEXTEDITOR
738 set(liststr, MUIA_String_AttachedList, (IPTR)list);
739 #endif
741 // menu
742 DoMethod(aboutmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
743 (IPTR) application, 2,
744 MUIM_Application_ReturnID, RETURNID_ABOUT);
745 DoMethod(infomenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
746 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 0);
747 DoMethod(protectmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
748 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 1);
749 DoMethod(toolmenu, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
750 (IPTR) registergroup, 3, MUIM_Set, MUIA_Group_ActivePage, 2);
751 DoMethod(quit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
752 (IPTR) application, 2, MUIM_Application_ReturnID,
753 MUIV_Application_ReturnID_Quit);
755 DoMethod(cancelbutton, MUIM_Notify, MUIA_Pressed, FALSE,
756 (IPTR) application, 2,
757 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
758 DoMethod(savebutton, MUIM_Notify, MUIA_Pressed, FALSE,
759 (IPTR) application, 2,
760 MUIM_Application_ReturnID, RETURNID_SAVE);
761 DoMethod(application, MUIM_Notify, MUIA_Application_Sleep, FALSE,
762 (IPTR) application, 2,
763 MUIM_Application_ReturnID, RETURNID_WAKE);
764 DoMethod(application, MUIM_Notify, MUIA_Application_Sleep, TRUE,
765 (IPTR) application, 2,
766 MUIM_Application_ReturnID, RETURNID_SLEEP);
767 DoMethod(window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
768 (IPTR) application, 2, MUIM_Application_ReturnID,
769 MUIV_Application_ReturnID_Quit );
770 #if !USE_TEXTEDITOR
771 DoMethod(newkey, MUIM_Notify, MUIA_Pressed, FALSE,
772 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_NEWKEY);
773 DoMethod(delkey, MUIM_Notify, MUIA_Pressed, FALSE,
774 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_DELKEY);
775 DoMethod(list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
776 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_LVACK);
777 DoMethod(liststr, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
778 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_STRINGACK);
779 #endif
780 DoMethod(commentspace, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
781 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_COMMENTACK);
782 DoMethod(versionspace, MUIM_Notify, MUIA_Pressed, FALSE,
783 (IPTR) application, 2,
784 MUIM_Application_ReturnID, RETURNID_VERSION);
786 #if USE_TEXTEDITOR
787 set(editor, MUIA_TextEditor_Slider, slider);
789 if (icon->do_ToolTypes)
791 char *tt = NULL, *contents;
792 int i = 0;
793 ULONG len = 0;
795 while ((tt = icon->do_ToolTypes[i]) != NULL)
797 len = len + strlen(icon->do_ToolTypes[i]) + 1;
798 i++;
801 contents = AllocVec(len + 1, MEMF_ANY);
802 if (contents)
804 contents[0] = 0;
805 i = 0;
807 while ((tt = icon->do_ToolTypes[i]) != NULL)
809 strcat(contents, icon->do_ToolTypes[i]);
810 strcat(contents, "\n");
811 i++;
814 set(editor, MUIA_TextEditor_Contents, contents);
815 FreeVec(contents);
818 #else
820 if (icon->do_ToolTypes)
822 char *tt = NULL;
823 int i = 0;
824 while ((tt = icon->do_ToolTypes[i]) != NULL)
826 DoMethod(list, MUIM_List_InsertSingle, tt, MUIV_List_Insert_Bottom);
827 i++;
830 #endif
832 switch(icon->do_Type)
834 case WBPROJECT:
835 toolspace = MUI_NewObject(MUIC_Popasl, ASLFR_DoSaveMode, TRUE,
836 MUIA_Popstring_String,
837 filename_string = MUI_MakeObject(MUIO_String, NULL, MAX_PATH_LEN),
838 MUIA_Popstring_Button, PopButton(MUII_PopFile), TAG_DONE);
839 toollabel = MUI_MakeObject(MUIO_Label, _(MSG_DEFTOOL), NULL);
840 if ((toolspace != NULL)&&(toollabel != NULL)&&(filename_string != NULL))
842 DoMethod(group, MUIM_Group_InitChange);
843 DoMethod(group, OM_ADDMEMBER, toollabel);
844 DoMethod(group, OM_ADDMEMBER, toolspace);
845 DoMethod(group, MUIM_Group_ExitChange);
847 set(filename_string, MUIA_String_Contents, deftool);
848 set(toolspace, MUIA_CycleChain, 1);
849 DoMethod(filename_string, MUIM_Notify,
850 MUIA_String_Acknowledge, MUIV_EveryTime,
851 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_TOOLACK);
853 break;
854 case WBTOOL:
855 stackspace = MUI_MakeObject(MUIO_String, NULL, 16);
856 stacklabel = MUI_MakeObject(MUIO_Label, _(MSG_STACK), NULL);
857 if ((stackspace != NULL)&&(stacklabel !=NULL))
859 DoMethod(group, MUIM_Group_InitChange);
860 DoMethod(group, OM_ADDMEMBER, stacklabel);
861 DoMethod(group, OM_ADDMEMBER, stackspace);
862 DoMethod(group, MUIM_Group_ExitChange);
863 SetAttrs(stackspace, MUIA_String_Contents, stack,
864 MUIA_CycleChain, 1,
865 MUIA_String_Accept, (IPTR)"0123456789",TAG_DONE);
866 DoMethod(stackspace, MUIM_Notify,
867 MUIA_String_Acknowledge, MUIV_EveryTime,
868 (IPTR) application, 2, MUIM_Application_ReturnID, RETURNID_STACKACK);
870 break;
871 case WBDRAWER:
872 drawerspace = MUI_NewObject(MUIC_Rectangle, TAG_DONE);
873 if ((drawerspace != NULL))
875 DoMethod(group, MUIM_Group_InitChange);
876 DoMethod(group, OM_ADDMEMBER, drawerspace);
877 DoMethod(group, MUIM_Group_ExitChange);
879 break;
882 if (comment != NULL)
883 set(commentspace, MUIA_String_Contents, comment);
885 set(readobject, MUIA_Selected, flags[3]);
886 set(writeobject, MUIA_Selected, flags[4]);
887 set(executeobject, MUIA_Selected, flags[5]);
888 set(deleteobject, MUIA_Selected, flags[6]);
890 set(scriptobject, MUIA_Selected, flags[0]);
891 set(pureobject, MUIA_Selected, flags[1]);
892 set(archiveobject, MUIA_Selected, flags[2]);
894 SetAttrs(window, MUIA_Window_Open, TRUE, TAG_DONE);
896 while (returnid != MUIV_Application_ReturnID_Quit)
898 #ifdef DEBUG
899 if (returnid)
901 D(bug("[WBInfo] broker command received: %ld\n", returnid));
902 #endif
903 switch(returnid)
905 case RETURNID_SLEEP:
906 set(window, MUIA_Window_Open, FALSE);
907 set(window, MUIA_Window_Activate, TRUE);
908 break;
909 case RETURNID_WAKE:
910 set(window, MUIA_Window_Open, TRUE);
911 break;
912 case RETURNID_ABOUT:
913 if (MUI_RequestA(application,NULL,0,
914 _(MSG_ABOUT), _(MSG_OK), _(MSG_COPYRIGHT), NULL))
915 break;
916 #if !USE_TEXTEDITOR
917 case RETURNID_NEWKEY:
918 NewKey();
919 break;
920 case RETURNID_DELKEY:
921 DelKey();
922 icon_altered = TRUE;
923 break;
924 case RETURNID_LVACK:
925 ListToString();
926 break;
927 case RETURNID_STRINGACK:
928 StringToKey();
929 icon_altered = TRUE;
930 break;
931 #endif
932 case RETURNID_SAVE:
933 #if !USE_TEXTEDITOR
934 if (icon_altered)
935 #endif
936 SaveIcon(icon, name, lock);
937 if (file_altered)
938 SaveFile(ap, lock);
939 DoMethod(application, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
940 break;
941 case RETURNID_STACKACK:
942 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
943 icon_altered = TRUE;
944 break;
945 case RETURNID_TOOLACK:
946 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
947 icon_altered = TRUE;
948 break;
949 case RETURNID_COMMENTACK:
950 set(window, MUIA_Window_ActiveObject, (IPTR)savebutton);
951 file_altered = TRUE;
952 break;
953 case RETURNID_VERSION:
954 set(versionspace, MUIA_Text_Contents, GetVersion(name, lock));
955 break;
957 #ifdef DEBUG
959 #endif
960 if (signals)
962 signals = Wait(signals | SIGBREAKF_CTRL_C);
963 if(signals & SIGBREAKF_CTRL_C) break;
966 returnid = ((LONG) DoMethod(application, MUIM_Application_NewInput, (IPTR) &signals));
968 SetAttrs(window, MUIA_Window_Open, FALSE, TAG_DONE);
969 MUI_DisposeObject(application);
970 } else {
971 PrintFault(ERROR_INVALID_RESIDENT_LIBRARY, argv[0]);
972 D(bug("[WBInfo: Couldn't create app\n"));
974 FreeDiskObject(icon);
975 FreeVec(ap);
976 return RETURN_OK;