Subversion Repositories Kolibri OS

Rev

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