Subversion Repositories Kolibri OS

Rev

Rev 9536 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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