home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / xap / xfm / xfm-1.000 / xfm-1 / xfm-1.3.2 / src / FmPopup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-25  |  23.4 KB  |  924 lines

  1. /*---------------------------------------------------------------------------
  2.   Module FmPopup
  3.  
  4.   (c) Simon Marlow 1990-92
  5.   (c) Albert Graef 1994
  6.  
  7.   Routines for creating and managing popup forms and dialog boxes
  8.  
  9.   modified 1-29-95 by rodgers@lvs-emh.lvs.loral.com (Kevin M. Rodgers)
  10.   to add filtering of icon/text directory displays by a filename filter.
  11.  
  12. ---------------------------------------------------------------------------*/
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <unistd.h>
  17.  
  18. #include <X11/Intrinsic.h>
  19. #include <X11/StringDefs.h>
  20. #include <X11/Shell.h>
  21. #include <X11/Xaw/Dialog.h>
  22. #include <X11/Xaw/Toggle.h>
  23.  
  24. #include "Fm.h"
  25.  
  26. /*---------------------------------------------------------------------------
  27.   STATIC DATA
  28. ---------------------------------------------------------------------------*/
  29.  
  30. typedef struct {
  31.   FileWindowRec *fw;
  32.   Widget mkdir, createFile, goTo, move, copy, link, select, filter;
  33.   char s[MAXPATHLEN], t[MAXPATHLEN];
  34.   char select_s[MAXPATHLEN];
  35.   char filter_s[MAXPATHLEN];
  36.   char mkdir_s[MAXPATHLEN];
  37.   char createFile_s[MAXPATHLEN];
  38.   char goTo_s[MAXPATHLEN];
  39.   char move_s[MAXPATHLEN];
  40.   char copy_s[MAXPATHLEN];
  41.   char link_s[MAXPATHLEN];
  42. } PopupsRec;
  43.  
  44. static PopupsRec popups;
  45.  
  46. /*---------------------------------------------------------------------------
  47.   PRIVATE FUNCTIONS
  48. ---------------------------------------------------------------------------*/
  49.  
  50. char *dir_prefix(char *dir, char *path)
  51. {
  52.   char *p;
  53.   if ((p = strrchr(path, '/'))) {
  54.     strcpy(dir, path);
  55.     if (p == path)
  56.       dir[1] = '\0';
  57.     else
  58.       dir[p-path] = '\0';
  59.   } else
  60.     dir[0] = '\0';
  61.   return dir;
  62. }
  63.  
  64. static FmCallbackProc 
  65.   mkdirOkCb, mkdirCancelCb, createFileOkCb, createFileCancelCb, goToOkCb,
  66.   goToCancelCb, moveOkCb, moveCancelCb, copyOkCb, copyCancelCb, linkOkCb,
  67.   linkCancelCb, selectAddCb, selectRemoveCb, selectCancelCb, selectReplaceCb,
  68.   filterOkCb, filterClearCb, filterCancelCb;
  69.  
  70. static void mkdirOkCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  71. {
  72.   XtPopdown(popups.mkdir);
  73.   fnexpand(popups.mkdir_s);
  74.   if (chdir(popups.fw->directory))
  75.     sysError("System error:");
  76.   else if (mkdir(popups.mkdir_s, user.umask & 0777)) {
  77.     char s[0xff];
  78.     sprintf(s, "Error creating folder %s:", popups.mkdir_s);
  79.     sysError(s);
  80.   } else
  81.     intUpdate();
  82.   freeze = False;
  83. }
  84.  
  85. /*---------------------------------------------------------------------------*/
  86.  
  87. static void mkdirCancelCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  88. {
  89.   XtPopdown(popups.mkdir);
  90.   freeze = False;
  91. }
  92.  
  93. /*---------------------------------------------------------------------------*/
  94.  
  95. static void createFileOkCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  96. {
  97.   XtPopdown(popups.createFile);
  98.   fnexpand(popups.createFile_s);
  99.   if (chdir(popups.fw->directory))
  100.     sysError("System error:");
  101.   else if (create(popups.createFile_s, user.umask & 0666)) {
  102.     char s[0xff];
  103.     sprintf(s, "Error creating file %s:", popups.createFile_s);
  104.     sysError(s);
  105.   } else
  106.     intUpdate();
  107.   freeze = False;
  108. }
  109.  
  110. /*---------------------------------------------------------------------------*/
  111.  
  112. static void createFileCancelCb(Widget w, FileWindowRec *fw, 
  113.                XtPointer call_data)
  114. {
  115.   XtPopdown(popups.createFile);
  116.   freeze = False;
  117. }
  118.  
  119. /*---------------------------------------------------------------------------*/
  120.  
  121. static void goToOkCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  122. {
  123.   char path[MAXPATHLEN];
  124.  
  125.   XtPopdown(popups.goTo);
  126.   fnexpand(popups.goTo_s);
  127.   if (chdir(popups.fw->directory) || chdir(popups.goTo_s)) {
  128.     char s[0xff];
  129.     sprintf(s, "Can't open folder %s:", popups.goTo_s);
  130.     sysError(s);
  131.   } else if (!getwd(path))
  132.     sysError("System error:");
  133.   else {
  134.     strcpy(popups.fw->directory, path);
  135.     updateFileDisplay(popups.fw);
  136.   }
  137.   freeze = False;
  138. }
  139.  
  140. /*---------------------------------------------------------------------------*/
  141.  
  142. static void goToCancelCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  143. {
  144.   XtPopdown(popups.goTo);
  145.   freeze = False;
  146. }
  147.  
  148. /*---------------------------------------------------------------------------*/
  149.  
  150. static void moveOkCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  151. {
  152.   struct stat stats;
  153.   int i, toi, n_moved = 0;
  154.   char *from = NULL, to[MAXPATHLEN], todir[MAXPATHLEN];
  155.  
  156.   XtPopdown(popups.move);
  157.   strcpy(to, popups.move_s);
  158.   fnexpand(to);
  159.  
  160.   if (chdir(popups.fw->directory))
  161.  
  162.     sysError("System error:");
  163.  
  164.   else {
  165.  
  166.     /* if target exists and is a directory, move the source into that
  167.        directory */
  168.  
  169.     if (!stat(to, &stats) && S_ISDIR(stats.st_mode)) {
  170.  
  171.       if (chdir(to) || !getwd(to) || chdir(popups.fw->directory)) {
  172.     sysError("System error:");
  173.     goto out;
  174.       } else if (!strcmp(popups.fw->directory, to)) {
  175.     error("Move:", "Source and destination are identical");
  176.     goto out;
  177.       }
  178.  
  179.       strcpy(todir, to);
  180.  
  181.       toi = strlen(to);
  182.       if (to[toi-1] != '/') {
  183.     to[toi++] = '/';
  184.     to[toi] = '\0';
  185.       }
  186.  
  187.       for (i=0; i < popups.fw->n_files; i++)
  188.     if (popups.fw->files[i]->selected) {
  189.       if (!strcmp(popups.fw->files[i]->name, ".") ||
  190.           !strcmp(popups.fw->files[i]->name, "..")) {
  191.         error("Cannot move . or ..", "");
  192.         continue;
  193.       }
  194.       from = popups.fw->files[i]->name;
  195.       strcpy(to+toi, from);
  196.       if (exists(to) && resources.confirm_overwrite) {
  197.         char s[0xff];
  198.         sprintf(s, "Move: file %s already exists at destination", from);
  199.         if (!confirm(s, "Overwrite?", ""))
  200.           if (aborted)
  201.         break;
  202.           else
  203.         continue;
  204.       }
  205.       if (rename(from,to)) {
  206.         char s[0xff];
  207.         sprintf(s, "Error moving %s:", from);
  208.         sysError(s);
  209.       } else
  210.         n_moved++;
  211.     }
  212.     }
  213.  
  214.     /* otherwise only a single file may be selected; move it to the target
  215.        file */
  216.  
  217.     else if (popups.fw->n_selections > 1) {
  218.  
  219.       error("Move: target for multiple files", "must be a folder");
  220.       goto out;
  221.  
  222.     } else {
  223.  
  224.       struct stat stats1;
  225.  
  226.       for (i = 0; i < popups.fw->n_files; i++)
  227.     if (popups.fw->files[i]->selected) {
  228.       from = popups.fw->files[i]->name;
  229.       break;
  230.     }
  231.  
  232.       if (!strcmp(from, ".") || !strcmp(from, "..")) {
  233.     error("Cannot move . or ..", "");
  234.     goto out;
  235.       } else if (!lstat(to, &stats) && !lstat(from, &stats1) &&
  236.          stats.st_ino == stats1.st_ino) {
  237.     error("Move:", "Source and destination are identical");
  238.     goto out;
  239.       }
  240.  
  241.       if (exists(to) && resources.confirm_overwrite) {
  242.     char s[0xff];
  243.     sprintf(s, "Move: file %s already exists", to);
  244.     if (!confirm(s, "Overwrite?", ""))
  245.       goto out;
  246.       }
  247.  
  248.       if (rename(from, to)) {
  249.     char s[0xff];
  250.     sprintf(s, "Error moving %s:", from);
  251.     sysError(s);
  252.       } else {
  253.     n_moved = 1;
  254.     dir_prefix(todir, to);
  255.     if ((*todir?chdir(todir):0) || !getwd(todir))
  256.       sysError("System error:");
  257.       }
  258.     }
  259.  
  260.     if (n_moved) {
  261.       markForUpdate(popups.fw->directory); markForUpdate(todir);
  262.       intUpdate();
  263.     }
  264.  
  265.   }
  266.  
  267.  out:
  268.   freeze = False;
  269. }
  270.  
  271. /*---------------------------------------------------------------------------*/
  272.  
  273. static void moveCancelCb(Widget w, FileWindowRec *fw, 
  274.                XtPointer call_data)
  275. {
  276.   XtPopdown(popups.move);
  277.   freeze = False;
  278. }
  279.  
  280. /*---------------------------------------------------------------------------*/
  281.  
  282. static void copyOkCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  283. {
  284.   struct stat stats;
  285.   int i, toi, n_copied = 0;
  286.   char *from = NULL, to[MAXPATHLEN], todir[MAXPATHLEN];
  287.  
  288.   XtPopdown(popups.copy);
  289.   strcpy(to, popups.copy_s);
  290.   fnexpand(to);
  291.  
  292.   if (chdir(popups.fw->directory))
  293.  
  294.     sysError("System error:");
  295.  
  296.   else {
  297.  
  298.     /* if target exists and is a directory, copy the source into that
  299.        directory */
  300.  
  301.     if (!stat(to, &stats) && S_ISDIR(stats.st_mode)) {
  302.  
  303.       if (chdir(to) || !getwd(to) || chdir(popups.fw->directory)) {
  304.     sysError("System error:");
  305.     goto out;
  306.       } else if (!strcmp(popups.fw->directory, to)) {
  307.     error("Copy:", "Source and destination are identical");
  308.     goto out;
  309.       }
  310.  
  311.       strcpy(todir, to);
  312.  
  313.       toi = strlen(to);
  314.       if (to[toi-1] != '/') {
  315.     to[toi++] = '/';
  316.     to[toi] = '\0';
  317.       }
  318.  
  319.       for (i=0; i < popups.fw->n_files; i++)
  320.     if (popups.fw->files[i]->selected) {
  321.       if (!strcmp(popups.fw->files[i]->name, ".") ||
  322.           !strcmp(popups.fw->files[i]->name, "..")) {
  323.         error("Cannot copy . or ..", "");
  324.         continue;
  325.       }
  326.       from = popups.fw->files[i]->name;
  327.       strcpy(to+toi, from);
  328.       if (exists(to) && resources.confirm_overwrite) {
  329.         char s[0xff];
  330.         sprintf(s, "Copy: file %s already exists at destination", from);
  331.         if (!confirm(s, "Overwrite?", ""))
  332.           if (aborted)
  333.         break;
  334.           else
  335.         continue;
  336.       }
  337.       if (rcopy(from,to)) {
  338.         char s[0xff];
  339.         sprintf(s, "Error copying %s:", from);
  340.         sysError(s);
  341.       } else
  342.         n_copied++;
  343.     }
  344.     }
  345.  
  346.     /* otherwise only a single file may be selected; copy it to the target
  347.        file */
  348.  
  349.     else if (popups.fw->n_selections > 1) {
  350.  
  351.       error("Copy: target for multiple files", "must be a folder");
  352.       goto out;
  353.  
  354.     } else {
  355.  
  356.       struct stat stats1;
  357.  
  358.       for (i = 0; i < popups.fw->n_files; i++)
  359.     if (popups.fw->files[i]->selected) {
  360.       from = popups.fw->files[i]->name;
  361.       break;
  362.     }
  363.  
  364.       if (!strcmp(from, ".") || !strcmp(from, "..")) {
  365.     error("Cannot copy . or ..", "");
  366.     goto out;
  367.       } else if (!lstat(to, &stats) && !lstat(from, &stats1) &&
  368.          stats.st_ino == stats1.st_ino) {
  369.     error("Copy:", "Source and destination are identical");
  370.     goto out;
  371.       }
  372.  
  373.       if (exists(to) && resources.confirm_overwrite) {
  374.     char s[0xff];
  375.     sprintf(s, "Copy: file %s already exists", to);
  376.     if (!confirm(s, "Overwrite?", ""))
  377.       goto out;
  378.       }
  379.  
  380.       if (rcopy(from, to)) {
  381.     char s[0xff];
  382.     sprintf(s, "Error copying %s:", from);
  383.     sysError(s);
  384.       } else {
  385.     n_copied = 1;
  386.     dir_prefix(todir, to);
  387.     if ((*todir?chdir(todir):0) || !getwd(todir))
  388.       sysError("System error:");
  389.       }
  390.     }
  391.  
  392.     if (n_copied) {
  393.       markForUpdate(todir);
  394.       intUpdate();
  395.     }
  396.  
  397.   }
  398.  
  399.  out:
  400.   freeze = False;
  401. }
  402.  
  403. /*---------------------------------------------------------------------------*/
  404.  
  405. static void copyCancelCb(Widget w, FileWindowRec *fw, 
  406.                XtPointer call_data)
  407. {
  408.   XtPopdown(popups.copy);
  409.   freeze = False;
  410. }
  411.  
  412. /*---------------------------------------------------------------------------*/
  413.  
  414. static void linkOkCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  415. {
  416.   struct stat stats;
  417.   int i, namei, toi, n_linked = 0;
  418.   char *from = NULL, name[MAXPATHLEN], to[MAXPATHLEN], todir[MAXPATHLEN];
  419.  
  420.   XtPopdown(popups.link);
  421.   strcpy(to, popups.link_s);
  422.   fnexpand(to);
  423.  
  424.   strcpy(name, popups.fw->directory);
  425.  
  426.   namei = strlen(name);
  427.   if (name[namei-1] != '/') {
  428.     name[namei++] = '/';
  429.     name[namei] = '\0';
  430.   }
  431.  
  432.   if (chdir(popups.fw->directory))
  433.  
  434.     sysError("System error:");
  435.  
  436.   else {
  437.  
  438.     /* if target exists and is a directory, link the source into that
  439.        directory */
  440.  
  441.     if (!stat(to, &stats) && S_ISDIR(stats.st_mode)) {
  442.  
  443.       if (chdir(to) || !getwd(to) || chdir(popups.fw->directory)) {
  444.     sysError("System error:");
  445.     goto out;
  446.       } else if (!strcmp(popups.fw->directory, to)) {
  447.     error("Link:", "Source and destination are identical");
  448.     goto out;
  449.       }
  450.  
  451.       strcpy(todir, to);
  452.  
  453.       toi = strlen(to);
  454.       if (to[toi-1] != '/') {
  455.     to[toi++] = '/';
  456.     to[toi] = '\0';
  457.       }
  458.  
  459.       for (i=0; i < popups.fw->n_files; i++)
  460.     if (popups.fw->files[i]->selected) {
  461.       from = popups.fw->files[i]->name;
  462.       strcpy(name+namei, from);
  463.       strcpy(to+toi, from);
  464.       if (exists(to) && resources.confirm_overwrite) {
  465.         char s[0xff];
  466.         sprintf(s, "Link: file %s already exists at destination", from);
  467.         if (!confirm(s, "Overwrite?", ""))
  468.           if (aborted)
  469.         break;
  470.           else
  471.         continue;
  472.       }
  473.       if (symlink(name,to)) {
  474.         char s[0xff];
  475.         sprintf(s, "Error linking %s:", from);
  476.         sysError(s);
  477.       } else
  478.         n_linked++;
  479.     }
  480.     }
  481.  
  482.     /* otherwise only a single file may be selected; link it to the target
  483.        file */
  484.  
  485.     else if (popups.fw->n_selections > 1) {
  486.  
  487.       error("Link: target for multiple files", "must be a folder");
  488.       goto out;
  489.  
  490.     } else {
  491.  
  492.       struct stat stats1;
  493.  
  494.       for (i = 0; i < popups.fw->n_files; i++)
  495.     if (popups.fw->files[i]->selected) {
  496.       from = popups.fw->files[i]->name;
  497.       break;
  498.     }
  499.  
  500.       strcpy(name+namei, from);
  501.  
  502.       if (!lstat(to, &stats) && !lstat(from, &stats1) &&
  503.          stats.st_ino == stats1.st_ino) {
  504.     error("Link:", "Source and destination are identical");
  505.     goto out;
  506.       }
  507.  
  508.       if (exists(to) && resources.confirm_overwrite) {
  509.     char s[0xff];
  510.     sprintf(s, "Link: file %s already exists", to);
  511.     if (!confirm(s, "Overwrite?", ""))
  512.       goto out;
  513.       }
  514.  
  515.       if (symlink(name, to)) {
  516.     char s[0xff];
  517.     sprintf(s, "Error linking %s:", from);
  518.     sysError(s);
  519.       } else {
  520.     n_linked = 1;
  521.     dir_prefix(todir, to);
  522.     if ((*todir?chdir(todir):0) || !getwd(todir))
  523.       sysError("System error:");
  524.       }
  525.     }
  526.  
  527.     if (n_linked) {
  528.       markForUpdate(todir);
  529.       intUpdate();
  530.     }
  531.  
  532.   }
  533.  
  534.  out:
  535.   freeze = False;
  536. }
  537.  
  538. /*---------------------------------------------------------------------------*/
  539.  
  540. static void linkCancelCb(Widget w, FileWindowRec *fw, 
  541.                XtPointer call_data)
  542. {
  543.   XtPopdown(popups.link);
  544.   freeze = False;
  545. }
  546.  
  547. /*---------------------------------------------------------------------------*/
  548.  
  549. /* The following variant of fnmatch matches the . and .. dirs only if
  550.    specified explicitly. */
  551.  
  552. #define fnmatchnodot(pattern,fn) (strcmp(fn,".")&&strcmp(fn,"..")? \
  553.                   fnmatch(pattern,fn):!strcmp(pattern,fn))
  554.  
  555. static void selectReplaceCb(Widget w, FileWindowRec *fw, 
  556.                 XtPointer call_data)
  557. {
  558.   int i;
  559.   Pixel pix;
  560.  
  561.   XtPopdown(popups.select);
  562.   popups.fw->n_selections = 0;
  563.   popups.fw->n_bytes_selected = 0;
  564.   for (i=0; i<popups.fw->n_files; i++) {
  565.     if (popups.fw->files[i]->icon.toggle) {
  566.       if (fnmatchnodot(popups.select_s, popups.fw->files[i]->name)) {
  567.     popups.fw->files[i]->selected = True;
  568.     popups.fw->n_selections++;
  569.     popups.fw->n_bytes_selected += popups.fw->files[i]->stats.st_size;
  570.       }
  571.       else
  572.     popups.fw->files[i]->selected = False;
  573.       XtVaGetValues(popups.fw->files[i]->icon.toggle,
  574.             popups.fw->files[i]->selected?XtNforeground:XtNbackground,
  575.             &pix, NULL);
  576.       XtVaSetValues(popups.fw->files[i]->icon.toggle, XtNborder,
  577.             (XtArgVal) pix, NULL);
  578.     }
  579.   }
  580.   updateStatus(popups.fw);
  581.   freeze = False;
  582. }
  583.  
  584. /*---------------------------------------------------------------------------*/
  585.  
  586. static void selectAddCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  587. {
  588.   int i;
  589.   Pixel pix;
  590.   
  591.   XtPopdown(popups.select);
  592.   for(i=0; i<popups.fw->n_files; i++)
  593.     if (popups.fw->files[i]->icon.toggle) {
  594.       if (!popups.fw->files[i]->selected && 
  595.       (fnmatchnodot(popups.select_s, popups.fw->files[i]->name))) {
  596.     popups.fw->files[i]->selected = True;
  597.     popups.fw->n_selections++;
  598.     popups.fw->n_bytes_selected += popups.fw->files[i]->stats.st_size;
  599.     XtVaGetValues(popups.fw->files[i]->icon.toggle, XtNforeground, &pix,
  600.               NULL);
  601.     XtVaSetValues(popups.fw->files[i]->icon.toggle, XtNborder,
  602.               (XtArgVal) pix, NULL);
  603.       }
  604.     }
  605.   updateStatus(popups.fw);
  606.   freeze = False;
  607. }
  608.  
  609. /*---------------------------------------------------------------------------*/
  610.  
  611. static void selectRemoveCb(Widget w, FileWindowRec *fw, XtPointer call_data)
  612. {
  613.   int i;
  614.   Pixel pix;
  615.   
  616.   XtPopdown(popups.select);
  617.   for(i=0; i<popups.fw->n_files; i++)
  618.     if (popups.fw->files[i]->icon.toggle) {
  619.       if (popups.fw->files[i]->selected && 
  620.       (fnmatch(popups.select_s, popups.fw->files[i]->name))) {
  621.     popups.fw->files[i]->selected = False;
  622.     popups.fw->n_selections--;
  623.     popups.fw->n_bytes_selected -= popups.fw->files[i]->stats.st_size;
  624.     XtVaGetValues(popups.fw->files[i]->icon.toggle, XtNbackground, &pix,
  625.               NULL);
  626.     XtVaSetValues(popups.fw->files[i]->icon.toggle, XtNborder,
  627.               (XtArgVal) pix, NULL);
  628.       }
  629.     }
  630.   updateStatus(popups.fw);
  631.   freeze = False;
  632. }
  633.  
  634. /*---------------------------------------------------------------------------*/
  635.  
  636. static void selectCancelCb(Widget w, FileWindowRec *fw, 
  637.                XtPointer call_data)
  638. {
  639.   XtPopdown(popups.select);
  640.   freeze = False;
  641. }
  642.  
  643. /*---------------------------------------------------------------------------*/
  644.  
  645. /* KMR */
  646. static void filterCancelCb(Widget w, FileWindowRec *fw, 
  647.                XtPointer call_data)
  648. {
  649.   XtPopdown(popups.filter);
  650.   freeze = False;
  651. }
  652.  
  653. /*---------------------------------------------------------------------------*/
  654.  
  655. /* KMR */
  656. static void filterOkCb(Widget w, FileWindowRec *fw, 
  657.                XtPointer call_data)
  658. {
  659.   XtPopdown(popups.filter);
  660.   popups.fw->do_filter = True;
  661.   strcpy(popups.fw->dirFilter,popups.filter_s);
  662.   updateFileDisplay(popups.fw);
  663.   freeze = False;
  664. }
  665.  
  666. /*---------------------------------------------------------------------------*/
  667.  
  668. /* KMR */
  669. static void filterClearCb(Widget w, FileWindowRec *fw, 
  670.                XtPointer call_data)
  671. {
  672.   XtPopdown(popups.filter);
  673.   popups.fw->do_filter = False;
  674.   popups.fw->dirFilter[0] = '\0';
  675.   updateFileDisplay(popups.fw);
  676.   freeze = False;
  677. }
  678.  
  679. /*---------------------------------------------------------------------------
  680.   Button information for popups
  681. ---------------------------------------------------------------------------*/
  682.  
  683. static ButtonRec mkdir_buttons[] = {
  684.   { "ok", "Ok", mkdirOkCb },
  685.   { "cancel", "Cancel", mkdirCancelCb }
  686. };
  687.  
  688. static ButtonRec createFile_buttons[] = {
  689.   { "ok", "Ok", createFileOkCb },
  690.   { "cancel", "Cancel", createFileCancelCb }
  691. };
  692.  
  693. static ButtonRec goTo_buttons[] = {
  694.   { "ok", "Ok", goToOkCb },
  695.   { "cancel", "Cancel", goToCancelCb }
  696. };
  697.  
  698. static ButtonRec move_buttons[] = {
  699.   { "ok", "Ok", moveOkCb },
  700.   { "cancel", "Cancel", moveCancelCb }
  701. };
  702.  
  703. static ButtonRec copy_buttons[] = {
  704.   { "ok", "Ok", copyOkCb },
  705.   { "cancel", "Cancel", copyCancelCb }
  706. };
  707.  
  708. static ButtonRec link_buttons[] = {
  709.   { "ok", "Ok", linkOkCb },
  710.   { "cancel", "Cancel", linkCancelCb }
  711. };
  712.  
  713. static ButtonRec select_buttons[] = {
  714.   { "replace", "Replace", selectReplaceCb },
  715.   { "add", "Add", selectAddCb },
  716.   { "remove", "Remove", selectRemoveCb },
  717.   { "cancel", "Cancel", selectCancelCb }
  718. };
  719.  
  720. static ButtonRec filter_buttons[] = {       /* KMR */
  721.   { "ok", "Ok", filterOkCb },
  722.   { "clear", "Clear", filterClearCb },
  723.   { "cancel", "Cancel", filterCancelCb }
  724. }; 
  725.  
  726. /*---------------------------------------------------------------------------
  727.   Question information for popups
  728. ---------------------------------------------------------------------------*/
  729.  
  730. static QuestionRec mkdir_questions[] = {
  731.   { "Create folder:", popups.mkdir_s, MAXPATHLEN, NULL }
  732. };
  733.  
  734. static QuestionRec createFile_questions[] = {
  735.   { "Create file:", popups.createFile_s, MAXPATHLEN, NULL }
  736. };
  737.  
  738. static QuestionRec goTo_questions[] = {
  739.   { "Go to folder:", popups.goTo_s, MAXPATHLEN, NULL }
  740. };
  741.  
  742. static QuestionRec move_questions[] = {
  743.   { "Move to:", popups.move_s, MAXPATHLEN, NULL }
  744. };
  745.  
  746. static QuestionRec copy_questions[] = {
  747.   { "Copy to:", popups.copy_s, MAXPATHLEN, NULL }
  748. };
  749.  
  750. static QuestionRec link_questions[] = {
  751.   { "Link to:", popups.link_s, MAXPATHLEN, NULL }
  752. };
  753.  
  754. static QuestionRec select_questions[] = {
  755.   { "Filename pattern:", popups.select_s, MAXPATHLEN, NULL }
  756. };
  757.  
  758. static QuestionRec filter_questions[] = {             /* KMR */
  759.   { "Filename pattern:", popups.filter_s, MAXPATHLEN, NULL }
  760. };
  761.  
  762. /*---------------------------------------------------------------------------
  763.   PUBLIC FUNCTIONS
  764. ---------------------------------------------------------------------------*/
  765.  
  766. void createMainPopups()
  767. {
  768.   /* New Folder */
  769.   popups.mkdir = createPopupQuestions("mkdir", "New Folder", bm[DIR_BM], 
  770.                    mkdir_questions, XtNumber(mkdir_questions),
  771.                    mkdir_buttons, XtNumber(mkdir_buttons) );
  772.  
  773.   /* New File */
  774.   popups.createFile = createPopupQuestions("create", "New File", bm[FILE_BM],
  775.                    createFile_questions,
  776.                    XtNumber(createFile_questions),
  777.                    createFile_buttons,
  778.                    XtNumber(createFile_buttons) );
  779.  
  780.   /* Change current folder */
  781.   popups.goTo = createPopupQuestions("goto", "Go To", bm[DIR_BM],
  782.                    goTo_questions, XtNumber(goTo_questions),
  783.                    goTo_buttons, XtNumber(goTo_buttons) );
  784.  
  785.   /* Move file */
  786.   popups.move = createPopupQuestions("move", "Move", bm[FILES_BM], 
  787.                    move_questions, XtNumber(move_questions),
  788.                    move_buttons, XtNumber(move_buttons) );
  789.  
  790.   /* Copy file */
  791.   popups.copy = createPopupQuestions("copy", "Copy", bm[FILES_BM],
  792.                    copy_questions, XtNumber(copy_questions),
  793.                    copy_buttons, XtNumber(copy_buttons) );
  794.  
  795.   /* Create link */
  796.   popups.link = createPopupQuestions("link", "Link", bm[SYMLNK_BM],
  797.                    link_questions, XtNumber(link_questions),
  798.                    link_buttons, XtNumber(link_buttons) );
  799.  
  800.   /* Select */
  801.   popups.select = createPopupQuestions("select", "Select", bm[FILES_BM],
  802.                    select_questions, XtNumber(select_questions),
  803.                    select_buttons, XtNumber(select_buttons) );
  804.  
  805.   /* Filter */  /* KMR */
  806.   popups.filter = createPopupQuestions("filter", "Filter", bm[FILES_BM],
  807.                    filter_questions, XtNumber(filter_questions),
  808.                    filter_buttons, XtNumber(filter_buttons) );
  809.  
  810.   /* Change Access Mode */
  811.   createChmodPopup();
  812.  
  813.   /* Info */
  814.   createInfoPopup();
  815.  
  816.   /* Errors */
  817.   createErrorPopup();
  818.  
  819.   /* Deletions */
  820.   createConfirmPopup();
  821. }
  822.  
  823. /*---------------------------------------------------------------------------*/ 
  824.  
  825. void selectPopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  826. {
  827.   popups.fw = fw;
  828.   XtVaSetValues(select_questions[0].widget, XtNstring, 
  829.         (XtArgVal) popups.select_s, NULL);
  830.   freeze = True;
  831.   popupByCursor(popups.select, XtGrabExclusive);
  832. }
  833.  
  834. /*---------------------------------------------------------------------------*/ 
  835.  
  836. /* KMR */
  837. void filterPopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  838. {
  839.   popups.fw = fw;
  840.   strcpy(popups.filter_s,fw->dirFilter);
  841.   XtVaSetValues(filter_questions[0].widget, XtNstring, 
  842.         (XtArgVal) popups.filter_s, NULL);
  843.   freeze = True;
  844.   popupByCursor(popups.filter, XtGrabExclusive);
  845. }
  846.  
  847. /*---------------------------------------------------------------------------*/
  848.  
  849. void mkdirPopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  850. {
  851.   popups.fw = fw;
  852.   XtVaSetValues(mkdir_questions[0].widget, XtNstring, 
  853.         (XtArgVal) popups.mkdir_s, NULL);
  854.   freeze = True;
  855.   popupByCursor(popups.mkdir, XtGrabExclusive);
  856. }
  857.  
  858. /*---------------------------------------------------------------------------*/
  859.  
  860. void createFilePopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  861. {
  862.   popups.fw = fw;
  863.   XtVaSetValues(createFile_questions[0].widget, XtNstring, 
  864.         (XtArgVal) popups.createFile_s, NULL);
  865.   freeze = True;
  866.   popupByCursor(popups.createFile, XtGrabExclusive);
  867. }
  868.  
  869. /*---------------------------------------------------------------------------*/
  870.  
  871. void goToPopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  872. {
  873.   popups.fw = fw;
  874.   XtVaSetValues(goTo_questions[0].widget, XtNstring, 
  875.         (XtArgVal) popups.goTo_s, NULL);
  876.   freeze = True;
  877.   popupByCursor(popups.goTo, XtGrabExclusive);
  878. }
  879.  
  880. /*---------------------------------------------------------------------------*/
  881.  
  882. void movePopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  883. {
  884.   if (fw == NULL) fw = popup_fw;
  885.  
  886.   if (!fw->n_selections) return;
  887.  
  888.   popups.fw = fw;
  889.   XtVaSetValues(move_questions[0].widget, XtNstring, 
  890.         (XtArgVal) popups.move_s, NULL);
  891.   freeze = True;
  892.   popupByCursor(popups.move, XtGrabExclusive);
  893. }
  894.  
  895. /*---------------------------------------------------------------------------*/
  896.  
  897. void copyPopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  898. {
  899.   if (fw == NULL) fw = popup_fw;
  900.  
  901.   if (!fw->n_selections) return;
  902.  
  903.   popups.fw = fw;
  904.   XtVaSetValues(copy_questions[0].widget, XtNstring, 
  905.         (XtArgVal) popups.copy_s, NULL);
  906.   freeze = True;
  907.   popupByCursor(popups.copy, XtGrabExclusive);
  908. }
  909.  
  910. /*---------------------------------------------------------------------------*/
  911.  
  912. void linkPopup(Widget w, FileWindowRec *fw, XtPointer call_data)
  913. {
  914.   if (fw == NULL) fw = popup_fw;
  915.  
  916.   if (!fw->n_selections) return;
  917.  
  918.   popups.fw = fw;
  919.   XtVaSetValues(link_questions[0].widget, XtNstring, 
  920.         (XtArgVal) popups.link_s, NULL);
  921.   freeze = True;
  922.   popupByCursor(popups.link, XtGrabExclusive);
  923. }
  924.