Subversion Repositories Kolibri OS

Rev

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