Subversion Repositories Kolibri OS

Rev

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