Subversion Repositories Kolibri OS

Rev

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