Subversion Repositories Kolibri OS

Rev

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