Subversion Repositories Kolibri OS

Rev

Rev 7972 | Rev 7999 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. //===================================================//
  3. //                                                   //
  4. //                   MASS ACTIONS                    //
  5. //                                                   //
  6. //===================================================//
  7.  
  8. void setElementSelectedFlag(dword n, int state) {
  9.         dword selected_offset = items.get(n)*304 + buf+32 + 7;
  10.         ESBYTE[selected_offset] = state;
  11.         if (n==0) && (strncmp(items.get(n)*304+buf+72,"..",2)==0) {
  12.                 ESBYTE[selected_offset] = false; //do not selec ".." directory
  13.                 return;
  14.         }
  15.         if (state==true) selected_count++;
  16.         if (state==false) selected_count--;
  17.         if (selected_count<0) selected_count=0;
  18. }
  19.  
  20. int getElementSelectedFlag(dword n) {
  21.         dword selected_offset = items.get(n)*304 + buf+32 + 7;
  22.         return ESBYTE[selected_offset];
  23. }
  24.  
  25. dword GetFilesCount(dword _in_path)
  26. {
  27.         int j;
  28.         BDVK file_info_count;
  29.         DIR_SIZE paste_dir_size;
  30.  
  31.         GetFileInfo(_in_path, #file_info_count);
  32.         if ( file_info_count.isfolder ) {
  33.                 return paste_dir_size.get(_in_path);
  34.         } else {
  35.                 return 1;
  36.         }
  37. }
  38.  
  39. //===================================================//
  40. //                                                   //
  41. //                  COPY AND PASTE                   //
  42. //                                                   //
  43. //===================================================//
  44. byte copy_to[4096];
  45. byte copy_from[4096];
  46. bool cut_active = false;
  47.  
  48. enum {NOCUT, CUT};
  49.  
  50. void EventCopy(bool _cut_active)
  51. {
  52.         byte copy_t[4096];
  53.         dword buff_data;
  54.         dword path_len = 0;
  55.         dword size_buf = 0;
  56.         dword copy_buf_offset = 0;
  57.         dword i;
  58.  
  59.         if (files.count<=0) return; //no files
  60.  
  61.         cut_active = _cut_active;
  62.  
  63.         //if no element selected by "Insert" key, then we copy current element
  64.         if (!selected_count) {
  65.                 setElementSelectedFlag(files.cur_y, true);
  66.         }
  67.  
  68.         if (!selected_count) return;
  69.        
  70.         size_buf = 4;
  71.         for (i=0; i<files.count; i++)
  72.         {
  73.                 if (getElementSelectedFlag(i) == true) {
  74.                         sprintf(#copy_t,"%s/%s",#path,items.get(i)*304+buf+72);
  75.                         path_len = strlen(#copy_t);
  76.                         size_buf += path_len + 1;
  77.                 }
  78.         }
  79.         size_buf += 20;
  80.         buff_data = malloc(size_buf);
  81.         ESDWORD[buff_data] = size_buf;
  82.         ESDWORD[buff_data+4] = SLOT_DATA_TYPE_RAW;
  83.         ESINT[buff_data+8] = selected_count;
  84.         copy_buf_offset = buff_data + 10;
  85.         for (i=0; i<files.count; i++)
  86.         {
  87.                 if (getElementSelectedFlag(i) == true) {
  88.                         sprintf(copy_buf_offset,"%s/%s",#path,items.get(i)*304+buf+72);
  89.                         copy_buf_offset += strlen(copy_buf_offset) + 1;
  90.  
  91.                         setElementSelectedFlag(i, false);
  92.  
  93.                         if (cut_active) {
  94.                                 if (i>=files.first) && (i<files.first+files.visible)
  95.                                         PutShadow(files.x+4,i-files.first*files.item_h+files.y,16,files.item_h,1,-3);
  96.                         }
  97.                 }
  98.         }
  99.         if (cut_active) {
  100.                 pause(20);
  101.                 List_ReDraw();         
  102.         }
  103.         if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
  104.         Clipboard__SetSlotData(size_buf, buff_data);
  105.         free(buff_data);
  106. }
  107.  
  108.  
  109. void PasteThread()
  110. {
  111.         char copy_rezult;
  112.         int j;
  113.         int paste_elements_count = 0;
  114.         dword buf;
  115.         dword path_offset;
  116.        
  117.         buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  118.         if (DSDWORD[buf+4] != 3) return;
  119.         paste_elements_count = ESINT[buf+8];
  120.         path_offset = buf + 10;
  121.  
  122.         if (cut_active) {
  123.                 DisplayOperationForm(MOVE_FLAG);
  124.         } else {
  125.                 DisplayOperationForm(COPY_FLAG);       
  126.         }
  127.  
  128.         for (j = 0; j < paste_elements_count; j++) {
  129.                 copy_bar.max += GetFilesCount(path_offset);
  130.                 path_offset += strlen(path_offset) + 1;
  131.         }
  132.        
  133.         path_offset = buf + 10;
  134.         for (j = 0; j < paste_elements_count; j++) {
  135.                 strcpy(#copy_from, path_offset);
  136.                 if (!copy_from) DialogExit();
  137.                 sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
  138.                 if (!strcmp(#copy_from,#copy_to))
  139.                 {
  140.                         sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
  141.                 }
  142.                 if (strstr(#copy_to, #copy_from))
  143.                 {
  144.                         notify("Copy directory into itself is a bad idea...");
  145.                         DialogExit();
  146.                 }
  147.  
  148.                 if (copy_rezult = copyf(#copy_from,#copy_to))
  149.                 {
  150.                         Write_Error(copy_rezult);
  151.                         if (copy_rezult==8) DialogExit(); //not enough space
  152.                 }
  153.                 else if (cut_active)
  154.                 {
  155.                         strcpy(#file_path, #copy_from);
  156.                         Del_File2(#copy_from, 0);
  157.                        
  158.                 }
  159.                 path_offset += strlen(path_offset) + 1;
  160.         }
  161.         cut_active=false;
  162.         if (info_after_copy.checked) notify(INFO_AFTER_COPY);
  163.         DialogExit();
  164. }
  165.  
  166.  
  167. //===================================================//
  168. //                                                   //
  169. //                     DELETE                        //
  170. //                                                   //
  171. //===================================================//
  172.  
  173. int del_error;
  174. int Del_File2(dword way, sh_progr)
  175. {    
  176.         dword dirbuf, fcount, i, filename;
  177.         int error;
  178.         char del_from[4096];
  179.         if (dir_exists(way))
  180.         {
  181.                 if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
  182.                 for (i=0; i<fcount; i++)
  183.                 {
  184.                         //if (CheckEvent()==evReDraw) draw_window();
  185.                         filename = i*304+dirbuf+72;
  186.                         sprintf(#del_from,"%s/%s",way,filename);
  187.                         if ( TestBit(ESDWORD[filename-40], 4) )
  188.                         {
  189.                                 Del_File2(#del_from, 1);
  190.                         }
  191.                         else
  192.                         {
  193.                                 if (sh_progr) Operation_Draw_Progress(filename);
  194.                                 if (error = DeleteFile(#del_from)) del_error = error;
  195.                         }
  196.                 }
  197.         }
  198.         if (error = DeleteFile(way)) del_error = error;
  199. }
  200.  
  201. void DeleteSingleElement()
  202. {  
  203.         DIR_SIZE delete_dir_size;
  204.         del_error = NULL;
  205.        
  206.         if (itdir) {
  207.                 copy_bar.max = delete_dir_size.get(#file_path);
  208.         } else {
  209.                 copy_bar.max = 1;
  210.         }
  211.        
  212.         Del_File2(#file_path, 1);                      
  213.  
  214.         if (del_error) Write_Error(del_error);
  215.         DialogExit();
  216. }
  217.  
  218. void DeleteSelectedElements()
  219. {  
  220.         byte del_from[4096];
  221.         int i;
  222.  
  223.         DisplayOperationForm(DELETE_FLAG);
  224.  
  225.         if (!selected_count) { DeleteSingleElement(); return; }
  226.        
  227.         for (i=0; i<files.count; i++)
  228.         {
  229.                 if (getElementSelectedFlag(i) == true) {
  230.                         sprintf(#del_from,"%s/%s",#path,items.get(i)*304+buf+72);
  231.                         copy_bar.max += GetFilesCount(#del_from);
  232.                 }
  233.         }      
  234.  
  235.         del_error = 0;
  236.  
  237.         for (i=0; i<files.count; i++)
  238.         {
  239.                 if (getElementSelectedFlag(i) == true) {
  240.                         sprintf(#del_from,"%s/%s", #path, items.get(i)*304+buf+72);
  241.                         Del_File2(#del_from, 1);
  242.                 }
  243.         }
  244.  
  245.         if (del_error) Write_Error(del_error);
  246.         cmd_free = 6;
  247.         DialogExit();
  248. }
  249.