Subversion Repositories Kolibri OS

Rev

Rev 8943 | Rev 8949 | 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.         BDVK file_info_count;
  28.         DIR_SIZE paste_dir_size;
  29.  
  30.         GetFileInfo(_in_path, #file_info_count);
  31.         if ( file_info_count.isfolder ) {
  32.                 return paste_dir_size.get(_in_path);
  33.         } else {
  34.                 return 1;
  35.         }
  36. }
  37.  
  38. //===================================================//
  39. //                                                   //
  40. //                  COPY AND PASTE                   //
  41. //                                                   //
  42. //===================================================//
  43. byte copy_to[4096];
  44. byte copy_from[4096];
  45. bool cut_active = false;
  46.  
  47. enum {COPY, CUT, DELETE};
  48.  
  49. void CopyFilesListToClipboard(bool _cut_active)
  50. {
  51.         byte copy_t[4096];
  52.         dword buff_data;
  53.         dword path_len = 0;
  54.         dword size_buf = 0;
  55.         dword copy_buf_offset = 0;
  56.         dword i;
  57.  
  58.         if (files.count<=0) return; //no files
  59.  
  60.         if (_cut_active!=DELETE) cut_active = _cut_active;
  61.  
  62.         //if no element selected by "Insert" key, then we copy current element
  63.         if (!selected_count) {
  64.                 setElementSelectedFlag(files.cur_y, true);
  65.         }
  66.  
  67.         if (!selected_count) return;
  68.        
  69.         size_buf = 10;
  70.         for (i=0; i<files.count; i++)
  71.         {
  72.                 if (getElementSelectedFlag(i) == true) {
  73.                         sprintf(#copy_t,"%s/%s",#path,items.get(i)*304+buf+72);
  74.                         path_len = strlen(#copy_t);
  75.                         size_buf += path_len + 1;
  76.                 }
  77.         }
  78.         buff_data = malloc(size_buf);
  79.         ESDWORD[buff_data] = size_buf;
  80.         ESDWORD[buff_data+4] = SLOT_DATA_TYPE_RAW;
  81.         ESINT[buff_data+8] = selected_count;
  82.         copy_buf_offset = buff_data + 10;
  83.         for (i=0; i<files.count; i++)
  84.         {
  85.                 if (getElementSelectedFlag(i) == true) {
  86.                         sprintf(copy_buf_offset,"%s/%s",#path,items.get(i)*304+buf+72);
  87.                         copy_buf_offset += strlen(copy_buf_offset) + 1;
  88.  
  89.                         if (cut_active) {
  90.                                 if (i>=files.first) && (i<files.first+files.visible)
  91.                                         PutShadow(files.x+4,i-files.first*files.item_h+files.y,icons16_default.w,files.item_h,1,-3);
  92.                         }
  93.                 }
  94.         }
  95.         if (cut_active) {
  96.                 pause(20);
  97.                 List_ReDraw();
  98.         }
  99.         if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
  100.         Clipboard__SetSlotData(size_buf, buff_data);
  101.         free(buff_data);
  102. }
  103.  
  104.  
  105. void PasteThread()
  106. {
  107.         char copy_rezult;
  108.         int j, i, slash_count=0;
  109.         int paste_elements_count = 0;
  110.         dword buf;
  111.         dword path_offset;
  112.        
  113.         buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  114.         if (DSDWORD[buf+4] != 3) return;
  115.         paste_elements_count = ESINT[buf+8];
  116.         path_offset = buf + 10;
  117.  
  118.         if (cut_active) {
  119.                 DisplayOperationForm(MOVE_FLAG);
  120.         } else {
  121.                 DisplayOperationForm(COPY_FLAG);       
  122.         }
  123.  
  124.         if (cut_active) {
  125.                 for (j = 0; j < paste_elements_count; j++) {
  126.                         sprintf(#copy_to, "%s/%s", #path, path_offset+strrchr(path_offset,'/'));
  127.                         slash_count = 0;
  128.                         for (i=0; i<=10; i++) {
  129.                                 if (copy_to[i]=='/') slash_count++;
  130.                                 if (slash_count==3) break;
  131.                         }
  132.                         if (strncmp(#copy_to, path_offset, i)!=0) goto _DIFFERENT_DRIVES;
  133.                         RenameMove(#copy_to+i, path_offset);
  134.                         if (EAX!=0) goto _DIFFERENT_DRIVES;
  135.                         path_offset += strlen(path_offset) + 1;
  136.                 }
  137.                 DialogExit();
  138.         }
  139.  
  140. _DIFFERENT_DRIVES:
  141.         path_offset = buf + 10;
  142.         for (j = 0; j < paste_elements_count; j++) {
  143.                 copy_bar.max += GetFilesCount(path_offset);
  144.                 path_offset += strlen(path_offset) + 1;
  145.         }
  146.        
  147.         path_offset = buf + 10;
  148.         for (j = 0; j < paste_elements_count; j++) {
  149.                 strcpy(#copy_from, path_offset);
  150.                 if (!copy_from) DialogExit();
  151.                 sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
  152.                 if (streq(#copy_from,#copy_to))
  153.                 {
  154.                         if (cut_active) continue;
  155.                         sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
  156.                 }
  157.                 if (strstr(#copy_to, #copy_from))
  158.                 {
  159.                         notify("'Not possible to copy directory into itself.\nProcess terminated.' -E");
  160.                         DialogExit();
  161.                 }
  162.  
  163.                 if (copy_rezult = copyf(#copy_from,#copy_to))
  164.                 {
  165.                         Write_Error(copy_rezult);
  166.                         if (copy_rezult==8) DialogExit(); //not enough space
  167.                 }
  168.                 else if (cut_active)
  169.                 {
  170.                         strcpy(#file_path, #copy_from);
  171.                         RecursiveDelete(#copy_from, false);
  172.                        
  173.                 }
  174.                 path_offset += strlen(path_offset) + 1;
  175.         }
  176.         DialogExit();
  177. }
  178.  
  179.  
  180. //===================================================//
  181. //                                                   //
  182. //                     DELETE                        //
  183. //                                                   //
  184. //===================================================//
  185.  
  186. int del_error;
  187. int RecursiveDelete(dword way, bool show_progress)
  188. {    
  189.         dword dirbuf, fcount, i, filename;
  190.         int error;
  191.         char del_from[4096];
  192.         if (dir_exists(way))
  193.         {
  194.                 if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
  195.                 for (i=0; i<fcount; i++)
  196.                 {
  197.                         //if (CheckEvent()==evReDraw) draw_window();
  198.                         filename = i*304+dirbuf+72;
  199.                         sprintf(#del_from,"%s/%s",way,filename);
  200.                         if ( ESDWORD[filename-40] & ATR_FOLDER ) {
  201.                                 RecursiveDelete(#del_from, true);
  202.                         } else {
  203.                                 if (show_progress) Operation_Draw_Progress(filename);
  204.                                 if (error = DeleteFile(#del_from)) del_error = error;
  205.                         }
  206.                 }
  207.         }
  208.         if (error = DeleteFile(way)) del_error = error;
  209. }
  210.  
  211. void DeleteThread()
  212. {
  213.         int j;
  214.         int elements_count = 0;
  215.         dword buf;
  216.         dword path_offset;
  217.  
  218.         DisplayOperationForm(DELETE_FLAG);
  219.        
  220.         buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  221.         Clipboard__DeleteLastSlot();
  222.         if (DSDWORD[buf+4] != 3) return;
  223.         elements_count = ESINT[buf+8];
  224.  
  225.         path_offset = buf + 10;
  226.         for (j = 0; j < elements_count; j++) {
  227.                 copy_bar.max += GetFilesCount(path_offset);
  228.                 path_offset += strlen(path_offset) + 1;
  229.         }
  230.        
  231.         path_offset = buf + 10;
  232.         for (j = 0; j < elements_count; j++) {
  233.                 RecursiveDelete(path_offset, true);
  234.                 path_offset += strlen(path_offset) + 1;
  235.         }
  236.         if (del_error) Write_Error(del_error);
  237.         DialogExit();
  238. }