Subversion Repositories Kolibri OS

Rev

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