Subversion Repositories Kolibri OS

Rev

Rev 7245 | Rev 7278 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //Leency, Veliant, Punk_Joker, PavelYakov & KolibriOS Team 2008-2018
  2. //GNU GPL licence.
  3.  
  4. #ifndef AUTOBUILD
  5. #include "lang.h--"
  6. #endif
  7.  
  8. //libraries
  9. #define MEMSIZE 1024 * 720
  10. #include "../lib/clipboard.h"
  11. #include "../lib/strings.h"
  12. #include "../lib/mem.h"
  13. #include "../lib/fs.h"
  14. #include "../lib/gui.h"
  15. #include "../lib/list_box.h"
  16. #include "../lib/random.h"
  17. #include "../lib/kfont.h"
  18. #include "../lib/collection.h"
  19. #include "../lib/menu.h"
  20. #include "../lib/copyf.h"
  21.  
  22. #include "../lib/obj/libini.h"
  23. #include "../lib/obj/box_lib.h"
  24. #include "../lib/obj/libimg.h"
  25.  
  26. #include "../lib/patterns/history.h"
  27.  
  28. //images
  29. #include "imgs/left_p.txt"
  30.  
  31. //Button IDs
  32. enum {
  33.         POPUP_BTN1 = 201,
  34.         POPUP_BTN2 = 202,
  35.         BREADCRUMB_ID = 300
  36. };
  37.  
  38. //NewElement options
  39. enum {
  40.         CREATE_FILE=1,
  41.         CREATE_FOLDER,
  42.         RENAME_ITEM
  43. };
  44.  
  45. //OpenDir options
  46. enum {
  47.         ONLY_SHOW,
  48.         WITH_REDRAW,
  49.         ONLY_OPEN
  50. };
  51.  
  52. dword col_padding, col_selec, col_lpanel, col_work, col_graph, col_list_line=0xDDD7CF;
  53.  
  54. int toolbar_buttons_x[7]={9,46,85,134,167,203};
  55.  
  56. byte active_about=0;
  57. word about_window;
  58. word settings_window;
  59. byte active_settings=0;
  60. dword _not_draw = false;
  61. byte menu_call_mouse=0;
  62. byte exif_load=0;
  63.  
  64. byte del_active=0;
  65. byte new_element_active=0;
  66.  
  67. llist files, files_active, files_inactive;
  68.  
  69. byte list_full_redraw;
  70.  
  71. dword buf;
  72. dword file_mas[6898];
  73. int selected_count;
  74. int count_dir;
  75.  
  76. byte
  77.         path[4096],
  78.         file_path[4096],
  79.         file_name[256],
  80.         new_element_name[256],
  81.         temp[4096],
  82.         itdir;
  83.  
  84. char active_path[4096], inactive_path[4096];
  85.  
  86. dword eolite_ini_path[4096];
  87. _ini ini;
  88.  
  89. char scroll_used=false;
  90.  
  91. dword menu_stak,about_stak,properties_stak,settings_stak,copy_stak,delete_stak;
  92.  
  93. proc_info Form;
  94. int sc_slider_h;
  95. int j, i;
  96. int action_buf;
  97. int rand_n;
  98.  
  99. char sort_num=2;
  100. int active_panel=1;
  101.  
  102. libimg_image icons16_default;
  103. libimg_image icons16_selected;
  104.  
  105. libimg_image icons32_default;
  106. libimg_image icons32_selected;
  107.  
  108. #define STATUS_BAR_H 16;
  109. int status_bar_h = 0;
  110.  
  111. int icon_size = 16;
  112.  
  113. edit_box new_file_ed = {200,213,180,0xFFFFFF,0x94AECE,0xFFFFFF,0xFFFFFF,0x10000000,
  114.         248,#new_element_name,0,100000000000010b,6,0};
  115. PathShow_data FileShow = {0, 56,215, 8, 100, 1, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
  116. byte cmd_free=0;
  117. #include "include\translations.h"
  118. #include "include\fs.h"
  119.  
  120. #include "include\settings.h"
  121. #include "include\progress_dialog.h"
  122. #include "include\copy.h"
  123. #include "include\gui.h"
  124. #include "include\sorting.h"
  125. #include "include\icons.h"
  126. #include "include\left_panel.h"
  127. #include "include\menu.h"
  128. #include "include\delete.h"
  129. #include "include\about.h"
  130. #include "include\properties.h"
  131. #include "include\breadcrumbs.h"
  132.  
  133. void main()
  134. {
  135.         dword id;
  136.         byte count_sl = 0;
  137.         signed x_old, y_old, dif_x, dif_y, adif_x, adif_y;
  138.         char stats;
  139.         rand_n = random(40);
  140.  
  141.         load_dll(boxlib, #box_lib_init,0);
  142.         load_dll(libini, #lib_init,1);
  143.         load_dll(libio,  #libio_init,1);
  144.         load_dll(libimg, #libimg_init,1);
  145.        
  146.         LoadIniSettings();
  147.         SystemDiscs.Get();
  148.         SetAppColors();
  149.  
  150.         Libimg_LoadImage(#icons16_default, "/sys/icons16.png");
  151.         Libimg_LoadImage(#icons16_selected, "/sys/icons16.png");
  152.         Libimg_ReplaceColor(icons16_selected.image, icons16_selected.w, icons16_selected.h, 0xffFFFfff, col_selec);
  153.         Libimg_ReplaceColor(icons16_selected.image, icons16_selected.w, icons16_selected.h, 0xffCACBD6, MixColors(col_selec, 0, 200));
  154.  
  155.         //-p just show file/folder properties dialog
  156.         if (param) && (param[0]=='-') && (param[1]=='p')
  157.         {
  158.                 strcpy(#file_path, #param + 3);
  159.                 strcpy(#file_name, #param + strrchr(#param, '/'));
  160.                 properties_dialog();
  161.                 ExitProcess(); 
  162.         }
  163.  
  164.         if (param)
  165.         {
  166.                 if (strlen(#param)>1) && (param[strlen(#param)-1]=='/') param[strlen(#param)-1]=NULL; //no "/" at the end
  167.  
  168.                 if (dir_exists(#param)==true)
  169.                 {
  170.                         strcpy(#path, #param);
  171.                 }
  172.                 else
  173.                 {
  174.                         notify(T_NOTIFY_APP_PARAM_WRONG);
  175.                 }
  176.         }
  177.        
  178.         Open_Dir(#path,ONLY_OPEN);
  179.         strcpy(#inactive_path, #path);
  180.         llist_copy(#files_inactive, #files);
  181.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  182.         loop(){
  183.                 switch(WaitEvent())
  184.                 {
  185.                         case evMouse:
  186.                                 if (del_active) || (Form.status_window>2) break;
  187.                                 if (new_element_active)
  188.                                 {
  189.                                         edit_box_mouse stdcall(#new_file_ed);
  190.                                         break;
  191.                                 }                              
  192.                                
  193.                                 mouse.get();
  194.                                
  195.                                 if (!mouse.mkm) && (stats>0) stats = 0;
  196.                                 if (mouse.mkm) && (!stats)
  197.                                 {
  198.                                         x_old = mouse.x;
  199.                                         y_old = mouse.y;
  200.                                         stats = 1;
  201.                                 }
  202.                                 if (mouse.mkm) && (stats==1)
  203.                                 {
  204.                                         dif_x = mouse.x-x_old;
  205.                                         dif_y = mouse.y-y_old;
  206.                                         adif_x = fabs(dif_x);
  207.                                         adif_y = fabs(dif_y);
  208.                                        
  209.                                         if (adif_x>adif_y)
  210.                                         {
  211.                                                 if (dif_x > 150)
  212.                                                 {
  213.                                                         if (history.forward())
  214.                                                                 {
  215.                                                                         strcpy(#path, history.current());
  216.                                                                         files.KeyHome();
  217.                                                                         Open_Dir(#path,WITH_REDRAW);
  218.                                                                 }
  219.                                                         stats = 0;
  220.                                                 }
  221.                                                 if (dif_x < -150)
  222.                                                 {
  223.                                                         GoBack();
  224.                                                         stats = 0;
  225.                                                 }
  226.                                         }
  227.                                         else
  228.                                         {
  229.                                                 if (dif_y < -100)
  230.                                                 {
  231.                                                         Dir_Up();
  232.                                                         stats = 0;
  233.                                                 }
  234.                                         }
  235.                                 }      
  236.                                 if (files.MouseOver(mouse.x, mouse.y))
  237.                                 {
  238.                                         //select file
  239.                                         if (mouse.key&MOUSE_LEFT) && (mouse.up)
  240.                                         {
  241.                                                 if (files.ProcessMouse(mouse.x, mouse.y)) List_ReDraw(); else {
  242.                                                         if (mouse.y - files.y / files.item_h + files.first == files.cur_y) Open(0);
  243.                                                 }
  244.                                         }
  245.                                         //file menu
  246.                                         if (mouse.key&MOUSE_RIGHT)
  247.                                         {
  248.                                                 menu_call_mouse = 1;
  249.                                                 if (files.ProcessMouse(mouse.x, mouse.y)) List_ReDraw();
  250.                                                 if (getElementSelectedFlag(files.cur_y) == false) selected_count = 0; //on redraw selection would be flashed, see [L001]
  251.                                                 menu_stak = malloc(4096);
  252.                                                 CreateThread(#FileMenu,menu_stak+4092);
  253.                                                 break;
  254.                                         }
  255.                                 }
  256.  
  257.                                 if (mouse.vert)
  258.                                 {
  259.                                         if (files.MouseScroll(mouse.vert)) List_ReDraw();
  260.                                         break;
  261.                                 }
  262.  
  263.                                 if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y-17) && (mouse.y<files.y)
  264.                                 {
  265.                                         if (mouse.lkm==1) DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,0xC7C7C7,0xFFFFFF);
  266.                                         WHILE (mouse.lkm==1) && (files.first>0)
  267.                                         {
  268.                                                 pause(8);
  269.                                                 files.first--;
  270.                                                 List_ReDraw();
  271.                                                 mouse.get();
  272.                                         }
  273.                                         DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,0xFFFFFF,0xC7C7C7);
  274.                                 }
  275.  
  276.                                 if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y+files.h-16) && (mouse.y<files.y+files.h)
  277.                                 {
  278.                                         if (mouse.lkm==1) DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,0xC7C7C7,0xFFFFFF);
  279.                                         while (mouse.lkm==1) && (files.first<files.count-files.visible)
  280.                                         {
  281.                                                 pause(8);
  282.                                                 files.first++;
  283.                                                 List_ReDraw();
  284.                                                 mouse.get();
  285.                                         }
  286.                                         DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,0xFFFFFF,0xC7C7C7);
  287.                                 }
  288.  
  289.                                 //Scrooll
  290.                                 if (!mouse.lkm) && (scroll_used) { scroll_used=false; Scroll(); }
  291.                                 if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+18) && (mouse.y>files.y) && (mouse.y<files.y+files.h-18) && (mouse.lkm) && (!scroll_used) {scroll_used=true; Scroll();}
  292.                                
  293.                                 if (scroll_used)
  294.                                 {
  295.                                         if (sc_slider_h/2+files.y>mouse.y) || (mouse.y<0) || (mouse.y>4000) mouse.y=sc_slider_h/2+files.y; //anee eo?ni? iaa ieiii
  296.                                         id = files.first;
  297.                                         files.first = -sc_slider_h / 2 + mouse.y -j -files.y * files.count;
  298.                                         files.first /= files.h - 18;
  299.                                         if (files.visible+files.first>files.count) files.first=files.count-files.visible;
  300.                                         if (files.first<0) files.first=0;
  301.                                         if (id!=files.first) List_ReDraw();
  302.                                         break;
  303.                                 }
  304.  
  305.                                 if (two_panels.checked) && (mouse.y > files.y) && (mouse.down) {
  306.                                         if (mouse.x<Form.cwidth/2)
  307.                                         {
  308.                                                 if (active_panel!=1)
  309.                                                 {
  310.                                                         active_panel = 1;
  311.                                                         ChangeActivePanel();
  312.                                                 }
  313.                                         }
  314.                                         else
  315.                                         {
  316.                                                 if (active_panel!=2)
  317.                                                 {
  318.                                                         active_panel = 2;
  319.                                                         ChangeActivePanel();
  320.                                                 }
  321.                                         }
  322.                                 }
  323.                                 break;  
  324.         //Button pressed-----------------------------------------------------------------------------
  325.                         case evButton:
  326.                                 id=GetButtonID();                              
  327.                                 switch(id)
  328.                                 {
  329.                                         case CLOSE_BTN:
  330.                                                         KillProcess(about_window);
  331.                                                         SaveIniSettings();
  332.                                                         ExitProcess();
  333.                                         case 21: //Back
  334.                                                         GoBack();
  335.                                                         break;
  336.                                         case 22: //Forward
  337.                                                         if (history.forward())
  338.                                                         {
  339.                                                                 strcpy(#path, history.current());
  340.                                                                 files.KeyHome();
  341.                                                                 Open_Dir(#path,WITH_REDRAW);
  342.                                                         }
  343.                                                         break;
  344.                                         case 23:
  345.                                                         Dir_Up();
  346.                                                         break;
  347.                                         case 24:
  348.                                                         Copy(#file_path, CUT);
  349.                                                         break;
  350.                                         case 25:
  351.                                                         Copy(#file_path, NOCUT);
  352.                                                         break;
  353.                                         case 26:
  354.                                                         Paste();
  355.                                                         break;
  356.                                         case 31...33: //sorting
  357.                                                         sort_num = id - 30;
  358.                                                         DrawList();
  359.                                                         Open_Dir(#path,WITH_REDRAW);
  360.                                                         break;
  361.                                         case 50...60: //Actions
  362.                                                         FnProcess(id-50);
  363.                                                         break;
  364.                                         case 100...120:
  365.                                                 SystemDiscs.Click(id-100);
  366.                                                 break;
  367.                                         case POPUP_BTN1...POPUP_BTN2:
  368.                                                 if (del_active) Del_File(id-POPUP_BTN2);
  369.                                                 if (new_element_active) NewElement(id-POPUP_BTN2);
  370.                                                 DeleteButton(POPUP_BTN1);
  371.                                                 DeleteButton(POPUP_BTN2);
  372.                                                 break;
  373.                                         case BREADCRUMB_ID...360:
  374.                                                 ClickOnBreadCrumb(id-BREADCRUMB_ID);
  375.                                                 break;
  376.                                 }
  377.                                 break;
  378.                                
  379.         //Key pressed-----------------------------------------------------------------------------
  380.                         case evKey:
  381.                                 GetKeys();
  382.  
  383.                                 if (Form.status_window>2) break;
  384.                                 if (del_active)
  385.                                 {
  386.                                         if (key_scancode == SCAN_CODE_ENTER) Del_File(true);
  387.                                         if (key_scancode == SCAN_CODE_ESC) Del_File(false);
  388.                                         break;
  389.                                 }
  390.                                 if (new_element_active)
  391.                                 {
  392.                                         if (key_scancode == SCAN_CODE_ENTER) NewElement(true);
  393.                                         if (key_scancode == SCAN_CODE_ESC) NewElement(false);
  394.                                         EAX = key_editbox;
  395.                                         edit_box_key stdcall (#new_file_ed);
  396.                                         break;
  397.                                 }
  398.                                 if (files.ProcessKey(key_scancode))
  399.                                 {
  400.                                         List_ReDraw();
  401.                                         break;
  402.                                 }
  403.  
  404.                                 if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
  405.                                 {
  406.                                         switch(key_scancode)
  407.                                         {
  408.                                                 case 059...068:
  409.                                                                 key_scancode -= 59;
  410.                                                                 if (key_scancode < SystemDiscs.list.count)
  411.                                                                 {
  412.                                                                         if (!two_panels.checked)
  413.                                                                         {
  414.                                                                                 DrawRectangle(17,key_scancode*16+74,159,16, 0); //display click
  415.                                                                                 pause(7);                                                                              
  416.                                                                         }
  417.                                                                         SystemDiscs.Click(key_scancode);
  418.                                                                 }
  419.                                                                 break;
  420.                                                 case 45:  //Ctrl+X
  421.                                                                 Copy(#file_path, CUT);
  422.                                                                 break;                                         
  423.                                                 case 46:  //Ctrl+C
  424.                                                                 Copy(#file_path, NOCUT);
  425.                                                                 break;
  426.                                                 case 47:  //Ctrl+V
  427.                                                                 Paste();
  428.                                                                 break;
  429.                                                 case 032: //Ctrl+D - set as bg
  430.                                                                 strlcpy(#temp, "\\S__",4);
  431.                                                                 strcat(#temp, #file_path);
  432.                                                                 RunProgram("/sys/media/kiv", #temp);
  433.                                                                 break;
  434.                                                 case 049: //Ctrl+N - create new window
  435.                                                                 if (Form.left==98) MoveSize(Form.left-20,Form.top-20,OLD,OLD);
  436.                                                                 RunProgram(I_Path, #path);
  437.                                                                 break;
  438.                                                 case 050: //Ctrl+M
  439.                                                                 Open_Dir(#inactive_path,WITH_REDRAW);
  440.                                                                 break;
  441.                                                 case SCAN_CODE_ENTER: //Ctrl+Enter
  442.                                                                 if (!itdir) ShowOpenWithDialog();
  443.                                                                 else Open(1);
  444.                                                                 break;
  445.                                                 case 030: //Ctrl+A - select all files
  446.                                                                 for (i=0; i<files.count; i++) setElementSelectedFlag(i, true);
  447.                                                                 List_ReDraw();
  448.                                                                 DrawStatusBar();
  449.                                                                 break;
  450.                                                 case 022: //Ctrl+U - unselect all files
  451.                                                                 for (i=0; i<files.count; i++) setElementSelectedFlag(i, false);
  452.                                                                 selected_count = 0;
  453.                                                                 List_ReDraw();
  454.                                                                 DrawStatusBar();
  455.                                                                 break;
  456.                                         }
  457.                                         break;
  458.                                 }
  459.  
  460.                                 switch (key_scancode)
  461.                                 {
  462.                                                 case SCAN_CODE_BS:
  463.                                                                 //GoBack();
  464.                                                                 Dir_Up();
  465.                                                                 break;
  466.                                                 case SCAN_CODE_ENTER:
  467.                                                                 Open(0);
  468.                                                                 break;
  469.                                                 case SCAN_CODE_TAB:
  470.                                                                 if (!two_panels.checked) break;
  471.                                                                 if (active_panel==1) active_panel=2; else active_panel=1;
  472.                                                                 ChangeActivePanel();
  473.                                                                 DrawStatusBar();
  474.                                                                 break;
  475.                                                 case 093: //menu
  476.                                                                 menu_call_mouse=0;
  477.                                                                 menu_stak = malloc(4096);
  478.                                                                 CreateThread(#FileMenu,menu_stak+4092);
  479.                                                                 break;
  480.                                                 case SCAN_CODE_DEL:
  481.                                                                 Del_Form();
  482.                                                                 break;
  483.                                                 case SCAN_CODE_INS:
  484.                                                                 if (getElementSelectedFlag(files.cur_y) == true) setElementSelectedFlag(files.cur_y, false);
  485.                                                                 else setElementSelectedFlag(files.cur_y, true);
  486.                                                                 files.KeyDown();
  487.                                                                 List_ReDraw();
  488.                                                                 DrawStatusBar();
  489.                                                                 break;
  490.                                                 case 059...068: //F1-F10
  491.                                                                 FnProcess(key_scancode-58);
  492.                                                                 break;
  493.                                                 default:
  494.                                                                 for (i=files.cur_y+1; i<files.count; i++)
  495.                                                                 {
  496.                                                                         strcpy(#temp, file_mas[i]*304+buf+72);
  497.                                                                         if (temp[0]==key_ascii) || (temp[0]==key_ascii-32)
  498.                                                                         {
  499.                                                                                 files.cur_y = i - 1;
  500.                                                                                 files.KeyDown();
  501.                                                                                 List_ReDraw();
  502.                                                                                 break;
  503.                                                                         }
  504.                                                                 }
  505.                                 }                        
  506.                         break;
  507.                         case evIPC:
  508.                         case evReDraw:
  509.                                 draw_window();
  510.                                 if (action_buf)
  511.                                 {
  512.                                         if (action_buf==OPERATION_END)
  513.                                         {
  514.                                                 FnProcess(5);
  515.                                                 if (copy_stak) SelectFileByName(#copy_to+strrchr(#copy_to,'/'));
  516.                                         }
  517.                                         if (action_buf==100) Open(0);
  518.                                         if (action_buf==201) ShowOpenWithDialog();
  519.                                         if (action_buf==202) FnProcess(3); //F3
  520.                                         if (action_buf==203) FnProcess(4); //F4
  521.                                         if (action_buf==104) Copy(#file_path, NOCUT);
  522.                                         if (action_buf==105) Copy(#file_path, CUT);
  523.                                         if (action_buf==106) Paste();
  524.                                         if (action_buf==207) FnProcess(2);
  525.                                         if (action_buf==108) Del_Form();
  526.                                         if (action_buf==109) FnProcess(5);
  527.                                         if (action_buf==110) FnProcess(8);
  528.                                         action_buf=0;
  529.                                 }
  530.                 }
  531.                 if(cmd_free)
  532.                 {
  533.                         if(cmd_free==1)      menu_stak=free(menu_stak);
  534.                         else if(cmd_free==2) about_stak=free(about_stak);
  535.                         else if(cmd_free==3) properties_stak=free(properties_stak);
  536.                         else if(cmd_free==4) settings_stak=free(settings_stak);
  537.                         else if(cmd_free==5) copy_stak=free(copy_stak);
  538.                         else if(cmd_free==6) delete_stak=free(delete_stak);
  539.                         cmd_free = false;
  540.                 }
  541.         }
  542. }
  543.  
  544. void DrawFavButton(int x)
  545. {
  546.         _PutImage(x,10,20,22,#fav);
  547.         DefineButton(x,11,20-2,22-2,61+BT_HIDE+BT_NOFRAME,0);
  548. }
  549.  
  550. void draw_window()
  551. {
  552.         if (show_status_bar.checked) status_bar_h = STATUS_BAR_H; else status_bar_h = 0;
  553.         DefineAndDrawWindow(WinX+rand_n,WinY+rand_n,WinW,WinH,0x73,NULL,TITLE,0);
  554.         GetProcessInfo(#Form, SelfInfo);
  555.         if (Form.status_window>2) return;
  556.         if (Form.height < 350) { MoveSize(OLD,OLD,OLD,350); return; }
  557.         if (Form.width  < 480) { MoveSize(OLD,OLD,480,OLD); return; }
  558.         GetProcessInfo(#Form, SelfInfo); //if win_size changed
  559.         _PutImage(0,0,246,34,#toolbar);
  560.         DrawBar(127, 8, 1, 25, col_graph);
  561.         for (j=0; j<3; j++) DefineButton(toolbar_buttons_x[j]+2,5+2,31-5,29-5,21+j+BT_HIDE,NULL);
  562.         for (j=3; j<6; j++) DefineButton(toolbar_buttons_x[j],5,31,29,21+j+BT_HIDE,NULL);
  563.         DrawBar(246,0, Form.cwidth - 246, 34, col_work);
  564.         _PutImage(Form.cwidth-17,11,6,18,#dots);
  565.         DefineButton(Form.cwidth-24,7,20,25,51+BT_HIDE+BT_NOFRAME,0); //dots
  566.         //main rectangles
  567.         DrawRectangle(1,40,Form.cwidth-3,Form.cheight - 42-status_bar_h,col_graph);
  568.         DrawRectangle(0,39,Form.cwidth-1,Form.cheight - 40,col_palette[4]); //bg
  569.         for (i=0; i<5; i++) DrawBar(0, 34+i, Form.cwidth, 1, col_palette[8-i]);
  570.         llist_copy(#files_active, #files);
  571.         strcpy(#active_path, #path);
  572.         DrawStatusBar();
  573.         if (selected_count==0) Open_Dir(#path,ONLY_OPEN); //if there are no selected files -> refresh folder [L001]
  574.         DrawFilePanels();
  575.         if (del_active) Del_Form();
  576.         if (new_element_active) NewElement_Form(new_element_active, #new_element_name);
  577. }
  578.  
  579. void DrawList()
  580. {
  581.         word sorting_arrow_x;
  582.         DrawFlatButtonSmall(files.x, files.y-17,     files.w - 141,16,31,T_FILE);
  583.         DrawFlatButtonSmall(files.x + files.w - 141, files.y-17,73,16,32,T_TYPE);
  584.         DrawFlatButtonSmall(files.x + files.w -  68, files.y-17,68,16,33,T_SIZE);
  585.         DrawFlatButtonSmall(files.x + files.w,       files.y-17,16,16, 0,"\x18");
  586.         DrawFlatButtonSmall(files.x + files.w,files.y+files.h-16,16,16,0,"\x19");
  587.         if (sort_num==1) sorting_arrow_x = files.w - 141 / 2 + files.x + 18;
  588.         if (sort_num==2) sorting_arrow_x = files.x + files.w - 90;
  589.         if (sort_num==3) sorting_arrow_x = strlen(T_SIZE)*3-30+files.x+files.w;
  590.         WriteText(sorting_arrow_x,files.y-12,0x80,col_graph,"\x19");
  591.         DrawBar(files.x+files.w,files.y,1,files.h,col_graph);
  592.         if (two_panels.checked) && (files.x<5) DrawBar(files.x+files.w+16,files.y,1,files.h,col_graph);
  593. }
  594.  
  595. void DrawStatusBar()
  596. {
  597.         char status_bar_str[80];
  598.         int go_up_folder_exists=0;
  599.         if (!show_status_bar.checked) return;
  600.         if (files.count>0) && (strcmp(file_mas[0]*304+buf+72,"..")==0) go_up_folder_exists=1;
  601.         DrawBar(1, Form.cheight - status_bar_h-1, Form.cwidth-2,  status_bar_h, system.color.work);
  602.         sprintf(#status_bar_str, STATUS_STR, files.count-go_up_folder_exists, count_dir-go_up_folder_exists, files.count-count_dir, selected_count);
  603.         WriteText(6,Form.cheight - 13,0x80,system.color.work_text,#status_bar_str);
  604. }
  605.  
  606. void DrawFilePanels()
  607. {
  608.         int files_y;
  609.         if (!two_panels.checked)
  610.         {
  611.                 DrawDeviceAndActionsLeftPanel();
  612.                 files.SetSizes(192, 57, Form.cwidth - 210, Form.cheight - 59 - status_bar_h, files.item_h);
  613.                 DrawList();
  614.                 Open_Dir(#path,ONLY_SHOW);
  615.         }
  616.         else
  617.         {
  618.                 SystemDiscs.Get();
  619.                 llist_copy(#files, #files_inactive);
  620.                 strcpy(#path, #inactive_path);
  621.                 col_selec = 0xCCCccc;
  622.                 SystemDiscs.Draw();
  623.                 files_y = files.y;
  624.  
  625.                 if (active_panel==1)
  626.                 {
  627.                         llist_copy(#files, #files_inactive);
  628.                         strcpy(#path, #inactive_path);
  629.                         col_selec = 0xCCCccc;
  630.                         files.SetSizes(Form.cwidth/2, files_y, Form.cwidth/2 -17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  631.                         DrawList();
  632.                         Open_Dir(#path,WITH_REDRAW);
  633.                         llist_copy(#files, #files_active);
  634.                         strcpy(#path, #active_path);
  635.                         col_selec = 0x94AECE;
  636.                         files.SetSizes(2, files_y, Form.cwidth/2-2-17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  637.                         DrawList();
  638.                         Open_Dir(#path,WITH_REDRAW);
  639.                 }
  640.                 if (active_panel==2)
  641.                 {
  642.                         files.SetSizes(2, files_y, Form.cwidth/2-2-17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  643.                         DrawList();
  644.                         Open_Dir(#path,WITH_REDRAW);
  645.                         llist_copy(#files, #files_active);
  646.                         strcpy(#path, #active_path);
  647.                         col_selec = 0x94AECE;
  648.                         files.SetSizes(Form.cwidth/2, files_y, Form.cwidth/2 -17, Form.cheight-files_y-2 - status_bar_h, files.item_h);
  649.                         DrawList();
  650.                         Open_Dir(#path,WITH_REDRAW);
  651.                 }
  652.         }
  653. }
  654.  
  655.  
  656. void List_ReDraw()
  657. {
  658.         int all_lines_h;
  659.         static int old_cur_y, old_first;
  660.  
  661.         files.CheckDoesValuesOkey(); //prevent some shit
  662.  
  663.         if (list_full_redraw) || (old_first != files.first)
  664.         {
  665.                 old_cur_y = files.cur_y;
  666.                 old_first = files.first;
  667.                 list_full_redraw = false;
  668.                 goto _ALL_LIST_REDRAW;
  669.         }
  670.         if (old_cur_y != files.cur_y)
  671.         {
  672.                 if (old_cur_y-files.first<files.visible) Line_ReDraw(0xFFFFFF, old_cur_y-files.first);
  673.                 Line_ReDraw(col_selec, files.cur_y-files.first);
  674.                 old_cur_y = files.cur_y;
  675.                 return;
  676.         }
  677.  
  678.         _ALL_LIST_REDRAW:
  679.  
  680.         for (j=0; j<files.visible; j++) if (files.cur_y-files.first!=j) Line_ReDraw(0xFFFFFF, j); else Line_ReDraw(col_selec, files.cur_y-files.first);
  681.         //in the bottom
  682.         all_lines_h = j * files.item_h;
  683.         DrawBar(files.x,all_lines_h + files.y,files.w,files.h - all_lines_h,0xFFFFFF);
  684.         DrawBar(files.x+files.w-141,all_lines_h + files.y,1,files.h - all_lines_h,col_list_line);
  685.         DrawBar(files.x+files.w-68,all_lines_h + files.y,1,files.h - all_lines_h,col_list_line);
  686.         Scroll();
  687. }
  688.  
  689.  
  690. void Line_ReDraw(dword bgcol, filenum){
  691.         dword text_col=0,
  692.                   ext1, attr,
  693.                   file_offet,
  694.                   file_name_off,
  695.                   y=filenum*files.item_h+files.y,
  696.                   icon_y = files.item_h-icon_size/2+1+y;
  697.                   BDVK file;
  698.                   char temp_path[sizeof(file_path)];
  699.         char label_file_name[4096];
  700.         if (filenum==-1) return;
  701.         DrawBar(files.x,y,4,files.item_h,bgcol);
  702.         DrawBar(files.x+20,y,files.w-20,files.item_h,bgcol);
  703.         DrawBar(files.x+4,y,icon_size,icon_y-y,bgcol);
  704.         if (files.item_h>icon_size) DrawBar(files.x+4,icon_y+icon_size-1,icon_size,y+files.item_h-icon_y-icon_size+1,bgcol);
  705.  
  706.         file_offet = file_mas[filenum+files.first]*304 + buf+32;
  707.         attr = ESDWORD[file_offet];
  708.         file.selected = ESBYTE[file_offet+7];
  709.         file.sizelo   = ESDWORD[file_offet+32];
  710.         file.sizehi   = ESDWORD[file_offet+36];
  711.         file_name_off = file_offet+40;
  712.  
  713.         if (! TestBit(attr, 4) ) //file or folder?
  714.         {      
  715.                 ext1 = strrchr(file_name_off,'.') + file_name_off;
  716.                 if (ext1==file_name_off) ext1 = NULL; //if no extension then show nothing
  717.                 WriteText(
  718.                         7-strlen(ConvertSize64(file.sizelo, file.sizehi))*6+files.x+files.w - 58,
  719.                         files.text_y+y+1,
  720.                         files.font_type,
  721.                         0,
  722.                         ConvertSize64(file.sizelo, file.sizehi)
  723.                 );
  724.                 if (ext1) && (strlen(ext1)<9) WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, 0, ext1);
  725.         }
  726.         else
  727.         {
  728.                 if (!strcmp(file_name_off,"..")) ext1="<up>"; else {
  729.                         ext1="<DIR>";
  730.                         WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, 0, ext1);
  731.                 }
  732.         }
  733.         sprintf(#temp_path,"%s/%s",#path,file_name_off);
  734.         DrawIconByExtension(#temp_path, ext1, files.x+4, icon_y, bgcol);
  735.  
  736.         if (TestBit(attr, 1)) || (TestBit(attr, 2)) text_col=0xA6A6B7; //system or hiden?
  737.         if (bgcol!=0xFFFfff)
  738.         {
  739.                 itdir = TestBit(attr, 4);
  740.                 strcpy(#file_name, file_name_off);
  741.                 if (!strcmp(#path,"/")) sprintf(#file_path,"%s%s",#path,file_name_off);
  742.                         else sprintf(#file_path,"%s/%s",#path,file_name_off);
  743.                 if (text_col==0xA6A6B7) text_col=0xFFFFFF;
  744.         }
  745.         if (file.selected) text_col=0xFF0000;
  746.         if (kfont.size.pt==9) || (!kfont.font)
  747.         {
  748.                 if (Form.width>=480)
  749.                 {
  750.                         FileShow.start_x = files.x + 23;
  751.                         FileShow.font_color = text_col;
  752.                         FileShow.area_size_x = files.w - 164;
  753.                         FileShow.text_pointer = file_name_off;
  754.                         FileShow.start_y = files.text_y + y - 3;
  755.                         PathShow_prepare stdcall(#FileShow);
  756.                         PathShow_draw stdcall(#FileShow);
  757.                 }              
  758.         }
  759.         else
  760.         {
  761.                 strcpy(#label_file_name, file_name_off);
  762.                 if (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w)
  763.                 {
  764.                         while (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w) {
  765.                                 ESBYTE[#label_file_name+strlen(#label_file_name)-1] = NULL;
  766.                         }
  767.                         strcpy(#label_file_name+strlen(#label_file_name)-2, "...");                    
  768.                 }
  769.                 kfont.WriteIntoWindow(files.x + icon_size+7, files.item_h - kfont.height / 2 + y, bgcol, text_col, kfont.size.pt, #label_file_name);
  770.         }
  771.         DrawBar(files.x+files.w-141,y,1,files.item_h,col_list_line); //gray line 1
  772.         DrawBar(files.x+files.w-68,y,1,files.item_h,col_list_line); //gray line 2
  773. }
  774.  
  775.  
  776. void Open_Dir(dword dir_path, redraw){
  777.         int errornum, maxcount, i;
  778.         if (redraw!=ONLY_SHOW)
  779.         {
  780.                 selected_count = 0;
  781.                 if (buf) free(buf);
  782.                 errornum = GetDir(#buf, #files.count, dir_path, DIRS_NOROOT);
  783.                 if (errornum)
  784.                 {
  785.                         history.add(#path);
  786.                         GoBack();
  787.                         Write_Error(errornum);
  788.                         return;
  789.                 }
  790.                 maxcount = sizeof(file_mas)/sizeof(dword)-1;
  791.                 if (files.count>maxcount) files.count = maxcount;
  792.                 if (files.count>0) && (files.cur_y-files.first==-1) files.cur_y=0;
  793.         }
  794.         if (files.count!=-1)
  795.         {
  796.                 if(!_not_draw) if (show_breadcrumb.checked) DrawBreadCrumbs(); else DrawPathBar();
  797.                 history.add(#path);
  798.                 SystemDiscs.Draw();
  799.                 files.visible = files.h / files.item_h;
  800.                 if (files.count < files.visible) files.visible = files.count;
  801.                 if (redraw!=ONLY_SHOW) Sorting();
  802.                 list_full_redraw = true;
  803.                 if (redraw!=ONLY_OPEN)&&(!_not_draw) {DrawStatusBar(); List_ReDraw();}
  804.                 SetCurDir(dir_path);
  805.         }
  806.         if (files.count==-1) && (redraw!=ONLY_OPEN)
  807.         {
  808.                 files.KeyHome();
  809.                 if(!_not_draw) { list_full_redraw=true; DrawStatusBar(); List_ReDraw(); }
  810.         }
  811. }
  812.  
  813.  
  814. inline Sorting()
  815. {
  816.         dword k=0, l=1;
  817.         dword file_off;
  818.         if (!strcmp(#path,"/")) //do not sort root folder
  819.         {
  820.                 for(k=1;k<files.count;k++;) file_mas[k]=k;
  821.                 count_dir = k;
  822.                 return;
  823.         }
  824.         for (j=files.count-1, file_off=files.count-1*304+buf+32; j>=0; j--, file_off-=304;)  //files | folders
  825.         {
  826.                 if (!show_real_names.checked) strttl(file_off+40);
  827.                 if (TestBit(ESDWORD[file_off],4)) //directory?
  828.                 {
  829.                         file_mas[k]=j;
  830.                         k++;
  831.                 }
  832.                 else
  833.                 {
  834.                         file_mas[files.count-l]=j;
  835.                         l++;
  836.                 }
  837.         }
  838.         count_dir = k;
  839.         //sorting: files first, then folders
  840.         Sort_by_Name(0,k-1);
  841.         if (sort_num==1) Sort_by_Name(k,files.count-1);
  842.         if (sort_num==2) Sort_by_Type(k,files.count-1);
  843.         if (sort_num==3) Sort_by_Size(k,files.count-1);
  844.         //make ".." first item in list
  845.         if (k>0) && (strncmp(file_mas[0]*304+buf+72,"..",2)!=0)
  846.                 for(k--; k>0; k--;) if (!strncmp(file_mas[k]*304+buf+72,"..",2)) {file_mas[k]><file_mas[0]; break;}
  847. }
  848.  
  849.  
  850. void Del_Form()
  851. {
  852.         byte f_count[128];
  853.         int dform_x = files.w - 220 / 2 + files.x;
  854.         if (selected_count==0) && (!strncmp(#file_name,"..",2)) return;
  855.         else
  856.         {
  857.                 if (!files.count) return;
  858.                 DrawEolitePopup(T_YES, T_NO);
  859.                 WriteText(-strlen(T_DELETE_FILE)*3+110+dform_x,175,0x80,system.color.work_text,T_DELETE_FILE);
  860.                 if (selected_count)
  861.                 {
  862.                         sprintf(#f_count,"%s%d%s",DEL_MORE_FILES_1,selected_count,DEL_MORE_FILES_2);
  863.                         WriteText(-strlen(#f_count)*3+110+dform_x,190,0x80,system.color.work_text,#f_count);
  864.                 }
  865.                 else
  866.                 {
  867.                         if (strlen(#file_name)<28)
  868.                         {
  869.                                 WriteText(strlen(#file_name)*3+110+dform_x+2,190,0x80,system.color.work_text,"?");
  870.                                 WriteText(-strlen(#file_name)*3+110+dform_x,190,0x80,system.color.work_text,#file_name);
  871.                         }
  872.                         else
  873.                         {
  874.                                 WriteText(164+dform_x,190,0x80,0,"...?");
  875.                                 ESI = 24;
  876.                                 WriteText(dform_x+20,190,0,0,#file_name);
  877.                         }
  878.                 }              
  879.                 del_active=1;
  880.         }
  881. }
  882.  
  883. void SelectFileByName(dword that_file)
  884. {
  885.         int ind;
  886.         files.KeyHome();
  887.         Open_Dir(#path,ONLY_OPEN);
  888.         if (!show_real_names.checked) strttl(that_file);
  889.         for (ind=files.count-1; ind>=0; ind--;) { if (!strcmp(file_mas[ind]*304+buf+72,that_file)) break; }
  890.         files.cur_y = ind - 1;
  891.         files.KeyDown();
  892.         DrawStatusBar();
  893.         List_ReDraw();
  894. }
  895.  
  896.  
  897. void Dir_Up()
  898. {
  899.         char old_folder_name[4096];
  900.         i=strlen(#path)-1;
  901.         if (i==0) return;
  902.         //path[i]=0x00;
  903.         i = strrchr(#path, '/');
  904.         strcpy(#old_folder_name, #path+i);
  905.         if (i>1) path[i-1]=NULL; else path[i]=NULL;
  906.         SelectFileByName(#old_folder_name);
  907. }
  908.  
  909. void Open(byte rez)
  910. {
  911.         byte temp[4096];
  912.         selected_count = 0;
  913.         if (rez)
  914.         {
  915.                 if (!strncmp(#file_name,"..",3)) return;
  916.                 strcpy(#temp, #file_path);
  917.                 RunProgram(I_Path, #temp);
  918.                 return;
  919.         }
  920.         if (!files.count) return;
  921.         if (!itdir)
  922.         {
  923.                 if (strrchr(#file_name, '.')==0) RunProgram(#file_path, ""); else RunProgram("/sys/@open", #file_path);
  924.         }
  925.         else
  926.         {
  927.                 if (!strncmp(#file_name,"..",3)) { Dir_Up(); return; }
  928.                 strcpy(#path, #file_path);
  929.                 files.first=files.cur_y=0;
  930.                 Open_Dir(#path,WITH_REDRAW);
  931.         }
  932. }
  933.  
  934. inline fastcall void GoBack()
  935. {
  936.         char cur_folder[4096];
  937.         strcpy(#cur_folder, #path);
  938.         if (history.back()) {
  939.                 strcpy(#path, history.current());
  940.                 SelectFileByName(#cur_folder+strrchr(#cur_folder,'/'));
  941.         }
  942. }
  943.  
  944. void ShowOpenWithDialog()
  945. {
  946.         byte open_param[4097];
  947.         sprintf(#open_param,"~%s",#file_path);
  948.         RunProgram("/sys/@open", #open_param);
  949. }
  950.  
  951. void NewElement(byte newf)
  952. {
  953.         BDVK element_info;
  954.         byte del_rezult, copy_rezult, info_result;
  955.         if (newf)
  956.         {
  957.                 sprintf(#temp,"%s/%s",#path,new_file_ed.text);
  958.                 info_result = GetFileInfo(#temp, #element_info);
  959.                 switch(new_element_active)
  960.                 {
  961.                         case CREATE_FILE:
  962.                                 if (info_result==5)
  963.                                 {
  964.                                         CreateFile(0, 0, #temp);
  965.                                         if (EAX)
  966.                                         {
  967.                                                 if (EAX==5) notify(NOT_CREATE_FILE);
  968.                                                 else Write_Error(EAX);
  969.                                         }
  970.                                 }
  971.                                 else
  972.                                 {
  973.                                         notify(FS_ITEM_ALREADY_EXISTS);
  974.                                 }
  975.                                 break;
  976.                         case CREATE_FOLDER:
  977.                                 if (info_result==5)
  978.                                 {
  979.                                         CreateDir(#temp);
  980.                                         if (EAX)
  981.                                         {
  982.                                                 if (EAX==5) notify(NOT_CREATE_FOLDER);
  983.                                                 else Write_Error(EAX);
  984.                                         }
  985.                                 }
  986.                                 else
  987.                                 {
  988.                                         notify(FS_ITEM_ALREADY_EXISTS);
  989.                                 }
  990.                                 break;
  991.                         case RENAME_ITEM:
  992.                                 if (info_result==5)
  993.                                 {
  994.                                         if (itdir)
  995.                                         {
  996.                                                 //rename only empty folders
  997.                                                 if (del_rezult = DeleteFile(#file_path))
  998.                                                 {
  999.                                                         Write_Error(del_rezult);
  1000.                                                         return;
  1001.                                                 }
  1002.                                                 if (CreateDir(#temp)) CreateDir(#file_path);
  1003.                                                 Open_Dir(#path,WITH_REDRAW);
  1004.                                                 SelectFileByName(new_file_ed.text);
  1005.                                         }
  1006.                                         else
  1007.                                         {
  1008.                                                 if (copy_rezult = CopyFile(#file_path,#temp))
  1009.                                                 {
  1010.                                                         Write_Error(copy_rezult);
  1011.                                                 }
  1012.                                                 else
  1013.                                                 {
  1014.                                                         DeleteFile(#file_path);
  1015.                                                         SelectFileByName(new_file_ed.text);
  1016.                                                 }
  1017.                                         }
  1018.                                 }
  1019.                                 else
  1020.                                 {
  1021.                                         notify(FS_ITEM_ALREADY_EXISTS);
  1022.                                 }
  1023.                 }
  1024.                 new_element_active = 0;
  1025.                 Open_Dir(#path,WITH_REDRAW);
  1026.                 SelectFileByName(new_file_ed.text);
  1027.         }
  1028.         new_element_active = 0;
  1029.         Open_Dir(#path,WITH_REDRAW);
  1030. }
  1031.  
  1032. void NewElement_Form(byte crt, dword strng)
  1033. {
  1034.         int dform_x=files.w-220/2+files.x;
  1035.         if (!new_element_active)
  1036.         {
  1037.                 new_element_active = crt;
  1038.                 strcpy(#new_element_name, strng);
  1039.                 new_file_ed.size = new_file_ed.pos = strlen(strng);
  1040.         }
  1041.         if (new_element_active==3) DrawEolitePopup(T_RENAME, T_CANCEL);
  1042.         else DrawEolitePopup(T_CREATE, T_CANCEL);
  1043.         new_file_ed.left = dform_x+10;
  1044.         DrawEditBox(#new_file_ed);
  1045. }
  1046.  
  1047. void FnProcess(byte N)
  1048. {
  1049.         switch(N)
  1050.         {
  1051.                 case 1:
  1052.                         if (!active_about)
  1053.                         {
  1054.                                 about_stak = malloc(4096);
  1055.                                 about_window = CreateThread(#about_dialog,about_stak+4092);
  1056.                                 break;
  1057.                         }
  1058.                         else
  1059.                         {
  1060.                                 ActivateWindow(GetProcessSlot(about_window));
  1061.                         }
  1062.                         break;
  1063.                 case 2:
  1064.                         if (!files.count) break;
  1065.                         NewElement_Form(RENAME_ITEM, #file_name);
  1066.                         break;
  1067.                 case 3:
  1068.                         if (!itdir) RunProgram("/sys/tinypad", #file_path);
  1069.                         break;
  1070.                 case 4:
  1071.                         if (!itdir) RunProgram("/sys/develop/heed", #file_path);
  1072.                         break;
  1073.                 case 5: //refresh cur dir & devs
  1074.                         if (two_panels.checked)
  1075.                         {
  1076.                                 DrawFilePanels();
  1077.                         }
  1078.                         else
  1079.                         {
  1080.                                 Tip(56, T_DEVICES, 55, "-");
  1081.                                 Open_Dir(#path,WITH_REDRAW);
  1082.                                 pause(10);
  1083.                                 SystemDiscs.Get();
  1084.                                 Open_Dir(#path,WITH_REDRAW);
  1085.                                 DrawDeviceAndActionsLeftPanel();                               
  1086.                         }
  1087.                         break;
  1088.                 case 6:
  1089.                         NewElement_Form(CREATE_FOLDER, T_NEW_FOLDER);
  1090.                         break;
  1091.                 case 7:
  1092.                         NewElement_Form(CREATE_FILE, T_NEW_FILE);
  1093.                         break;
  1094.                 case 8:
  1095.                         properties_stak = malloc(8096);
  1096.                         CreateThread(#properties_dialog, properties_stak+8092);
  1097.                         break;
  1098.                 case 10: //F10
  1099.                         if (!active_settings)
  1100.                         {
  1101.                                 settings_stak = malloc(4096);
  1102.                                 settings_window = CreateThread(#settings_dialog, settings_stak+4092);
  1103.                                 break;
  1104.                         }
  1105.                         else
  1106.                         {
  1107.                                 ActivateWindow(GetProcessSlot(settings_window));
  1108.                         }
  1109.                         break;
  1110.         }
  1111. }
  1112.  
  1113. void ChangeActivePanel()
  1114. {
  1115.         llist_copy(#files_active, #files_inactive);
  1116.         llist_copy(#files_inactive, #files);
  1117.         strcpy(#active_path, #inactive_path);
  1118.         strcpy(#inactive_path, #path);
  1119.         DrawFilePanels();
  1120. }
  1121.  
  1122.  
  1123. stop:
  1124.