Subversion Repositories Kolibri OS

Rev

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

  1. #define MEMSIZE 100*1000
  2.  
  3. #include "../lib/fs.h"
  4. #include "../lib/gui.h"
  5. #include "../lib/list_box.h"
  6. #include "../lib/obj/box_lib.h"
  7. #include "../lib/obj/proc_lib.h"
  8. #include "../lib/obj/libini.h"
  9. #include "../lib/patterns/select_list.h"
  10.  
  11. //===================================================//
  12. //                                                   //
  13. //                       DATA                        //
  14. //                                                   //
  15. //===================================================//
  16.  
  17. #ifdef LANG_RUS
  18.         ?define T_WINDOW_HEADER "®¨áª"
  19.         ?define T_BUTTON_SEARCH " ©â¨"
  20.         ?define T_SEARCH_PATH "Š â «®£ ¯®¨áª :"
  21.         ?define T_SEARCH_NAME "ˆ¬ï ä ©« :"
  22. #else
  23.         ?define T_WINDOW_HEADER "Search"
  24.         ?define T_BUTTON_SEARCH "Search"
  25.         ?define T_SEARCH_PATH "Search in:"
  26.         ?define T_SEARCH_NAME "File name:"
  27. #endif
  28.  
  29. char search_name[64];
  30. char search_path[4096];
  31.  
  32. enum {
  33.         BTN_SEARCH = 10,
  34.         BTN_CHOOSE_PATH
  35. };
  36.  
  37. proc_info Form;
  38. #define TOOLBAR_H 100
  39.  
  40. edit_box edit_name = {230,13, 30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(search_name)-2,#search_name,0, ed_focus,0,0};
  41. edit_box edit_path = {310,260,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(search_path)-2,#search_path,0, 0b,0,0};
  42.  
  43. opendialog open_folder_dialog =
  44. {
  45.   2, //0-file, 2-save, 3-select folder
  46.   #Form,
  47.   #communication_area_name,
  48.   0,
  49.   0, //dword opendir_path,
  50.   #search_path, //dword dir_default_path,
  51.   #open_dialog_path,
  52.   #draw_window,
  53.   0,
  54.   #search_path, //dword openfile_path,
  55.   0, //dword filename_area,
  56.   0, //dword filter_area,
  57.   420,
  58.   NULL,
  59.   320,
  60.   NULL
  61. };
  62.  
  63. //===================================================//
  64. //                                                   //
  65. //                      RESULTS                      //
  66. //                                                   //
  67. //===================================================//
  68.  
  69. struct RESULTS {
  70.         collection name;
  71.         collection path;
  72.         collection_int type;
  73.         unsigned count;
  74.         void add();
  75.         void drop();
  76. } results;
  77.  
  78. void RESULTS::add(dword _name, _path, _type)
  79. {
  80.         name.add(_name);
  81.         path.add(_path);
  82.         type.add(_type);
  83.         count++;
  84. }
  85.  
  86. void RESULTS::drop()
  87. {
  88.         name.drop();
  89.         path.drop();
  90.         type.drop();
  91.         count = 0;
  92. }
  93.  
  94. //===================================================//
  95. //                                                   //
  96. //                       CODE                        //
  97. //                                                   //
  98. //===================================================//
  99.  
  100. void main()
  101. {  
  102.         int prev_first, prev_cur_y;
  103.         load_dll(boxlib, #box_lib_init,0);
  104.         load_dll(libini, #lib_init,1);
  105.         load_dll(Proc_lib, #OpenDialog_init,0);
  106.         OpenDialog_init stdcall (#open_folder_dialog);
  107.  
  108.         edit_box_set_text stdcall (#edit_name, ".ini");
  109.         edit_box_set_text stdcall (#edit_path, "/kolibrios");
  110.        
  111.         @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  112.         loop() switch(@WaitEvent())
  113.         {
  114.                 case evMouse:
  115.                         edit_box_mouse stdcall (#edit_name);
  116.                         edit_box_mouse stdcall (#edit_path);
  117.                         if (SelectList_ProcessMouse()) {
  118.                                 SelectList_Draw();
  119.                         } else {
  120.                                 SelectList_DrawLine(select_list.cur_y);
  121.                         }
  122.                         if (mouse.key&MOUSE_RIGHT) && (mouse.up) && (select_list.MouseOver()) EventOpenFile(false);
  123.                         break;
  124.  
  125.                 case evButton:
  126.                         switch (@GetButtonID()) {
  127.                                 case 1: @ExitProcess(); break;
  128.                                 case BTN_SEARCH: EventSearch(); break;
  129.                                 case BTN_CHOOSE_PATH: EventChooseSearchInPath();
  130.                         }
  131.                         break;
  132.          
  133.                 case evKey:
  134.                         @GetKeys();
  135.                         edit_box_key stdcall (#edit_name);
  136.                         edit_box_key stdcall (#edit_path);
  137.                         if (edit_name.flags & ed_focus) || (edit_path.flags & ed_focus) {
  138.                                 if (SCAN_CODE_ENTER == key_scancode) EventSearch();
  139.                         } else {
  140.                                 if (SCAN_CODE_ENTER == key_scancode) EventOpenFile(true);
  141.                                 prev_first = select_list.first;
  142.                                 prev_cur_y = select_list.cur_y;
  143.                                 if (select_list.ProcessKey(key_scancode)) {
  144.                                         if (prev_first == select_list.first) {
  145.                                                 SelectList_DrawLine(prev_cur_y);
  146.                                                 SelectList_DrawLine(select_list.cur_y);
  147.                                         } else {
  148.                                                 SelectList_Draw();
  149.                                         }
  150.                                 }
  151.                         }
  152.                         break;
  153.                  
  154.                 case evReDraw:
  155.                         draw_window();
  156.                         break;
  157.    }
  158. }
  159.  
  160. void draw_window()
  161. {
  162.         sc.get();                      
  163.         DefineAndDrawWindow(screen.width-600/2,100,640,600,0x73,sc.work,T_WINDOW_HEADER,0);
  164.         GetProcessInfo(#Form, SelfInfo);
  165.         IF (Form.status_window&ROLLED_UP) return;
  166.         if (Form.width  < 270) { MoveSize(OLD,OLD,270,OLD); return; }
  167.         if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
  168.         SelectList_Init( 0, TOOLBAR_H,
  169.                 Form.cwidth-scroll1.size_x-1,
  170.                 Form.cheight-TOOLBAR_H-1);
  171.         SelectList_Draw();
  172.         DrawBar(0, TOOLBAR_H-1, Form.cwidth, 1, sc.work_graph);
  173.         DrawBar(0, 0, Form.cwidth, TOOLBAR_H-1, sc.work);
  174.         DrawEditBox(#edit_name);
  175.         WriteText(edit_name.left-2, edit_name.top-20, 0x90, sc.work_text, T_SEARCH_NAME);
  176.         edit_path.width = Form.cwidth - 314;
  177.         DrawFileBox(#edit_path, T_SEARCH_PATH, BTN_CHOOSE_PATH);
  178.         DrawStandartCaptButton(10, 63, BTN_SEARCH, T_BUTTON_SEARCH);
  179. }
  180.  
  181. _ini ini = { "/sys/File managers/icons.ini", "icons16" };
  182. void SelectList_DrawLine(dword i)
  183. {
  184.         int yyy = i*select_list.item_h+select_list.y;
  185.         dword bg = 0xFFFfff;
  186.         dword col = 0;
  187.         int icon;
  188.         char tname[4096];
  189.        
  190.         if (!select_list.count) return;
  191.  
  192.         if (select_list.cur_y-select_list.first==i)
  193.         {
  194.                 bg = sc.button;
  195.                 col = sc.button_text;
  196.                 if (edit_name.flags & ed_focus) || (edit_path.flags & ed_focus) bg = 0xAAAaaa;
  197.         }
  198.  
  199.         if (results.type.get(select_list.first + i)==true) {
  200.                 icon=0;
  201.         } else {
  202.                 strcpy(#tname, results.name.get(select_list.first + i));
  203.                 strlwr(#tname);
  204.                 icon = ini.GetInt(#tname + strrchr(#tname, '.'), 2);
  205.         }
  206.  
  207.         #define ICONX 7
  208.         DrawBar(select_list.x, yyy, ICONX-1, select_list.item_h, 0xFFFfff);
  209.         DrawBar(select_list.x+ICONX+18, yyy, select_list.w-ICONX-18, select_list.item_h, bg);
  210.         draw_icon_16(select_list.x+ICONX, yyy+1, icon);
  211.  
  212.         WriteText(select_list.x + ICONX+18+4,yyy+select_list.text_y,0x90, col, results.name.get(select_list.first + i));
  213.         WriteText(select_list.x + ICONX+18+206,yyy+select_list.text_y,0x90, col, results.path.get(select_list.first + i));
  214. }
  215.  
  216. void SelectList_LineChanged()
  217. {
  218.         return;
  219. }
  220.  
  221. //===================================================//
  222. //                                                   //
  223. //                     EVENTS                        //
  224. //                                                   //
  225. //===================================================//
  226.  
  227. void EventChooseSearchInPath()
  228. {
  229.         OpenDialog_start stdcall (#open_folder_dialog);
  230.         if (open_folder_dialog.status) {
  231.                 edit_box_set_text stdcall (#edit_path, #search_path);          
  232.         }
  233. }
  234.  
  235. void getfullpath(dword to, path, name) {
  236.         strcpy(to, path);
  237.         chrcat(to, '/');
  238.         strcat(to, name);
  239. }
  240.  
  241. void EventOpenFile(int run_file_not_show_in_folder)
  242. {
  243.         char full_path[4096];
  244.         int pos = select_list.cur_y;
  245.         getfullpath(#full_path, results.path.get(pos), results.name.get(pos));
  246.         if (run_file_not_show_in_folder) {
  247.                 RunProgram("/sys/@open", #full_path);
  248.         } else {
  249.                 RunProgram("/sys/file managers/eolite", #full_path);   
  250.         }
  251. }
  252.  
  253. void EventSearch()
  254. {
  255.         results.drop();
  256.         find_loop(#search_path);
  257.         select_list.count = results.count;
  258.         SelectList_Draw();
  259. }
  260.  
  261. void find_loop(dword way)
  262. {
  263.         dword dirbuf, fcount, i, filename;
  264.         dword cur_file;
  265.         bool folder;
  266.  
  267.         if (way) && (dir_exists(way))
  268.         {
  269.                 cur_file = malloc(4096);
  270.                 // In the process of recursive descent, memory must be allocated dynamically,
  271.                 // because the static memory -> was a bug !!! But unfortunately pass away to sacrifice speed.
  272.                 GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL);
  273.                 for (i=0; i<fcount; i++)
  274.                 {
  275.                         filename = i*304+dirbuf+72;
  276.                         getfullpath(cur_file,way,filename);
  277.                         if (ESDWORD[filename-40] & ATR_FOLDER) folder = true; else folder = false;
  278.  
  279.                         if (strstri(filename, #search_name)) {
  280.                                 results.add(filename, way, folder);
  281.                         }
  282.  
  283.                         if (folder) {
  284.                                 find_loop(cur_file);
  285.                         }
  286.                 }
  287.                 free(cur_file);
  288.                 free(dirbuf);
  289.         }
  290. }
  291.  
  292. stop:
  293.  
  294.  
  295.