Subversion Repositories Kolibri OS

Rev

Rev 3467 | Rev 3846 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //Leency & Veliant 2008-2013
  2. //GNU GPL licence.
  3.  
  4. //êîïèðîâàòü ÷åðåç ïîòîê
  5.  
  6. //libraries
  7. #define MEMSIZE 0xA0000
  8. #include "..\lib\kolibri.h"
  9. #include "..\lib\strings.h"
  10. #include "..\lib\mem.h"
  11. #include "..\lib\dll.h"
  12. #include "..\lib\lib.obj\box_lib.h"
  13. #include "..\lib\file_system.h"
  14. #include "..\lib\figures.h"
  15. #include "..\lib\encoding.h"
  16. #include "..\lib\list_box.h"
  17. #include "..\lib\copyf.h"
  18. //images
  19. #include "imgs\toolbar.txt"
  20. #include "imgs\left_p.txt"
  21.  
  22.  
  23. enum {ONLY_SHOW, WITH_REDRAW, ONLY_OPEN}; //OpenDir
  24.  
  25. #define TITLE "Eolite File Manager v1.90"
  26. #define ABOUT_TITLE "Eolite v1.90"
  27. dword col_work    = 0xE4DFE1;
  28. dword col_border  = 0x9098B0; //A0A0B8; //0x819FC5;
  29. dword col_padding = 0xC8C9C9;
  30. dword col_selec   = 0x94AECE;
  31. dword col_lpanel  = 0x00699C;
  32.  
  33. int toolbar_buttons_x[7]={9,46,85,134,167,203};
  34. char tmp_disk_del_param[3]="d0";
  35. struct path_string { char Item[4096]; };
  36.  
  37. llist files;
  38.  
  39. byte
  40.         path[4096],
  41.         file_path[4096],
  42.         file_name[256],
  43.         temp[4096];      
  44. byte
  45.         rename_active=0,
  46.         del_active=0,
  47.         show_dev_name=1,
  48.         sort_num=2,
  49.         itdir;
  50.  
  51. proc_info Form;
  52. mouse m;
  53. int mouse_dd, scroll_used, scroll_size;
  54. dword buf, off;
  55. dword file_mas[6898];
  56. int j, i;
  57.  
  58. edit_box edit2= {250,213,80,0xFFFFCC,0x94AECE,0xFFFFCC,0xffffff,0,248,#file_name,#mouse_dd,64,6,6};
  59. PathShow_data PathShow = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, #path, #temp, 0};
  60. PathShow_data FileShow = {0, 56,215, 6, 100, 0, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
  61.  
  62. #include "include\copypaste.h"
  63. #include "include\some_code.h"
  64. #include "include\sorting.h"
  65. #include "include\icons_f.h"
  66. #include "include\ini.h"
  67. #include "include\left_panel.h"
  68. #include "include\history.h"
  69. #include "include\file_menu.h"
  70. #include "include\about_dialog.h"
  71.  
  72. void main()
  73. {
  74.         word key, id, can_show, can_select, m_selected;
  75.  
  76.         files.line_h=18;
  77.         mem_Init();
  78.         if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("Error while loading library /rd/1/lib/box_lib.obj");
  79.         SystemDiscsGet();
  80.         GetIni(1);     
  81.         if (param)
  82.         {
  83.                 strcpy(#path, #param);
  84.                 if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //add "/" to the end of the string
  85.         }
  86.         else
  87.         {
  88.                 strcpy(#path, "/rd/1/");               
  89.         }
  90.         Open_Dir(#path,ONLY_OPEN);
  91.         SetEventMask(0x27);
  92.         loop() switch(WaitEvent())
  93.         {
  94.                 case evMouse:
  95.                         IF (del_active) break;         
  96.                         id=GetProcessSlot(Form.ID);
  97.                         IF (id!=GetActiveProcess()) || (Form.status_window>2) break;
  98.                         IF (rename_active) { edit_box_mouse stdcall(#edit2); break; }
  99.                        
  100.                         m.get();
  101.  
  102.                         if (m.x > files.x) && (m.x < files.x + files.w) && (m.y > files.y) && (m.y < files.y+files.h) && (!can_select)
  103.                         {
  104.                                 m_selected = m.y - 57 / files.line_h;
  105.                                 if (m.lkm) can_select = 1;
  106.                                 if (m.pkm)
  107.                                 {
  108.                                         can_show = 1;
  109.                                         if (m.y - 57 / files.line_h != files.current) can_select = 1;
  110.                                 }
  111.                         }
  112.  
  113.                         //select/open file {
  114.                         if (!m.lkm) && (!m.pkm) && (can_select)
  115.                         {
  116.                                 can_select = 0;
  117.                                 if (m.y>=57)
  118.                                 {
  119.                                         id = m.y - 57 / files.line_h;
  120.                                         if (id!=m_selected)
  121.                                         {
  122.                                                 can_show=0;
  123.                                                 break;
  124.                                         }
  125.                                         if (files.current!=id)
  126.                                                 List_Current(id-files.current);
  127.                                         else
  128.                                                 Open();
  129.                                 }
  130.                         };
  131.                         // } select/open file
  132.  
  133.                         //file menu {
  134.                         if (!m.pkm) && (!m.lkm) && (can_show)
  135.                         {
  136.                                 can_show = 0;
  137.                                 if (m.y>=57)
  138.                                 {
  139.                                         SwitchToAnotherThread();
  140.                                         CreateThread(#FileMenu,#menu_stak);
  141.                                 }
  142.                                 break;
  143.                         }
  144.                         // } file menu
  145.  
  146.                         if (m.vert)
  147.                         {
  148.                                 files.MouseScroll(m.vert);
  149.                                 List_ReDraw();
  150.                                 break;
  151.                         }
  152.  
  153.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>40) && (m.y<57)
  154.                         {
  155.                                 IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),41,14,14,0xC7C7C7,0xFFFFFF);
  156.                                 WHILE (m.lkm==1) && (files.first>0)
  157.                                 {
  158.                                         pause(8);
  159.                                         files.first--;
  160.                                         List_ReDraw();
  161.                                         m.get();
  162.                                 }
  163.                                 DrawRectangle3D(onLeft(26,0),41,14,14,0xFFFFFF,0xC7C7C7);
  164.                         }
  165.  
  166.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>onTop(22,0)+1) && (m.y<onTop(22,0)+16)
  167.                         {
  168.                                 IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xC7C7C7,0xFFFFFF);
  169.                                 while (m.lkm==1) && (files.first<files.count-files.visible)
  170.                                 {
  171.                                         pause(8);
  172.                                         files.first++;
  173.                                         List_ReDraw();
  174.                                         m.get();
  175.                                 }
  176.                                 DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xFFFFFF,0xC7C7C7);
  177.                         }
  178.  
  179.                         //Scrooll
  180.                         if (!m.lkm) && (scroll_used) { scroll_used=NULL; Scroll(); }
  181.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>56) && (m.y<Form.height) && (m.lkm) && (!scroll_used) {scroll_used=1;Scroll();}
  182.                        
  183.                         if (scroll_used)
  184.                         {
  185.                                 IF (scroll_size/2+57>m.y) || (m.y<0) || (m.y>4000) m.y=scroll_size/2+57; //anee eo?ni? iaa ieiii
  186.                                 id=files.first;
  187.                                 j= scroll_size/2;
  188.                                 files.first = m.y -j -57 * files.count;
  189.                                 files.first /= onTop(22,57);
  190.                                 IF (files.visible+files.first>files.count) files.first=files.count-files.visible;
  191.                                 IF (id!=files.first) List_ReDraw();
  192.                         }
  193.                         break;  
  194. //Button pressed-----------------------------------------------------------------------------
  195.                 case evButton:
  196.                         id=GetButtonID();
  197.                         if (id==1) ExitProcess();
  198.                         if (rename_active) break;
  199.                         if (del_active)
  200.                         {
  201.                                 IF (id==301) || (id==302) Del_File(302-id);
  202.                                 break;
  203.                         }
  204.                        
  205.                         switch(id)
  206.                         {
  207.                                 case 21: //Back
  208.                                                 GoBack();
  209.                                                 break;
  210.                                 case 22: //Forward
  211.                                                 if (HistoryPath(GO_FORWARD))
  212.                                                 {
  213.                                                         files.first=files.current=NULL; //aaa?o nienea
  214.                                                         Open_Dir(#path,WITH_REDRAW);
  215.                                                 }
  216.                                                 break;
  217.                                 case 23: //up!
  218.                                                 Dir_Up();
  219.                                                 break;
  220.                                 case 24: //cut
  221.                                                 Copy(#file_path, NOCUT);
  222.                                                 break;
  223.                                 case 25: //copy
  224.                                                 Copy(#file_path, CUT);
  225.                                                 break;
  226.                                 case 26: //paste
  227.                                                 CreateThread(#Paste,#copy_stak);
  228.                                                 break;
  229.                                 case 31...33: //sort
  230.                                                 IF(sort_num==1) DrawFilledBar(onLeft(192,168)/2+210,42,6,10);
  231.                                                 IF(sort_num==2) DrawFilledBar(onLeft(115,0),42,6,10);
  232.                                                 IF(sort_num==3) DrawFilledBar(onLeft(44,0),42,6,10);
  233.                                                 sort_num=id-30;
  234.                                                 Open_Dir(#path,WITH_REDRAW);
  235.                                                 break;
  236.                                 case 50...60: //Actions
  237.                                                 FnProcess(id-50);
  238.                                                 break;
  239.                                 case 100...120:
  240.                                         DEVICE_MARK:
  241.                                                 DrawRectangle(17,id-100*16+74,159,16, 0); //auaaeaiea
  242.                                                 strcpy(#path, #disk_list[id-100].Item);
  243.                                                 files.first=files.current=0;
  244.                                                 Open_Dir(#path,WITH_REDRAW);
  245.                                                 pause(5);
  246.                                                 DrawRectangle(17,id-100*16+74,159,16, 0xFFFFFF);
  247.                                                 break;
  248.                                 case 130...160:
  249.                                                 tmp_disk_del_param[1]=disk_list[id-130].Item[4];
  250.                                                 RunProgram("/sys/tmpdisk", #tmp_disk_del_param);
  251.                                                 pause(10);
  252.                                                 SystemDiscsGet();
  253.                                                 Open_Dir(#path,WITH_REDRAW);
  254.                                                 DrawLeftPanel();
  255.                                                 break;
  256.                         }
  257.                         break;
  258. //Key pressed-----------------------------------------------------------------------------
  259.                 case evKey:
  260.                         key = GetKey();
  261.                         if (Form.status_window>2) break;
  262.                         IF (del_active)
  263.                         {
  264.                                 IF (key==013) Del_File(true);
  265.                                 IF (key==027) Del_File(false);
  266.                                 break;
  267.                         }
  268.                         IF (edit2.flags!=64) && (key!=13) && (key!=27)
  269.                         {
  270.                                 EAX=key<<8;
  271.                                 edit_box_key stdcall (#edit2);
  272.                                 break;
  273.                         }
  274.                         switch (key)
  275.                         {
  276.                                         case 209...217:
  277.                                                         id=key-110;
  278.                                                         IF (id-100>=disc_num) break;
  279.                                                         GOTO DEVICE_MARK;
  280.                                         case 008:
  281.                                                         //GoBack();
  282.                                                         Dir_Up();
  283.                                                         break;
  284.                                         case 004: //Ctrl+D set as bg
  285.                                                         strcpy(#temp, "\\S__");
  286.                                                         strcat(#temp, #file_path);
  287.                                                         RunProgram("/sys/media/kiv", #temp);
  288.                                                         break;
  289.                                         case 014: //Ctrl+N new window
  290.                                                         IF (Form.left==98) MoveSize(Form.left-20,Form.top-20,OLD,OLD);
  291.                                                         RunProgram("/sys/File Managers/Eolite", #path);
  292.                                                         break;
  293.                                         case 024: //Ctrl+X
  294.                                                         Copy(#file_path, CUT);
  295.                                                         break;
  296.                                         case 003: //Ctrl+C
  297.                                                         Copy(#file_path, NOCUT);
  298.                                                         break;
  299.                                         case 022: //Ctrl+V
  300.                                                         CreateThread(#Paste,#copy_stak);
  301.                                                         break;
  302.                                         case 027: //Esc
  303.                                                         IF (rename_active==1) ReName(false);
  304.                                                         break;
  305.                                         case 013: //Enter
  306.                                                         IF (rename_active==1) {ReName(true); break;}
  307.                                                         Open();
  308.                                                         break;
  309.                                         case 178: //up
  310.                                                         List_Current(-1);
  311.                                                         break;
  312.                                         case 177: //down
  313.                                                         List_Current(1);
  314.                                                         break;
  315.                                         case 180: //home
  316.                                                         files.first=0;
  317.                                                         files.current=0;
  318.                                                         List_ReDraw();
  319.                                                         break;
  320.                                         case 181: //end
  321.                                                         files.first = files.count - files.visible;
  322.                                                         files.current = files.visible - 1;
  323.                                                         List_ReDraw();
  324.                                                         break;
  325.                                         case 183: //Page Down
  326.                                                         List_Current(files.visible-1);
  327.                                                         break;
  328.                                         case 184: //Page Up
  329.                                                         List_Current(-files.visible+1);
  330.                                                         break;
  331.                                         case 182: //del
  332.                                                         Del_Form();
  333.                                                         break;
  334.                                         case 050...059: //F1-F10
  335.                                                         FnProcess(key-49);
  336.                                                         break;
  337.                                         default:    
  338.                                                         for (i=files.current+files.first+1; i<files.count; i++)
  339.                                                         {
  340.                                                                 strcpy(#temp, file_mas[i]*304+buf+72);
  341.                                                                 IF (temp[0]==key) || (temp[0]==key-32)
  342.                                                                 {
  343.                                                                         List_Current(i-files.current-files.first);
  344.                                                                         break;
  345.                                                                 }
  346.                                                         }
  347.                         }                        
  348.                         break;
  349.                 case evReDraw:
  350.                         draw_window();
  351.         }
  352. }
  353.  
  354.  
  355. void draw_window()
  356. {
  357.         DefineAndDrawWindow(40,20,550,500,0x73,col_work,TITLE);
  358.         GetProcessInfo(#Form, SelfInfo);
  359.         if (Form.status_window>2) return;
  360.         files.SetSizes(192, 57, onLeft(192,27), onTop(57,6), disc_num*16+195,files.line_h);
  361.         if (Form.height < files.min_h) MoveSize(OLD,OLD,OLD,files.min_h);
  362.         if (Form.width<480) MoveSize(OLD,OLD,480,OLD);
  363.         GetProcessInfo(#Form, SelfInfo); //if win_size changed
  364.  
  365.         PutPaletteImage(#toolbar,246,34,0,0,8,#toolbar_pal);
  366.         DrawBar(127, 8, 1, 25, col_border);
  367.         for (j=0; j<3; j++) DefineButton(toolbar_buttons_x[j]+2,5+2,31-5,29-5,21+j+BT_HIDE,col_work);
  368.         for (j=3; j<6; j++) DefineButton(toolbar_buttons_x[j],5,31,29,21+j+BT_HIDE,col_work);
  369.         DrawBar(246,0,onLeft(246,60),12, col_work); //upper editbox
  370.         DrawBar(246,29,onLeft(246,60),5,col_work);  //under editbox
  371.         DrawRectangle(246,12,onLeft(66,246),16,col_border);
  372.         DefineButton(onLeft(34,0),6,27,28,51+BT_HIDE+BT_NOFRAME,0); //about
  373.         PutPaletteImage(#goto_about,56,34,Form.width-65,0,8,#goto_about_pal);
  374.         //main rectangles
  375.         DrawRectangle(1,40,Form.cwidth-3,onTop(46,0),col_border);
  376.         DrawRectangle(0,39,Form.cwidth-1,onTop(44,0),col_palette[4]); //bg
  377.         for (i=0; i<5; i++) DrawBar(0, 34+i, Form.cwidth, 1, col_palette[8-i]);
  378.         DrawLeftPanel();
  379.         //ListBox
  380.         DrawFlatButton(files.x,40,onLeft(files.x,168),16,31,col_work,"File");
  381.         DrawFlatButton(onLeft(168,0),40,73,16,32,col_work,"Type");
  382.         DrawFlatButton(onLeft(95,0),40,68,16,33,col_work,"Size");
  383.         DrawBar(onLeft(27,0),57,1,onTop(22,57),col_border); //line to the left from the scroll
  384.         DrawFlatButton(onLeft(27,0),40,16,16,0,col_work,"\x18");
  385.         DrawFlatButton(onLeft(27,0),onTop(22,0),16,16,0,col_work,"\x19");
  386.         Open_Dir(#path,ONLY_SHOW);
  387.         if (del_active) Del_Form();
  388.         if (rename_active) FnProcess(2);
  389. }
  390.  
  391.  
  392. void KEdit()
  393. {
  394.         if (Form.width<480) return;
  395.         PathShow.area_size_x = Form.cwidth-306;
  396.         DrawBar(PathShow.start_x-3, PathShow.start_y-4, PathShow.area_size_x+2, 15, 0xFFFfff);
  397.         PathShow_prepare stdcall(#PathShow);
  398.         PathShow_draw stdcall(#PathShow);
  399. }
  400.  
  401.  
  402. void List_Current(int cur)
  403. {
  404.         if (cur<=0) //up
  405.         {
  406.                 IF (files.first==0) && (files.current<=0) return;
  407.                 IF (-cur-1<files.current)
  408.                 {
  409.                         Line_ReDraw(0xFFFFFF, files.current);
  410.                         files.current+=cur;
  411.                         Line_ReDraw(col_selec, files.current);
  412.                         return;
  413.                 }
  414.                 ELSE
  415.                 {
  416.                         IF (-cur<files.first) files.first+=cur; ELSE files.first=0;
  417.                         files.current=0;
  418.                         List_ReDraw();
  419.                         return;
  420.                 }
  421.         }
  422.         else  //down
  423.         {
  424.                 IF (files.first==files.count-files.visible) && (files.current==files.visible-1) return;
  425.                 IF (files.visible-files.current>cur)
  426.                 {
  427.                         Line_ReDraw(0xFFFFFF, files.current);
  428.                         files.current+=cur;
  429.                         Line_ReDraw(col_selec, files.current);
  430.                         return;
  431.                 }
  432.                 else
  433.                 {
  434.                         IF(files.first+files.current+cur>=files.count)
  435.                         {
  436.                                 files.first=files.count-files.visible;
  437.                                 files.current=cur-files.first+files.current;
  438.                                 }
  439.                         ELSE
  440.                         {
  441.                                 files.first+=cur+files.current-files.visible+1;
  442.                                 files.current=files.visible-1;
  443.                         }
  444.                        
  445.                         IF (files.current<0) || (files.current>files.visible)
  446.                         {
  447.                                 files.current=files.visible-1;
  448.                         }
  449.                         List_ReDraw();
  450.                 }
  451.         }
  452. }
  453.  
  454.  
  455. void List_ReDraw()
  456. {
  457.         int paint_y;
  458.         //åñëè ìû â êîíöå ñïèñêà ôàéëîâ ðàçâåðí¸ì îêíî ïîÿâÿòüñÿ ïóñòÿå áåëûå êíîïêè
  459.         //ýòî åñëè âûäåëåíèå ïîñëå ñõëîïûâàíèÿ îêíà çà êàäðîì
  460.         if (files.count-files.first<files.visible) || (files.current>files.visible-1)
  461.         { files.first=files.count-files.visible; files.current=files.visible-1; }
  462.  
  463.         for (j=0; j<files.visible; j++) if (files.current!=j) Line_ReDraw(0xFFFFFF, j); else Line_ReDraw(col_selec, files.current);
  464.         //in the bottom
  465.         paint_y = j * files.line_h + files.y;
  466.         DrawBar(files.x,paint_y,files.w,onTop(paint_y,6),0xFFFFFF);
  467.         DrawBar(Form.cwidth-159,paint_y,1,onTop(paint_y,6),col_work);
  468.         DrawBar(Form.cwidth-86,paint_y,1,onTop(paint_y,6),col_work);
  469.         Scroll();
  470. }
  471.  
  472.  
  473. void Line_ReDraw(dword color, filenum){
  474.         dword text_col=0,
  475.               name_len=0,
  476.               attr,
  477.               y=filenum*files.line_h+57;
  478.         DrawBar(files.x,y,3,files.line_h,color);
  479.         DrawBar(files.x+19,y,files.w-19,files.line_h,color);
  480.         DrawBar(files.x+3,y+17,16,1,color);
  481.         if (files.line_h>18) DrawBar(files.x+3,y+18,16,files.line_h-18,color);
  482.         if (files.line_h>15) DrawBar(files.x+3,y,16,files.line_h-15,color);
  483.  
  484.         off=file_mas[filenum+files.first]*304 + buf+72;
  485.         attr = ESDWORD[off - 40];
  486.  
  487.         if (! TestBit(attr, 4) ) //file or folder?
  488.         {      
  489.                 Put_icon(off+_strrchr(off,'.'), files.line_h/2-7+y, color);
  490.                 WriteText(7-strlen(ConvertMemSize(ESDWORD[off-8]))*6+onLeft(75,0),files.line_h-6/2+y,0x80,0,ConvertMemSize(ESDWORD[off-8])); //size
  491.         }
  492.         else
  493.                 if (!strcmp("..",off))
  494.                         Put_icon("..", files.line_h/2-7+y, color);
  495.                 else
  496.                         Put_icon("<DIR>", files.line_h/2-7+y, color);
  497.         if ( TestBit(attr, 1) ) || ( TestBit(attr, 2) ) text_col=0xA6A6B7; //system or hiden?
  498.         if (color!=0xFFFfff)
  499.         {
  500.                 itdir = TestBit(attr, 4);
  501.                 strcpy(#file_name, off);
  502.                 strcpy(#file_path, #path);
  503.                 strcat(#file_path, #file_name);
  504.                 if (text_col==0xA6A6B7) text_col=0xFFFFFF;
  505.         }
  506.         if (Form.width>=480)
  507.         {
  508.                 FileShow.start_x = files.x + 23;
  509.                 FileShow.font_color = text_col;
  510.                 FileShow.area_size_x = Form.width - 380;
  511.                 FileShow.text_pointer = off;
  512.                 FileShow.start_y = files.line_h/2-3+y;
  513.                 PathShow_prepare stdcall(#FileShow);
  514.                 PathShow_draw stdcall(#FileShow);
  515.         }
  516.         DrawBar(Form.cwidth-159,y,1,files.line_h,col_work); //gray line 1
  517.         DrawBar(Form.cwidth-86,y,1,files.line_h,col_work); //gray line 2
  518. }
  519.  
  520.  
  521. void Open_Dir(dword dir_path, redraw){
  522.         int errornum, maxcount;
  523.  
  524.         if (redraw!=ONLY_SHOW)
  525.         {
  526.                 if (ESBYTE[dir_path+1]!='\0') ESBYTE[dir_path+strlen(dir_path)-1] = '\0';
  527.                 if (buf) free(buf);
  528.                 errornum = GetDir(#buf, #files.count, dir_path, DIRS_NOROOT);
  529.                 if (ESBYTE[dir_path+1]!='\0') chrcat(dir_path, '/');
  530.                 if (errornum)
  531.                 {
  532.                         HistoryPath(ADD_NEW_PATH);
  533.                         GoBack();
  534.                         Write_Error(errornum);
  535.                         return;
  536.                 }
  537.                 maxcount = sizeof(file_mas)/sizeof(dword)-1;
  538.                 if (files.count>maxcount) files.count = maxcount;              
  539.         }
  540.         if (files.count!=-1)
  541.         {
  542.                 KEdit();
  543.                 HistoryPath(ADD_NEW_PATH);
  544.                 files.visible = files.h / files.line_h;
  545.                 IF (files.count < files.visible) files.visible = files.count;
  546.                 IF (sort_num==1) WriteText(Form.width+60/2,45,0x80,col_border,"\x19");
  547.                 IF (sort_num==2) WriteText(Form.width-115,45,0x80,col_border,"\x19");
  548.                 IF (sort_num==3) WriteText(Form.width-44,45,0x80,col_border,"\x19");
  549.                 IF (redraw!=ONLY_SHOW) Sorting();
  550.                 IF (redraw!=ONLY_OPEN) List_ReDraw();
  551.         }
  552.         IF (files.count==-1) && (redraw!=ONLY_OPEN) {files.visible=files.count=0; List_ReDraw();}
  553. }
  554.  
  555.  
  556. inline Sorting()
  557. {
  558.         dword k=0, l=1;
  559.         int i;
  560.         if (!strcmp(#path,"/")) //do not sort
  561.         {
  562.                 FOR(k=1;k<files.count;k++;) file_mas[k]=k;
  563.                 return;
  564.         }
  565.         FOR (j=files.count-1, off=files.count-1*304+buf+32; j>=0; j--, off-=304;)  //files | folders
  566.         {
  567.                 strttl(off+40);
  568.                 if (TestBit(ESDWORD[off],4)) //directory?
  569.                 {
  570.                         file_mas[k]=j;
  571.                         k++;
  572.                 }
  573.                 else
  574.                 {
  575.                         file_mas[files.count-l]=j;
  576.                         l++;
  577.                 }
  578.         }
  579.         //sorting: files first, then folders
  580.         Sort_by_Name(0,k-1);
  581.         IF (sort_num==1) Sort_by_Name(k,files.count-1);
  582.         IF (sort_num==2) Sort_by_Type(k,files.count-1);
  583.         IF (sort_num==3) Sort_by_Size(k,files.count-1);
  584.         //".." should be first
  585.         IF (k>0) && (strcmp(file_mas[0]*304+buf+72,"..")!=0)
  586.                 FOR(k--; k>0; k--;) IF (!strcmp(file_mas[k]*304+buf+72,"..")) {file_mas[k]><file_mas[0]; break;}
  587. }
  588.  
  589.  
  590. void Del_Form()
  591. {
  592.         int dform_x = files.w - 200 / 2 + files.x;
  593.         //oeia ieii
  594.         if (!files.count) return;
  595.         DrawFlatButton(dform_x,160,200,80,0,col_work, ""); //oi?ia
  596.         WriteText(dform_x+19,175,0x80,0,"Do you really want to delete");
  597.         IF (strlen(#file_name)<28)
  598.                 {
  599.                         WriteText(strlen(#file_name)*6+dform_x+20,190,0x80,0,"?");
  600.                         WriteText(dform_x+20,190,0x80,0,#file_name); //ieoai eiy
  601.                 }
  602.         ELSE
  603.                 {
  604.                         WriteText(164+dform_x,190,0x80,0,"...?");
  605.                         ESI = 24;
  606.                         WriteText(dform_x+20,190,0,0,#file_name); //ieoai eiy
  607.                 }
  608.         DrawFlatButton(dform_x+20,208,70,20,301,0xFFB6B5,"Yes");
  609.         DrawFlatButton(dform_x+111,208,70,20,302,0xC6DFC6,"No");
  610.         del_active=1;
  611. }
  612.  
  613.        
  614. void Del_File(byte dodel)
  615. {    
  616.         int del_rezult;
  617.         IF (dodel==true)
  618.         {
  619.                 del_rezult = DeleteFile(#file_path);
  620.                 IF (del_rezult)
  621.                 {
  622.                         Write_Error(del_rezult);
  623.                         IF ( itdir) ShowMessage("Error. Folder isn't empty.");
  624.                         IF (!itdir) ShowMessage("Error. Filesystem read-only.");
  625.                 }
  626.         }
  627.         del_active=0;
  628.         DeleteButton(301); DeleteButton(302);
  629.         Open_Dir(#path,WITH_REDRAW);
  630. }
  631.  
  632.  
  633. void ReName(byte rename)
  634. {
  635.         int del_rezult, copy_rezult;
  636.         char edit_name[256];
  637.         rename_active=0;
  638.         edit2.flags=64;
  639.         if (rename==true)
  640.         {
  641.                 strcpy(#temp, #path);
  642.                 strcpy(#edit_name, #file_name); //save edit name to select it later
  643.                 strcat(#temp, #file_name);
  644.                 if (strcmp(#file_path,#temp)!=0) && (file_name)
  645.                 if (itdir)
  646.                 {
  647.                         del_rezult = DeleteFile(#file_path);
  648.                         if (del_rezult!=0)
  649.                         {
  650.                                 Write_Error(del_rezult);
  651.                                 ShowMessage("Error. Folder isn't empty.");
  652.                                 return;
  653.                         }
  654.                         ELSE CreateDir(#temp);
  655.                         Open_Dir(#path,WITH_REDRAW);
  656.                 }
  657.                 ELSE
  658.                 {
  659.                         copy_rezult = CopyFile(#file_path,#temp);
  660.                         if (copy_rezult!=0) Write_Error(copy_rezult); else Del_File(true);
  661.                 }
  662.                 SelectFile(#edit_name);
  663.         }
  664.         Line_ReDraw(col_selec,files.current);
  665. }
  666.  
  667.  
  668. void SelectFile(dword that_file)
  669. {
  670.         files.first=files.current=0;
  671.         Open_Dir(#path,ONLY_OPEN);
  672.         strttl(that_file);
  673.         for (i=files.count-1; i>=0; i--;)
  674.                 if (!strcmp(file_mas[i]*304+buf+72,that_file)) break;
  675.         List_Current(i);
  676.         List_ReDraw();
  677. }
  678.  
  679.  
  680. void Dir_Up()
  681. {
  682.         char cur_folder[4096];
  683.         i=strlen(#path)-1;
  684.         if (i==0) return;
  685.         path[i]=0x00;
  686.         i = strrchr(#path, '/');
  687.         strcpy(#cur_folder, #path+i);
  688.         path[i]=0x00;
  689.         SelectFile(#cur_folder);
  690. }
  691.  
  692. void Open()
  693. {
  694.         if (!files.count) return;
  695.         if (!itdir)
  696.         {
  697.                 GetIni(0);
  698.         }
  699.         else
  700.         {
  701.                 if (!strcmp(#file_name,"..")) { Dir_Up(); return; }
  702.                 strcpy(#path, #file_path);
  703.                 if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //need "/" in the end
  704.                 files.first=files.current=0;
  705.                 Open_Dir(#path,WITH_REDRAW);
  706.         }
  707. }
  708.  
  709.  
  710. inline fastcall void GoBack()
  711. {
  712.         char cur_folder[4096];
  713.         strcpy(#cur_folder, GetCurrentFolder());
  714.         if (HistoryPath(GO_BACK)) SelectFile(#cur_folder);
  715. }
  716.  
  717. void FnProcess(char N)
  718. {
  719.         switch(N)
  720.         {
  721.                 case 1:
  722.                         SwitchToAnotherThread();
  723.                         CreateThread(#about_dialog,#about_stak);
  724.                         break;
  725.                 case 2:
  726.                         if (!files.count) break;
  727.                         edit2.flags = 100000000000010b; //set active
  728.                         edit2.left = files.x + 21;
  729.                         edit2.width = files.w - 26;
  730.                         edit2.top=files.current*files.line_h+59;
  731.                         edit2.size=edit2.pos=strlen(#file_name);
  732.                         edit_box_draw  stdcall (#edit2);
  733.                         DrawBar(edit2.left,files.current*files.line_h+58,edit2.width+1,1,0xFFFFCC); //bg
  734.                         rename_active=1;
  735.                         break;
  736.                 case 3:
  737.                         IF (!itdir) RunProgram("/sys/tinypad", #file_path);
  738.                         break;
  739.                 case 4:
  740.                         IF (!itdir) RunProgram("/sys/develop/heed", #file_path);
  741.                         break;
  742.                 case 5: //refresh cur dir & devs
  743.                         Tip(56, "Devices", 55, "-");
  744.                         Open_Dir(#path,WITH_REDRAW);
  745.                         pause(10);
  746.                         GetIni(1);
  747.                         SystemDiscsGet();
  748.                         Open_Dir(#path,WITH_REDRAW);
  749.                         DrawLeftPanel();
  750.                         break;
  751.                 case 6:
  752.                         strcpy(#temp, #path);
  753.                         strcat(#temp, "New folder");
  754.                         CreateDir(#temp);
  755.                         if (!EAX){
  756.                                 SelectFile("New folder");
  757.                                 FnProcess(2);
  758.                         }
  759.                         else
  760.                         {
  761.                                 Write_Error(EAX);
  762.                                 ShowMessage("Folder can not be created.");
  763.                         }
  764.                         break;
  765.                 case 7:
  766.                         strcpy(#temp, #path);
  767.                         strcat(#temp, "New file");
  768.                         WriteFile(0, 0, #temp);
  769.                         if (!EAX){
  770.                                 SelectFile("New file");
  771.                                 FnProcess(2);
  772.                         }
  773.                         else
  774.                         {
  775.                                 Write_Error(EAX);
  776.                                 ShowMessage("File can not be created.");
  777.                         }
  778.                         break;
  779.                 case 10: //F10
  780.                         RunProgram(EDITOR_PATH, abspath("Eolite.ini"));
  781.                         break;
  782.         }
  783. }
  784.  
  785.  
  786. stop:
  787.  
  788. char about_stak[512];
  789. char menu_stak[512];
  790. char copy_stak[4096];