home *** CD-ROM | disk | FTP | other *** search
/ ftp.freefriends.org / ftp.freefriends.org.tar / ftp.freefriends.org / arnold / Source / mush.rstevens.tar.gz / mush.tar / panels.c < prev    next >
C/C++ Source or Header  |  1990-12-06  |  22KB  |  748 lines

  1. /* @(#)panel.c    (c) copyright    10/18/86 (Dan Heller) */
  2. /* @(#)panels.c    (c) copyright    9/29/89 (Dan Heller) */
  3.  
  4. #include "mush.h"
  5. /* mouse symbols */
  6. short dat_mouse_left[] = {
  7.     0x1FF8, 0x3FFC, 0x336C, 0x336C, 0x336C, 0x336C, 0x336C, 0x336C, 
  8.     0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FC4, 0x3FFC, 0x1FF8
  9. };
  10.  
  11. short dat_mouse_middle[] = {
  12.     0x1FF8, 0x3FFC, 0x366C, 0x366C, 0x366C, 0x366C, 0x366C, 0x366C, 
  13.     0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FC4, 0x3FFC, 0x1FF8
  14. };
  15.  
  16. short dat_mouse_right[] = {
  17.     0x1FF8, 0x3FFC, 0x36CC, 0x36CC, 0x36CC, 0x36CC, 0x36CC, 0x36CC, 
  18.     0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FFC, 0x3FC4, 0x3FFC, 0x1FF8
  19. };
  20.  
  21. mpr_static(mouse_left,      16, 16, 1, dat_mouse_left);
  22. mpr_static(mouse_middle,    16, 16, 1, dat_mouse_middle);
  23. mpr_static(mouse_right,     16, 16, 1, dat_mouse_right);
  24.  
  25. Panel_item
  26.     folder_item,    /* change folders */
  27.     folder_text_item,    /* text item for the folder item */
  28.     file_item,         /* text item for the save item */
  29.     msg_num_item,    /* text item explicitly states which message to read */
  30.     read_item,        /* read the current message */
  31.     save_item,        /* saves messages */
  32.     sub_hdr_item[6];    /* display items that just sit there and give help */
  33.  
  34. #ifndef NO_WALK_MENUS
  35. Panel
  36.     folder_panel,
  37.     save_panel;
  38. Menu      folder_menu;    /* Menu of folders for folder button */
  39. Menu      save_menu;    /* Menu of folders for save button */
  40. Menu      hdr_save_menu;/* Menu of folders for save option in hdr window */
  41. extern Menu msg_menu;    /* header subwindow menu, defined in hdr_sw.c */
  42. walk_menu_event();
  43. #endif /* NO_WALK_MENUS */
  44.  
  45. /* These global panel items for letter composition should eventually go away */
  46. Panel_item
  47.     edit_item,        /* edit a message */
  48.     reply_item;        /* reply button -- also called from hdr_sw menu */
  49.  
  50. extern void
  51.     close_frame(), do_options(), do_compose(), do_send(), do_sort(),
  52.     do_edit(), delete_mail(), respond_mail(), do_help(), do_lpr(),
  53.     do_update(), abort_mail(), do_include(), load_from_file(),
  54.     save_to_file(), tilde_from_menu(), fkey_interposer(), do_mark(),
  55.     close_compose();
  56.  
  57. extern Panel_setting
  58.     msg_num_done(), file_dir();
  59.  
  60. Panel
  61. make_hdr_panel(parent, choice_args, button_args)
  62. Frame parent;
  63. char **choice_args, **button_args;
  64. {
  65.     Panel panel = window_create(parent, PANEL,
  66.     WIN_CONSUME_KBD_EVENTS,
  67.         WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS, NULL,
  68.     NULL);
  69.     (void) notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  70.  
  71.     (void) panel_create_item(panel, PANEL_CHOICE,
  72.     PANEL_ATTRIBUTE_LIST,         choice_args,
  73.     PANEL_LABEL_IMAGE,
  74.         panel_button_image(panel, "Done", 4, mush_font),
  75.     PANEL_CHOICE_STRINGS,
  76.         "Close to Icon", "Quit Tool", "Help", NULL,
  77.     PANEL_NOTIFY_PROC,         toolquit,
  78.     NULL);
  79.  
  80.     (void) panel_create_item(panel, PANEL_CHOICE,
  81.     PANEL_ATTRIBUTE_LIST,         choice_args,
  82.     PANEL_LABEL_IMAGE,
  83.         panel_button_image(panel, "Help", 4, mush_font),
  84.     PANEL_CHOICE_STRINGS,
  85.         "About", "Help with \"help\"", "The Mouse", "Windows",
  86.         "Message headers", "Message lists", "Folders", NULL,
  87.     PANEL_NOTIFY_PROC,         do_help,
  88.     NULL);
  89.  
  90. #ifndef NO_WALK_MENUS
  91.     folder_panel = panel;
  92.     folder_item = panel_create_item(panel, PANEL_BUTTON,
  93.     PANEL_ATTRIBUTE_LIST,         button_args,
  94.     PANEL_LABEL_IMAGE,
  95.         panel_button_image(panel, "Folder", 6, mush_font),
  96.     PANEL_NOTIFY_PROC,         do_file_dir,
  97.     PANEL_EVENT_PROC,        walk_menu_event,
  98.     NULL);
  99. #else /* NO_WALK_MENUS */
  100.     folder_item = panel_create_item(panel, PANEL_CHOICE,
  101.     PANEL_ATTRIBUTE_LIST,         choice_args,
  102.     PANEL_LABEL_IMAGE,
  103.         panel_button_image(panel, "Folder", 6, mush_font),
  104.     PANEL_CHOICE_STRINGS,
  105.         "System Mailbox", "Main Mailbox", "Last Accessed Folder", NULL,
  106.     PANEL_NOTIFY_PROC,         do_file_dir,
  107.     NULL);
  108.  
  109.     add_folder_to_menu(folder_item, 3);
  110. #endif /* NO_WALK_MENUS */
  111.  
  112.     folder_text_item = panel_create_item(panel, PANEL_TEXT,
  113.     PANEL_ATTRIBUTE_LIST,         choice_args,
  114.     PANEL_LABEL_FONT,         mush_font,
  115.     PANEL_LABEL_STRING,        "Filename:",
  116.     PANEL_VALUE_DISPLAY_LENGTH,     28,
  117.     PANEL_NOTIFY_STRING,         "\n\r\033",
  118.     PANEL_NOTIFY_PROC,         file_dir,
  119.     NULL);
  120.  
  121.     (void) panel_create_item(panel, PANEL_CHOICE,
  122.     PANEL_ATTRIBUTE_LIST,         choice_args,
  123.     PANEL_LABEL_IMAGE,
  124.         panel_button_image(panel, "Update", 6, mush_font),
  125.     PANEL_CHOICE_STRINGS,         "New Mail", "Help", NULL,
  126.     PANEL_NOTIFY_PROC,         do_update,
  127.     NULL);
  128.  
  129.     (void) panel_create_item(panel, PANEL_CHOICE,
  130.     PANEL_ATTRIBUTE_LIST,         choice_args,
  131.     PANEL_LABEL_IMAGE,
  132.         panel_button_image(panel, "Options", 7, mush_font),
  133.     PANEL_CHOICE_STRINGS,        "Variables", "Headers", "Aliases", NULL,
  134.     PANEL_NOTIFY_PROC,         do_options,
  135.     NULL);
  136.  
  137.     msg_num_item = panel_create_item(panel, PANEL_TEXT,
  138.     PANEL_ATTRIBUTE_LIST,        choice_args,
  139.     PANEL_LABEL_STRING,        "Range:",
  140.     PANEL_MENU_CHOICE_STRINGS,     "Help", NULL,
  141.     PANEL_VALUE_DISPLAY_LENGTH,     17,
  142.     PANEL_VALUE_STORED_LENGTH,     80,
  143.     PANEL_LABEL_FONT,         mush_font,
  144.     PANEL_NOTIFY_STRING,         "\n\r",
  145.     PANEL_NOTIFY_PROC,         msg_num_done,
  146.     NULL);
  147.  
  148.     sub_hdr_item[0] = panel_create_item(panel, PANEL_CHOICE,
  149.     PANEL_ATTRIBUTE_LIST,         choice_args,
  150.     PANEL_LABEL_IMAGE,            &mouse_left,
  151.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  152.     PANEL_NOTIFY_PROC,            read_mail,
  153.     NULL);
  154.     sub_hdr_item[1] = panel_create_item(panel, PANEL_CHOICE,
  155.     PANEL_ATTRIBUTE_LIST,         choice_args,
  156.     PANEL_LABEL_STRING,           "Read ",
  157.     PANEL_MENU_TITLE_IMAGE,     &mouse_left,
  158.     PANEL_CHOICE_STRINGS,        "Help", NULL,
  159.     PANEL_NOTIFY_PROC,            read_mail,
  160.     NULL);
  161.     sub_hdr_item[2] = panel_create_item(panel, PANEL_CHOICE,
  162.     PANEL_ATTRIBUTE_LIST,         choice_args,
  163.     PANEL_LABEL_IMAGE,            &mouse_middle,
  164.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  165.     PANEL_NOTIFY_PROC,            delete_mail,
  166.     NULL);
  167.     sub_hdr_item[3] = panel_create_item(panel, PANEL_CHOICE,
  168.     PANEL_ATTRIBUTE_LIST,         choice_args,
  169.     PANEL_LABEL_STRING,           "Delete ",
  170.     PANEL_MENU_TITLE_IMAGE,     &mouse_middle,
  171.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  172.     PANEL_NOTIFY_PROC,            delete_mail,
  173.     NULL);
  174.     sub_hdr_item[4] = panel_create_item(panel, PANEL_CHOICE,
  175.     PANEL_ATTRIBUTE_LIST,         choice_args,
  176.     PANEL_LABEL_IMAGE,            &mouse_right,
  177.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  178.     PANEL_NOTIFY_PROC,            read_mail,
  179.     NULL);
  180.     sub_hdr_item[5] = panel_create_item(panel, PANEL_CHOICE,
  181.     PANEL_ATTRIBUTE_LIST,         choice_args,
  182.     PANEL_LABEL_STRING,           "Menu   ",
  183.     PANEL_MENU_TITLE_IMAGE,            &mouse_right,
  184.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  185.     PANEL_NOTIFY_PROC,            read_mail,
  186.     NULL);
  187.  
  188.     (void) panel_create_item(panel, PANEL_CHOICE,
  189.     PANEL_ATTRIBUTE_LIST,         choice_args,
  190.     PANEL_LABEL_IMAGE,
  191.         panel_button_image(panel, "Mark", 4, mush_font),
  192.     PANEL_CHOICE_STRINGS,
  193.         "Toggle Mark", "Priority A", "Priority B", "Priority C",
  194.         "Priority D", "Priority E", "Clear Priority", "Help", NULL,
  195.     PANEL_NOTIFY_PROC,         do_mark,
  196.     NULL);
  197.  
  198.     (void) panel_create_item(panel, PANEL_CHOICE,
  199.     PANEL_ATTRIBUTE_LIST,         choice_args,
  200.     PANEL_LABEL_IMAGE,
  201.         panel_button_image(panel, "Printer", 7, mush_font),
  202.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  203.     PANEL_NOTIFY_PROC,         do_lpr,
  204.     NULL);
  205.  
  206.     (void) panel_create_item(panel, PANEL_CHOICE,
  207.     PANEL_ATTRIBUTE_LIST,         choice_args,
  208.     PANEL_LABEL_IMAGE,
  209.         panel_button_image(panel, "Sort", 4, mush_font),
  210.     PANEL_CHOICE_STRINGS,
  211.         "By Status", "By Author", "By Size", "By Subject",
  212.         "By Subject (ignore Re:)", "By Date",
  213.         "By Priority", "Value of $sort", "Help", NULL,
  214.     PANEL_NOTIFY_PROC,         do_sort,
  215.     NULL);
  216.  
  217.     window_fit_height(panel);
  218.     return panel;
  219. }
  220.  
  221. Panel
  222. make_main_panel(parent, choice_args, button_args)
  223. Frame parent;
  224. char **choice_args, **button_args;
  225. {
  226.     /* main panel stuff: */
  227.     Panel panel = window_create(parent, PANEL,
  228.     WIN_CONSUME_KBD_EVENTS,
  229.         WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS, NULL,
  230.     NULL);
  231.     (void) notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  232.  
  233.     read_item = panel_create_item(panel, PANEL_CHOICE,
  234.     PANEL_ATTRIBUTE_LIST,         choice_args,
  235.     PANEL_LABEL_IMAGE,
  236.         panel_button_image(panel, "Next", 4, mush_font),
  237.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  238.     PANEL_NOTIFY_PROC,         read_mail,
  239.     NULL);
  240.  
  241.     (void) panel_create_item(panel, PANEL_CHOICE,
  242.     PANEL_ATTRIBUTE_LIST,         choice_args,
  243.     PANEL_LABEL_IMAGE,
  244.         panel_button_image(panel, "Delete", 6, mush_font),
  245.     PANEL_CHOICE_STRINGS,         "Delete",
  246.                     "Undelete",
  247.                     "Help", NULL,
  248.     PANEL_NOTIFY_PROC,         delete_mail,
  249.     NULL);
  250.  
  251. #ifndef NO_WALK_MENUS
  252.     save_panel = panel;
  253.     save_item = panel_create_item(panel, PANEL_BUTTON,
  254.     PANEL_ATTRIBUTE_LIST,         button_args,
  255.     PANEL_LABEL_IMAGE, panel_button_image(panel, "Save", 4, mush_font),
  256.     PANEL_NOTIFY_PROC,         do_file_dir,
  257.     PANEL_EVENT_PROC,        walk_menu_event,
  258.     NULL);
  259.  
  260.     create_folder_menus();
  261. #else /* NO_WALK_MENUS */
  262.     {
  263.     char *mbox = do_set(set_options, "mbox");
  264.     if (!mbox || !*mbox)
  265.         mbox = DEF_MBOX;
  266.     save_item = panel_create_item(panel, PANEL_CHOICE,
  267.         PANEL_ATTRIBUTE_LIST,     choice_args,
  268.         PANEL_LABEL_IMAGE, panel_button_image(panel, "Save", 4, mush_font),
  269.         PANEL_CHOICE_STRINGS,     trim_filename(mbox), NULL,
  270.         PANEL_NOTIFY_PROC,         do_file_dir,
  271.         NULL);
  272.     }
  273.  
  274.     add_folder_to_menu(save_item, 1);
  275. #endif /* NO_WALK_MENUS */
  276.  
  277.     file_item = panel_create_item(panel, PANEL_TEXT,
  278.     PANEL_ATTRIBUTE_LIST,         choice_args,
  279.     PANEL_LABEL_FONT,         mush_font,
  280.     PANEL_SHOW_MENU,        TRUE,
  281.     PANEL_LABEL_STRING,         "Filename:",
  282.     PANEL_MENU_CHOICE_STRINGS,    "Save message without message header",
  283.                     NULL,
  284.     PANEL_VALUE_DISPLAY_LENGTH,     28,
  285.     PANEL_NOTIFY_STRING,         "\n\r\033",
  286.     PANEL_NOTIFY_PROC,         file_dir,
  287.     NULL);
  288.  
  289.     (void) panel_create_item(panel, PANEL_CHOICE,
  290.     PANEL_ATTRIBUTE_LIST,         choice_args,
  291.     PANEL_LABEL_IMAGE,
  292.         panel_button_image(panel, "Compose", 7, mush_font),
  293.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  294.     PANEL_NOTIFY_PROC,        do_compose,
  295.     NULL);
  296.  
  297.     reply_item = panel_create_item(panel, PANEL_CHOICE,
  298.     PANEL_ATTRIBUTE_LIST,         choice_args,
  299.     PANEL_LABEL_IMAGE,
  300.         panel_button_image(panel, "Reply", 5, mush_font),
  301.     PANEL_CHOICE_STRINGS,
  302.         "Sender Only", "Sender Only (include msg)",
  303.         "All Recipients", "All Recipients (include msg)", "Help", NULL,
  304.     PANEL_NOTIFY_PROC,         respond_mail,
  305.     NULL);
  306.  
  307.     window_fit_height(panel);
  308.     return panel;
  309. }
  310.  
  311. Panel
  312. make_compose_panel(parent, choice_args, button_args)
  313. Frame parent;
  314. char **choice_args, **button_args;
  315. {
  316.     Panel panel = window_create(parent, PANEL, NULL);
  317.     Panel_item filename_item, fortune_item, sign_item, send_item;
  318.  
  319.     (void) notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  320.  
  321.     if (do_set(set_options, "compose_icon"))
  322.     (void) panel_create_item(panel, PANEL_CHOICE,
  323.         PANEL_ATTRIBUTE_LIST,         choice_args,
  324.         PANEL_LABEL_IMAGE,
  325.         panel_button_image(panel, "Close", 5, mush_font),
  326.         PANEL_CHOICE_STRINGS,
  327.         "Close to Icon", "Quit", "Help", NULL,
  328.         PANEL_NOTIFY_PROC,         close_compose,
  329.         NULL);
  330.     else
  331.     (void) panel_create_item(panel, PANEL_BUTTON,
  332.         PANEL_ATTRIBUTE_LIST,         button_args,
  333.         PANEL_LABEL_IMAGE,
  334.         panel_button_image(panel, "Close", 5, mush_font),
  335.         PANEL_NOTIFY_PROC,         close_frame,
  336.         NULL);
  337.  
  338.     (void) panel_create_item(panel, PANEL_CHOICE,
  339.     PANEL_ATTRIBUTE_LIST,         choice_args,
  340.     PANEL_LABEL_IMAGE,
  341.         panel_button_image(panel, "Compose", 7, mush_font),
  342.     PANEL_CHOICE_STRINGS,         "Help", NULL,
  343.     PANEL_NOTIFY_PROC,         do_compose,
  344.     NULL);
  345.  
  346.     send_item = panel_create_item(panel, PANEL_BUTTON,
  347.     PANEL_ATTRIBUTE_LIST,         button_args,
  348.     PANEL_SHOW_ITEM,         FALSE,
  349.     PANEL_LABEL_IMAGE,
  350.         panel_button_image(panel, "Send", 4, mush_font),
  351.     PANEL_NOTIFY_PROC,         do_send,
  352.     NULL);
  353.  
  354.     (void) panel_create_item(panel, PANEL_BUTTON,
  355.     PANEL_ATTRIBUTE_LIST,         button_args,
  356.     PANEL_SHOW_ITEM,        FALSE,
  357.     PANEL_LABEL_IMAGE,
  358.         panel_button_image(panel, "Abort", 5, mush_font),
  359.     PANEL_NOTIFY_PROC,         abort_mail,
  360.     NULL);
  361.  
  362.     (void) panel_create_item(panel, PANEL_CHOICE,
  363.     PANEL_ATTRIBUTE_LIST,         choice_args,
  364.     PANEL_SHOW_ITEM,         FALSE,
  365.     PANEL_LABEL_IMAGE,
  366.         panel_button_image(panel, "Include", 7, mush_font),
  367.     PANEL_CHOICE_STRINGS,         "Include Message",
  368.                     "Forward Message",
  369.                     "Help", NULL,
  370.     PANEL_NOTIFY_PROC,         do_include,
  371.     NULL);
  372.  
  373.     edit_item = panel_create_item(panel, PANEL_BUTTON,
  374.     PANEL_ATTRIBUTE_LIST,         button_args,
  375.     PANEL_SHOW_ITEM,         FALSE,
  376.     PANEL_LABEL_IMAGE,
  377.         panel_button_image(panel, "Edit", 4, mush_font),
  378.     PANEL_NOTIFY_PROC,         do_edit,
  379.     NULL);
  380.  
  381.     (void) panel_create_item(panel, PANEL_CHOICE,
  382.     PANEL_ATTRIBUTE_LIST,         choice_args,
  383.     PANEL_SHOW_ITEM,        FALSE,
  384.     PANEL_LABEL_IMAGE,
  385.         panel_button_image(panel, "Headers", 7, mush_font),
  386.     PANEL_CHOICE_STRINGS,    
  387.         "ALL      ~h", "To:      ~t", "Subject: ~s",
  388.         "Cc:      ~c", "Bcc:     ~b", "Fcc:", NULL,
  389.     PANEL_NOTIFY_PROC,        tilde_from_menu,
  390.     NULL);
  391.  
  392.     sign_item = panel_create_item(panel, PANEL_CHOICE,
  393.     PANEL_ATTRIBUTE_LIST,         choice_args,
  394.     PANEL_DISPLAY_LEVEL,        PANEL_ALL,
  395.     PANEL_SHOW_MENU_MARK,        TRUE,
  396.     PANEL_SHOW_ITEM,         FALSE,
  397.     PANEL_LABEL_STRING,        "Autosign:",
  398.     PANEL_CHOICE_STRINGS,        "Off", "On", NULL,
  399.     NULL);
  400.     panel_set_value(sign_item, !!do_set(set_options, "autosign"));
  401.     /* Create a link to avoid global */
  402.     panel_set(send_item, PANEL_CLIENT_DATA, sign_item, NULL);
  403.  
  404.     filename_item = panel_create_item(panel, PANEL_TEXT,
  405.     PANEL_ATTRIBUTE_LIST,         button_args,
  406.     PANEL_SHOW_ITEM,        FALSE,
  407.     PANEL_LABEL_STRING,        "Filename:",
  408.     PANEL_VALUE_DISPLAY_LENGTH,     30,
  409.     PANEL_NOTIFY_STRING,         "\033",
  410.     PANEL_NOTIFY_PROC,         file_dir,
  411.     NULL);
  412.  
  413.     (void) panel_create_item(panel, PANEL_CHOICE,
  414.     PANEL_ATTRIBUTE_LIST,         choice_args,
  415.     PANEL_SHOW_ITEM,        FALSE,
  416.     PANEL_CLIENT_DATA,        filename_item,
  417.     PANEL_LABEL_IMAGE,
  418.         panel_button_image(panel, "Import", 6, mush_font),
  419.     PANEL_CHOICE_STRINGS,        "Insert", "Replace", NULL,
  420.     PANEL_NOTIFY_PROC,        load_from_file,
  421.     NULL);
  422.  
  423.     (void) panel_create_item(panel, PANEL_BUTTON,
  424.     PANEL_ATTRIBUTE_LIST,         button_args,
  425.     PANEL_SHOW_ITEM,        FALSE,
  426.     PANEL_CLIENT_DATA,        filename_item,
  427.     PANEL_LABEL_IMAGE,
  428.         panel_button_image(panel, "Export", 6, mush_font),
  429.     PANEL_NOTIFY_PROC,        save_to_file,
  430.     NULL);
  431.  
  432.     fortune_item = panel_create_item(panel, PANEL_CHOICE,
  433.     PANEL_ATTRIBUTE_LIST,         choice_args,
  434.     PANEL_DISPLAY_LEVEL,        PANEL_ALL,
  435.     PANEL_SHOW_MENU_MARK,        TRUE,
  436.     PANEL_SHOW_ITEM,         FALSE,
  437.     PANEL_LABEL_STRING,        "Fortune:",
  438.     PANEL_CHOICE_STRINGS,        "Off", "On", NULL,
  439.     NULL);
  440.     panel_set_value(fortune_item, !!do_set(set_options, "fortune"));
  441.     /* Create a link to avoid global */
  442.     panel_set(sign_item, PANEL_CLIENT_DATA, fortune_item, NULL);
  443.  
  444.     window_fit_height(panel);
  445.     return panel;
  446. }
  447.  
  448. #include "glob.h"
  449.  
  450. #ifndef NO_WALK_MENUS
  451.  
  452. static
  453. Menu_item
  454. make_folder_item(path)
  455. char *path;
  456. {
  457.     Menu_item        mi;
  458.     Menu_item        sub_mi;
  459.     Menu        next_menu;
  460.     char        **names, **np;
  461.     struct stat     s_buf;
  462.     char        buf[MAXPATHLEN];
  463.  
  464.     if (glob(path, "*/{.,..}")) {
  465.     return NULL;
  466.     }
  467.  
  468.     /* don't add a folder to the list if user can't read it */
  469.     if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD)) {
  470.     return NULL;
  471.     }
  472.     mi = menu_create_item(
  473.     MENU_STRING,        savestr(basename(trim_filename(path))),
  474.     MENU_CLIENT_DATA,    NULL,
  475.     MENU_RELEASE,        /* no value */
  476.     NULL);
  477.     if ((s_buf.st_mode & S_IFMT) == S_IFDIR) {
  478.     int cnt = 0;
  479.     next_menu = menu_create(MENU_NOTIFY_PROC, menu_return_item, NULL);
  480.     sprintf(buf, "%s/{.*,*}", path);
  481.     if (filexp(buf, &names) > 0) {
  482.         for (np = names; np && *np; np++) {
  483.         if ((sub_mi = make_folder_item(*np)) != NULL) {
  484.             menu_set(next_menu, MENU_APPEND_ITEM, sub_mi, NULL);
  485.             ++cnt;
  486.         }
  487.         }
  488.         free_vec(names);
  489.     }
  490.     if (! cnt) {
  491.         menu_destroy(next_menu);
  492.         menu_set(mi, MENU_INACTIVE, TRUE, NULL);
  493.     } else {
  494.         menu_set(mi, MENU_PULLRIGHT, next_menu, NULL);
  495.     }
  496.     } else if (test_folder(path, NULL)) {
  497.     menu_set(mi, MENU_CLIENT_DATA, savestr(path), NULL);
  498.     } else {
  499.     menu_destroy(mi);
  500.     mi = NULL;
  501.     }
  502.     return mi;
  503. }
  504.  
  505. static
  506. void
  507. destroy_folder_item(menu_item, menu_type)
  508. Menu_item menu_item;
  509. Menu_attribute menu_type;
  510. {
  511.     char    *ptr;
  512.  
  513.     if (menu_type == MENU_ITEM) {
  514.     if ((ptr = (char *)menu_get(menu_item, MENU_STRING)) != NULL) {
  515.         free(ptr);
  516.     }
  517.     if ((ptr = (char *)menu_get(menu_item, MENU_CLIENT_DATA)) != NULL) {
  518.         free(ptr);
  519.     }
  520.     }
  521.     return;
  522. }
  523.  
  524. create_folder_menus()
  525. {
  526.     int       item_number;
  527.     Menu      menu;
  528.     Menu_item      menu_item;
  529.     int       nitems;
  530.     char     *mbox;
  531.     char     *tmp = NULL;
  532.     char     *p;
  533.     static int      menus_exist = 0;
  534.  
  535.     if (menus_exist) {
  536.     /* remove duplicated menu items from save_menu */
  537.     for (item_number = (int)menu_get(save_menu, MENU_NITEMS) ;
  538.           item_number > 1 ; --item_number) {
  539.         menu_set(save_menu, MENU_REMOVE, item_number, NULL);
  540.     }
  541.     /* remove duplicated menu items from hdr_save_menu */
  542.     for (item_number = (int)menu_get(hdr_save_menu, MENU_NITEMS) ;
  543.           item_number > 1 ; --item_number) {
  544.         menu_set(save_menu, MENU_REMOVE, item_number, NULL);
  545.     }
  546.     menu_destroy_with_proc(hdr_save_menu, destroy_folder_item);
  547.     menu_destroy_with_proc(save_menu, destroy_folder_item);
  548.     menu_destroy_with_proc(folder_menu, destroy_folder_item);
  549.     }
  550.  
  551.     if (!(p = do_set(set_options, "folder")) || !*p) {
  552.     p = DEF_FOLDER;
  553.     }
  554.     if (p) {
  555.     int x = 0;
  556.     tmp = getpath(p, &x);
  557.     if (x == -1) {
  558.         if (errno != ENOENT)
  559.         print("%s: %s\n", p, tmp);
  560.         tmp = NULL;
  561.     }
  562.     }
  563.     menu = NULL;
  564.     menu_item = NULL;
  565.     if (tmp != NULL) {
  566.     if ((menu_item = make_folder_item(tmp)) != NULL) {
  567.         if ((menu = menu_get(menu_item, MENU_PULLRIGHT)) != NULL) {
  568.             /* $folder was a directory, use the pullright
  569.          * instead of the directory menu item.
  570.          */
  571.         /* "unhook" the pullright (so it is not released) */
  572.         menu_set(menu_item, MENU_PULLRIGHT, NULL, NULL);
  573.         /* destroy the menu item */
  574.         menu_destroy_with_proc(menu_item, destroy_folder_item);
  575.         menu_item = NULL;
  576.         }
  577.     }
  578.     }
  579.     if (menu == NULL) {
  580.     menu = menu_create(MENU_NOTIFY_PROC, menu_return_item, NULL);
  581.     if (menu_item != NULL) {
  582.         menu_set(menu, MENU_APPEND_ITEM, menu_item, NULL);
  583.     }
  584.     }
  585.  
  586.     /* create save_menu */
  587.     save_menu = menu_create(MENU_NOTIFY_PROC, menu_return_item, NULL);
  588.     /* add magic first item */
  589.     mbox = do_set(set_options, "mbox");
  590.     if (!mbox || !*mbox) {
  591.     mbox = DEF_MBOX;
  592.     }
  593.     menu_item = menu_create_item(
  594.     MENU_STRING,        savestr(trim_filename(mbox)),
  595.     MENU_CLIENT_DATA,    savestr(mbox),
  596.     MENU_RELEASE,        /* no value */
  597.     NULL);
  598.     menu_set(save_menu, MENU_APPEND_ITEM, menu_item, NULL);
  599.     /* copy menu for save_menu */
  600.     nitems = (int)menu_get(menu, MENU_NITEMS);
  601.     for (item_number = 1 ; item_number <= nitems ; ++item_number) {
  602.     menu_set(save_menu,
  603.         MENU_APPEND_ITEM, menu_get(menu, MENU_NTH_ITEM, item_number),
  604.         NULL);
  605.     }
  606.  
  607.     /* create hdr_save_menu */
  608.     hdr_save_menu = menu_create(MENU_NOTIFY_PROC, menu_return_item, NULL);
  609.     /* add magic first item */
  610.     menu_item = menu_create_item(
  611.     MENU_STRING,        savestr("use Filename:"),
  612.     MENU_CLIENT_DATA,    savestr(""),    /* magic */
  613.     MENU_RELEASE,        /* no value */
  614.     NULL);
  615.     menu_set(hdr_save_menu, MENU_APPEND_ITEM, menu_item, NULL);
  616.     /* copy save_menu for hdr_save_menu */
  617.     nitems = (int)menu_get(save_menu, MENU_NITEMS);
  618.     for (item_number = 1 ; item_number <= nitems ; ++item_number) {
  619.     menu_set(hdr_save_menu,
  620.         MENU_APPEND_ITEM, menu_get(save_menu, MENU_NTH_ITEM, item_number),
  621.         NULL);
  622.     }
  623.     /* Make sure the header subwindow menu exists so we can tack on a
  624.      * pullright for Save.
  625.      */
  626.     if (! msg_menu) {
  627.     get_msg_menu();
  628.     }
  629.     if ((menu_item = menu_find(msg_menu, MENU_STRING, "Save", NULL))
  630.         != NULL) {
  631.     menu_set(menu_item, MENU_PULLRIGHT, hdr_save_menu, NULL);
  632.     }
  633.  
  634.     /* insert folder-specific initial options to menu */
  635.     folder_menu = menu;
  636.     menu_item = menu_create_item(
  637.     MENU_STRING,        savestr("System Mailbox"),
  638.     MENU_CLIENT_DATA,    savestr("%"),
  639.     MENU_RELEASE,        /* no value */
  640.     NULL);
  641.     menu_set(folder_menu, MENU_INSERT, 0, menu_item, NULL);
  642.     menu_item = menu_create_item(
  643.     MENU_STRING,        savestr("Main Mailbox"),
  644.     MENU_CLIENT_DATA,    savestr("&"),
  645.     MENU_RELEASE,        /* no value */
  646.     NULL);
  647.     menu_set(folder_menu, MENU_INSERT, 1, menu_item, NULL);
  648.     menu_item = menu_create_item(
  649.     MENU_STRING,        savestr("Last Accessed Folder"),
  650.     MENU_CLIENT_DATA,    savestr("#"),
  651.     MENU_RELEASE,        /* no value */
  652.     NULL);
  653.     menu_set(folder_menu, MENU_INSERT, 2, menu_item, NULL);
  654.  
  655.     menus_exist = 1;
  656.     return;
  657. }
  658.  
  659. static
  660. walk_menu_event(item, event)
  661. Panel_item item;
  662. Event *event;
  663. {
  664.     char     *folder_name;
  665.     Menu_item       selection;
  666.     Menu      menu;
  667.     Panel      panel;
  668.     void xx_file_dir();
  669.  
  670.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  671.     if (item == folder_item) {
  672.         menu = folder_menu;
  673.         panel = folder_panel;
  674.     } else {
  675.         menu = save_menu;
  676.         panel = save_panel;
  677.     }
  678.     selection = (Menu_item)menu_show(menu, panel, event, 0);
  679.     if (! selection) {
  680.         /* no selection was made */
  681.         return;
  682.     }
  683.     if ((folder_name = (char *)menu_get(selection, MENU_CLIENT_DATA))
  684.         != NULL) {
  685.         xx_file_dir(item, folder_name);
  686.     }
  687.     } else {
  688.     panel_default_handle_event(item, event);
  689.     }
  690. }
  691.  
  692. #else /* NO_WALK_MENUS */
  693.  
  694. static
  695. add_path_to_menu(item, path, n)
  696. Panel_item item;
  697. char *path;
  698. int *n;
  699. {
  700.     char        **names, **np;
  701.     struct stat     s_buf;
  702.     char        buf[MAXPATHLEN];
  703.  
  704.     /* don't add a folder to the list if user can't read it */
  705.     if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD))
  706.     return;
  707.     if ((s_buf.st_mode & S_IFMT) == S_IFDIR) {
  708.     sprintf(buf, "%s/{.*,*}", path);
  709.     if (filexp(buf, &names) > 0) {
  710.         for (np = names; np && *np; np++) {
  711.         if (!glob(*np, "*/{.,..}"))
  712.             add_path_to_menu(item, *np, n);
  713.         }
  714.         free_vec(names);
  715.     }
  716.     } else if (test_folder(path, NULL))
  717.     panel_set(item,
  718.         PANEL_CHOICE_STRING, (*n)++, savestr(trim_filename(path)),
  719.         NULL);
  720. }
  721.  
  722. /*
  723.  * Open the user's mail folder (either user set or default path) and find all
  724.  * the files (assumed to be mail folders) and add them to the menu list of
  725.  * folders to use.
  726.  */
  727. add_folder_to_menu(item, n)
  728. Panel_item item;
  729. {
  730.     char    *tmp = NULL, *p;
  731.  
  732.     if (!(p = do_set(set_options, "folder")) || !*p)
  733.     p = DEF_FOLDER;
  734.     if (p) {
  735.     int x = 0;
  736.     tmp = getpath(p, &x);
  737.     if (x == -1) {
  738.         if (errno != ENOENT)
  739.         print("%s: %s\n", p, tmp);
  740.         tmp = NULL;
  741.     }
  742.     }
  743.     if (tmp) {
  744.     add_path_to_menu(item, tmp, &n);
  745.     }
  746. }
  747. #endif /* NO_WALK_MENUS */
  748.