Subversion Repositories Kolibri OS

Rev

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