Subversion Repositories Kolibri OS

Rev

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