Subversion Repositories Kolibri OS

Rev

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