home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 18 / amigaformatcd18.iso / mui / mui_developer / c / examples / wbman.c < prev   
C/C++ Source or Header  |  1997-03-10  |  36KB  |  1,563 lines

  1.  
  2.  
  3.   /**********************************************\
  4.   *                                              *
  5.   *  WbMan                                       *
  6.   *                                              *
  7.   *  Version: 0.42 (27.8.93)                     *
  8.   *                                              *
  9.   *  Copyright 1993 by kMel, Klaus Melchior      *
  10.   *  kmel@eifel.adsp.sub.org, 2:242/7.2@Fidonet  *
  11.   *                                              *
  12.   *  Manages the tools in the WBStartup-         *
  13.   *  Folder, the ToolTypes could be changed.     *
  14.   *                                              *
  15.   \**********************************************/
  16.  
  17. /* DMAKE */
  18.  
  19. /* TAB=4 */
  20.  
  21.  
  22.  
  23.  
  24. /*** escape sequences ***/
  25.  
  26. #define eR "\033r"
  27. #define eC "\033c"
  28. #define eL "\033l"
  29.  
  30. #define eN "\033n"
  31. #define eB "\033b"
  32. #define eI "\033i"
  33.  
  34. #define ePB "\0332"
  35. #define ePW "\0338"
  36.  
  37.  
  38.  
  39.  
  40. /*** includes ***/
  41.  
  42. #include "demo.h"
  43. #define MAXNAMELEN 256
  44.  
  45. #include <exec/memory.h>
  46. #include <workbench/workbench.h>
  47. #include <clib/icon_protos.h>
  48.  
  49.  
  50.  
  51.  
  52. /*** ids ***/
  53.  
  54. enum ids {
  55.     ID_DUMMY,
  56.     ID_ABOUT,
  57.     ID_RESCAN, ID_SELECT_ALL, ID_SELECT_NONE, ID_SELECT_PATTERN,
  58.     ID_EDIT, ID_LV_ACTIVE,
  59.     ID_ACTIVATE, ID_TOGGLE, ID_DEACTIVATE, ID_RESTORE,
  60.     ID_PERFORM, ID_QUIT,
  61.  
  62.     ID_STRING_OK, ID_STRING_CANCEL,
  63.  
  64.     ID_EDIT_LV_ACTIVE,
  65.     ID_EDIT_NEW, ID_EDIT_COPY, ID_EDIT_REMOVE,
  66.     ID_EDIT_ACTIVATE, ID_EDIT_DEACTIVATE,
  67.     ID_EDIT_ST_READY,
  68.     ID_EDIT_SAVE, ID_EDIT_CANCEL,
  69. };
  70.  
  71. enum mode_change {
  72.     MODE_ACTIVATE, MODE_DEACTIVATE,
  73.     MODE_TOGGLE, MODE_RESTORE,
  74. };
  75.  
  76.  
  77.  
  78.  
  79. /*** variables ***/
  80.  
  81. static APTR app;
  82. static APTR wi_main;
  83. static APTR lv_tools;
  84. static APTR bt_activate, bt_toggle, bt_deactivate;
  85. static APTR bt_edit;
  86. static APTR tx_info;
  87. static APTR bt_perform, bt_quit;
  88.  
  89. static APTR wi_string_request;
  90. static APTR st_string;
  91. static APTR bt_string_ok, bt_string_cancel;
  92.  
  93. static APTR wi_edit;
  94. static APTR tx_edit;
  95. static APTR lv_edit;
  96. static APTR bt_edit_new, bt_edit_copy, bt_edit_remove;
  97. static APTR bt_edit_activate, bt_edit_deactivate;
  98. static APTR st_edit_string, st_edit_default;
  99. static APTR bt_edit_save, bt_edit_cancel;
  100.  
  101.  
  102. static struct DiskObject *disk_object;
  103. static BOOL temp_dobj_flag;
  104.  
  105. static BOOL edit_window_open = FALSE;
  106. static BOOL string_request_open = FALSE;
  107.  
  108.  
  109.  
  110.  
  111. /*** funcs ***/
  112.  
  113. /*** clear tools_listview ***/
  114.  
  115. BOOL clear_tools_list(void)
  116. {
  117.     DoMethod(lv_tools, MUIM_List_Clear);
  118.  
  119.     return(TRUE);
  120. }
  121.  
  122.  
  123.  
  124.  
  125. /*** insert tools in tools_listview ***/
  126.  
  127. BOOL insert_tools_list(void)
  128. {
  129.     BOOL ok = FALSE;
  130.     struct FileInfoBlock *fib;
  131.  
  132.     /*** alloc mem for fileinfoblock ***/
  133.     if (fib = AllocDosObject(DOS_FIB, NULL))
  134.     {
  135.         BPTR lock;
  136.  
  137.         /*** lock on the wbstartup-directory ***/
  138.         if (lock = Lock("SYS:WBStartup/", ACCESS_READ))
  139.         {
  140.             /*** first examine ***/
  141.             Examine(lock, fib);
  142.  
  143.             /*** scan, until last entry ***/
  144.             while (ExNext(lock, fib) && (IoErr()!=ERROR_NO_MORE_ENTRIES))
  145.             {
  146.                 /*** mui refresh ***/
  147.                 DoMethod(app, MUIM_Application_InputBuffered);
  148.  
  149.                 /*** insert fib-entry ***/
  150.                 DoMethod(lv_tools, MUIM_List_Insert, &fib, 1, MUIV_List_Insert_Sorted);
  151.             }
  152.  
  153.             UnLock(lock);
  154.             ok = TRUE;
  155.         }
  156.  
  157.         FreeDosObject(DOS_FIB, fib);
  158.     }
  159.  
  160.     return(ok);
  161. }
  162.  
  163.  
  164.  
  165.  
  166. /*** rescan filenames of tools in the wbstartup-path ***/
  167.  
  168. void rescan_tools_list(void)
  169. {
  170.     if (!(
  171.         clear_tools_list() &&
  172.         insert_tools_list()
  173.         ))
  174.     {
  175.         fail(app,"Lock on 'SYS:WBStartup/' failed !");
  176.     }
  177. }
  178.  
  179.  
  180.  
  181.  
  182. /*** check tool, if it exists in wbstartup-path ***/
  183.  
  184. BOOL check_tool_name(char *n)
  185. {
  186.     char *fn;
  187.     BPTR fh = NULL;
  188.  
  189.     /*** alloc mem for complete filename ***/
  190.     if (fn = AllocMem(MAXNAMELEN, MEMF_ANY))
  191.     {
  192.         sprintf(fn, "SYS:WBStartup/%s", n);
  193.  
  194.         if (fh = Open(fn, MODE_OLDFILE))
  195.             Close(fh);
  196.  
  197.         FreeMem(fn, MAXNAMELEN);
  198.     }
  199.  
  200.     return((BOOL) fh);
  201. }
  202.  
  203.  
  204.  
  205.  
  206. /*** count active & inactive tools ***/
  207.  
  208. void count_tools_list(void)
  209. {
  210.     ULONG i;
  211.     UWORD nr_active = 0, nr_inactive = 0, nr_changed = 0;
  212.     char *line;
  213.  
  214.     /*** count ***/
  215.     for (i=0; ; i++)
  216.     {
  217.         DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  218.  
  219.         /*** last line ? ***/
  220.         if (!line)
  221.             break;
  222.  
  223.         /*** count tools ***/
  224.         if (*(line+2) == '8')
  225.             nr_active++;
  226.         else
  227.             nr_inactive++;
  228.  
  229.         if (*(line+4) == 'b')
  230.             nr_changed++;
  231.     }
  232.  
  233.     {
  234.         char *s_inactive = "s";
  235.  
  236.         /*** check if 'tool' or 'tools' ***/
  237.         if (nr_inactive == 1)
  238.             s_inactive = "";
  239.  
  240.         /*** generate info text ***/
  241.         DoMethod(tx_info, MUIM_SetAsString, MUIA_Text_Contents,
  242.             eC ePB "%ld tool%s inactive · " ePW "%ld active · " eB ePB "%ld changed",
  243.             nr_inactive, s_inactive, nr_active, nr_changed);
  244.     }
  245. }
  246.  
  247.  
  248.  
  249.  
  250.  
  251. /*** disable gadgets & menus, show changes ***/
  252.  
  253. void check_entries(void)
  254. {
  255.     ULONG i, sel, c_pos;
  256.     UWORD nr_active = 0, nr_inactive = 0, nr_selected = 0;
  257.     char *line;
  258.  
  259.     BOOL disable_activate = TRUE, disable_toggle = TRUE;
  260.     BOOL disable_deactivate = TRUE, disable_restore = TRUE;
  261.     BOOL disable_perform = TRUE, disable_edit = TRUE;
  262.  
  263.     BOOL refresh_display = FALSE;
  264.  
  265.  
  266.     /*** cursor position ***/
  267.     get(lv_tools, MUIA_List_Active, &c_pos);
  268.  
  269.     /*** count ***/
  270.     for (i=0;; i++)
  271.     {
  272.         DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  273.  
  274.         /*** last line ? ***/
  275.         if (!line)
  276.             break;
  277.  
  278.         /*** count selected or at cursor-position ***/
  279.         DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_Ask, &sel);
  280.         if (sel || i==c_pos)
  281.         {
  282.             /*** count status of selected tools ***/
  283.             if (*(line+2)=='8')
  284.                 nr_active++;
  285.             else
  286.                 nr_inactive++;
  287.  
  288.             nr_selected++;
  289.         }
  290.  
  291.         /*** check difference between stored and new status ***/
  292.         if (*(line+2) != *line)
  293.         {
  294.             /*** make entry bold ***/
  295.             if (*(line+4)!='b')
  296.                 refresh_display = TRUE;
  297.             *(line+4)='b';
  298.  
  299.             disable_perform = FALSE;
  300.         }
  301.         else
  302.         {
  303.             /*** now a normal entry ***/
  304.             if (*(line+4)!='n')
  305.                 refresh_display = TRUE;
  306.             *(line+4)='n';
  307.         }
  308.     }
  309.  
  310.     if (nr_selected > 0)
  311.     {
  312.         disable_toggle = FALSE;
  313.         disable_restore = FALSE;
  314.  
  315.         if (nr_inactive)
  316.             disable_activate = FALSE;
  317.  
  318.         if (nr_active)
  319.             disable_deactivate = FALSE;
  320.     }
  321.  
  322.     if (nr_selected == 1)
  323.         disable_edit = FALSE;
  324.  
  325.  
  326.     /*** set status of gadgets ***/
  327.     set(bt_perform, MUIA_Disabled, disable_perform);
  328.  
  329.     set(bt_activate, MUIA_Disabled, disable_activate);
  330.     set(bt_toggle, MUIA_Disabled, disable_toggle);
  331.     set(bt_deactivate, MUIA_Disabled, disable_deactivate);
  332.     set(bt_edit, MUIA_Disabled, disable_edit);
  333.  
  334.  
  335.     /*** set status of menus ***/
  336.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_PERFORM, !disable_perform);
  337.  
  338.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_ACTIVATE, !disable_activate);
  339.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_DEACTIVATE, !disable_deactivate);
  340.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_TOGGLE, !disable_toggle);
  341.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_RESTORE, !disable_restore);
  342.  
  343.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_EDIT, !disable_edit);
  344.  
  345.     /*** refresh display ***/
  346.     if (refresh_display)
  347.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  348. }
  349.  
  350.  
  351.  
  352.  
  353. /*** change status of tools ***/
  354.  
  355. void change_tools_list_entry(LONG pos, UWORD mode)
  356. {
  357.     char *line, *pen;
  358.  
  359.     /*** get entry ***/
  360.     DoMethod(lv_tools, MUIM_List_GetEntry, pos, &line);
  361.     pen = line+2;
  362.  
  363.     /*** change entry ***/
  364.     switch (mode)
  365.     {
  366.         case MODE_ACTIVATE:
  367.             *pen = '8';
  368.         break;
  369.  
  370.         case MODE_DEACTIVATE:
  371.             *pen = '2';
  372.         break;
  373.  
  374.         case MODE_TOGGLE:
  375.             if (*pen=='2')
  376.                 *pen = '8';
  377.             else
  378.                 *pen = '2';
  379.         break;
  380.  
  381.         case MODE_RESTORE:
  382.             *pen = *line;
  383.         break;
  384.     }
  385. }
  386.  
  387. void change_tools_list_entry_cursor(UWORD mode)
  388. {
  389.     LONG i;
  390.  
  391.     get(lv_tools, MUIA_List_Active, &i);
  392.  
  393.     if (i >= 0)
  394.     {
  395.         change_tools_list_entry(i, mode);
  396.         DoMethod(lv_tools, MUIM_List_Redraw, i);
  397.     }
  398. }
  399.  
  400. void change_tools_list(UWORD mode)
  401. {
  402.     ULONG end, i, nr=0;
  403.     ULONG sel;
  404.  
  405.     /*** get number of all entries ***/
  406.     get(lv_tools, MUIA_List_Entries, &end);
  407.  
  408.     set(lv_tools, MUIA_List_Quiet, TRUE);
  409.     for (i=0; i<end ; i++)
  410.     {
  411.         /*** entry selected ? ***/
  412.         DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_Ask, &sel);
  413.         if (sel)
  414.         {
  415.             change_tools_list_entry(i, mode);
  416.             nr++;
  417.         }
  418.     }
  419.     set(lv_tools, MUIA_List_Quiet, FALSE);
  420.  
  421.     /*** refresh display, if almost one entry is selected ***/
  422.     if (nr>0)
  423.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  424.  
  425.     /*** change entry on cursor-position ***/
  426.     else
  427.         change_tools_list_entry_cursor(mode);
  428. }
  429.  
  430.  
  431.  
  432.  
  433. /*** select every entry of tools_list ***/
  434.  
  435. void select_tools_list(ULONG mode)
  436. {
  437.     ULONG end, i;
  438.     ULONG sel;
  439.  
  440.     /*** get number of all entries ***/
  441.     get(lv_tools, MUIA_List_Entries, &end);
  442.  
  443.     for (i=0; i<end ; i++)
  444.         DoMethod(lv_tools, MUIM_List_Select, i, mode, &sel);
  445.  
  446.     /*** refresh display ***/
  447.     DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  448. }
  449.  
  450.  
  451.  
  452.  
  453. /*** select tools of tools_list matching pattern ***/
  454.  
  455. void select_pattern_tools_list(char *pattern)
  456. {
  457.     ULONG end, i;
  458.     ULONG sel;
  459.     char *tool_name, *pattern_token;
  460.  
  461.     /*** alloc mem for pattern_name ***/
  462.     if (pattern_token = AllocMem(MAXNAMELEN, MEMF_ANY))
  463.     {
  464.         /*** tokenize pattern ***/
  465.         ParsePatternNoCase(pattern, pattern_token, MAXNAMELEN);
  466.  
  467.         /*** get number of all entries ***/
  468.         get(lv_tools, MUIA_List_Entries, &end);
  469.  
  470.         for (i=0; i<end ; i++)
  471.         {
  472.             DoMethod(lv_tools, MUIM_List_GetEntry, i, &tool_name);
  473.  
  474.             /*** check tool_name, if it fits on pattern ***/
  475.             if (MatchPatternNoCase(pattern_token, tool_name+5))
  476.                 DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_On, &sel);
  477.         }
  478.  
  479.         /*** refresh display ***/
  480.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  481.  
  482.         FreeMem(pattern_token, MAXNAMELEN);
  483.     }
  484. }
  485.  
  486.  
  487.  
  488.  
  489. /*** rename the tools in the wbstartup-directory ***/
  490.  
  491. void rename_tools_list(void)
  492. {
  493.     char *file_name, *new_file_name;
  494.  
  495.     /*** alloc mem for filenames ***/
  496.     if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  497.     {
  498.         if (new_file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  499.         {
  500.             char *line;
  501.             ULONG i;
  502.  
  503.             for (i=0; ; i++)
  504.             {
  505.                 DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  506.  
  507.                 if (!line)
  508.                     break;
  509.  
  510.                 /*** check if old and new status different ***/
  511.                 if (*(line+4) == 'b')
  512.                 {
  513.  
  514.                     /*** turn status to active ***/
  515.                     if (*(line+2) == '8')
  516.                     {
  517.                         sprintf(file_name, "SYS:WBStartup/%s.noinfo", line+5);
  518.                         sprintf(new_file_name, "SYS:WBStartup/%s.info", line+5);
  519.                     }
  520.  
  521.                     /*** turn status to inactive ***/
  522.                     else
  523.                     {
  524.                         sprintf(file_name, "SYS:WBStartup/%s.info", line+5);
  525.                         sprintf(new_file_name, "SYS:WBStartup/%s.noinfo", line+5);
  526.                     }
  527.  
  528.                     if (rename(file_name, new_file_name))
  529.                         printf("Can't rename: '%s' -> '%s'\n", file_name, new_file_name);
  530.                 }
  531.             }
  532.             FreeMem(new_file_name, MAXNAMELEN);
  533.  
  534.         }
  535.         FreeMem(file_name, MAXNAMELEN);
  536.  
  537.     }
  538. }
  539.  
  540.  
  541.  
  542.  
  543. /*** string requester ***/
  544.  
  545. /*** open requester ***/
  546.  
  547. BOOL open_string_request(char *title_text, ULONG string_len)
  548. {
  549.     wi_string_request = WindowObject,
  550.         MUIA_Window_ID, MAKE_ID('S','R','E','Q'),
  551.         MUIA_Window_Title, "WbMan",
  552.         MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
  553.         WindowContents, VGroup,
  554.             Child, HGroup,
  555.                 GroupFrameT(title_text),
  556.                 Child, st_string = StringObject,
  557.                     StringFrame,
  558.                     MUIA_String_MaxLen, string_len,
  559.                     End,
  560.                 End,
  561.             Child, VSpace(2),
  562.             Child, HGroup,
  563.                 MUIA_Group_SameSize, TRUE,
  564.                 Child, bt_string_ok = SimpleButton("_OK"),
  565.                 Child, HSpace(0),
  566.                 Child, bt_string_cancel = SimpleButton("_Cancel"),
  567.                 End,
  568.             End,
  569.         End;
  570.  
  571.  
  572.     /*** string requester failed ? ***/
  573.     if (!wi_string_request)
  574.         fail(app, "Creating string-requester failed !");
  575.  
  576.  
  577.  
  578.     /*** connections & cycle ***/
  579.  
  580.     DoMethod(wi_string_request,    MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_CANCEL    );
  581.  
  582.     DoMethod(bt_string_ok,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_OK        );
  583.     DoMethod(bt_string_cancel,    MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_CANCEL    );
  584.  
  585.     /*** activate ok-button if string is ready ***/
  586.     DoMethod(st_string,
  587.         MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  588.         wi_string_request, 3,
  589.         MUIM_Set, MUIA_Window_ActiveObject, bt_string_ok);
  590.  
  591.     DoMethod(wi_string_request, MUIM_Window_SetCycleChain,
  592.         st_string,
  593.         bt_string_ok, bt_string_cancel,
  594.         NULL);
  595.  
  596.  
  597.     /*** add & open window ***/
  598.  
  599.     DoMethod(app, OM_ADDMEMBER, wi_string_request);
  600.     set(wi_string_request, MUIA_Window_Open            , TRUE);
  601.     set(wi_string_request, MUIA_Window_ActiveObject    , st_string);
  602.  
  603.     return(TRUE);
  604. }
  605.  
  606.  
  607. /*** close requester ***/
  608.  
  609. void close_string_request(void)
  610. {
  611.     /*** close & remove window ***/
  612.     set(wi_string_request, MUIA_Window_Open, FALSE);
  613.     DoMethod(app, OM_REMMEMBER, wi_string_request);
  614.     MUI_DisposeObject(wi_string_request);
  615.  
  616.     /*** wake up main-window ***/
  617.     set(wi_main, MUIA_Window_Sleep, FALSE);
  618. }
  619.  
  620.  
  621.  
  622.  
  623. /*** edit tooltypes ***/
  624.  
  625. /*** open edit-window ***/
  626.  
  627. BOOL open_edit_window(struct DiskObject *dobj, char *name)
  628. {
  629.     wi_edit = WindowObject,
  630.         MUIA_Window_ID, MAKE_ID('E','D','I','T'),
  631.         MUIA_Window_Title, "WbMan",
  632.         MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
  633.         WindowContents, VGroup,
  634.             Child, HGroup,
  635.                 TextFrame,
  636.                 InnerSpacing(4,3),
  637.                 Child, ImageObject,
  638.                     MUIA_Image_OldImage, dobj->do_Gadget.GadgetRender,
  639.                     End,
  640.                 Child, VGroup,
  641.                     Child, VSpace(0),
  642.                     Child, tx_edit = TextObject,
  643.                         MUIA_Text_PreParse, eC,
  644.                         MUIA_Text_Contents, name,
  645.                         MUIA_Text_SetMin, TRUE,
  646.                         End,
  647.                     Child, VSpace(0),
  648.                     End,
  649.                 Child, ImageObject,
  650.                     MUIA_Image_OldImage, dobj->do_Gadget.GadgetRender,
  651.                     End,
  652.                 End,
  653.             Child, VGroup,
  654.                 GroupFrameT("ToolTypes"),
  655.                 Child, VGroup,
  656.                     GroupSpacing(0),
  657.                     Child, lv_edit = ListviewObject,
  658.                         MUIA_Listview_Input, TRUE,
  659.                         MUIA_Listview_List, ListObject,
  660.                             InputListFrame,
  661.                             MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
  662.                             MUIA_List_DestructHook, MUIV_List_DestructHook_String,
  663.                             End,
  664.                         End,
  665.                     Child, HGroup,
  666.                         GroupSpacing(0),
  667.                         Child, bt_edit_new = SimpleButton("_New"),
  668.                         Child, bt_edit_copy = SimpleButton("Cop_y"),
  669.                         Child, bt_edit_remove = SimpleButton("_Remove"),
  670.                         End,
  671.                     Child, HGroup,
  672.                         GroupSpacing(0),
  673.                         Child, bt_edit_activate = SimpleButton("_Activate"),
  674.                         Child, bt_edit_deactivate = SimpleButton("_Deactivate"),
  675.                         End,
  676.                     Child, st_edit_string = StringObject,
  677.                         StringFrame,
  678.                         End,
  679.                     End,
  680.                 End,
  681.             Child, HGroup,
  682.                 Child, Label2("Default Tool:"),
  683.                 Child, st_edit_default = String(NULL, MAXNAMELEN),
  684.                 End,
  685.             Child, VSpace(2),
  686.             Child, HGroup,
  687.                 MUIA_Group_SameSize, TRUE,
  688.                 Child, bt_edit_save = SimpleButton("_Save"),
  689.                 Child, HSpace(0),
  690.                 Child, bt_edit_cancel = SimpleButton("_Cancel"),
  691.                 End,
  692.             End,
  693.         End;
  694.  
  695.  
  696.     /*** window failed ? ***/
  697.     if (!wi_edit)
  698.         fail(app, "Creating edit-window failed !");
  699.  
  700.  
  701.     /*** connections & cycle ***/
  702.  
  703.     DoMethod(wi_edit,                MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_CANCEL        );
  704.  
  705.     DoMethod(bt_edit_new,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_NEW            );
  706.     DoMethod(bt_edit_copy,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_COPY        );
  707.     DoMethod(bt_edit_remove,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_REMOVE        );
  708.  
  709.     DoMethod(bt_edit_activate,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_ACTIVATE    );
  710.     DoMethod(bt_edit_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_DEACTIVATE    );
  711.  
  712.     DoMethod(bt_edit_save,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_SAVE        );
  713.     DoMethod(bt_edit_cancel,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_CANCEL        );
  714.  
  715.     DoMethod(lv_edit,                MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_LV_ACTIVE    );
  716.  
  717.     set(lv_edit, MUIA_List_Active, MUIV_List_Active_Top);
  718.     DoMethod(lv_edit,
  719.         MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  720.         app, 2,
  721.         MUIM_Application_ReturnID, ID_EDIT_LV_ACTIVE);
  722.  
  723.     set(st_edit_string, MUIA_String_AttachedList, lv_edit);
  724.     DoMethod(st_edit_string,
  725.         MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  726.         app, 2,
  727.         MUIM_Application_ReturnID,  ID_EDIT_ST_READY);
  728.  
  729.     DoMethod(wi_edit, MUIM_Window_SetCycleChain,
  730.         st_edit_string,
  731.         bt_edit_new, bt_edit_copy, bt_edit_remove,
  732.         st_edit_default,
  733.         bt_edit_save, bt_edit_cancel,
  734.         NULL);
  735.  
  736.  
  737.     /*** add & open window ***/
  738.     DoMethod(app, OM_ADDMEMBER, wi_edit);
  739.     set(wi_edit, MUIA_Window_Open, TRUE);
  740.     set(wi_edit, MUIA_Window_ActiveObject, st_edit_string);
  741.  
  742.     return(TRUE);
  743. }
  744.  
  745.  
  746. /*** close edit-window ***/
  747.  
  748. void close_edit_window(void)
  749. {
  750.     /*** close & remove window ***/
  751.     set(wi_edit, MUIA_Window_Open, FALSE);
  752.     DoMethod(app, OM_REMMEMBER, wi_edit);
  753.     MUI_DisposeObject(wi_edit);
  754.  
  755.     if (disk_object)
  756.         FreeDiskObject(disk_object);
  757.  
  758.     /*** wake up main-window ***/
  759.     set(wi_main, MUIA_Window_Sleep, FALSE);
  760. }
  761.  
  762.  
  763. /*** disable gadgets ***/
  764.  
  765. void check_edit_entries(void)
  766. {
  767.     LONG pos;
  768.     char *line;
  769.  
  770.     BOOL disable_cursor = TRUE;
  771.     BOOL disable_activate = TRUE, disable_deactivate = TRUE;
  772.  
  773.  
  774.     /*** cursor position ***/
  775.     get(lv_edit, MUIA_List_Active, &pos);
  776.  
  777.     if (pos >= 0)
  778.     {
  779.         disable_cursor = FALSE;
  780.  
  781.         /*** get active line ***/
  782.         DoMethod(lv_edit, MUIM_List_GetEntry, pos, &line);
  783.  
  784.         /*** check if there are brakets -> inactive ***/
  785.         if (*line == '(' && *(line + strlen(line) - 1) == ')')
  786.             disable_activate = FALSE;
  787.         else
  788.             disable_deactivate = FALSE;
  789.     }
  790.  
  791.     set(bt_edit_copy, MUIA_Disabled, disable_cursor);
  792.     set(bt_edit_remove, MUIA_Disabled, disable_cursor);
  793.     set(st_edit_string, MUIA_Disabled, disable_cursor);
  794.  
  795.     set(bt_edit_activate, MUIA_Disabled, disable_activate);
  796.     set(bt_edit_deactivate, MUIA_Disabled, disable_deactivate);
  797.  
  798.     /*** clear string if disabled ***/
  799.     if (disable_cursor)
  800.         set(st_edit_string, MUIA_String_Contents, "");
  801.  
  802. }
  803.  
  804.  
  805. /*** edit the active tool ***/
  806.  
  807. void edit_tooltypes_diskobject(struct DiskObject *dobj, char *fn)
  808. {
  809.     char **tt;
  810.  
  811.     /*** open window ***/
  812.     if (open_edit_window(dobj, fn))
  813.     {
  814.         tt = dobj->do_ToolTypes;
  815.  
  816.         /*** copy tooltype-array into listview ***/
  817.         while (tt && *tt)
  818.             DoMethod(lv_edit, MUIM_List_Insert, tt++, 1, MUIV_List_Insert_Bottom);
  819.  
  820.         /*** fill in strings ***/
  821.         set(st_edit_default, MUIA_String_Contents, dobj->do_DefaultTool);
  822.         set(lv_edit, MUIA_List_Active, MUIV_List_Active_Top);
  823.     }
  824. }
  825.  
  826. void edit_tooltypes_entry(void)
  827. {
  828.     char *file_name;
  829.  
  830.     if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  831.     {
  832.         char *line;
  833.  
  834.         /*** get entry ***/
  835.         DoMethod(lv_tools, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  836.  
  837.         sprintf(file_name, "SYS:WBStartup/%s", line+5);
  838.  
  839.         if (disk_object = GetDiskObject(file_name))
  840.         {
  841.             temp_dobj_flag = FALSE;
  842.             edit_tooltypes_diskobject(disk_object, line+5);
  843.         }
  844.         else
  845.         {
  846.             /*** is tool inactive ? create temporary .info-file ***/
  847.             temp_dobj_flag = TRUE;
  848.             sprintf(file_name, "copy SYS:WBStartup/%s.noinfo T:WbMan_Temp.info", line+5);
  849.             if (Execute(file_name, NULL, NULL) &&
  850.                 (disk_object = GetDiskObjectNew("T:WbMan_Temp"))
  851.                 )
  852.                 edit_tooltypes_diskobject(disk_object, line+5);
  853.             else
  854.             {
  855.             }
  856.         }
  857.  
  858.         check_edit_entries();
  859.  
  860.         FreeMem(file_name, MAXNAMELEN);
  861.     }
  862. }
  863.  
  864. void save_tooltypes(void)
  865. {
  866.     if (disk_object)
  867.     {
  868.         char *file_name;
  869.  
  870.         if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  871.         {
  872.             char *old_def_tool;
  873.             char **old_tooltypes;
  874.             char *line;
  875.             ULONG nr;
  876.             char **new_tooltypes;
  877.  
  878.             /*** store actual data ***/
  879.             old_def_tool = disk_object->do_DefaultTool;
  880.             old_tooltypes = disk_object->do_ToolTypes;
  881.  
  882.             /*** new data ***/
  883.             get(st_edit_default, MUIA_String_Contents, &line);
  884.             disk_object->do_DefaultTool = line;
  885.  
  886.             /*** generate array of tooltypes ***/
  887.             get(lv_edit, MUIA_List_Entries, &nr);
  888.             if (new_tooltypes = AllocMem((nr+1) << 2, MEMF_ANY))
  889.             {
  890.                 char **l;
  891.                 ULONG i;
  892.  
  893.                 l = new_tooltypes;
  894.                 for (i=0; ; i++)
  895.                 {
  896.                     DoMethod(lv_edit, MUIM_List_GetEntry, i, &line);
  897.  
  898.                     /*** last line ? ***/
  899.                     if (!line)
  900.                         break;
  901.  
  902.                     *l++ = line;
  903.                 }
  904.                 /*** terminate array ***/
  905.                 *l = NULL;
  906.  
  907.                 /*** new_data ***/
  908.                 disk_object->do_ToolTypes = new_tooltypes;
  909.  
  910.                 /*** get entry ***/
  911.                 DoMethod(lv_tools, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  912.  
  913.                 if (temp_dobj_flag)
  914.                 {
  915.                     PutDiskObject("T:WbMan_Temp", disk_object);
  916.  
  917.                     sprintf(file_name, "copy T:WbMan_Temp.info SYS:WBStartup/%s.noinfo", line+5);
  918.                     Execute(file_name, NULL, NULL);
  919.                 }
  920.                 else
  921.                 {
  922.                     /*** get disk object ***/
  923.                     sprintf(file_name, "SYS:WBStartup/%s", line+5);
  924.  
  925.                     PutDiskObject(file_name, disk_object);
  926.                 }
  927.  
  928.                 FreeMem(new_tooltypes, (nr+1) << 2);
  929.             }
  930.  
  931.             /*** restore data ***/
  932.             disk_object->do_DefaultTool = old_def_tool;
  933.             disk_object->do_ToolTypes = old_tooltypes;
  934.  
  935.             FreeMem(file_name, MAXNAMELEN);
  936.         }
  937.     }
  938. }
  939.  
  940.  
  941.  
  942.  
  943. /*** image-stuff ***/
  944.  
  945. static UWORD wbman_sleep_img1_data[] = {
  946.     0x0003,0xc000,0x0000,0x0000,0x0004,0x4000,0x0000,0x0000,
  947.     0x0008,0x4000,0x0000,0x0000,0x0018,0x4de0,0x0000,0x0000,
  948.     0x0020,0x3210,0x0000,0x0000,0x0020,0x0008,0x0000,0x0000,
  949.     0x0020,0x0008,0x0000,0x0000,0x0020,0xf008,0x0000,0x0000,
  950.     0x0020,0x2788,0x0000,0x0000,0x0010,0x4108,0x0000,0x0000,
  951.     0x0010,0xf208,0x0000,0x0000,0x0008,0x0790,0x0000,0x0000,
  952.     0x0008,0x0020,0x0000,0x0000,0x003c,0x00c0,0x0000,0x0400,
  953.     0x0046,0x3f00,0x0000,0x0c00,0x0083,0xe000,0x0000,0x0c00,
  954.     0x0100,0x8004,0x0000,0x2c00,0x0101,0x001c,0x0000,0x2c00,
  955.     0x0386,0x007e,0x0000,0x2c00,0x04c8,0x01fe,0x0001,0x2c00,
  956.     0x08b0,0x07f8,0x0001,0x2c00,0x0500,0x1fe0,0x0001,0x2c00,
  957.     0x0200,0x7f80,0x0009,0x2c00,0x0001,0xfe00,0x0009,0x2c00,
  958.     0x0007,0xf8f8,0x2009,0x2c00,0x001f,0xe1cc,0x7009,0x2c00,
  959.     0x007f,0x8038,0x7009,0xcc00,0x01fe,0x0070,0x2009,0x0c00,
  960.     0x01f8,0x0000,0x0009,0x0c00,0x00e0,0x0070,0x700e,0x0c00,
  961.     0x0080,0x0000,0x0008,0x0c00,0x0000,0x0000,0x0008,0x0c00,
  962.     0x0000,0x3fff,0xfff0,0x0c00,0x0000,0x0000,0x0000,0x0c00,
  963.     0x7fff,0xffff,0xffff,0xfc00,0x0003,0xc000,0x0000,0x0000,
  964.     0x0007,0xc000,0x0000,0x0000,0x000f,0xc000,0x0000,0x0000,
  965.     0x001f,0xcde0,0x0000,0x0000,0x003f,0xfff0,0x0000,0x0000,
  966.     0x003f,0xfff8,0x0000,0x0000,0x003f,0xfff8,0x0000,0x0000,
  967.     0x003f,0x0ff8,0x0000,0x0000,0x003f,0xd878,0x0000,0x0000,
  968.     0x001f,0xbef8,0x0000,0x0000,0x001f,0x0df8,0x0000,0x0000,
  969.     0x000f,0xf870,0x0000,0x0000,0x000f,0xffe0,0x0000,0x0000,
  970.     0xffff,0xffff,0xffff,0xf800,0xd57f,0xff54,0x1555,0x5000,
  971.     0xd5ff,0xf5f8,0xcfff,0xd000,0xd5ff,0xd7e7,0xefff,0x9000,
  972.     0xd5ff,0x5713,0xcaa9,0x1000,0xd7ff,0x5e41,0x1ffe,0x1000,
  973.     0xd7fd,0x5902,0x7ffc,0x1000,0xdff5,0x4409,0x5548,0x1000,
  974.     0xd755,0x1027,0xfff0,0x1000,0xd754,0x409f,0xffe0,0x1000,
  975.     0xd551,0x022a,0xaa40,0x1000,0xd544,0x0802,0x8a80,0x1000,
  976.     0xd510,0x2222,0x8a80,0x9000,0xd440,0x8a82,0x8a80,0x3000,
  977.     0xd102,0x6a8a,0x8a80,0x5000,0xc209,0xeaaa,0xaa84,0x5000,
  978.     0xcf25,0xea8a,0x8a81,0x5000,0xdf95,0xf2aa,0xaa45,0x5000,
  979.     0xcc55,0xe000,0x0025,0x5000,0xc155,0xc000,0x000d,0x5000,
  980.     0xd555,0x5555,0x5555,0x5000,0x8000,0x0000,0x0000,0x0000,
  981.  
  982. };
  983.  
  984. static struct Image wbman_sleep_img1 = {
  985.     0x0000,0x0000,0x0036,0x0023,0x0002,
  986.     &wbman_sleep_img1_data[0],
  987.     0x03,0x00,0x00000000,
  988. };
  989.  
  990. static struct DiskObject wbman_sleep_dobj = {
  991.     0xe310,0x0001,
  992.     0x00000000,
  993.     0x00a9,0x00fa,0x0036,0x0024,0x0005,0x0001,0x95a5,
  994.     (APTR)&wbman_sleep_img1,NULL,
  995.     0x00000000,0x00000000,0x00000000,
  996.     0x0064,
  997.     0x00000000,
  998.     0x0003,
  999.     0x00000000,0x00000000,0x000000a5,0x000000e5,
  1000.     0x00000000,0x00000000,0x00001000,
  1001. };
  1002.  
  1003.  
  1004.  
  1005.  
  1006. /*** mui-stuff ***/
  1007.  
  1008. /*** list hooks ***/
  1009.  
  1010. SAVEDS ASM char *tools_list_confunc(
  1011.     REG(a0) struct Hook *hook,
  1012.     REG(a2) APTR mem_pool,
  1013.     REG(a1) struct FileInfoBlock *fib)
  1014. {
  1015.     char active_pattern[14];
  1016.     char inactive_pattern[20];
  1017.  
  1018.     /*** tokenize pattern ***/
  1019.     ParsePatternNoCase("#?.info", active_pattern, 14);
  1020.     ParsePatternNoCase("#?.noinfo", inactive_pattern, 20);
  1021.  
  1022.     /*** check, only files ***/
  1023.     if (fib->fib_DirEntryType < 0)
  1024.     {
  1025.         char *file_name, *entry;
  1026.  
  1027.         if (entry = AllocMem(MAXNAMELEN, MEMF_ANY))
  1028.         {
  1029.             file_name = &fib->fib_FileName[0];
  1030.  
  1031.             /*** check if active ***/
  1032.             if (MatchPatternNoCase(active_pattern, file_name))
  1033.             {
  1034.                 /*** cut the ".info" at end ***/
  1035.                 *(file_name + strlen(file_name) - 5) = 0;
  1036.  
  1037.                 /*** valid filename ? ***/
  1038.                 if (check_tool_name(file_name))
  1039.                 {
  1040.                     sprintf(entry, "8" ePW eN "%s", file_name);
  1041.                     return(entry);
  1042.                 }
  1043.             }
  1044.  
  1045.             /*** or inactive ***/
  1046.             else if (MatchPatternNoCase(inactive_pattern, file_name))
  1047.             {
  1048.                 /*** cut the ".noinfo" at end ***/
  1049.                 *(file_name + strlen(file_name) - 7) = 0;
  1050.  
  1051.                 /*** valid filename ? ***/
  1052.                 if (check_tool_name(file_name))
  1053.                 {
  1054.                     sprintf(entry, "2" ePB eN "%s", file_name);
  1055.                     return(entry);
  1056.                 }
  1057.             }
  1058.  
  1059.             FreeMem(entry, MAXNAMELEN);
  1060.         }
  1061.     }
  1062.  
  1063.     /*** insert nothing ***/
  1064.     return(0);
  1065. }
  1066.  
  1067. static struct Hook tools_list_conhook = {
  1068.     {NULL, NULL},
  1069.     (void *)tools_list_confunc,
  1070.     NULL, NULL
  1071. };
  1072.  
  1073.  
  1074. SAVEDS ASM LONG tools_list_desfunc(
  1075.     REG(a0) struct Hook *hook,
  1076.     REG(a2) APTR mem_pool,
  1077.     REG(a1) char *line)
  1078. {
  1079.     FreeMem(line, MAXNAMELEN);
  1080.  
  1081.     return(0);
  1082. }
  1083.  
  1084. static struct Hook tools_list_deshook = {
  1085.     {NULL, NULL},
  1086.     (void *)tools_list_desfunc,
  1087.     NULL, NULL
  1088. };
  1089.  
  1090.  
  1091. SAVEDS ASM LONG tools_list_dspfunc(
  1092.     REG(a0) struct Hook *hook,
  1093.     REG(a2) char **array,
  1094.     REG(a1) char *line)
  1095. {
  1096.     *array = line+1;
  1097.     return(0);
  1098. }
  1099.  
  1100. static struct Hook tools_list_dsphook = {
  1101.     {NULL, NULL},
  1102.     (void *)tools_list_dspfunc,
  1103.     NULL, NULL
  1104. };
  1105.  
  1106.  
  1107. SAVEDS ASM LONG tools_list_cmpfunc(
  1108.     REG(a0) struct Hook *hook,
  1109.     REG(a2) char *line1,
  1110.     REG(a1) char *line2)
  1111. {
  1112.     return(stricmp(line2+5, line1+5));
  1113. }
  1114.  
  1115. static struct Hook tools_list_cmphook = {
  1116.     {NULL, NULL},
  1117.     (void *)tools_list_cmpfunc,
  1118.     NULL, NULL
  1119. };
  1120.  
  1121.  
  1122.  
  1123. /*** arexx hooks ***/
  1124.  
  1125. SAVEDS ASM APTR select_rxfunc(
  1126.     REG(a0) struct Hook *hook,
  1127.     REG(a2) Object *appl,
  1128.     REG(a1) ULONG *arg)
  1129. {
  1130.     char *pattern;
  1131.  
  1132.     /*** pattern valid ? ***/
  1133.     if (pattern = (char *)*arg)
  1134.     {
  1135.         /*** clear list & select matching pattern ***/
  1136.         select_tools_list(MUIV_List_Select_Off);
  1137.         select_pattern_tools_list(pattern);
  1138.     }
  1139.  
  1140.     return(RETURN_OK);
  1141. }
  1142.  
  1143. static const struct Hook select_rxhook = {
  1144.     {NULL, NULL},
  1145.     (void *)select_rxfunc,
  1146.     NULL,NULL
  1147. };
  1148.  
  1149.  
  1150.  
  1151.  
  1152. /*** arexx list ***/
  1153.  
  1154. static struct MUI_Command arexx_list[] =
  1155. {
  1156.     {"rescan",        MC_TEMPLATE_ID,        ID_RESCAN,        NULL},
  1157.  
  1158.     {"select",        "PATTERN/A",        1,                &select_rxhook},
  1159.  
  1160.     {"activate",    MC_TEMPLATE_ID,        ID_ACTIVATE,    NULL},
  1161.     {"deactivate",    MC_TEMPLATE_ID,        ID_DEACTIVATE,    NULL},
  1162.     {"toggle",        MC_TEMPLATE_ID,        ID_TOGGLE,        NULL},
  1163.     {"restore",        MC_TEMPLATE_ID,        ID_RESTORE,        NULL},
  1164.  
  1165.     {NULL,            NULL,                0,                NULL}
  1166. };
  1167.  
  1168.  
  1169.  
  1170. /*** menu ***/
  1171.  
  1172. static const struct NewMenu menu_list[] =
  1173. {
  1174.     { NM_TITLE,    "Project",            0,    0,    0,    0                            },
  1175.  
  1176.     { NM_ITEM,    "About...",            "?",0,    0,    (APTR) ID_ABOUT                },
  1177.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1178.     { NM_ITEM,    "Rescan",            "S",0,    0,    (APTR) ID_RESCAN            },
  1179.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1180.     { NM_ITEM,    "Perform",            "P",0,    0,    (APTR) ID_PERFORM            },
  1181.     { NM_ITEM,    "Quit",                "Q",0,    0,    (APTR) ID_QUIT                },
  1182.  
  1183.  
  1184.     { NM_TITLE,    "Tools",            0,    0,    0,    0                            },
  1185.  
  1186.     { NM_ITEM,    "Select All",        "A",0,    0,    (APTR) ID_SELECT_ALL        },
  1187.     { NM_ITEM,    "Select None",        "N",0,    0,    (APTR) ID_SELECT_NONE        },
  1188.     { NM_ITEM,    "Select Pattern",    "E",0,    0,    (APTR) ID_SELECT_PATTERN    },
  1189.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1190.     { NM_ITEM,    "Activate",            "V",0,    0,    (APTR) ID_ACTIVATE            },
  1191.     { NM_ITEM,    "Deactivate",        "D",0,    0,    (APTR) ID_DEACTIVATE        },
  1192.     { NM_ITEM,    "Toggle",            "T",0,    0,    (APTR) ID_TOGGLE            },
  1193.     { NM_ITEM,    "Restore",            "R",0,    0,    (APTR) ID_RESTORE            },
  1194.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1195.     { NM_ITEM,    "Edit Tooltypes",    "O",0,    0,    (APTR) ID_EDIT                },
  1196.  
  1197.  
  1198.     { NM_END,    NULL,                0,    0,    0,    0                            },
  1199. };
  1200.  
  1201.  
  1202.  
  1203.  
  1204. /*** main ***/
  1205.  
  1206. int main(int argc, char *argv[])
  1207. {
  1208.     /*** init ***/
  1209.     BOOL not_end = TRUE;
  1210.  
  1211.     init();
  1212.  
  1213.  
  1214.     /*** create mui-application ***/
  1215.     app = ApplicationObject,
  1216.         MUIA_Application_Title,                "WbMan",
  1217.         MUIA_Application_Version,            "$VER: WbMan 0.42 (27.8.93)",
  1218.         MUIA_Application_Copyright,            "© 1993 by kMel, Klaus Melchior",
  1219.         MUIA_Application_Author,            "Klaus Melchior",
  1220.         MUIA_Application_Description,        "Manages the WBStartup",
  1221.         MUIA_Application_Base,                "WBMAN",
  1222.         MUIA_Application_Menu,                menu_list,
  1223.         MUIA_Application_Commands,            arexx_list,
  1224.         MUIA_Application_SingleTask,        TRUE,
  1225.         MUIA_Application_DiskObject,        &wbman_sleep_dobj,
  1226.  
  1227.         SubWindow, wi_main = WindowObject,
  1228.             MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  1229.             MUIA_Window_Title, "WbMan",
  1230.             WindowContents, VGroup,
  1231.                 Child, VGroup,
  1232.                     Child, tx_info = TextObject,
  1233.                         TextFrame,
  1234.                         MUIA_Background, MUII_TextBack,
  1235.                         End,
  1236.                     Child, VGroup,
  1237.                         GroupSpacing(0),
  1238.                         Child, lv_tools = ListviewObject,
  1239.                             MUIA_Listview_MultiSelect, TRUE,
  1240.                             MUIA_Listview_DoubleClick, TRUE,
  1241.                             MUIA_Listview_List, ListObject,
  1242.                                 InputListFrame,
  1243.                                 MUIA_List_ConstructHook, &tools_list_conhook,
  1244.                                 MUIA_List_DestructHook, &tools_list_deshook,
  1245.                                 MUIA_List_CompareHook, &tools_list_cmphook,
  1246.                                 MUIA_List_DisplayHook, &tools_list_dsphook,
  1247.                                 End,
  1248.                             End,
  1249.                         Child, HGroup,
  1250.                             GroupSpacing(0),
  1251.                             Child, bt_activate        = SimpleButton("_Activate"),
  1252.                             Child, bt_toggle        = SimpleButton("_Toggle"),
  1253.                             Child, bt_deactivate    = SimpleButton("_Deactivate"),
  1254.                             End,
  1255.                         Child, HGroup,
  1256.                             GroupSpacing(0),
  1257.                             Child, bt_edit            = SimpleButton("_Edit Tooltypes"),
  1258.                             End,
  1259.                         End,
  1260.                     End,
  1261.                 Child, VSpace(2),
  1262.                 Child, HGroup,
  1263.                     MUIA_Group_SameSize, TRUE,
  1264.                     Child, bt_perform = SimpleButton("_Perform"),
  1265.                     Child, HSpace(0),
  1266.                     Child, bt_quit = SimpleButton("_Quit"),
  1267.                     End,
  1268.                 End,
  1269.             End,
  1270.         End;
  1271.  
  1272.  
  1273.     /*** application failed ? ***/
  1274.     if (!app)
  1275.         fail(app, "Creating application failed !");
  1276.  
  1277.     /*** connections & cycle ***/
  1278.     DoMethod(wi_main,        MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_QUIT            );
  1279.  
  1280.     DoMethod(bt_activate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_ACTIVATE        );
  1281.     DoMethod(bt_toggle,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_TOGGLE        );
  1282.     DoMethod(bt_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_DEACTIVATE    );
  1283.     DoMethod(bt_edit,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_EDIT            );
  1284.  
  1285.     DoMethod(bt_perform,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_PERFORM        );
  1286.     DoMethod(bt_quit,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_QUIT            );
  1287.  
  1288.     DoMethod(lv_tools,        MUIM_Notify,    MUIA_Listview_DoubleClick,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_EDIT            );
  1289.     DoMethod(lv_tools,        MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_LV_ACTIVE    );
  1290.  
  1291.     DoMethod(lv_tools, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  1292.         app, 2,
  1293.         MUIM_Application_ReturnID, ID_LV_ACTIVE);
  1294.  
  1295.     DoMethod(wi_main,        MUIM_Window_SetCycleChain,
  1296.         lv_tools,
  1297.         bt_activate, bt_toggle, bt_deactivate,
  1298.         bt_perform, bt_quit,
  1299.         NULL);
  1300.  
  1301.  
  1302.     /*** open window ***/
  1303.     set(wi_main, MUIA_Window_Open,            TRUE);
  1304.     set(wi_main, MUIA_Window_DefaultObject,    lv_tools);
  1305.  
  1306.  
  1307.     /*** get files ***/
  1308.     rescan_tools_list();
  1309.     count_tools_list();
  1310.  
  1311.     /*** set cursor on listview & check disable gadget ***/
  1312.     check_entries();
  1313.  
  1314.     /*** main-loop ***/
  1315.     while (not_end)
  1316.     {
  1317.         ULONG signal, id;
  1318.         ULONG pos;
  1319.         char *line;
  1320.  
  1321.         switch (id = DoMethod(app, MUIM_Application_Input, &signal))
  1322.         {
  1323.             case ID_ABOUT:
  1324.                 MUI_Request(app, wi_main, 0, NULL, "OK",
  1325.                     eC ePW "WbMan\n\n"
  1326.                     ePB "WbMan 0.41 (13.8.93)\n"
  1327.                     "Copyright 1993 by kMel, Klaus Melchior.\n"
  1328.                     "\nThis is a MUI-Application.\n"
  1329.                     "MUI is copyrighted by Stefan Stuntz.",
  1330.                     TAG_END);
  1331.             break;
  1332.  
  1333.             case MUIV_Application_ReturnID_Quit:
  1334.             case ID_QUIT:
  1335.                 not_end = FALSE;
  1336.             break;
  1337.  
  1338.             case ID_PERFORM:
  1339.                 rename_tools_list();
  1340.                 not_end = FALSE;
  1341.             break;
  1342.  
  1343.  
  1344.             case ID_EDIT:
  1345.                 if (!edit_window_open)
  1346.                 {
  1347.                     edit_window_open = TRUE;
  1348.  
  1349.                     /*** main-window must sleep now ***/
  1350.                     set(wi_main, MUIA_Window_Sleep, TRUE);
  1351.  
  1352.                     edit_tooltypes_entry();
  1353.                 }
  1354.             break;
  1355.  
  1356.             case ID_LV_ACTIVE:
  1357.                 check_entries();
  1358.             break;
  1359.  
  1360.  
  1361.             case ID_RESCAN:
  1362.                 rescan_tools_list();
  1363.                 check_entries();
  1364.                 count_tools_list();
  1365.             break;
  1366.  
  1367.             case ID_ACTIVATE:
  1368.                 change_tools_list(MODE_ACTIVATE);
  1369.                 check_entries();
  1370.                 count_tools_list();
  1371.             break;
  1372.  
  1373.             case ID_DEACTIVATE:
  1374.                 change_tools_list(MODE_DEACTIVATE);
  1375.                 check_entries();
  1376.                 count_tools_list();
  1377.             break;
  1378.  
  1379.             case ID_TOGGLE:
  1380.                 change_tools_list(MODE_TOGGLE);
  1381.                 check_entries();
  1382.                 count_tools_list();
  1383.             break;
  1384.  
  1385.             case ID_RESTORE:
  1386.                 change_tools_list(MODE_RESTORE);
  1387.                 check_entries();
  1388.                 count_tools_list();
  1389.             break;
  1390.  
  1391.  
  1392.             /*** pattern window ***/
  1393.  
  1394.             case ID_SELECT_ALL:
  1395.                 select_tools_list(MUIV_List_Select_On);
  1396.                 check_entries();
  1397.             break;
  1398.  
  1399.             case ID_SELECT_NONE:
  1400.                 select_tools_list(MUIV_List_Select_Off);
  1401.                 check_entries();
  1402.             break;
  1403.  
  1404.             case ID_SELECT_PATTERN:
  1405.                 if (!string_request_open)
  1406.                 {
  1407.                     string_request_open = TRUE;
  1408.  
  1409.                     /*** main-window must sleep now ***/
  1410.                     set(wi_main, MUIA_Window_Sleep, TRUE);
  1411.  
  1412.                     open_string_request("Pattern", 127);
  1413.                 }
  1414.             break;
  1415.  
  1416.  
  1417.             case ID_STRING_OK:
  1418.                 /*** get pattern ***/
  1419.                 get(st_string, MUIA_String_Contents, &line);
  1420.  
  1421.                 /*** clear list & select matching pattern ***/
  1422.                 select_tools_list(MUIV_List_Select_Off);
  1423.                 select_pattern_tools_list(line);
  1424.  
  1425.                 close_string_request();
  1426.                 string_request_open = FALSE;
  1427.                 check_entries();
  1428.             break;
  1429.  
  1430.             case ID_STRING_CANCEL:
  1431.                 close_string_request();
  1432.                 string_request_open = FALSE;
  1433.             break;
  1434.  
  1435.  
  1436.  
  1437.             /*** edit window ***/
  1438.  
  1439.             case ID_EDIT_LV_ACTIVE:
  1440.                 /*** copy active line into string ***/
  1441.                 DoMethod(lv_edit, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  1442.                 set(st_edit_string, MUIA_String_Contents, line);
  1443.                 check_edit_entries();
  1444.                 set(wi_edit, MUIA_Window_ActiveObject, st_edit_string);
  1445.             break;
  1446.  
  1447.  
  1448.             case ID_EDIT_NEW:
  1449.                 line = ">> new <<";
  1450.  
  1451.                 /*** insert at cursor-position ***/
  1452.                 get(lv_edit, MUIA_List_Active, &pos);
  1453.                 if (pos == -1)
  1454.                     pos = 0;
  1455.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1456.                 set(lv_edit, MUIA_List_Active, pos);
  1457.  
  1458.                 check_edit_entries();
  1459.             break;
  1460.  
  1461.             case ID_EDIT_COPY:
  1462.                 get(lv_edit, MUIA_List_Active, &pos);
  1463.                 DoMethod(lv_edit, MUIM_List_GetEntry, pos, &line);
  1464.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1465.                 set(lv_edit, MUIA_List_Active, pos);
  1466.             break;
  1467.  
  1468.             case ID_EDIT_REMOVE:
  1469.                 get(lv_edit, MUIA_List_Active, &pos);
  1470.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1471.  
  1472.                 check_edit_entries();
  1473.             break;
  1474.  
  1475.             case ID_EDIT_ACTIVATE:
  1476.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1477.                 get(lv_edit, MUIA_List_Active, &pos);
  1478.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1479.                 get(st_edit_string, MUIA_String_Contents, &line);
  1480.  
  1481.                 {
  1482.                     char *new_line, *insert_line;
  1483.  
  1484.                     new_line = strdup(line);
  1485.                     if (new_line)
  1486.                     {
  1487.                         *(new_line + strlen(new_line) - 1) = 0;
  1488.                         insert_line = new_line + 1;
  1489.                         DoMethod(lv_edit, MUIM_List_Insert, &insert_line, 1, pos);
  1490.                         free(new_line);
  1491.                     }
  1492.  
  1493.                 }
  1494.  
  1495.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1496.                 set(lv_edit, MUIA_List_Active, pos);
  1497.                 check_edit_entries();
  1498.             break;
  1499.  
  1500.             case ID_EDIT_DEACTIVATE:
  1501.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1502.                 get(lv_edit, MUIA_List_Active, &pos);
  1503.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1504.                 get(st_edit_string, MUIA_String_Contents, &line);
  1505.  
  1506.                 {
  1507.                     char *insert_line;
  1508.  
  1509.                     if (insert_line = AllocMem(MAXNAMELEN, MEMF_ANY))
  1510.                     {
  1511.                         sprintf(insert_line, "(%s)", line);
  1512.                         DoMethod(lv_edit, MUIM_List_Insert, &insert_line, 1, pos);
  1513.  
  1514.                         FreeMem(insert_line, MAXNAMELEN);
  1515.                     }
  1516.                 }
  1517.  
  1518.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1519.                 set(lv_edit, MUIA_List_Active, pos);
  1520.                 check_edit_entries();
  1521.             break;
  1522.  
  1523.  
  1524.             case ID_EDIT_ST_READY:
  1525.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1526.                 get(lv_edit, MUIA_List_Active, &pos);
  1527.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1528.                 get(st_edit_string, MUIA_String_Contents, &line);
  1529.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1530.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1531.                 set(lv_edit, MUIA_List_Active, pos);
  1532.             break;
  1533.  
  1534.  
  1535.             case ID_EDIT_SAVE:
  1536.                 save_tooltypes();
  1537.                 close_edit_window();
  1538.                 edit_window_open = FALSE;
  1539.             break;
  1540.  
  1541.             case ID_EDIT_CANCEL:
  1542.                 close_edit_window();
  1543.                 edit_window_open = FALSE;
  1544.             break;
  1545.  
  1546.  
  1547.             /*** default ***/
  1548.  
  1549.             default:
  1550.                 if (id)
  1551.                     printf("ID: %d = %08lx\n", id, id);
  1552.             break;
  1553.         }
  1554.  
  1555.         if (not_end && signal)
  1556.             Wait(signal);
  1557.     }
  1558.  
  1559.     fail(app, NULL);
  1560. }
  1561.  
  1562.  
  1563.