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