Rev 8389 | Rev 8749 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8389 | Rev 8584 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | Quark Code Edit |
2 | Quark Code Edit |
3 | Author: Kiril Lipatov aka Leency |
3 | Author: Kiril Lipatov aka Leency |
4 | Licence: GPLv2 |
4 | Licence: GPLv2 |
Line 5... | Line 5... | ||
5 | 5 | ||
- | 6 | The core components of this app are: |
|
6 | The core components of this app are: |
7 | 1. textbuf: page data |
7 | 1. list: text grid with keyboard and mouse events |
8 | 2. list: text grid with keyboard and mouse events |
8 | 2. lines: the mas of pointers for each line start |
9 | 3. lines: the mas of pointers for each line start |
9 | 3. selection |
10 | 4. selection |
Line 10... | Line 11... | ||
10 | */ |
11 | */ |
Line 11... | Line 12... | ||
11 | 12 | ||
12 | #define MEMSIZE 1024*100 |
13 | #define MEMSIZE 60*1024 |
13 | 14 | ||
14 | //===================================================// |
15 | //===================================================// |
Line 41... | Line 42... | ||
41 | // // |
42 | // // |
42 | //===================================================// |
43 | //===================================================// |
Line 43... | Line 44... | ||
43 | 44 | ||
44 | proc_info Form; |
45 | proc_info Form; |
- | 46 | llist list; |
|
- | 47 | scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee, |
|
Line 45... | Line 48... | ||
45 | llist list; |
48 | 0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
46 | 49 | ||
47 | #define TOOLBAR_H 38 |
50 | #define TOOLBAR_H 38 |
48 | #define TOOLBAR_ICON_WIDTH 24 |
51 | #define TOOLBAR_ICON_WIDTH 24 |
Line 53... | Line 56... | ||
53 | int user_encoding; |
56 | int user_encoding; |
54 | int real_encoding = CH_CP866; |
57 | int real_encoding = CH_CP866; |
55 | int curcol_scheme; |
58 | int curcol_scheme; |
56 | int font_size; |
59 | int font_size; |
Line 57... | Line -... | ||
57 | - | ||
58 | bool enable_edit = false; |
60 | |
Line 59... | Line 61... | ||
59 | bool search_next = false; |
61 | bool search_next = false; |
60 | - | ||
61 | #include "data.h" |
62 | |
62 | 63 | #include "data.h" |
|
- | 64 | #include "textbuf.h" |
|
63 | #include "search.h" |
65 | #include "selection.h" |
Line 64... | Line 66... | ||
64 | #include "selection.h" |
66 | #include "search.h" |
65 | #include "prepare_page.h" |
67 | #include "prepare_page.h" |
66 | 68 | ||
67 | //===================================================// |
69 | //===================================================// |
68 | // // |
70 | // // |
Line 69... | Line -... | ||
69 | // DATA // |
- | |
70 | // // |
- | |
71 | //===================================================// |
- | |
72 | 71 | // DATA // |
|
Line 73... | Line 72... | ||
73 | scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee, |
72 | // // |
74 | 0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
73 | //===================================================// |
75 | 74 | ||
Line 84... | Line 83... | ||
84 | CHANGE_CHARSET=12, |
83 | CHANGE_CHARSET=12, |
85 | REOPEN_IN_APP=1, |
84 | REOPEN_IN_APP=1, |
86 | COLOR_SCHEME=8, |
85 | COLOR_SCHEME=8, |
87 | RMB_MENU, |
86 | RMB_MENU, |
88 | BTN_FIND_NEXT, |
87 | BTN_FIND_NEXT, |
- | 88 | BTN_FIND_PREVIOUS, |
|
89 | BTN_FIND_CLOSE, |
89 | BTN_FIND_CLOSE, |
90 | BTN_CHANGE_CHARSET |
90 | BTN_CHANGE_CHARSET |
91 | }; |
91 | }; |
Line 92... | Line 92... | ||
92 | 92 | ||
Line 111... | Line 111... | ||
111 | OpenDialog_init stdcall (#o_dialog); |
111 | OpenDialog_init stdcall (#o_dialog); |
112 | } |
112 | } |
Line 113... | Line 113... | ||
113 | 113 | ||
114 | void LoadFileFromDocPack() |
114 | void LoadFileFromDocPack() |
115 | { |
115 | { |
116 | dword bufsize = atoi(#param + 1) + 20; |
116 | dword bufsize = atoi(#file_path + 1) + 20; |
Line 117... | Line 117... | ||
117 | dword bufpointer = malloc(bufsize); |
117 | dword bufpointer = malloc(bufsize); |
118 | 118 | ||
119 | ESDWORD[bufpointer+0] = 0; |
119 | ESDWORD[bufpointer+0] = 0; |
Line 120... | Line 120... | ||
120 | ESDWORD[bufpointer+4] = 8; |
120 | ESDWORD[bufpointer+4] = 8; |
121 | IpcSetArea(bufpointer, bufsize); |
121 | IpcSetArea(bufpointer, bufsize); |
122 | 122 | ||
123 | SetEventMask(EVM_IPC); |
123 | SetEventMask(EVM_IPC); |
- | 124 | if (@WaitEventTimeout(200) != evIPC) { |
|
124 | if (@WaitEventTimeout(200) != evIPC) { |
125 | notify("'IPC FAIL'E"); |
125 | notify("'IPC FAIL'E"); |
- | |
126 | return; |
126 | } else { |
- | 127 | textbuf.set(bufpointer + 16, ESDWORD[bufpointer+12]); |
|
127 | } |
128 | } |
128 | 129 | free(bufpointer); |
|
Line 129... | Line 130... | ||
129 | io.buffer_data = malloc(ESDWORD[bufpointer+12]); |
130 | file_path[0]='\0'; |
130 | strcpy(io.buffer_data, bufpointer + 16); |
131 | sprintf(#title, "#DOCPACK - %s", #short_app_name); |
131 | } |
132 | } |
132 | 133 | ||
133 | void main() |
134 | void main() |
134 | { |
135 | { |
135 | InitDlls(); |
136 | InitDlls(); |
136 | LoadIniSettings(); |
- | |
137 | EventSetColorScheme(curcol_scheme); |
- | |
138 | if (param[0] == '*') { |
137 | LoadIniSettings(); |
139 | LoadFileFromDocPack(); |
138 | EventSetColorScheme(curcol_scheme); |
140 | param[0]='\0'; |
139 | if (file_path[0] == '*') { |
141 | sprintf(#title, "#DOCPACK - %s", #short_app_name); |
140 | LoadFileFromDocPack(); |
142 | } else { |
141 | } else { |
143 | if (streq(#param,"-new")) {Form.left+=40;Form.top+=40;} |
- | |
144 | LoadFile(#param); |
- | |
145 | } |
142 | if (streq(#file_path,"-new")) {Form.left+=40;Form.top+=40;} |
146 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
143 | LoadFile(#file_path); |
147 | loop() |
- | |
148 | { |
144 | } |
149 | switch(@WaitEventTimeout(400)) |
- | |
150 | { |
- | |
151 | case evMouse: |
145 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
152 | HandleMouseEvent(); |
- | |
153 | break; |
- | |
154 | case evKey: |
146 | loop() switch(@WaitEventTimeout(400)) |
155 | HandleKeyEvent(); |
- | |
156 | break; |
- | |
157 | case evButton: |
- | |
158 | HandleButtonEvent(); |
147 | { |
159 | break; |
- | |
160 | case evReDraw: |
- | |
161 | if (CheckActiveProcess(Form.ID)) EventMenuClick(); |
148 | case evMouse: HandleMouseEvent(); break; |
162 | draw_window(); |
- | |
163 | break; |
149 | case evKey: HandleKeyEvent(); break; |
164 | default: |
150 | case evButton: HandleButtonEvent(); break; |
Line 165... | Line 151... | ||
165 | DrawStatusBar(" "); //clean DrawStatusBar text with delay |
151 | case evReDraw: draw_window(); break; |
166 | } |
152 | default: DrawStatusBar(" "); //clean DrawStatusBar text with delay |
Line 181... | Line 167... | ||
181 | ExitProcess(); |
167 | ExitProcess(); |
182 | } |
168 | } |
183 | button.press(btn); |
169 | button.press(btn); |
184 | switch(btn-10) |
170 | switch(btn-10) |
185 | { |
171 | { |
186 | case BTN_FIND_NEXT: |
172 | case BTN_FIND_NEXT: EventSearchNext(); break; |
187 | EventSearchNext(); |
173 | case BTN_FIND_PREVIOUS: EventSearchPrevious(); break; |
188 | break; |
- | |
189 | case BTN_FIND_CLOSE: |
174 | case BTN_FIND_CLOSE: search.hide(); break; |
190 | search.hide(); |
- | |
191 | break; |
- | |
192 | case BTN_CHANGE_CHARSET: |
- | |
193 | EventShowCharsetsList(); |
175 | case BTN_CHANGE_CHARSET: EventShowCharsetsList(); break; |
194 | break; |
- | |
195 | } |
176 | } |
196 | } |
177 | } |
Line 197... | Line 178... | ||
197 | 178 | ||
198 | void HandleKeyEvent() |
179 | void HandleKeyEvent() |
Line 206... | Line 187... | ||
206 | return; |
187 | return; |
207 | case SCAN_CODE_ESC: |
188 | case SCAN_CODE_ESC: |
208 | search.hide(); |
189 | search.hide(); |
209 | return; |
190 | return; |
210 | case SCAN_CODE_ENTER: |
191 | case SCAN_CODE_ENTER: |
211 | if (! search_box.flags & ed_focus) return; |
192 | if (! search_box.flags & ed_focus) break; |
212 | case SCAN_CODE_F3: |
193 | case SCAN_CODE_F3: |
- | 194 | if (key_modifier & KEY_LSHIFT) { |
|
- | 195 | EventSearchPrevious(); |
|
- | 196 | } else { |
|
213 | EventSearchNext(); |
197 | EventSearchNext(); |
- | 198 | } |
|
214 | return; |
199 | return; |
215 | } |
200 | } |
Line 216... | Line 201... | ||
216 | 201 | ||
Line 217... | Line 202... | ||
217 | if (search.edit_key()) return; |
202 | if (search.edit_key()) return; |
218 | 203 | ||
219 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
204 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
220 | if (key.press(ECTRL + key_scancode)) return; |
205 | if (key.press(ECTRL + key_scancode)) return; |
221 | switch (key_scancode) |
206 | switch (key_scancode) |
222 | { |
- | |
223 | case SCAN_CODE_KEY_A: |
- | |
224 | selection.select_all(); |
- | |
225 | DrawPage(); |
207 | { |
226 | return; |
- | |
227 | case SCAN_CODE_KEY_X: |
- | |
228 | EventCut(); |
208 | case SCAN_CODE_KEY_A: EventSelectAllText(); return; |
229 | return; |
- | |
230 | case SCAN_CODE_KEY_C: |
- | |
231 | EventCopy(); |
209 | case SCAN_CODE_KEY_X: EventCut(); return; |
232 | return; |
- | |
233 | case SCAN_CODE_KEY_V: |
- | |
234 | EventPaste(); |
- | |
235 | return; |
210 | case SCAN_CODE_KEY_C: EventCopy(); return; |
236 | case SCAN_CODE_UP: |
- | |
237 | EventMagnifyPlus(); |
- | |
238 | return; |
211 | case SCAN_CODE_KEY_V: EventPaste(); return; |
239 | case SCAN_CODE_DOWN: |
- | |
240 | EventMagnifyMinus(); |
- | |
241 | return; |
212 | case SCAN_CODE_UP: EventMagnifyPlus(); return; |
242 | case SCAN_CODE_TAB: |
- | |
243 | EventShowCharsetsList(); |
213 | case SCAN_CODE_DOWN: EventMagnifyMinus(); return; |
244 | return; |
- | |
245 | case SCAN_CODE_KEY_F: |
- | |
246 | search.show(); |
214 | case SCAN_CODE_TAB: EventShowCharsetsList(); return; |
247 | return; |
215 | case SCAN_CODE_KEY_F: search.show(); return; |
Line 248... | Line 216... | ||
248 | } |
216 | } |
249 | } |
217 | } |
250 | 218 | ||
- | 219 | if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) { |
|
251 | if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) { |
220 | selection.set_start(); |
252 | selection.set_start(); |
221 | } else { |
Line -... | Line 222... | ||
- | 222 | EventInsertCharIntoText(); |
|
253 | } else { |
223 | selection.cancel(); |
254 | selection.cancel(); |
224 | } |
255 | } |
225 | |
256 | 226 | if (key_scancode == SCAN_CODE_LEFT) && (!list.cur_x) && (list.cur_y) list.column_max = lines.len(list.cur_y-1); |
|
257 | if (list.ProcessKey(key_scancode)) { |
227 | if (list.ProcessKey(key_scancode)) { |
258 | if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end(); |
- | |
259 | DrawPage(); |
228 | if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end(); |
Line 260... | Line 229... | ||
260 | return; |
229 | DrawPage(); |
261 | } |
230 | return; |
262 | if(enable_edit) EventInsertCharIntoText(); |
231 | } |
Line 313... | Line 282... | ||
313 | // // |
282 | // // |
314 | //===================================================// |
283 | //===================================================// |
Line 315... | Line 284... | ||
315 | 284 | ||
316 | bool EventSearchNext() |
285 | bool EventSearchNext() |
317 | { |
286 | { |
- | 287 | if (search.find_next(list.first+1)) { |
|
- | 288 | list.first = EAX; |
|
- | 289 | list.CheckDoesValuesOkey(); |
|
318 | int new_y = search.find_next(list.first+1); |
290 | search_next = true; |
- | 291 | DrawPage(); |
|
- | 292 | } |
|
- | 293 | } |
|
- | 294 | ||
- | 295 | bool EventSearchPrevious() |
|
- | 296 | { |
|
319 | if (new_y) { |
297 | if (search.find_prior(list.first)) { |
320 | list.first = new_y; |
298 | list.first = EAX; |
321 | list.CheckDoesValuesOkey(); |
299 | list.CheckDoesValuesOkey(); |
322 | search_next = true; |
300 | search_next = true; |
323 | DrawPage(); |
301 | DrawPage(); |
324 | } |
302 | } |
Line 340... | Line 318... | ||
340 | 318 | ||
341 | void EventSave() |
319 | void EventSave() |
342 | { |
320 | { |
343 | int res; |
321 | int res; |
344 | char backy_param[4096]; |
- | |
345 | if (io.buffer_data) { |
322 | char backy_param[4096]; |
346 | io.dir.make("/tmp0/1/quark_backups"); |
323 | io.dir.make("/tmp0/1/quark_backups"); |
347 | sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #param); |
324 | sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #file_path); |
348 | io.run("/sys/develop/backy", #backy_param); |
325 | RunProgram("/sys/develop/backy", #backy_param); |
349 | if (! io.write(#param, io.buffer_data) ) { |
326 | if (! WriteFile(0, textbuf.len, textbuf.p, #file_path) ) { |
350 | notify(FILE_SAVED_WELL); |
327 | notify(FILE_SAVED_WELL); |
351 | } else { |
328 | } else { |
352 | notify(FILE_NOT_SAVED); |
329 | notify(FILE_NOT_SAVED); |
353 | } |
330 | } |
354 | } |
- | |
Line 355... | Line 331... | ||
355 | } |
331 | } |
356 | 332 | ||
357 | void EventShowFileInfo() |
333 | void EventShowFileInfo() |
358 | { |
334 | { |
359 | char ss_param[4096]; |
335 | char ss_param[4096]; |
360 | if (!param) return; |
336 | if (!file_path) return; |
361 | strcpy(#ss_param, "-p "); |
337 | strcpy(#ss_param, "-p "); |
362 | strcpy(#ss_param+3, #param); |
338 | strcpy(#ss_param+3, #file_path); |
Line 363... | Line 339... | ||
363 | RunProgram("/sys/File managers/Eolite", #ss_param); |
339 | RunProgram("/sys/File managers/Eolite", #ss_param); |
364 | } |
340 | } |
- | 341 | ||
365 | 342 | void EventMagnifyMinus() |
|
366 | void EventMagnifyMinus() |
343 | { |
367 | { |
344 | font_size = math.max(0, font_size-1); |
Line 368... | Line 345... | ||
368 | SetSizes('S'); |
345 | SetFontSize(font_size); |
369 | ParseAndPaint(); |
346 | ParseAndPaint(); |
- | 347 | } |
|
370 | } |
348 | |
371 | 349 | void EventMagnifyPlus() |
|
372 | void EventMagnifyPlus() |
350 | { |
Line 373... | Line 351... | ||
373 | { |
351 | font_size = math.min(3, font_size+1); |
374 | SetSizes('M'); |
352 | SetFontSize(font_size); |
Line 417... | Line 395... | ||
417 | if (list.count) ParseAndPaint(); |
395 | if (list.count) ParseAndPaint(); |
418 | } |
396 | } |
Line 419... | Line 397... | ||
419 | 397 | ||
420 | - | ||
421 | void EventShowInfo() { |
398 | |
422 | static dword shared_about; |
- | |
423 | if (!shared_about) { |
- | |
424 | shared_about = memopen("QUARK_ABOUT", sizeof(about)+1, SHM_OPEN_ALWAYS + SHM_READ); |
- | |
425 | strcpy(shared_about, #about); |
- | |
426 | } |
399 | void EventShowInfo() { |
Line 427... | Line 400... | ||
427 | RunProgram("/sys/dialog", "-info 122 *QUARK_ABOUT"); |
400 | notify(#about); |
428 | } |
401 | } |
429 | 402 | ||
430 | void EventChangeCharset(dword id) |
403 | void EventChangeCharset(dword id) |
431 | { |
404 | { |
432 | if (param[0]=='\0') return; |
405 | if (file_path[0]=='\0') return; |
433 | user_encoding = id; |
406 | user_encoding = id; |
434 | LoadFile(#param); |
407 | LoadFile(#file_path); |
Line 435... | Line 408... | ||
435 | ParseAndPaint(); |
408 | ParseAndPaint(); |
Line 445... | Line 418... | ||
445 | case 1: app = "/sys/develop/t_edit"; break; |
418 | case 1: app = "/sys/develop/t_edit"; break; |
446 | case 2: app = "/sys/network/webview"; break; |
419 | case 2: app = "/sys/network/webview"; break; |
447 | case 3: app = "/sys/fb2read"; break; |
420 | case 3: app = "/sys/fb2read"; break; |
448 | case 4: app = "/sys/develop/heed"; break; |
421 | case 4: app = "/sys/develop/heed"; break; |
449 | case 5: open_param[0]='~'; |
422 | case 5: open_param[0]='~'; |
450 | strcpy(#open_param+1,#param); |
423 | strcpy(#open_param+1,#file_path); |
451 | RunProgram("/sys/@open", #open_param); |
424 | RunProgram("/sys/@open", #open_param); |
452 | return; |
425 | return; |
453 | } |
426 | } |
454 | RunProgram(app, #param); |
427 | RunProgram(app, #file_path); |
455 | } |
428 | } |
Line 456... | Line 429... | ||
456 | 429 | ||
457 | void EventMenuClick() |
430 | void EventMenuClick() |
458 | { |
431 | { |
Line 478... | Line 451... | ||
478 | } |
451 | } |
479 | } |
452 | } |
Line 480... | Line 453... | ||
480 | 453 | ||
481 | void EventInsertCharIntoText() |
454 | void EventInsertCharIntoText() |
- | 455 | { |
|
482 | { |
456 | dword i; |
Line 483... | Line 457... | ||
483 | dword cursor_pos = lines.get(list.cur_y) + list.cur_x; |
457 | dword cursor_pos = lines.get(list.cur_y) + list.cur_x; |
484 | 458 | ||
485 | switch(key_scancode) |
459 | switch(key_scancode) |
486 | { |
460 | { |
- | 461 | case SCAN_CODE_DOWN: |
|
- | 462 | case SCAN_CODE_UP: |
|
487 | case SCAN_CODE_DOWN: |
463 | case SCAN_CODE_LEFT: |
488 | case SCAN_CODE_UP: |
464 | case SCAN_CODE_RIGHT: |
489 | case SCAN_CODE_HOME: |
465 | case SCAN_CODE_HOME: |
490 | case SCAN_CODE_END: |
466 | case SCAN_CODE_END: |
491 | case SCAN_CODE_PGUP: |
467 | case SCAN_CODE_PGUP: |
492 | case SCAN_CODE_PGDN: |
468 | case SCAN_CODE_PGDN: |
- | 469 | return; |
|
- | 470 | case SCAN_CODE_BS: |
|
- | 471 | if (selection.is_active()) { |
|
- | 472 | EventDeleteSelectedText(); |
|
- | 473 | } else { |
|
- | 474 | if (!list.cur_x) && (!list.cur_y) break; |
|
- | 475 | textbuf.del(cursor_pos-1, cursor_pos); |
|
- | 476 | if (!list.cur_x) && (list.cur_y) { |
|
- | 477 | list.column_max = lines.len(list.cur_y-1); |
|
- | 478 | list.KeyLeft(); |
|
- | 479 | } |
|
- | 480 | list.KeyLeft(); |
|
- | 481 | } |
|
493 | return; |
482 | ParseAndPaint(); |
- | 483 | return; |
|
494 | case SCAN_CODE_BS: |
484 | case SCAN_CODE_DEL: |
- | 485 | if (selection.is_active()) { |
|
- | 486 | EventDeleteSelectedText(); |
|
- | 487 | } else { |
|
- | 488 | if (cursor_pos < textbuf.p + textbuf.len) textbuf.del(cursor_pos, cursor_pos+1); |
|
495 | case SCAN_CODE_DEL: |
489 | } |
- | 490 | ParseAndPaint(); |
|
- | 491 | return; |
|
- | 492 | default: |
|
- | 493 | if (selection.is_active()) { |
|
496 | notify("'Not supported yet'A"); |
494 | EventDeleteSelectedText(); |
497 | return; |
- | |
498 | } |
495 | Parse(); |
499 | - | ||
500 | if (list.cur_x >= list.column_max) return; |
496 | } |
501 | 497 | cursor_pos = lines.get(list.cur_y) + list.cur_x; |
|
502 | ESBYTE[cursor_pos] = key_ascii; |
498 | textbuf.insert_ch(cursor_pos, key_ascii); |
- | 499 | list.KeyRight(); |
|
- | 500 | Parse(); |
|
- | 501 | list.column_max = lines.len(list.cur_y); |
|
- | 502 | if (key_scancode == SCAN_CODE_ENTER) list.KeyRight(); |
|
503 | list.KeyRight(); |
503 | DrawPage(); |
Line 504... | Line 504... | ||
504 | PaintVisible(); |
504 | } |
505 | } |
505 | } |
506 | 506 | ||
507 | void EventOpenSysfuncs() |
507 | void EventOpenSysfuncs() |
508 | { |
508 | { |
509 | if (io.run("/sys/docpack", "f") <= 0) { |
509 | if (RunProgram("/sys/docpack", "f") <= 0) { |
Line 510... | Line 510... | ||
510 | notify("'Can not open SysFunctions because\n/rd/1/docpack is not found!'E"); |
510 | notify("'Can not open SysFunctions because\n/rd/1/docpack is not found!'E"); |
511 | } |
511 | } |
512 | } |
512 | } |
513 | 513 | ||
Line 514... | Line 514... | ||
514 | void EventOpenPipet() |
514 | void EventOpenPipet() |
515 | { |
515 | { |
516 | io.run("/sys/develop/pipet", NULL); |
516 | RunProgram("/sys/develop/pipet", NULL); |
Line 525... | Line 525... | ||
525 | case 3: EventRevealInFolder(); break; |
525 | case 3: EventRevealInFolder(); break; |
526 | case 4: EventCopyFilePath(); break; |
526 | case 4: EventCopyFilePath(); break; |
527 | } |
527 | } |
528 | } |
528 | } |
Line 529... | Line 529... | ||
529 | 529 | ||
530 | void EventCut() |
530 | void EventSelectAllText() |
531 | { |
531 | { |
- | 532 | selection.select_all(); |
|
532 | //selection.copy(); |
533 | DrawPage(); |
Line 533... | Line 534... | ||
533 | } |
534 | } |
534 | 535 | ||
535 | void EventCopy() |
536 | void EventCopy() |
Line 558... | Line 559... | ||
558 | 559 | ||
559 | sprintf(#copy_status_text, #copied_chars, copy_len); |
560 | sprintf(#copy_status_text, #copied_chars, copy_len); |
560 | DrawStatusBar(#copy_status_text); |
561 | DrawStatusBar(#copy_status_text); |
Line -... | Line 562... | ||
- | 562 | } |
|
- | 563 | ||
- | 564 | void EventCut() |
|
- | 565 | { |
|
- | 566 | if (!selection.is_active()) { |
|
- | 567 | selection.start_offset = lines.get(list.cur_y); |
|
- | 568 | selection.end_offset = lines.get(list.cur_y+1); |
|
- | 569 | } |
|
- | 570 | EventCopy(); |
|
- | 571 | EventDeleteSelectedText(); |
|
- | 572 | ParseAndPaint(); |
|
561 | } |
573 | } |
562 | 574 | ||
- | 575 | void EventPaste() |
|
- | 576 | { |
|
- | 577 | int i; |
|
- | 578 | dword buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1); |
|
- | 579 | if (selection.is_active()) { |
|
- | 580 | EventDeleteSelectedText(); |
|
- | 581 | } |
|
- | 582 | cursor_pos = lines.get(list.cur_y) + list.cur_x; |
|
- | 583 | textbuf.insert_str(cursor_pos, buf+12, ESDWORD[buf]-12); |
|
- | 584 | for (i=0; i |
|
- | 585 | ParseAndPaint(); |
|
- | 586 | } |
|
- | 587 | ||
- | 588 | void EventDeleteSelectedText() |
|
- | 589 | { |
|
- | 590 | textbuf.del(selection.start_offset, selection.end_offset); |
|
563 | void EventPaste() |
591 | list.cur_x = math.min(selection.start_x, selection.end_x); |
564 | { |
592 | list.cur_y = math.min(selection.start_y, selection.end_y); |
Line 565... | Line 593... | ||
565 | //selection.copy(); |
593 | selection.cancel(); |
566 | } |
594 | } |
567 | 595 | ||
568 | void EventRevealInFolder() |
596 | void EventRevealInFolder() |
Line 569... | Line 597... | ||
569 | { |
597 | { |
570 | RunProgram("/sys/File managers/Eolite", #param); |
598 | RunProgram("/sys/File managers/Eolite", #file_path); |
571 | } |
599 | } |
572 | 600 | ||
573 | void EventCopyFilePath() |
601 | void EventCopyFilePath() |
574 | { |
602 | { |
575 | char copy_status_text[32]; |
603 | char copy_status_text[32]; |
Line 576... | Line -... | ||
576 | Clipboard__CopyText(#param); |
- | |
577 | sprintf(#copy_status_text, #copied_chars, strlen(#param)); |
- | |
578 | DrawStatusBar(#copy_status_text); |
- | |
579 | } |
- | |
580 | - | ||
581 | void EventEnableEdit() |
- | |
582 | { |
- | |
583 | enable_edit ^= 1; |
604 | Clipboard__CopyText(#file_path); |
584 | if (enable_edit) notify("'Edit mode is enabled.\nNow you can only replace text, not insert, nor delete.'I"); |
605 | sprintf(#copy_status_text, #copied_chars, strlen(#file_path)); |
585 | draw_window(); |
606 | DrawStatusBar(#copy_status_text); |
586 | } |
607 | } |
587 | 608 | ||
Line 596... | Line 617... | ||
596 | real_encoding = user_encoding; |
617 | real_encoding = user_encoding; |
Line 597... | Line 618... | ||
597 | 618 | ||
598 | // Autodetecting charset |
619 | // Autodetecting charset |
599 | if (real_encoding == CH_AUTO) { |
620 | if (real_encoding == CH_AUTO) { |
600 | real_encoding = CH_CP866; |
621 | real_encoding = CH_CP866; |
601 | if (strstr(io.buffer_data, "\208\190")) real_encoding = CH_UTF8; |
622 | if (strstr(textbuf.p, "\208\190")) real_encoding = CH_UTF8; |
602 | else { |
623 | else { |
603 | if (chrnum(io.buffer_data, '\246')>5) |
624 | if (chrnum(textbuf.p, '\246')>5) |
604 | || (strstr(io.buffer_data, "\239\240")) real_encoding = CH_CP1251; |
625 | || (strstr(textbuf.p, "\239\240")) real_encoding = CH_CP1251; |
605 | } |
626 | } |
606 | } |
627 | } |
607 | if (real_encoding != CH_CP866) { |
628 | if (real_encoding != CH_CP866) { |
608 | ChangeCharset(real_encoding, "CP866", io.buffer_data); |
629 | ChangeCharset(real_encoding, "CP866", textbuf.p); |
609 | } |
630 | } |
Line 610... | Line 631... | ||
610 | } |
631 | } |
611 | 632 | ||
612 | void LoadFile(dword f_path) |
- | |
613 | { |
633 | void LoadFile(dword f_path) |
614 | if (io.buffer_data) free(io.buffer_data); |
634 | { |
615 | if (ESBYTE[f_path]) { |
635 | if (ESBYTE[f_path]) { |
- | 636 | strcpy(#file_path, f_path); |
|
- | 637 | if (!io.read(#file_path)) goto NO_DATA; |
|
616 | strcpy(#param, f_path); |
638 | textbuf.set(io.buffer_data, io.FILES_SIZE); |
617 | if (!io.read(#param)) goto NO_DATA; |
639 | free(io.buffer_data); |
618 | sprintf(#title, "%s - %s", #param, #short_app_name); |
640 | sprintf(#title, "%s - %s", #file_path, #short_app_name); |
619 | EncodeToDos(); |
641 | EncodeToDos(); |
620 | } |
642 | } |
621 | else { |
643 | else { |
622 | NO_DATA: |
- | |
623 | io.buffer_data = malloc(sizeof(intro)); |
644 | NO_DATA: |
624 | strcpy(io.buffer_data, #intro); |
645 | textbuf.set(#intro, sizeof(intro)-1); |
625 | strcpy(#title, #short_app_name); |
646 | strcpy(#title, #short_app_name); |
626 | } |
647 | } |
Line 627... | Line 648... | ||
627 | list.ClearList(); |
648 | list.ClearList(); |
628 | } |
649 | } |
629 | 650 | ||
630 | int AddTopBarButton(dword _event, _hotkey, char image_id, int x, pressed) { |
651 | int TopBarBt(dword _event, _hotkey, char image_id, int x, pressed) { |
Line 631... | Line 652... | ||
631 | if (_hotkey) key.add_n(_hotkey, _event); |
652 | if (_hotkey) key.add_n(_hotkey, _event); |
632 | return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed); |
653 | return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed); |
633 | } |
654 | } |
634 | 655 | ||
635 | 656 | ||
636 | void DrawToolbar() |
657 | void DrawToolbar() |
637 | { |
658 | { |
Line 638... | Line -... | ||
638 | #define SMALL_GAP 26+5 |
- | |
639 | #define BIG_GAP 26+18 |
659 | #define GAP_S 26+5 |
640 | incn x; |
660 | #define GAP_B 26+18 |
Line 641... | Line 661... | ||
641 | bool thema = false; |
661 | incn x; |
642 | bool reopa = false; |
662 | bool thema = false; |
Line 643... | Line 663... | ||
643 | 663 | bool reopa = false; |
|
644 | bool serha = search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H - STATUSBAR_H); |
664 | |
645 | if (menu_id == COLOR_SCHEME) thema = true; |
665 | if (menu_id == COLOR_SCHEME) thema = true; |
646 | if (menu_id == REOPEN_IN_APP) reopa = true; |
666 | if (menu_id == REOPEN_IN_APP) reopa = true; |
647 | 667 | ||
648 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work); |
668 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work); |
649 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph); |
669 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph); |
650 | 670 | ||
651 | x.set(-SMALL_GAP+8); |
671 | x.set(-GAP_S+8); |
652 | if(enable_edit) AddTopBarButton(#EventNewFile, ECTRL+SCAN_CODE_KEY_N, 2, x.inc(SMALL_GAP), false); |
- | |
653 | AddTopBarButton(#EventOpenDialog, ECTRL+SCAN_CODE_KEY_O, 0, x.inc(SMALL_GAP), false); |
672 | TopBarBt(#EventNewFile, ECTRL+SCAN_CODE_KEY_N, 2, x.inc(GAP_S), false); |
654 | if(enable_edit) && (param[0]) AddTopBarButton(#EventSave, ECTRL+SCAN_CODE_KEY_S, 5, x.inc(SMALL_GAP), false); |
673 | TopBarBt(#EventOpenDialog, ECTRL+SCAN_CODE_KEY_O, 0, x.inc(GAP_S), false); |
655 | AddTopBarButton(#EventShowFileInfo, ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false); |
674 | TopBarBt(#EventSave, ECTRL+SCAN_CODE_KEY_S, 5, x.inc(GAP_S), false); |
656 | AddTopBarButton(#EventMagnifyMinus, ECTRL+SCAN_CODE_MINUS, 33, x.inc(BIG_GAP), false); |
675 | TopBarBt(#EventShowFileInfo, ECTRL+SCAN_CODE_KEY_I, 10, x.inc(GAP_S), false); |
657 | AddTopBarButton(#EventMagnifyPlus, ECTRL+SCAN_CODE_PLUS, 32, x.inc(SMALL_GAP), false); |
676 | TopBarBt(#EventMagnifyMinus, ECTRL+SCAN_CODE_MINUS, 33, x.inc(GAP_B), false); |
658 | AddTopBarButton(#EventClickSearch, ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP), serha); search_mx = EAX; |
677 | TopBarBt(#EventMagnifyPlus, ECTRL+SCAN_CODE_PLUS, 32, x.inc(GAP_S), false); |
Line 659... | Line 678... | ||
659 | x.set(Form.cwidth-4); |
678 | TopBarBt(#EventClickSearch, ECTRL+SCAN_CODE_KEY_F, 49, x.inc(GAP_B), search.visible); search_mx = EAX; |
660 | AddTopBarButton(#EventEnableEdit, NULL, 38, x.inc(-SMALL_GAP), enable_edit); |
679 | x.set(Form.cwidth-4); |
661 | //if(enable_edit) AddTopBarButton(#EventShowInfo, NULL, -1, x.inc(-SMALL_GAP), false); burger_mx = EAX; |
680 | TopBarBt(#EventShowInfo, NULL, -1, x.inc(-GAP_S), false); burger_mx = EAX; |
662 | AddTopBarButton(#EventShowThemesList, NULL, 40, x.inc(-BIG_GAP), thema); theme_mx = EAX; |
681 | TopBarBt(#EventShowThemesList, NULL, 40, x.inc(-GAP_B), thema); theme_mx = EAX; |
663 | AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP), reopa); reopenin_mx = EAX; |
682 | TopBarBt(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-GAP_S), reopa); reopenin_mx = EAX; |
664 | if(enable_edit) AddTopBarButton(#EventOpenSysfuncs, NULL, 18, x.inc(-SMALL_GAP), false); |
683 | TopBarBt(#EventOpenSysfuncs, NULL, 18, x.inc(-GAP_S), false); |
665 | if(enable_edit) AddTopBarButton(#EventOpenPipet, NULL, 39, x.inc(-SMALL_GAP), false); |
684 | TopBarBt(#EventOpenPipet, NULL, 39, x.inc(-GAP_S), false); |
666 | } |
685 | } |
667 | 686 | ||
668 | void DrawStatusBar(dword _in_text) |
687 | void DrawStatusBar(dword _in_text) |
669 | { |
688 | { |
670 | static char status_text[64]; |
689 | static char status_text[64]; |
671 | if (Form.status_window>2) return; |
690 | if (Form.status_window>2) return; |
672 | if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text)); |
691 | if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text)); |
673 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph); |
692 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph); |
Line 674... | Line 693... | ||
674 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); |
693 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); |
675 | WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text); |
694 | WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text); |
676 | if (param[0]) { |
695 | if (file_path[0]) { |
- | 696 | WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4, |
|
677 | WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4, |
697 | 60, sc.work_text, real_encoding*10+#charsets); |
678 | 60, sc.work_text, real_encoding*10+#charsets); |
698 | DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1, |
679 | DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1, |
699 | 60, 12, BTN_CHANGE_CHARSET+10); |
680 | 60, 12, BTN_CHANGE_CHARSET+10); |
700 | } |
681 | } |
701 | } |
682 | } |
702 | |
Line 683... | Line 703... | ||
683 | 703 | void draw_window() |
|
684 | void draw_window() |
704 | { |
Line 685... | Line 705... | ||
685 | { |
705 | int old_w = list.w; |
Line 686... | Line 706... | ||
686 | int old_w = list.w; |
706 | if (CheckActiveProcess(Form.ID)) EventMenuClick(); |
687 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); |
707 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); |
688 | GetProcessInfo(#Form, SelfInfo); |
708 | GetProcessInfo(#Form, SelfInfo); |
689 | sc.get(); |
709 | sc.get(); |
690 | if (Form.status_window>2) return; |
710 | if (Form.status_window>2) return; |
Line 691... | Line 711... | ||
691 | if (Form.width < 450) { MoveSize(OLD,OLD,450,OLD); return; } |
711 | if (Form.width < 450) { MoveSize(OLD,OLD,450,OLD); return; } |
- | 712 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
|
692 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
713 | |
693 | 714 | button.init(40); |
|
Line 694... | Line 715... | ||
694 | button.init(40); |
715 | key.init(40); |
695 | key.init(40); |
716 | |
696 | 717 | SetFontSize(font_size); |
|
697 | SetSizes(font_size); |
718 | |
698 | 719 | if ((list.w == old_w) && (list.count)) { |
|
699 | if ((list.w == old_w) && (list.count)) { |
- | |
700 | DrawPage(); |
720 | DrawPage(); |
701 | } else { |
- | |
702 | ParseAndPaint(); |
- | |
703 | } |
721 | } else { |
Line 704... | Line 722... | ||
704 | 722 | ParseAndPaint(); |
|
705 | DrawToolbar(); |
723 | } |
706 | DrawStatusBar(NULL); |
- | |
707 | } |
- | |
Line -... | Line 724... | ||
- | 724 | ||
- | 725 | DrawToolbar(); |
|
- | 726 | DrawSearch(); |
|
- | 727 | DrawStatusBar(NULL); |
|
- | 728 | } |
|
- | 729 | ||
- | 730 | bool DrawSearch() |
|
- | 731 | { |
|
- | 732 | char matches[30]; |
|
- | 733 | int _y = Form.cheight - SEARCH_H - STATUSBAR_H; |
|
- | 734 | if (!search.visible) return false; |
|
- | 735 | DrawBar(0, _y, Form.cwidth, 1, sc.work_graph); |
|
- | 736 | DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work); |
|
- | 737 | ||
- | 738 | search_box.top = _y + 6; |
|
- | 739 | search_box.width = math.min(Form.width - 200, 150); |
|
- | 740 | ||
- | 741 | DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph); |
|
Line 708... | Line 742... | ||
708 | 742 | ||
709 | void DrawPage() |
743 | edit_box_draw stdcall(#search_box); |
710 | { |
744 | |
711 | scroll.max_area = list.count; |
745 | DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 30, |
712 | scroll.cur_area = list.visible; |
746 | TOOLBAR_ICON_HEIGHT+1, BTN_FIND_PREVIOUS+10, sc.work_light, sc.work_text, "<"); |
- | 747 | DrawCaptButton(search_box.left+search_box.width+44, search_box.top-1, 30, |
|
- | 748 | TOOLBAR_ICON_HEIGHT+1, BTN_FIND_NEXT+10, sc.work_light, sc.work_text, ">"); |
|
713 | scroll.position = list.first; |
749 | |
714 | scroll.all_redraw = 0; |
750 | sprintf(#matches, T_MATCHES, search.found.count); |
715 | scroll.start_x = list.x + list.w; |
751 | WriteTextWithBg(search_box.left+search_box.width+14+85, |
716 | scroll.start_y = list.y; |
752 | search_box.top+3, 0xD0, sc.work_text, #matches, sc.work); |
717 | scroll.size_y = list.h; |
753 |