Subversion Repositories Kolibri OS

Rev

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