Subversion Repositories Kolibri OS

Rev

Rev 8995 | Rev 9536 | Go to most recent revision | 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.         dword copy_state_ex = 0;
  128.        
  129.         clipbuf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  130.         if (DSDWORD[clipbuf+4] != 3) return;
  131.         paste_elements_count = ESINT[clipbuf+8];
  132.         path_offset = clipbuf + 10;
  133.  
  134.         if (cut_active) {
  135.                 DisplayOperationForm(MOVE_FLAG);
  136.         } else {
  137.                 DisplayOperationForm(COPY_FLAG);       
  138.         }
  139.  
  140.         if (cut_active) {
  141.                 for (j = 0; j < paste_elements_count; j++) {
  142.                         sprintf(#copy_to, "%s/%s", path, path_offset+strrchr(path_offset,'/'));
  143.                         slash_count = 0;
  144.                         for (i=0; i<=10; i++) {
  145.                                 if (copy_to[i]=='/') slash_count++;
  146.                                 if (slash_count==3) break;
  147.                         }
  148.                         if (strncmp(#copy_to, path_offset, i)!=0) goto _DIFFERENT_DRIVES;
  149.                         RenameMove(#copy_to+i, path_offset);
  150.                         if (EAX!=0) goto _DIFFERENT_DRIVES;
  151.                         path_offset += strlen(path_offset) + 1;
  152.                 }
  153.                 DialogExit();
  154.         }
  155.  
  156. _DIFFERENT_DRIVES:
  157.         path_offset = clipbuf + 10;
  158.         for (j = 0; j < paste_elements_count; j++) {
  159.                 copy_bar.max += GetFilesCount(path_offset);
  160.                 path_offset += strlen(path_offset) + 1;
  161.         }
  162.        
  163.         path_offset = clipbuf + 10;
  164.         copy_state = FILE_DEFAULT;
  165.         saved_state = FILE_DEFAULT;
  166.         for (j = 0; j < paste_elements_count; j++) {
  167.                 strcpy(#copy_from, path_offset);
  168.                 if (!copy_from) DialogExit();
  169.                 sprintf(#copy_to, "%s/%s", path, #copy_from+strrchr(#copy_from,'/'));
  170.                 if (streq(#copy_from,#copy_to))
  171.                 {
  172.                         if (cut_active) continue;
  173.                         sprintf(#copy_to, "%s/NEW_%s", path, #copy_from+strrchr(#copy_from,'/'));
  174.                 }
  175.                 if (strstr(#copy_to, #copy_from))
  176.                 {
  177.                         notify("'Not possible to copy directory into itself.\nProcess terminated.' -E");
  178.                         DialogExit();
  179.                 }
  180.  
  181.                 if (copy_rezult = copyf(#copy_from,#copy_to))
  182.                 {
  183.                         Write_Error(copy_rezult);
  184.                         if (copy_rezult==8) DialogExit(); //not enough space
  185.                 }
  186.                 else if (cut_active)
  187.                 {
  188.                         strcpy(#file_path, #copy_from);
  189.                         RecursiveDelete(#copy_from, false);
  190.                        
  191.                 }
  192.                 path_offset += strlen(path_offset) + 1;
  193.         }
  194.         DialogExit();
  195. }
  196.  
  197.  
  198. //===================================================//
  199. //                                                   //
  200. //                     DELETE                        //
  201. //                                                   //
  202. //===================================================//
  203.  
  204. int del_error;
  205. int RecursiveDelete(dword way, bool show_progress)
  206. {    
  207.         dword dirbuf, fcount, i, filename;
  208.         int error;
  209.         char del_from[4096];
  210.         if (dir_exists(way))
  211.         {
  212.                 if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
  213.                 for (i=0; i<fcount; i++)
  214.                 {
  215.                         //if (CheckEvent()==evReDraw) draw_window();
  216.                         filename = i*304+dirbuf+72;
  217.                         sprintf(#del_from,"%s/%s",way,filename);
  218.                         if ( ESDWORD[filename-40] & ATR_FOLDER ) {
  219.                                 RecursiveDelete(#del_from, true);
  220.                         } else {
  221.                                 if (show_progress) Operation_Draw_Progress(filename);
  222.                                 if (error = DeleteFile(#del_from)) del_error = error;
  223.                         }
  224.                 }
  225.         }
  226.         if (error = DeleteFile(way)) del_error = error;
  227. }
  228.  
  229. void DeleteThread()
  230. {
  231.         int j;
  232.         int elements_count = 0;
  233.         dword clipbuf;
  234.         dword path_offset;
  235.  
  236.         DisplayOperationForm(DELETE_FLAG);
  237.        
  238.         clipbuf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  239.         Clipboard__DeleteLastSlot();
  240.         if (DSDWORD[clipbuf+4] != 3) return;
  241.         elements_count = ESINT[clipbuf+8];
  242.  
  243.         path_offset = clipbuf + 10;
  244.         for (j = 0; j < elements_count; j++) {
  245.                 copy_bar.max += GetFilesCount(path_offset);
  246.                 path_offset += strlen(path_offset) + 1;
  247.         }
  248.        
  249.         path_offset = clipbuf + 10;
  250.         for (j = 0; j < elements_count; j++) {
  251.                 RecursiveDelete(path_offset, true);
  252.                 path_offset += strlen(path_offset) + 1;
  253.         }
  254.         if (del_error) Write_Error(del_error);
  255.         DialogExit();
  256. }