Subversion Repositories Kolibri OS

Rev

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

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