Subversion Repositories Kolibri OS

Rev

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

  1. //Leency, Veliant, Punk_Joker, PavelYakov & KolibriOS Team 2008-2021
  2. //GNU GPL license.
  3.  
  4. /*
  5. TODO:
  6. - fix a kfm2 bug with selected files on window deactivation
  7. - click on a path bar opens edit
  8. - click to show breadcrumbs
  9. - 70.5 - get volume info and label
  10. */
  11.  
  12. #define ABOUT_TITLE "EOLITE 5 Beta11"
  13. #define TITLE_EOLITE "Eolite File Manager 5 Beta11"
  14. #define TITLE_KFM "Kolibri File Manager 2 Beta11";
  15.  
  16. #define MEMSIZE 1024 * 250
  17. #include "../lib/clipboard.h"
  18. #include "../lib/strings.h"
  19. #include "../lib/mem.h"
  20. #include "../lib/fs.h"
  21. #include "../lib/gui.h"
  22. #include "../lib/list_box.h"
  23. #include "../lib/random.h"
  24. #include "../lib/kfont.h"
  25. #include "../lib/collection.h"
  26. #include "../lib/copyf.h"
  27.  
  28. #include "../lib/obj/libini.h"
  29. #include "../lib/obj/box_lib.h"
  30. #include "../lib/obj/libimg.h"
  31.  
  32. #include "../lib/patterns/history.h"
  33.  
  34. #include "imgs/images.h"
  35. #include "include/const.h"
  36.  
  37. _history history;
  38.  
  39. struct Eolite_colors
  40. {
  41.         bool  def;
  42.         dword lpanel;
  43.         dword list_vert_line; //vertical line between columns in list
  44.         dword selec;
  45.         dword selec_active;
  46.         dword selec_inactive;
  47.         dword selec_text;
  48.         dword list_bg;
  49.         dword list_gb_text;
  50.         dword list_text_hidden;
  51.         dword work_gradient[24];
  52.         dword slider_bg_big;
  53.         dword slider_bg_left;
  54.         dword odd_line;
  55. } col;
  56. dword waves_pal[256];
  57.  
  58. bool efm = false;
  59.  
  60. int toolbar_buttons_x[7]={9,46,85,134,167,203};
  61.  
  62. byte del_active=0;
  63. byte new_element_active=0;
  64.  
  65. llist files, files_active, files_inactive;
  66.  
  67. bool list_full_redraw;
  68.  
  69. //Folder data
  70.         dword buf;
  71.         collection_int items=0;
  72.         int selected_count;
  73.         int folder_count;
  74.         dword path;
  75.         bool dir_at_fat16 = NULL;
  76.  
  77. //Sselected element data
  78.         byte file_path[4096];
  79.         byte file_name[256];
  80.         byte new_element_name[256];
  81.         byte temp[4096];
  82.         bool itdir;
  83.  
  84. //Window data
  85.         proc_info Form;
  86.         int sc_slider_h;
  87.         bool scroll_used=false;
  88.         char sort_type=2;
  89.         bool sort_desc=false;
  90.         int status_bar_h;
  91.         int icon_size = 18;
  92.  
  93. //Threads data
  94.         dword about_thread_id;
  95.         dword settings_window;
  96.         bool active_about = false;
  97.         bool active_settings = false;
  98.         dword about_stak=0,properties_stak=0,settings_stak=0;
  99.         byte cmd_free=0;
  100.  
  101. //Multipanes
  102.         int active_panel=0;
  103.         int disk_popin_active_on_panel=0;
  104.         #define PANES_COUNT 2
  105.         dword location[PANES_COUNT];
  106.  
  107. libimg_image icons16_default;
  108. libimg_image icons16_selected;
  109.  
  110. libimg_image icons32_default;
  111. libimg_image icons32_selected;
  112.  
  113. edit_box new_file_ed = {200,213,180,0xFFFFFF,0x94AECE,0xFFFFFF,0xFFFFFF,0x10000000,
  114.         248,#new_element_name,0,ed_focus+ed_always_focus,6,0};
  115. PathShow_data FileShow = {0, 56,215, 8, 100, 1, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
  116.  
  117. #include "include\settings.h"
  118. #include "include\gui.h"
  119. #include "include\progress_dialog.h"
  120. #include "include\copy_and_delete.h"
  121. #include "include\sorting.h"
  122. #include "include\icons.h"
  123. #include "include\left_panel.h"
  124. #include "include\menu.h"
  125. #include "include\about.h"
  126. #include "include\properties.h"
  127.  
  128. void handle_param()
  129. {
  130.         //-p <path> : just show file/folder properties dialog
  131.         //-d <path> : delete file/folder
  132.         //-v : paste files/folder from clipboard
  133.         int i;
  134.         dword p = #param;
  135.         if (streq(#program_path+strrchr(#program_path,'/'), "KFM")) efm = true;
  136.  
  137.         LoadIniSettings();
  138.  
  139.         for (i=0; i<PANES_COUNT; i++) {
  140.                 location[i] = malloc(4096);
  141.                 strcpy(location[i], #path_start);
  142.         }
  143.         path = location[0];
  144.  
  145.         if (ESBYTE[p]=='\0') return;
  146.  
  147.         if (ESBYTE[p]=='-') switch (ESBYTE[p+1])
  148.         {
  149.                 case 'p':
  150.                         strcpy(#file_path, p + 3);
  151.                         itdir = dir_exists(#file_path);
  152.                         strcpy(#file_name, p + strrchr(p, '/'));
  153.                         ESBYTE[strrchr(p, '/')+p-1] = '\0';
  154.                         strcpy(path, p + 3);
  155.                         properties_dialog();
  156.                         ExitProcess();
  157.                 case 'd':
  158.                         strcpy(path, p + 3);
  159.                         DeleteThread();
  160.                         ExitProcess();
  161.                 case 'v':
  162.                         cut_active = ESBYTE[p+2] - '0';
  163.                         strcpy(path, p + 4);
  164.                         PasteThread();
  165.                         ExitProcess();
  166.         }
  167.  
  168.         if (param[strlen(#param)-1]=='/') ESBYTE[strlen(#param)-1]=NULL; //no "/" at the end
  169.  
  170.         if (dir_exists(p)) {
  171.                 strcpy(path, p);
  172.         } else {
  173.                 if (file_exists(p)) {
  174.                         ESBYTE[strrchr(p, '/')+p-1] = '\0';
  175.                         strcpy(path, p);
  176.                         SelectFileByName(p+strlen(path)+1);
  177.                 } else {
  178.                         notify(T_NOTIFY_APP_PARAM_WRONG);
  179.                 }
  180.         }      
  181. }
  182.  
  183. void main()
  184. {
  185.         dword id;
  186.         int old_cur_y;
  187.  
  188.         load_dll(boxlib, #box_lib_init,0);
  189.         load_dll(libini, #lib_init,1);
  190.         load_dll(libimg, #libimg_init,1);
  191.  
  192.         SetAppColors();
  193.         handle_param();
  194.  
  195.         SystemDiscs.Get();
  196.         Open_Dir(path,ONLY_OPEN);
  197.         llist_copy(#files_inactive, #files);
  198.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  199.         loop() switch(@WaitEventTimeout(100))
  200.         {
  201.                 case evMouse:
  202.                         if (del_active) || (disk_popin_active_on_panel) || (Form.status_window&ROLLED_UP) break;
  203.                         if (new_element_active)
  204.                         {
  205.                                 edit_box_mouse stdcall(#new_file_ed);
  206.                                 break;
  207.                         }      
  208.                        
  209.                         mouse.get();
  210.  
  211.                         ProceedMouseGestures();
  212.  
  213.                         if (mouse.vert)
  214.                         {
  215.                                 if (files.MouseScroll(mouse.vert)) List_ReDraw();
  216.                                 break;
  217.                         }
  218.  
  219.                         if (files.MouseOver(mouse.x, mouse.y))
  220.                         {
  221.                                 //select file
  222.                                 if (mouse.key&MOUSE_LEFT) && (mouse.up)
  223.                                 {
  224.                                         GetKeyModifier();
  225.                                         old_cur_y = files.cur_y;
  226.                                         if (files.ProcessMouse(mouse.x, mouse.y)) && (!key_modifier) {
  227.                                                 List_ReDraw();
  228.                                                 break;
  229.                                         }
  230.                                         if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
  231.                                                 EventChooseFilesRange(old_cur_y, files.cur_y);
  232.                                         } else if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  233.                                                 EventChooseFile(files.cur_y);
  234.                                                 DrawStatusBar();
  235.                                                 List_ReDraw();
  236.                                         } else {
  237.                                                 if (mouse.y - files.y / files.item_h + files.first == files.cur_y) EventOpen(0);
  238.                                         }
  239.                                 }
  240.                                 //file menu
  241.                                 if (mouse.key&MOUSE_RIGHT) && (mouse.up)
  242.                                 {
  243.                                         if (files.ProcessMouse(mouse.x, mouse.y)) List_ReDraw();
  244.                                         if (getElementSelectedFlag(files.cur_y) == false) selected_count = 0; //on redraw selection would be flashed, see [L001]
  245.                                         EventShowListMenu();
  246.                                 }
  247.                         }
  248.  
  249.                         if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y-17) && (mouse.y<files.y)
  250.                         {
  251.                                 if (mouse.lkm) DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,sc.work_dark,sc.work_light);
  252.                                 WHILE (mouse.lkm) && (files.first>0)
  253.                                 {
  254.                                         pause(8);
  255.                                         files.first--;
  256.                                         List_ReDraw();
  257.                                         mouse.get();
  258.                                 }
  259.                                 DrawRectangle3D(files.x+files.w+1,files.y-16,14,14,sc.work_light,sc.work_dark);
  260.                         }
  261.  
  262.                         if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+16) && (mouse.y>files.y+files.h-16) && (mouse.y<files.y+files.h)
  263.                         {
  264.                                 if (mouse.lkm) DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,sc.work_dark,sc.work_light);
  265.                                 while (mouse.lkm) && (files.first<files.count-files.visible)
  266.                                 {
  267.                                         pause(8);
  268.                                         files.first++;
  269.                                         List_ReDraw();
  270.                                         mouse.get();
  271.                                 }
  272.                                 DrawRectangle3D(files.x+files.w+1,files.y+files.h-15,14,14,sc.work_light,sc.work_dark);
  273.                         }
  274.  
  275.                         //Scrooll
  276.                         if (mouse.x>=files.x+files.w) && (mouse.x<=files.x+files.w+18) && (mouse.y>files.y)
  277.                                 && (mouse.y<files.y+files.h-18) && (mouse.lkm) && (!scroll_used) {scroll_used=true; DrawScroll(scroll_used);}
  278.                         if (scroll_used) && (!mouse.key&MOUSE_LEFT) { scroll_used=false; DrawScroll(scroll_used); }
  279.                        
  280.                         if (scroll_used)
  281.                         {
  282.                                 if (sc_slider_h/2+files.y>mouse.y) || (mouse.y<0) || (mouse.y>4000) mouse.y=sc_slider_h/2+files.y; //anee eo?ni? iaa ieiii
  283.                                 id = files.first;
  284.                                 files.first = -sc_slider_h / 2 + mouse.y -files.y * files.count;
  285.                                 files.first /= files.h - 18;
  286.                                 if (files.visible+files.first>files.count) files.first=files.count-files.visible;
  287.                                 if (files.first<0) files.first=0;
  288.                                 if (id!=files.first) List_ReDraw();
  289.                                 break;
  290.                         }
  291.  
  292.                         if (efm) && (mouse.y < files.y + files.h) && (mouse.down) {
  293.                                 if (mouse.x<Form.cwidth/2) {
  294.                                         SetActivePanel(0);
  295.                                 } else {
  296.                                         SetActivePanel(1);
  297.                                 }
  298.                         }
  299.                         break;  
  300. //Button pressed-----------------------------------------------------------------------------
  301.                 case evButton:
  302.                         id = GetButtonID();
  303.  
  304.                         if (id==CLOSE_BTN) {
  305.                                 KillProcess(about_thread_id);
  306.                                 SaveIniSettings();
  307.                                 ExitProcess();
  308.                         }
  309.  
  310.                         if (new_element_active) || (del_active) || (disk_popin_active_on_panel) {
  311.                                 if (POPUP_BTN1==id) && (del_active) EventDelete();
  312.                                 if (POPUP_BTN1==id) && (new_element_active) NewElement();
  313.                                 if (POPUP_BTN2==id) EventClosePopinForm();
  314.                                 if (disk_popin_active_on_panel) {
  315.                                         if (id>=100) && (id<=120) EventDriveClick(id);
  316.                                         else EventClosePopinForm();
  317.                                 }
  318.                                 break;                                 
  319.                         }
  320.  
  321.                         switch(id)
  322.                         {
  323.                                 case PATH_BTN:
  324.                                                 notify(COPY_PATH_STR);
  325.                                                 Clipboard__CopyText(path);
  326.                                                 break;
  327.                                 case KFM_DEV_DROPDOWN_1:
  328.                                 case KFM_DEV_DROPDOWN_1+1:
  329.                                 case KFM_DEV_DROPDOWN_2:
  330.                                 case KFM_DEV_DROPDOWN_2+1:
  331.                                                 EventOpenDiskPopin(active_panel);
  332.                                                 break;
  333.                                 case BACK_BTN...PASTE_BTN:
  334.                                                 EventToolbarButtonClick(id);
  335.                                                 break;
  336.                                 case 31...33:
  337.                                                 EventSort(id-30);
  338.                                                 break;
  339.                                 case 51:
  340.                                                 EventShowBurgerMenu();
  341.                                                 break;
  342.                                 case 52...60: //Actions
  343.                                                 FnProcess(id-50);
  344.                                                 break;
  345.                                 case 61: // Set path as default
  346.                                                 SetDefaultPath(path);
  347.                                                 break;
  348.                                 case 100...120:
  349.                                         EventDriveClick(id);
  350.                                         break;
  351.                                 case BREADCRUMB_ID...360:
  352.                                         ClickOnBreadCrumb(id-BREADCRUMB_ID);
  353.                                         break;
  354.                                 case KFM_FUNC_ID...KFM_FUNC_ID+10:
  355.                                         FnProcess(id-KFM_FUNC_ID);
  356.                                         break;
  357.                         }
  358.                         break;
  359.                        
  360. //Key pressed-----------------------------------------------------------------------------
  361.                 case evKey:
  362.                         GetKeys();
  363.  
  364.                         if (Form.status_window&ROLLED_UP) break;
  365.  
  366.                         if (new_element_active) || (del_active) || (disk_popin_active_on_panel)
  367.                         {
  368.                                 if (key_scancode == SCAN_CODE_ESC) EventClosePopinForm();
  369.  
  370.                                 if (del_active) {
  371.                                         if (key_scancode == SCAN_CODE_ENTER) EventDelete();
  372.                                 }
  373.                                 if (new_element_active) {
  374.                                         if (key_scancode == SCAN_CODE_ENTER) NewElement();
  375.                                         EAX = key_editbox;
  376.                                         edit_box_key stdcall (#new_file_ed);
  377.                                 }
  378.                                 break;
  379.                         }
  380.  
  381.                         if (key_modifier&KEY_LALT) || (key_modifier&KEY_RALT) {
  382.                                 if (key_scancode == SCAN_CODE_F1) EventOpenDiskPopin(1);
  383.                                 if (key_scancode == SCAN_CODE_F2) EventOpenDiskPopin(2);
  384.                                 break;
  385.                         }
  386.                         if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
  387.  
  388.                                 if (key_scancode == SCAN_CODE_ENTER) {
  389.                                         EventOpenSelected();
  390.                                         break;
  391.                                 }
  392.  
  393.                                 old_cur_y = files.cur_y;
  394.                                 files.ProcessKey(key_scancode);
  395.                                 EventChooseFilesRange(old_cur_y, files.cur_y);
  396.                                 break;
  397.                         }
  398.  
  399.                         if (files.ProcessKey(key_scancode))
  400.                         {
  401.                                 List_ReDraw();
  402.                                 break;
  403.                         }
  404.  
  405.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
  406.                         {
  407.                                 switch(key_scancode)
  408.                                 {
  409.                                         case SCAN_CODE_F1...SCAN_CODE_F3:
  410.                                                         EventSort(key_scancode - 58);
  411.                                                         break;
  412.                                         case SCAN_CODE_1...SCAN_CODE_10:
  413.                                                         key_scancode-=2;
  414.                                                         if (key_scancode >= SystemDiscs.list.count) break;
  415.                                                         if (!efm) {
  416.                                                                 DrawRectangle(17,key_scancode*16+74,159,16, 0); //display click
  417.                                                                 pause(7);                                                                              
  418.                                                         }
  419.                                                         SystemDiscs.Click(key_scancode);
  420.                                                         break;
  421.                                         case SCAN_CODE_KEY_X:
  422.                                                         CopyFilesListToClipboard(CUT);
  423.                                                         break;                                         
  424.                                         case SCAN_CODE_KEY_C:
  425.                                                         CopyFilesListToClipboard(COPY);
  426.                                                         break;
  427.                                         case SCAN_CODE_KEY_G:
  428.                                                         EventOpenConsoleHere();
  429.                                                         break;
  430.                                         case SCAN_CODE_KEY_V:
  431.                                                         EventPaste(path);
  432.                                                         break;
  433.                                         case SCAN_CODE_KEY_D: //set image as bg
  434.                                                         strlcpy(#temp, "\\S__",4);
  435.                                                         strcat(#temp, #file_path);
  436.                                                         RunProgram("/sys/media/kiv", #temp);
  437.                                                         break;
  438.                                         case SCAN_CODE_KEY_N:
  439.                                                         EventOpenNewEolite();
  440.                                                         break;
  441.                                         case SCAN_CODE_KEY_R:
  442.                                                         EventManualFolderRefresh();
  443.                                                         break;
  444.                                         case SCAN_CODE_ENTER:
  445.                                                         if (!itdir) ShowOpenWithDialog();
  446.                                                         else EventOpen(1);
  447.                                                         break;
  448.                                         case SCAN_CODE_KEY_A:
  449.                                                         EventChooseAllFiles(true);
  450.                                                         break;
  451.                                         case SCAN_CODE_KEY_U: //unselect all files
  452.                                                         EventChooseAllFiles(false);
  453.                                                         break;
  454.                                 }
  455.                                 break;
  456.                         }
  457.  
  458.                         switch (key_scancode)
  459.                         {
  460.                                         case SCAN_CODE_BS:
  461.                                                         Dir_Up();
  462.                                                         break;
  463.                                         case SCAN_CODE_ENTER:
  464.                                                         EventOpen(0);
  465.                                                         break;
  466.                                         case SCAN_CODE_TAB:
  467.                                                         if (!efm) break;
  468.                                                         SetActivePanel(active_panel^1);
  469.                                                         break;
  470.                                         case SCAN_CODE_MENU:
  471.                                                         mouse.x = files.x+15;
  472.                                                         mouse.y = files.cur_y - files.first * files.item_h + files.y + 5;
  473.                                                         EventShowListMenu();
  474.                                                         break;
  475.                                         case SCAN_CODE_DEL:
  476.                                                         Del_Form();
  477.                                                         break;
  478.                                         case SCAN_CODE_SPACE:
  479.                                                         EventChooseFile(files.cur_y);
  480.                                                         DrawStatusBar();
  481.                                                         Line_ReDraw(col.selec, files.cur_y);
  482.                                                         break;
  483.                                         case SCAN_CODE_INS:
  484.                                                         EventChooseFile(files.cur_y);
  485.                                                         files.KeyDown();
  486.                                                         DrawStatusBar();
  487.                                                         List_ReDraw();
  488.                                                         break;
  489.                                         case SCAN_CODE_F1...SCAN_CODE_F10:
  490.                                                         FnProcess(key_scancode-58);
  491.                                                         break;
  492.                                         default:
  493.                                                         EventSelectFileByKeyPress();
  494.                         }                        
  495.                         break;
  496.                 case evIPC:
  497.                 case evReDraw:
  498.                         draw_window();
  499.                         if (CheckActiveProcess(Form.ID)) && (GetMenuClick()) break;
  500.                         break;
  501.                 default:
  502.                         if (!Form.status_window&ROLLED_UP) EventRefreshDisksAndFolders();
  503.         }
  504.        
  505.         if(cmd_free)
  506.         {
  507.                 if(cmd_free==2) about_stak=free(about_stak);
  508.                 else if(cmd_free==3) properties_stak=free(properties_stak);
  509.                 else if(cmd_free==4) settings_stak=free(settings_stak);
  510.                 cmd_free = false;
  511.         }
  512. }
  513.  
  514. void draw_window()
  515. {
  516.         dword i=0;
  517.         incn x;
  518.         dword title;
  519.         static int rand_n;
  520.         if (rand_n) rand_n = random(80);
  521.  
  522.         if (show_status_bar.checked) {
  523.                 #define STBAR_EOLITE_H 16
  524.                 #define STBAR_KFM_H 21
  525.                 if (efm) status_bar_h = STBAR_KFM_H;
  526.                 else status_bar_h = STBAR_EOLITE_H;
  527.         } else {
  528.                 status_bar_h = 0;
  529.         }
  530.         if (efm) title = TITLE_KFM; else title = TITLE_EOLITE;
  531.         DefineAndDrawWindow(Form.left+rand_n,Form.top+rand_n,Form.width,Form.height,0x73,NULL,title,0);
  532.         GetProcessInfo(#Form, SelfInfo);
  533.         if (Form.status_window&ROLLED_UP) return;
  534.         if (Form.height < 356) { MoveSize(OLD,OLD,OLD,356); return; }
  535.         GetProcessInfo(#Form, SelfInfo);
  536.         SetAppColors();
  537.         if (efm) {
  538.                 if (screen.width > 693) && (Form.width < 693) { MoveSize(OLD,OLD,693,OLD); return; }
  539.                 DrawBar(0, 4, Form.cwidth, SELECTY-5, sc.work);
  540.                 DrawBar(0, SELECTY+KFM2_DEVH+1, Form.cwidth, 3, sc.work);
  541.                 DrawBar(0, SELECTY-1, 1, KFM2_DEVH+2, sc.work);
  542.                 DrawBar(Form.cwidth-1, SELECTY-1, 1, KFM2_DEVH+2, sc.work);
  543.                 DrawBar(Form.cwidth/2-16, SELECTY-1, 16, KFM2_DEVH+2, sc.work);
  544.                 /*
  545.                 #define PAD 7
  546.                 #define GAP_S 26+5
  547.                 #define GAP_B 26+14
  548.                 x.set(Form.cwidth/2-DDW-203/2-GAP_S);
  549.                 while (i<200) {
  550.                         DrawTopPanelButton(i+BACK_BTN, x.inc(GAP_S), PAD, 30, false);
  551.                         DrawTopPanelButton(i+FWRD_BTN, x.inc(GAP_S), PAD, 31, false);
  552.                         DrawTopPanelButton(i+GOUP_BTN, x.inc(GAP_B), PAD, 01, false);
  553.                         DrawTopPanelButton(i+COPY_BTN, x.inc(GAP_B), PAD, 55, false);
  554.                         DrawTopPanelButton(i+CUT_BTN,  x.inc(GAP_S), PAD, 20, false);
  555.                         DrawTopPanelButton(i+PASTE_BTN,x.inc(GAP_S), PAD, 56, false);
  556.                         x.set(Form.cwidth/2-DDW-203/2-GAP_S+calc(Form.cwidth/2));
  557.                         i+=100;
  558.                 }
  559.                 //DrawTopPanelButton(51, Form.cwidth-GAP_S-PAD, PAD, -1, false); //burger menu
  560.                 */
  561.         } else {
  562.                 if (Form.width < 480) { MoveSize(OLD,OLD,480,OLD); return; }
  563.                 ESDWORD[#toolbar_pal] = sc.work;
  564.                 ESDWORD[#toolbar_pal+4] = MixColors(0, sc.work, 35);
  565.                 PutPaletteImage(#toolbar, 246, 34, 0, 0, 8, #toolbar_pal);             
  566.                 for (i=0; i<3; i++) DefineHiddenButton(toolbar_buttons_x[i]+2,7,31-5,29-5,BACK_BTN+i);
  567.                 for (i=3; i<6; i++) DefineHiddenButton(toolbar_buttons_x[i],  5,31,  29,  BACK_BTN+i);
  568.                 DrawBar(127, 8, 1, 25, sc.work_graph);
  569.                 DrawBar(246,0, Form.cwidth - 246, 34, sc.work);
  570.                 DrawDot(Form.cwidth-17,12);
  571.                 DrawDot(Form.cwidth-17,12+6);
  572.                 DrawDot(Form.cwidth-17,12+12);
  573.                 DefineHiddenButton(Form.cwidth-24,7,20,25,51+BT_NOFRAME); //dots
  574.         }
  575.         //main rectangles
  576.         DrawRectangle(1,40,Form.cwidth-3,Form.cheight - 42-status_bar_h,sc.work_graph);
  577.         DrawRectangle(0,39,Form.cwidth-1,-show_status_bar.checked*status_bar_h + Form.cheight - 40,col.work_gradient[4]); //bg
  578.         for (i=0; i<6; i++) DrawBar(0, 34+i, Form.cwidth, 1, MixColors(sc.work_dark, sc.work, i*10));
  579.         for (i=0; i<6; i++) DrawBar(0, 5-i, Form.cwidth, 1, MixColors(sc.work_light, sc.work, i*10));
  580.         llist_copy(#files_active, #files);
  581.         DrawStatusBar();
  582.         if (!selected_count) {
  583.                 Open_Dir(path,ONLY_OPEN); //if there are no selected files -> refresh folder [L001]
  584.         }
  585.         DrawFilePanels();
  586.         disk_popin_active_on_panel = 0;
  587. }
  588.  
  589. void DrawButtonsAroundList()
  590. {
  591.         word sorting_arrow_x;
  592.         dword sorting_arrow_t = "\x19";
  593.         if (sort_desc) sorting_arrow_t = "\x18";
  594.         DrawFlatButtonSmall(files.x - efm,           files.y-17,files.w-141+efm,16,31,T_FILE);
  595.         DrawFlatButtonSmall(files.x + files.w - 141, files.y-17,73,16,32,T_TYPE);
  596.         DrawFlatButtonSmall(files.x + files.w -  68, files.y-17,68,16,33,T_SIZE);
  597.         DrawFlatButtonSmall(files.x + files.w,       files.y-17,16,16, 0,"\x18");
  598.         DrawFlatButtonSmall(files.x + files.w,files.y+files.h-16,16,16,0,"\x19");
  599.         if (sort_type==1) sorting_arrow_x = files.w - 141 / 2 + files.x + 18;
  600.         if (sort_type==2) sorting_arrow_x = files.x + files.w - 90;
  601.         if (sort_type==3) sorting_arrow_x = strlen(T_SIZE)*3-30+files.x+files.w;
  602.         WriteText(sorting_arrow_x,files.y-12,0x80, sc.work_text, sorting_arrow_t);
  603.         DrawBar(files.x+files.w,files.y,1,files.h,sc.work_graph);
  604.         if (efm) && (files.x<5) {
  605.                 DrawBar(files.x+files.w+16,files.y,1,files.h,EDX); //line between panel
  606.         }
  607. }
  608.  
  609. void DrawFuncButtonsInKfm()
  610. {
  611.         int i, x=0, len, min_w=0, padding;
  612.         for (i=0; i<10; i++) min_w += strlen(kfm_func[i])+2*6 + 2;
  613.         padding = Form.cwidth - min_w + 4 / 10;
  614.         for (i=0; i<10; i++) {
  615.                 len = strlen(kfm_func[i])+2*6 + padding;
  616.                 if (i==9) len = Form.cwidth - x - 3;
  617.                 DrawBar(x, Form.cheight - 19, 1, 17, sc.work);
  618.                 DrawFuncButton(x+1, Form.cheight - 19, len, i+KFM_FUNC_ID+1, i+1, kfm_func[i]);
  619.                 x += len + 2;
  620.         }
  621. }
  622.  
  623. void DrawStatusBar()
  624. {
  625.         char status_bar_str[80];
  626.         int go_up_folder_exists=0;
  627.  
  628.         if (efm) {
  629.                 DrawBar(0, Form.cheight - status_bar_h, Form.cwidth, 2, sc.work);
  630.                 DrawBar(0, Form.cheight - 2, Form.cwidth,  2, sc.work);
  631.                 DrawBar(Form.cwidth-1, Form.cheight - 19, 1,  17, sc.work);
  632.                 DrawFuncButtonsInKfm();
  633.         } else {
  634.                 if (!show_status_bar.checked) return;
  635.                 if (files.count>0) && (streq(items.get(0)*304+buf+72,"..")) go_up_folder_exists=1;
  636.                 DrawBar(0, Form.cheight - status_bar_h, Form.cwidth,  status_bar_h, sc.work);
  637.                 sprintf(#status_bar_str, T_STATUS_EVEMENTS, folder_count-go_up_folder_exists, files.count-folder_count);
  638.                 WriteText(6,Form.cheight - 13,0x80,sc.work_text,#status_bar_str);
  639.                 if (selected_count) {
  640.                         sprintf(#status_bar_str, T_STATUS_SELECTED, selected_count);
  641.                         WriteText(Form.cwidth - calc(strlen(#status_bar_str)*6)-6,Form.cheight - 13,
  642.                                 0x80,sc.work_text,#status_bar_str);
  643.                 }
  644.         }
  645. }
  646.  
  647. void DrawFilePanels()
  648. {
  649.         int files_y = files.y;
  650.         int w2 = -Form.cwidth-1/2+Form.cwidth;
  651.         int h2 = Form.cheight-files_y-2 - status_bar_h;
  652.         if (!efm)
  653.         {
  654.                 SystemDiscs.Draw();
  655.                 files.SetSizes(192, 57, Form.cwidth - 210, Form.cheight - 59 - status_bar_h, files.item_h);
  656.                 DrawButtonsAroundList();
  657.                 List_ReDraw();
  658.                 DrawPathBar();
  659.         }
  660.         else
  661.         {
  662.                 llist_copy(#files_active, #files);
  663.                 llist_copy(#files, #files_inactive);
  664.  
  665.                 if (!active_panel) {
  666.                         files.SetSizes(Form.cwidth/2, files_y, w2-17, h2, files.item_h);
  667.                 } else {
  668.                         files.SetSizes(2, files_y, Form.cwidth/2-2-17, h2, files.item_h);
  669.                 }
  670.  
  671.                 files_inactive.x = files.x;
  672.                 DrawButtonsAroundList();
  673.                 path = location[active_panel^1];
  674.                 Open_Dir(path,WITH_REDRAW);
  675.                 if (!selected_count) files_inactive.count = files.count;
  676.                 llist_copy(#files, #files_active);
  677.  
  678.                 if (!active_panel) {
  679.                         files.SetSizes(2, files_y, Form.cwidth/2-2-17, h2, files.item_h);
  680.                 } else {
  681.                         files.SetSizes(Form.cwidth/2, files_y, w2 -17, h2, files.item_h);
  682.                 }
  683.  
  684.                 DrawButtonsAroundList();
  685.                 path = location[active_panel];
  686.                 Open_Dir(path,WITH_REDRAW);
  687.         }
  688. }
  689.  
  690. void List_ReDraw()
  691. {
  692.         int all_lines_h;
  693.         dword j;
  694.         static int old_cur_y, old_first;
  695.         dword separator_color;
  696.  
  697.         files.CheckDoesValuesOkey(); //prevent some shit
  698.         if (files.count < files.visible) files.visible = files.count;
  699.  
  700.         if (list_full_redraw) || (old_first != files.first)
  701.         {
  702.                 old_cur_y = files.cur_y;
  703.                 old_first = files.first;
  704.                 list_full_redraw = false;
  705.                 goto _ALL_LIST_REDRAW;
  706.         }
  707.         if (old_cur_y != files.cur_y)
  708.         {
  709.                 if (old_cur_y-files.first<files.visible) Line_ReDraw(col.list_bg, old_cur_y-files.first);
  710.                 Line_ReDraw(col.selec, files.cur_y-files.first);
  711.                 old_cur_y = files.cur_y;
  712.                 return;
  713.         }
  714.  
  715.         _ALL_LIST_REDRAW:
  716.  
  717.         for (j=0; j<files.visible; j++) {
  718.                 if (files.cur_y-files.first!=j) Line_ReDraw(col.list_bg, j);
  719.                 else Line_ReDraw(col.selec, files.cur_y-files.first);          
  720.         }
  721.         //in the bottom
  722.         all_lines_h = j * files.item_h;
  723.         DrawBar(files.x,all_lines_h + files.y,files.w,files.h - all_lines_h, col.list_bg);
  724.         if (colored_lines.checked) separator_color = col.list_bg; else separator_color = col.list_vert_line;
  725.         DrawBar(files.x+files.w-141,all_lines_h + files.y,1,files.h - all_lines_h, separator_color);
  726.         DrawBar(files.x+files.w-68,all_lines_h + files.y,1,files.h - all_lines_h, separator_color);
  727.         DrawScroll(scroll_used);
  728.  
  729.         if (del_active) Del_Form();
  730.         if (new_element_active) && (col.selec != 0xCCCccc) NewElement_Form(new_element_active, #new_element_name);
  731. }
  732.  
  733. void Line_ReDraw(dword bgcol, filenum){
  734.         dword text_col=col.list_gb_text,
  735.                   ext1, attr,
  736.                   file_name_off,
  737.                   file_size=0,
  738.                   y=filenum*files.item_h+files.y,
  739.                   icon_y = files.item_h-icon_size/2+y;
  740.                   BDVK file;
  741.                   char full_path[4096];
  742.                   dword separator_color;
  743.                   bool current_inactive = false;
  744.         char label_file_name[4096];
  745.         if (filenum==-1) return;
  746.  
  747.         if (bgcol==col.selec) && (files.x==files_inactive.x) {
  748.                 bgcol = col.list_bg;
  749.                 current_inactive = true;
  750.         }
  751.  
  752.         DrawBar(files.x,y,4,files.item_h,bgcol);
  753.         DrawBar(files.x+4,y,icon_size,icon_y-y,bgcol);
  754.         if (files.item_h>icon_size) DrawBar(files.x+4,icon_y+icon_size-1,icon_size,y+files.item_h-icon_y-icon_size+1,bgcol);
  755.         if (colored_lines.checked) {
  756.                 if (bgcol!=col.selec) && (filenum%2) bgcol=col.odd_line;
  757.                 separator_color = bgcol;
  758.         } else {
  759.                 separator_color = col.list_vert_line;
  760.         }
  761.         DrawBar(files.x+icon_size+4,y,files.w-icon_size-4,files.item_h,bgcol);
  762.         DrawBar(files.x+files.w-141,y,1,files.item_h, separator_color);
  763.         DrawBar(files.x+files.w-68,y,1,files.item_h, separator_color);
  764.  
  765.         ESI = items.get(filenum+files.first)*304 + buf+32;
  766.         attr = ESDWORD[ESI];
  767.         file.selected = ESBYTE[ESI+7];
  768.         file.sizelo   = ESDWORD[ESI+32];
  769.         file.sizehi   = ESDWORD[ESI+36];
  770.         file_name_off = ESI+40;
  771.         sprintf(#full_path,"%s/%s",path,file_name_off);
  772.  
  773.         if (attr&ATR_FOLDER)
  774.         {      
  775.                 if (!strcmp(file_name_off,"..")) ext1="<up>"; else {
  776.                         ext1="<DIR>";
  777.                         WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, col.list_gb_text, ext1);
  778.                 }
  779.                 if (chrnum(path, '/')==1) && (streq(path, "/kolibrios")==false) file_size = GetDeviceSize(#full_path);
  780.         }
  781.         else
  782.         {
  783.                 ext1 = strrchr(file_name_off,'.') + file_name_off;
  784.                 if (ext1==file_name_off) ext1 = NULL; //if no extension then show nothing
  785.                 file_size = ConvertSize64(file.sizelo, file.sizehi);
  786.                 if (ext1) && (strlen(ext1)<9) WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, col.list_gb_text, ext1);
  787.         }
  788.         if (file_size) WriteText(7-strlen(file_size)*6+files.x+files.w-58,
  789.                         files.text_y+y+1, files.font_type, col.list_gb_text, file_size);
  790.  
  791.         if (attr&ATR_HIDDEN) || (attr&ATR_SYSTEM) text_col=col.list_text_hidden;
  792.         if (bgcol==col.selec)
  793.         {
  794.                 file_name_is_8_3(file_name_off);
  795.                 itdir = attr & ATR_FOLDER;
  796.                 strcpy(#file_name, file_name_off);
  797.                 if (streq(path,"/")) sprintf(#file_path,"%s%s",path,file_name_off);
  798.                         else sprintf(#file_path,"%s/%s",path,file_name_off);
  799.                 if (text_col==col.list_text_hidden) {
  800.                         text_col=MixColors(col.selec_text, col.list_text_hidden, 65);
  801.                 } else text_col=col.selec_text;
  802.         }
  803.         if (file.selected) text_col=0xFF0000;
  804.         if (kfont.size.pt==9) || (!kfont.font)
  805.         {
  806.                 if (Form.width>=480)
  807.                 {
  808.                         FileShow.start_x = files.x + icon_size + 7;
  809.                         FileShow.font_color = text_col;
  810.                         FileShow.area_size_x = files.w - 164;
  811.                         FileShow.text_pointer = file_name_off;
  812.                         FileShow.start_y = files.text_y + y - 3;
  813.                         PathShow_prepare stdcall(#FileShow);
  814.                         PathShow_draw stdcall(#FileShow);
  815.                 }              
  816.         }
  817.         else
  818.         {
  819.                 //that shit must be it a library
  820.                 strcpy(#label_file_name, file_name_off);
  821.                 if (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w)
  822.                 {
  823.                         while (kfont.getsize(kfont.size.pt, #label_file_name) + 141 + 26 > files.w) {
  824.                                 ESBYTE[#label_file_name+strlen(#label_file_name)-1] = NULL;
  825.                         }
  826.                         strcpy(#label_file_name+strlen(#label_file_name)-2, "...");                    
  827.                 }
  828.                 kfont.WriteIntoWindow(files.x + icon_size+7, files.item_h - kfont.height / 2 + y,
  829.                         bgcol, text_col, kfont.size.pt, #label_file_name);
  830.         }
  831.         DrawIconByExtension(#full_path, ext1, files.x+4, icon_y, bgcol);
  832.         if (current_inactive) DrawWideRectangle(files.x+2, y, files.w-4, files.item_h, 2, col.selec_active);
  833. }
  834.  
  835.  
  836. void Open_Dir(dword dir_path, redraw){
  837.         int errornum;
  838.  
  839.         selected_count = 0;
  840.         if (buf) free(buf);
  841.         if (errornum = GetDir(#buf, #files.count, dir_path, DIRS_NOROOT))
  842.         {
  843.                 history.add(path);
  844.                 EventHistoryGoBack();
  845.                 Write_Error(errornum);
  846.                 return;
  847.         }
  848.         if (files.count>0) && (files.cur_y-files.first==-1) files.cur_y=0;
  849.  
  850.         SystemDiscs.Draw();
  851.         files.visible = files.h / files.item_h;
  852.         if (files.count < files.visible) files.visible = files.count;
  853.         if (!strncmp(dir_path, "/rd/1",5)) || (!strncmp(dir_path, "/sys/",4))
  854.                 dir_at_fat16 = true; else dir_at_fat16 = false;
  855.         Sorting();
  856.         list_full_redraw = true;
  857.         SetCurDir(dir_path);
  858.         if (redraw!=ONLY_OPEN) {
  859.                 history.add(path);
  860.                 List_ReDraw();
  861.                 DrawStatusBar();
  862.                 DrawPathBar();
  863.         }
  864. }
  865.  
  866. inline Sorting()
  867. {
  868.         dword d=0, f=1;
  869.         int j=0;
  870.         dword file_off;
  871.  
  872.         items.drop();
  873.  
  874.         if (streq(path,"/")) //do not sort root folder
  875.         {
  876.                 for(d=1;d<files.count;d++;) items.set(d, d);
  877.                 folder_count = d;
  878.                 return;
  879.         }
  880.         for (j=files.count-1, file_off=files.count-1*304+buf+32; j>=0; j--, file_off-=304;)  //files | folders
  881.         {
  882.                 if (dir_at_fat16) && (file_name_is_8_3(file_off+40)) strttl(file_off+40);
  883.                 if (ESDWORD[file_off] & ATR_FOLDER) {
  884.                         items.set(d, j);
  885.                         d++;
  886.                 } else {
  887.                         items.set(files.count-f, j);
  888.                         f++;
  889.                 }
  890.         }
  891.         folder_count = d;
  892.         //sorting: files first, then folders
  893.         Sort_by_Name(0,d-1);
  894.         if (sort_type==1) Sort_by_Name(d,files.count-1);
  895.         else if (sort_type==2) Sort_by_Type(d,files.count-1);
  896.         else if (sort_type==3) Sort_by_Size(d,files.count-1);
  897.         //reversed sorting
  898.         if (sort_desc) {
  899.                 for (j=0; j<f/2; j++) {
  900.                         items.swap(files.count-j-1, d+j);
  901.                 }
  902.                 //if (sort_type==1) for (j=0; j<d/2; j++) items[d-j]><items[j];
  903.         }
  904.         //make ".." first item in list
  905.         if (d>0) && (strncmp(items.get(0)*304+buf+72,"..",2)!=0)
  906.                 for(d--; d>0; d--;) if (!strncmp(items.get(d)*304+buf+72,"..",2)) {items.swap(d,0); break;}
  907. }
  908.  
  909.  
  910. void Del_Form()
  911. {
  912.         byte f_count[128];
  913.         int dform_x = files.w - 220 / 2 + files.x;
  914.         if (!selected_count) && (!strncmp(#file_name,"..",2)) return;
  915.         else
  916.         {
  917.                 if (!files.count) return;
  918.                 DrawEolitePopup(T_YES, T_NO);
  919.                 WriteText(-strlen(T_DELETE_FILE)*3+110+dform_x,175,0x80,sc.work_text,T_DELETE_FILE);
  920.                 if (selected_count)
  921.                 {
  922.                         sprintf(#f_count,"%s%d%s",DEL_MORE_FILES_1,selected_count,DEL_MORE_FILES_2);
  923.                         WriteText(-strlen(#f_count)*3+110+dform_x,190,0x80,sc.work_text,#f_count);
  924.                 }
  925.                 else
  926.                 {
  927.                         if (strlen(#file_name)<28)
  928.                         {
  929.                                 WriteText(strlen(#file_name)*3+110+dform_x+2,190,0x80,sc.work_text,"?");
  930.                                 WriteText(-strlen(#file_name)*3+110+dform_x,190,0x80,sc.work_text,#file_name);
  931.                         }
  932.                         else
  933.                         {
  934.                                 WriteText(164+dform_x,190,0x80,0,"...?");
  935.                                 ESI = 24;
  936.                                 WriteText(dform_x+20,190,0,0,#file_name);
  937.                         }
  938.                 }              
  939.                 del_active=1;
  940.         }
  941. }
  942.  
  943. void SelectFileByName(dword that_file)
  944. {
  945.         int ind;
  946.         files.KeyHome();
  947.         Open_Dir(path,ONLY_OPEN);
  948.         if (dir_at_fat16) && (file_name_is_8_3(that_file)) strttl(that_file);
  949.         for (ind=files.count-1; ind>=0; ind--;) { if (!strcmpi(items.get(ind)*304+buf+72,that_file)) break; }
  950.         files.cur_y = ind - 1;
  951.         files.KeyDown();
  952.         DrawStatusBar();
  953.         List_ReDraw();
  954. }
  955.  
  956.  
  957. void Dir_Up()
  958. {
  959.         int iii;
  960.         char old_folder_name[4096];
  961.         iii=strlen(path)-1;
  962.         if (iii==0) return;
  963.         iii = strrchr(path, '/');
  964.         strcpy(#old_folder_name, path+iii);
  965.         if (iii>1) ESBYTE[path+iii-1]=NULL; else ESBYTE[path+iii]=NULL;
  966.         SelectFileByName(#old_folder_name);
  967.         if(efm)DrawPathBarKfm();
  968. }
  969.  
  970. void EventOpenSelected()
  971. {
  972.         int i;
  973.         for (i=0; i<files.count; i++) if (getElementSelectedFlag(i)) {
  974.                 EDX = items.get(i)*304 + buf+32;
  975.                 if (ESDWORD[EDX]&ATR_FOLDER) continue; //is foder
  976.                 sprintf(#param,"%s/%s",path, EDX+40);
  977.                 RunProgram("/sys/@open", #param);
  978.         }
  979. }
  980.  
  981. void EventOpen(byte _new_window)
  982. {
  983.         if (selected_count) && (!itdir) notify(T_USE_SHIFT_ENTER);
  984.         if (_new_window)
  985.         {
  986.                 if (streq(#file_name,"..")) return;
  987.                 RunProgram(I_Path, #file_path);
  988.                 return;
  989.         }
  990.         if (!files.count) return;
  991.         if (!itdir)
  992.         {
  993.                 if (strrchr(#file_name, '.')==0) RunProgram(#file_path, ""); else RunProgram("/sys/@open", #file_path);
  994.         }
  995.         else
  996.         {
  997.                 if (!strncmp(#file_name,"..",3)) { Dir_Up(); return; }
  998.                 strcpy(path, #file_path);
  999.                 files.first=files.cur_y=0;
  1000.                 Open_Dir(path,WITH_REDRAW);
  1001.         }
  1002. }
  1003.  
  1004. inline fastcall void EventHistoryGoBack()
  1005. {
  1006.         char cur_folder[4096];
  1007.         strcpy(#cur_folder, path);
  1008.         if (history.back()) {
  1009.                 strcpy(path, history.current());
  1010.                 SelectFileByName(#cur_folder+strrchr(#cur_folder,'/'));
  1011.         }
  1012. }
  1013.  
  1014. void ShowOpenWithDialog()
  1015. {
  1016.         byte open_param[4097];
  1017.         sprintf(#open_param,"~%s",#file_path);
  1018.         RunProgram("/sys/@open", #open_param);
  1019. }
  1020.  
  1021. void NewElement()
  1022. {
  1023.         BDVK element_info;
  1024.         byte copy_result, info_result;
  1025.  
  1026.         sprintf(#temp,"%s/%s",path,new_file_ed.text);
  1027.         info_result = GetFileInfo(#temp, #element_info);
  1028.         switch(new_element_active)
  1029.         {
  1030.                 case CREATE_FILE:
  1031.                         if (info_result!=5) {
  1032.                                 notify(FS_ITEM_ALREADY_EXISTS);
  1033.                         } else {
  1034.                                 CreateFile(0, 0, #temp);
  1035.                                 if (EAX)
  1036.                                 {
  1037.                                         if (EAX==5) notify(NOT_CREATE_FILE);
  1038.                                         else Write_Error(EAX);
  1039.                                 }
  1040.                         }
  1041.                         break;
  1042.                 case CREATE_FOLDER:
  1043.                         if (info_result!=5) {
  1044.                                 notify(FS_ITEM_ALREADY_EXISTS);
  1045.                         } else {
  1046.                                 CreateDir(#temp);
  1047.                                 if (EAX)
  1048.                                 {
  1049.                                         if (EAX==5) notify(NOT_CREATE_FOLDER);
  1050.                                         else Write_Error(EAX);
  1051.                                 }
  1052.                         }
  1053.                         break;
  1054.                 case RENAME_ITEM:
  1055.                         if (info_result!=5) {
  1056.                                 notify(FS_ITEM_ALREADY_EXISTS);
  1057.                         } else {
  1058.                                 if (RenameMove(new_file_ed.text, #file_path))
  1059.                                 {
  1060.                                         if (itdir) {
  1061.                                                 notify("'Error renaming folder' -E");
  1062.                                                 return;
  1063.                                         } else {
  1064.                                                 if (copy_result = CopyFile(#file_path,#temp)) {
  1065.                                                         Write_Error(copy_result);
  1066.                                                 } else {
  1067.                                                         DeleteFile(#file_path);
  1068.                                                         SelectFileByName(new_file_ed.text);
  1069.                                                 }
  1070.                                         }
  1071.                                 }
  1072.                         }
  1073.         }
  1074.         Open_Dir(path,WITH_REDRAW);
  1075.         SelectFileByName(new_file_ed.text);
  1076.         EventClosePopinForm();
  1077. }
  1078.  
  1079. void NewElement_Form(byte crt, dword strng)
  1080. {
  1081.         int dform_x=files.w-220/2+files.x;
  1082.         if (!new_element_active)
  1083.         {
  1084.                 new_element_active = crt;
  1085.                 edit_box_set_text stdcall (#new_file_ed, strng);
  1086.         }
  1087.         if (new_element_active==3) DrawEolitePopup(T_RENAME, T_CANCEL);
  1088.         else DrawEolitePopup(T_CREATE, T_CANCEL);
  1089.         new_file_ed.left = dform_x+10;
  1090.         DrawEditBox(#new_file_ed);
  1091. }
  1092.  
  1093. void EventShowAbout()
  1094. {
  1095.         if (!active_about) {
  1096.                 about_stak = malloc(4096);
  1097.                 about_thread_id = CreateThread(#about_dialog,about_stak+4092);
  1098.         } else {
  1099.                 ActivateWindow(GetProcessSlot(about_thread_id));
  1100.         }
  1101. }
  1102.  
  1103. void FnProcess(byte N)
  1104. {
  1105.         switch(N)
  1106.         {
  1107.                 case 1:
  1108.                         EventShowProperties();
  1109.                         break;
  1110.                 case 2:
  1111.                         if (files.count) NewElement_Form(RENAME_ITEM, #file_name);
  1112.                         break;
  1113.                 case 3:
  1114.                         if (files.count) && (!itdir) RunProgram("/sys/quark", #file_path);
  1115.                         break;
  1116.                 case 4:
  1117.                         if (files.count) && (!itdir) RunProgram("/sys/develop/cedit", #file_path);
  1118.                         break;
  1119.                 case 5:
  1120.                         if (efm) {
  1121.                                 CopyFilesListToClipboard(COPY);
  1122.                                 EventPaste(location[active_panel^1]);
  1123.                         } else {
  1124.                                 EventManualFolderRefresh();
  1125.                         }
  1126.                         break;
  1127.                 case 6:
  1128.                         if (efm) {
  1129.                                 CopyFilesListToClipboard(CUT);
  1130.                                 EventPaste(location[active_panel^1]);
  1131.                         }
  1132.                         break;
  1133.                 case 7:
  1134.                         NewElement_Form(CREATE_FOLDER, T_NEW_FOLDER);
  1135.                         break;
  1136.                 case 8:
  1137.                         Del_Form();
  1138.                         break;
  1139.                 case 9:
  1140.                         NewElement_Form(CREATE_FILE, T_NEW_FILE);
  1141.                         break;
  1142.                 case 10: //F10
  1143.                         if (active_settings) {
  1144.                                 ActivateWindow(GetProcessSlot(settings_window));
  1145.                         } else {
  1146.                                 settings_stak = malloc(4096);
  1147.                                 settings_window = CreateThread(#settings_dialog, settings_stak+4092);
  1148.                         }
  1149.                         break;
  1150.         }
  1151. }
  1152.  
  1153. void SetActivePanel(int _active)
  1154. {
  1155.         if (active_panel != _active) { 
  1156.                 active_panel = _active;
  1157.                 llist_copy(#files_active, #files_inactive);
  1158.                 llist_copy(#files_inactive, #files);
  1159.                 llist_copy(#files, #files_active);
  1160.                 path = location[active_panel];
  1161.                 DrawFilePanels();
  1162.         }
  1163. }
  1164.  
  1165. void EventSelectFileByKeyPress()
  1166. {
  1167.         int i;
  1168.         for (i=files.cur_y+1; i<files.count; i++)
  1169.         {
  1170.                 strcpy(#temp, items.get(i)*304+buf+72);
  1171.                 if (temp[0]==key_ascii) || (temp[0]==key_ascii-32)
  1172.                 {
  1173.                         files.cur_y = i - 1;
  1174.                         files.KeyDown();
  1175.                         List_ReDraw();
  1176.                         return;
  1177.                 }
  1178.         }
  1179. }
  1180.  
  1181. dword GetDeviceSize(dword p)
  1182. {
  1183.         BDVK bdvk;
  1184.         if (ESBYTE[p+1] == '/') p++;
  1185.         if (ESBYTE[p+1] == 'c') && (ESBYTE[p+2] == 'd')
  1186.                 && (ESBYTE[p+4] == 0) return 0;
  1187.         GetFileInfo(p, #bdvk);
  1188.         return ConvertSize64(bdvk.sizelo, bdvk.sizehi);
  1189. }
  1190.  
  1191. int GetRealFileCountInFolder(dword folder_path)
  1192. {
  1193.         int fcount;
  1194.         dword countbuf;
  1195.  
  1196.         GetDir(#countbuf, #fcount, folder_path, DIRS_NOROOT);
  1197.         if (countbuf) free(countbuf);
  1198.  
  1199.         return fcount;
  1200. }
  1201.  
  1202. void EventRefreshDisksAndFolders()
  1203. {
  1204.         if(efm) {
  1205.                 if (GetRealFileCountInFolder(location[active_panel^1]) != files_inactive.count) {
  1206.                         DrawFilePanels();
  1207.                         return;
  1208.                 }
  1209.         } else {
  1210.                 if (GetRealFileCountInFolder("/")+dir_exists("/kolibrios") != SystemDiscs.dev_num) {
  1211.                         SystemDiscs.Get();
  1212.                         SystemDiscs.Draw();
  1213.                 }
  1214.         }
  1215.         if(GetRealFileCountInFolder(path) != files.count) Open_Dir(path,WITH_REDRAW);
  1216. }
  1217.  
  1218. void EventManualFolderRefresh()
  1219. {
  1220.         Tip(56, T_DEVICES, 55, "-");
  1221.         pause(10);
  1222.         DrawFilePanels();
  1223. }
  1224.  
  1225. void EventSort(dword id)
  1226. {
  1227.         char selected_filename[256];
  1228.         if (sort_type == id) sort_desc ^= 1;
  1229.         else sort_type = id;
  1230.         strcpy(#selected_filename, #file_name);
  1231.         DrawButtonsAroundList();
  1232.         Open_Dir(path,WITH_REDRAW);
  1233.         SelectFileByName(#selected_filename);
  1234. }
  1235.  
  1236. void EventHistoryGoForward()
  1237. {
  1238.         if (history.forward()) {
  1239.                 strcpy(path, history.current());
  1240.                 files.KeyHome();
  1241.                 Open_Dir(path,WITH_REDRAW);
  1242.         }
  1243. }
  1244.  
  1245. void EventOpenNewEolite()
  1246. {
  1247.         RunProgram(I_Path, path);
  1248. }
  1249.  
  1250. void EventOpenConsoleHere()
  1251. {
  1252.         sprintf(#param, "pwd cd %s", path);
  1253.         RunProgram("/sys/shell", #param);
  1254. }
  1255.  
  1256. void ProceedMouseGestures()
  1257. {
  1258.         char stats;
  1259.         signed x_old, y_old, dif_x, dif_y, adif_x, adif_y;
  1260.         if (!mouse.mkm) && (stats>0) stats = 0;
  1261.         if (mouse.mkm) && (!stats)
  1262.         {
  1263.                 x_old = mouse.x;
  1264.                 y_old = mouse.y;
  1265.                 stats = 1;
  1266.         }
  1267.         if (mouse.mkm) && (stats==1)
  1268.         {
  1269.                 dif_x = mouse.x-x_old;
  1270.                 dif_y = mouse.y-y_old;
  1271.                 adif_x = fabs(dif_x);
  1272.                 adif_y = fabs(dif_y);
  1273.                
  1274.                 if (adif_x>adif_y) {
  1275.                         if (dif_x > 150) {
  1276.                                 EventHistoryGoForward();
  1277.                                 stats = 0;
  1278.                         }
  1279.                         if (dif_x < -150) {
  1280.                                 EventHistoryGoBack();
  1281.                                 stats = 0;
  1282.                         }
  1283.                 } else {
  1284.                         if (dif_y < -100) {
  1285.                                 Dir_Up();
  1286.                                 stats = 0;
  1287.                         }
  1288.                 }
  1289.         }
  1290. }
  1291.  
  1292. void EventPaste(dword _into_path) {
  1293.         char paste_line[4096+6];
  1294.         sprintf(#paste_line, "-v%i %s", cut_active, _into_path);
  1295.         RunProgram(#program_path, #paste_line);
  1296.         EventClosePopinForm();
  1297. }
  1298.  
  1299. void EventDelete()
  1300. {
  1301.         char line_param[4096+5];
  1302.         CopyFilesListToClipboard(DELETE);
  1303.         EventClosePopinForm();
  1304.         sprintf(#line_param, "-d %s", #file_path);
  1305.         RunProgram(#program_path, #line_param);
  1306. }
  1307.  
  1308. void EventClosePopinForm()
  1309. {
  1310.         del_active = 0;
  1311.         new_element_active = 0;
  1312.         disk_popin_active_on_panel = 0;
  1313.         draw_window();
  1314. }
  1315.  
  1316. void EventShowProperties()
  1317. char line_param[4096+5];
  1318. {
  1319.         if (!selected_count) {
  1320.                 sprintf(#line_param, "-p %s", #file_path);
  1321.                 RunProgram(#program_path, #line_param);
  1322.         } else {
  1323.                 properties_stak = malloc(8096);
  1324.                 CreateThread(#properties_dialog, properties_stak+8092);
  1325.         }
  1326. }
  1327.  
  1328. void EventChooseFile(int _id)
  1329. {
  1330.         if (getElementSelectedFlag(_id) == true) {
  1331.                 setElementSelectedFlag(_id, false);
  1332.         } else {
  1333.                 setElementSelectedFlag(_id, true);
  1334.         }
  1335. }
  1336.  
  1337. void EventChooseFilesRange(int _start, _end)
  1338. {
  1339.         if (_start > _end) _start >< _end;
  1340.         if (_end - _start > 1) list_full_redraw = true;
  1341.         while (_start < _end) {
  1342.                 EventChooseFile(_start);
  1343.                 _start++;
  1344.         }
  1345.         DrawStatusBar();
  1346.         List_ReDraw();
  1347. }
  1348.  
  1349. void EventChooseAllFiles(dword state)
  1350. {
  1351.         int i;
  1352.         for (i=0; i<files.count; i++) setElementSelectedFlag(i, state);
  1353.         List_ReDraw();
  1354.         DrawStatusBar();
  1355. }
  1356.  
  1357. void EventToolbarButtonClick(int _btid)
  1358. {
  1359.         switch(_btid) {
  1360.                 case BACK_BTN: EventHistoryGoBack(); break;
  1361.                 case FWRD_BTN: EventHistoryGoForward(); break;
  1362.                 case GOUP_BTN: Dir_Up(); break;
  1363.                 case COPY_BTN: CopyFilesListToClipboard(CUT); break;
  1364.                 case CUT_BTN:  CopyFilesListToClipboard(COPY); break;
  1365.                 case PASTE_BTN:EventPaste(path); break;        
  1366.         }
  1367. }
  1368.  
  1369. void EventDriveClick(int __id)
  1370. {
  1371.         SystemDiscs.Click(__id-100);
  1372.         if (efm) {
  1373.                 draw_window();
  1374.         }
  1375. }
  1376.  
  1377. void EventOpenDiskPopin(int panel_n)
  1378. {
  1379.         DefineHiddenButton(0,0,5000,3000,9999+BT_NOFRAME);
  1380.         if (panel_n==0) {
  1381.                 disk_popin_active_on_panel = 1;
  1382.                 SystemDiscs.DrawOptions(1);
  1383.         } else {
  1384.                 disk_popin_active_on_panel = 2;
  1385.                 SystemDiscs.DrawOptions(Form.cwidth/2-1);
  1386.         }
  1387. }
  1388.  
  1389. stop:
  1390.