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