Subversion Repositories Kolibri OS

Rev

Rev 8952 | Rev 8995 | 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]--;
  30.         //if (selected_count[active_panel]<0) selected_count[active_panel]=0;
  31. }
  32.  
  33. int getElementSelectedFlag(dword n) {
  34.         if (active_panel) {
  35.                 return selected0.get(n);
  36.         } else {
  37.                 return selected1.get(n);
  38.         }
  39. }
  40.  
  41. dword GetFilesCount(dword _in_path)
  42. {
  43.         BDVK file_info_count;
  44.         DIR_SIZE paste_dir_size;
  45.  
  46.         GetFileInfo(_in_path, #file_info_count);
  47.         if ( file_info_count.isfolder ) {
  48.                 return paste_dir_size.get(_in_path);
  49.         } else {
  50.                 return 1;
  51.         }
  52. }
  53.  
  54. //===================================================//
  55. //                                                   //
  56. //                  COPY AND PASTE                   //
  57. //                                                   //
  58. //===================================================//
  59. byte copy_to[4096];
  60. byte copy_from[4096];
  61. bool cut_active = false;
  62.  
  63. enum {COPY, CUT, DELETE};
  64.  
  65. void CopyFilesListToClipboard(bool _cut_active)
  66. {
  67.         byte copy_t[4096];
  68.         dword buff_data;
  69.         dword path_len = 0;
  70.         dword size_buf = 0;
  71.         dword copy_buf_offset = 0;
  72.         dword i;
  73.  
  74.         if (files.count<=0) return; //no files
  75.  
  76.         if (_cut_active!=DELETE) cut_active = _cut_active;
  77.  
  78.         //if no element selected by "Insert" key, then we copy current element
  79.         if (!getSelectedCount()) {
  80.                 setElementSelectedFlag(files.cur_y, true);
  81.         }
  82.  
  83.         if (!getSelectedCount()) return;
  84.        
  85.         size_buf = 10;
  86.         for (i=0; i<files.count; i++)
  87.         {
  88.                 if (getElementSelectedFlag(i) == true) {
  89.                         sprintf(#copy_t,"%s/%s",path,items.get(i)*304+buf+72);
  90.                         path_len = strlen(#copy_t);
  91.                         size_buf += path_len + 1;
  92.                 }
  93.         }
  94.         buff_data = malloc(size_buf);
  95.         ESDWORD[buff_data] = size_buf;
  96.         ESDWORD[buff_data+4] = SLOT_DATA_TYPE_RAW;
  97.         ESINT[buff_data+8] = getSelectedCount();
  98.         copy_buf_offset = buff_data + 10;
  99.         for (i=0; i<files.count; i++)
  100.         {
  101.                 if (getElementSelectedFlag(i) == true) {
  102.                         sprintf(copy_buf_offset,"%s/%s",path,items.get(i)*304+buf+72);
  103.                         copy_buf_offset += strlen(copy_buf_offset) + 1;
  104.  
  105.                         if (cut_active) {
  106.                                 if (i>=files.first) && (i<files.first+files.visible)
  107.                                         PutShadow(files.x+4,i-files.first*files.item_h+files.y,icons16_default.w,files.item_h,1,-3);
  108.                         }
  109.                 }
  110.         }
  111.         if (cut_active) {
  112.                 pause(20);
  113.                 List_ReDraw();
  114.         }
  115.         if (getSelectedCount()==1) setElementSelectedFlag(files.cur_y, false);
  116.         Clipboard__SetSlotData(size_buf, buff_data);
  117.         free(buff_data);
  118. }
  119.  
  120.  
  121. void PasteThread()
  122. {
  123.         char copy_rezult;
  124.         int j, i, slash_count=0;
  125.         int paste_elements_count = 0;
  126.         dword clipbuf;
  127.         dword path_offset;
  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.         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. }