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