Subversion Repositories Kolibri OS

Rev

Rev 7878 | 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.         }
  92.         if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
  93.         Clipboard__SetSlotData(size_buf, buff_data);
  94.         free(buff_data);
  95. }
  96.  
  97.  
  98. void PasteThread()
  99. {
  100.         char copy_rezult;
  101.         int j;
  102.         int paste_elements_count = 0;
  103.         dword buf;
  104.         dword path_offset;
  105.        
  106.         buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  107.         if (DSDWORD[buf+4] != 3) return;
  108.         paste_elements_count = ESINT[buf+8];
  109.         path_offset = buf + 10;
  110.  
  111.         if (cut_active) {
  112.                 DisplayOperationForm(MOVE_FLAG);
  113.         } else {
  114.                 DisplayOperationForm(COPY_FLAG);       
  115.         }
  116.  
  117.         for (j = 0; j < paste_elements_count; j++) {
  118.                 copy_bar.max += GetFilesCount(path_offset);
  119.                 path_offset += strlen(path_offset) + 1;
  120.         }
  121.        
  122.         path_offset = buf + 10;
  123.         for (j = 0; j < paste_elements_count; j++) {
  124.                 strcpy(#copy_from, path_offset);
  125.                 if (!copy_from) DialogExit();
  126.                 sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
  127.                 if (!strcmp(#copy_from,#copy_to))
  128.                 {
  129.                         sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
  130.                 }
  131.                 if (strstr(#copy_to, #copy_from))
  132.                 {
  133.                         notify("Copy directory into itself is a bad idea...");
  134.                         DialogExit();
  135.                 }
  136.  
  137.                 if (copy_rezult = copyf(#copy_from,#copy_to))
  138.                 {
  139.                         Write_Error(copy_rezult);
  140.                         if (copy_rezult==8) DialogExit(); //not enough space
  141.                 }
  142.                 else if (cut_active)
  143.                 {
  144.                         strcpy(#file_path, #copy_from);
  145.                         Del_File2(#copy_from, 0);
  146.                        
  147.                 }
  148.                 path_offset += strlen(path_offset) + 1;
  149.         }
  150.         cut_active=false;
  151.         if (info_after_copy.checked) notify(INFO_AFTER_COPY);
  152.         DialogExit();
  153. }
  154.  
  155.  
  156. //===================================================//
  157. //                                                   //
  158. //                     DELETE                        //
  159. //                                                   //
  160. //===================================================//
  161.  
  162. int del_error;
  163. int Del_File2(dword way, sh_progr)
  164. {    
  165.         dword dirbuf, fcount, i, filename;
  166.         int error;
  167.         char del_from[4096];
  168.         if (dir_exists(way))
  169.         {
  170.                 if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
  171.                 for (i=0; i<fcount; i++)
  172.                 {
  173.                         //if (CheckEvent()==evReDraw) draw_window();
  174.                         filename = i*304+dirbuf+72;
  175.                         sprintf(#del_from,"%s/%s",way,filename);
  176.                         if ( TestBit(ESDWORD[filename-40], 4) )
  177.                         {
  178.                                 Del_File2(#del_from, 1);
  179.                         }
  180.                         else
  181.                         {
  182.                                 if (sh_progr) Operation_Draw_Progress(filename);
  183.                                 if (error = DeleteFile(#del_from)) del_error = error;
  184.                         }
  185.                 }
  186.         }
  187.         if (error = DeleteFile(way)) del_error = error;
  188. }
  189.  
  190. void DeleteSingleElement()
  191. {  
  192.         DIR_SIZE delete_dir_size;
  193.         del_error = NULL;
  194.        
  195.         if (itdir) {
  196.                 copy_bar.max = delete_dir_size.get(#file_path);
  197.         } else {
  198.                 copy_bar.max = 1;
  199.         }
  200.        
  201.         Del_File2(#file_path, 1);                      
  202.  
  203.         if (del_error) Write_Error(del_error);
  204.         DialogExit();
  205. }
  206.  
  207. void DeleteSelectedElements()
  208. {  
  209.         byte del_from[4096];
  210.         int i;
  211.  
  212.         DisplayOperationForm(DELETE_FLAG);
  213.  
  214.         if (!selected_count) { DeleteSingleElement(); return; }
  215.        
  216.         for (i=0; i<files.count; i++)
  217.         {
  218.                 if (getElementSelectedFlag(i) == true) {
  219.                         sprintf(#del_from,"%s/%s",#path,items.get(i)*304+buf+72);
  220.                         copy_bar.max += GetFilesCount(#del_from);
  221.                 }
  222.         }      
  223.  
  224.         del_error = 0;
  225.  
  226.         for (i=0; i<files.count; i++)
  227.         {
  228.                 if (getElementSelectedFlag(i) == true) {
  229.                         sprintf(#del_from,"%s/%s", #path, items.get(i)*304+buf+72);
  230.                         Del_File2(#del_from, 1);
  231.                 }
  232.         }
  233.  
  234.         if (del_error) Write_Error(del_error);
  235.         cmd_free = 6;
  236.         DialogExit();
  237. }
  238.