Subversion Repositories Kolibri OS

Rev

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