home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFM / XFM-1.3 / XFM-1 / xfm-1.3 / xfm / FmDelete.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-02  |  2.8 KB  |  116 lines

  1. /*---------------------------------------------------------------------------
  2.   Module FmDelete
  3.  
  4.   (c) Simon Marlow 1990-92
  5.   (c) Albert Graef 1994
  6.  
  7.   Functions for implementing the delete and empty operations
  8. ---------------------------------------------------------------------------*/
  9.  
  10. #include <X11/Intrinsic.h>
  11.  
  12. #include "Fm.h"
  13.  
  14. void deleteItems(Widget w, FileWindowRec *fw, XtPointer call_data)
  15. {
  16.   char error_string[0xff];
  17.   int i, n_deleted = 0;
  18.  
  19.   if (fw == NULL) fw = popup_fw;
  20.  
  21.   if (!fw->n_selections) return;
  22.  
  23.   if (chdir(fw->directory)) {
  24.     sysError("System error:");
  25.     return;
  26.   }
  27.  
  28.   freeze = True;
  29.  
  30.   if (resources.confirm_deletes) {
  31.     sprintf(error_string, "Deleting %d item%s from", fw->n_selections,
  32.         fw->n_selections > 1 ? "s" : "" );
  33.     if (!confirm(error_string, fw->directory, ""))
  34.       goto out;
  35.   }
  36.  
  37.   for (i=0; i < fw->n_files; i++)
  38.     if (fw->files[i]->selected) {
  39.       if (!fw->files[i]->sym_link && S_ISDIR(fw->files[i]->stats.st_mode))
  40.     if (!strcmp(fw->files[i]->name, ".") ||
  41.         !strcmp(fw->files[i]->name, "..")) {
  42.       error("Cannot delete . or ..", "");
  43.       continue;
  44.     } else if (resources.confirm_delete_folder &&
  45.          !confirm("Do you REALLY wish to delete folder",
  46.               fw->files[i]->name,
  47.               "and ALL items contained in it?"))
  48.       if (aborted)
  49.         break;
  50.           else
  51.         continue;
  52.       if (rdel(fw->files[i]->name)) {
  53.     sprintf(error_string, "Error deleting %s:", fw->files[i]->name);
  54.     sysError(error_string);
  55.       } else
  56.     n_deleted++;
  57.     }
  58.  
  59.   if (n_deleted) {
  60.     markForUpdate(fw->directory);
  61.     intUpdate();
  62.   }
  63.  
  64.  out:
  65.   freeze = False;
  66. }
  67.  
  68. /*---------------------------------------------------------------------------*/
  69.  
  70. void emptyDir(Widget w, FileWindowRec *fw, XtPointer call_data)
  71. {
  72.   char error_string[0xff];
  73.   int i, n_deleted = 0;
  74.  
  75.   if (chdir(fw->directory)) {
  76.     sysError("System error:");
  77.     return;
  78.   }
  79.  
  80.   freeze = True;
  81.  
  82.   if (resources.confirm_deletes) {
  83.     int n_files = fw->display_type == Tree?fw->n_files-2:fw->n_files-1;
  84.  
  85.     sprintf(error_string, "Deleting %d item%s from", n_files,
  86.         n_files > 1 ? "s" : "" );
  87.     if (!confirm(error_string, fw->directory, ""))
  88.       goto out;
  89.   }
  90.  
  91.   for (i=0; i < fw->n_files; i++)
  92.     if (strcmp(fw->files[i]->name, ".") && strcmp(fw->files[i]->name, "..")) {
  93.       if (!fw->files[i]->sym_link && S_ISDIR(fw->files[i]->stats.st_mode) &&
  94.       resources.confirm_delete_folder &&
  95.       !confirm("Do you REALLY wish to delete folder", fw->files[i]->name,
  96.            "and ALL items contained in it?"))
  97.     if (aborted)
  98.       break;
  99.         else
  100.       continue;
  101.       if (rdel(fw->files[i]->name)) {
  102.     sprintf(error_string, "Error deleting %s:", fw->files[i]->name);
  103.     sysError(error_string);
  104.       } else
  105.     n_deleted++;
  106.     }
  107.  
  108.   if (n_deleted) {
  109.     markForUpdate(fw->directory);
  110.     intUpdate();
  111.   }
  112.  
  113.  out:
  114.   freeze = False;
  115. }
  116.