Changes in uspace/app/edit/edit.c [994f87b:e0cf963] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r994f87b re0cf963 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * Copyright (c) 2012 Martin Sucha 4 4 * All rights reserved. … … 60 60 #include <ui/menu.h> 61 61 #include <ui/menubar.h> 62 #include <ui/menudd.h>63 62 #include <ui/menuentry.h> 64 63 #include <ui/promptdialog.h> … … 177 176 static void pos_handle(pos_event_t *ev); 178 177 179 static errno_t file_new(void);180 static void file_open(void);181 static errno_t file_open_file(const char *fname);182 178 static errno_t file_save(char const *fname); 183 179 static void file_save_as(void); 184 static errno_t file_insert(c onst char *fname);180 static errno_t file_insert(char *fname); 185 181 static errno_t file_save_range(char const *fname, spt_t const *spos, 186 182 spt_t const *epos); … … 241 237 242 238 static void edit_wnd_close(ui_window_t *, void *); 243 static void edit_wnd_focus(ui_window_t *, void *, unsigned);244 239 static void edit_wnd_kbd_event(ui_window_t *, void *, kbd_event_t *); 245 static void edit_wnd_unfocus(ui_window_t *, void *, unsigned);246 240 247 241 static ui_window_cb_t edit_window_cb = { 248 242 .close = edit_wnd_close, 249 .focus = edit_wnd_focus, 250 .kbd = edit_wnd_kbd_event, 251 .unfocus = edit_wnd_unfocus 243 .kbd = edit_wnd_kbd_event 252 244 }; 253 245 254 static void edit_menubar_activate(ui_menu_bar_t *, void *);255 static void edit_menubar_deactivate(ui_menu_bar_t *, void *);256 257 static ui_menu_bar_cb_t edit_menubar_cb = {258 .activate = edit_menubar_activate,259 .deactivate = edit_menubar_deactivate260 };261 262 static void edit_file_new(ui_menu_entry_t *, void *);263 static void edit_file_open(ui_menu_entry_t *, void *);264 246 static void edit_file_save(ui_menu_entry_t *, void *); 265 247 static void edit_file_save_as(ui_menu_entry_t *, void *); … … 286 268 }; 287 269 288 static void open_dialog_bok(ui_file_dialog_t *, void *, const char *);289 static void open_dialog_bcancel(ui_file_dialog_t *, void *);290 static void open_dialog_close(ui_file_dialog_t *, void *);291 292 static ui_file_dialog_cb_t open_dialog_cb = {293 .bok = open_dialog_bok,294 .bcancel = open_dialog_bcancel,295 .close = open_dialog_close296 };297 298 270 static void save_as_dialog_bok(ui_file_dialog_t *, void *, const char *); 299 271 static void save_as_dialog_bcancel(ui_file_dialog_t *, void *); … … 328 300 int main(int argc, char *argv[]) 329 301 { 302 bool new_file; 330 303 errno_t rc; 331 304 332 305 pane.sh_row = 1; 333 306 pane.sh_column = 1; 307 308 /* Start with an empty sheet. */ 309 rc = sheet_create(&doc.sh); 310 if (rc != EOK) { 311 printf("Out of memory.\n"); 312 return -1; 313 } 314 315 /* Place caret at the beginning of file. */ 316 spt_t sof; 317 pt_get_sof(&sof); 318 sheet_place_tag(doc.sh, &sof, &pane.caret_pos); 319 pane.ideal_column = 1; 320 321 if (argc == 2) { 322 doc.file_name = str_dup(argv[1]); 323 } else if (argc > 1) { 324 printf("Invalid arguments.\n"); 325 return -2; 326 } else { 327 doc.file_name = NULL; 328 } 329 330 new_file = false; 331 332 if (doc.file_name == NULL || file_insert(doc.file_name) != EOK) 333 new_file = true; 334 335 /* Place selection start tag. */ 336 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 337 338 /* Move to beginning of file. */ 339 pt_get_sof(&sof); 334 340 335 341 /* Create UI */ … … 338 344 return 1; 339 345 340 if (argc == 2) { 341 doc.file_name = str_dup(argv[1]); 342 rc = file_open_file(argv[1]); 343 if (rc != EOK) { 344 status_display("File not found. Starting empty file."); 345 rc = file_new(); 346 } 347 } else if (argc > 1) { 348 printf("Invalid arguments.\n"); 349 return -2; 350 } else { 351 rc = file_new(); 352 } 346 caret_move(sof, true, true); 353 347 354 348 /* Initial display */ … … 358 352 return rc; 359 353 } 354 355 pane_status_display(&pane); 356 if (new_file && doc.file_name != NULL) 357 status_display("File not found. Starting empty file."); 358 pane_caret_display(&pane); 359 cursor_setvis(true); 360 360 361 361 ui_run(edit.ui); … … 377 377 ui_menu_t *mfile = NULL; 378 378 ui_menu_t *medit = NULL; 379 ui_menu_entry_t *mnew = NULL;380 ui_menu_entry_t *mopen = NULL;381 379 ui_menu_entry_t *msave = NULL; 382 380 ui_menu_entry_t *msaveas = NULL; … … 432 430 } 433 431 434 ui_menu_bar_set_cb(edit->menubar, &edit_menubar_cb, (void *) edit); 435 436 rc = ui_menu_dd_create(edit->menubar, "~F~ile", NULL, &mfile); 432 rc = ui_menu_create(edit->menubar, "File", &mfile); 437 433 if (rc != EOK) { 438 434 printf("Error creating menu.\n"); … … 440 436 } 441 437 442 rc = ui_menu_entry_create(mfile, " ~N~ew", "Ctrl-N", &mnew);438 rc = ui_menu_entry_create(mfile, "Save", "Ctrl-S", &msave); 443 439 if (rc != EOK) { 444 440 printf("Error creating menu.\n"); … … 446 442 } 447 443 448 ui_menu_entry_set_cb(m new, edit_file_new, (void *) edit);449 450 rc = ui_menu_entry_create(mfile, " ~O~pen", "Ctrl-O", &mopen);444 ui_menu_entry_set_cb(msave, edit_file_save, (void *) edit); 445 446 rc = ui_menu_entry_create(mfile, "Save As", "Ctrl-E", &msaveas); 451 447 if (rc != EOK) { 452 448 printf("Error creating menu.\n"); … … 454 450 } 455 451 456 ui_menu_entry_set_cb(m open, edit_file_open, (void *) edit);457 458 rc = ui_menu_entry_ create(mfile, "~S~ave", "Ctrl-S", &msave);452 ui_menu_entry_set_cb(msaveas, edit_file_save_as, (void *) edit); 453 454 rc = ui_menu_entry_sep_create(mfile, &mfsep); 459 455 if (rc != EOK) { 460 456 printf("Error creating menu.\n"); … … 462 458 } 463 459 464 ui_menu_entry_set_cb(msave, edit_file_save, (void *) edit); 465 466 rc = ui_menu_entry_create(mfile, "Save ~A~s", "Ctrl-E", &msaveas); 460 rc = ui_menu_entry_create(mfile, "Exit", "Ctrl-Q", &mexit); 467 461 if (rc != EOK) { 468 462 printf("Error creating menu.\n"); … … 470 464 } 471 465 472 ui_menu_entry_set_cb(m saveas, edit_file_save_as, (void *) edit);473 474 rc = ui_menu_ entry_sep_create(mfile, &mfsep);466 ui_menu_entry_set_cb(mexit, edit_file_exit, (void *) edit); 467 468 rc = ui_menu_create(edit->menubar, "Edit", &medit); 475 469 if (rc != EOK) { 476 470 printf("Error creating menu.\n"); … … 478 472 } 479 473 480 rc = ui_menu_entry_create(m file, "E~x~it", "Ctrl-Q", &mexit);474 rc = ui_menu_entry_create(medit, "Cut", "Ctrl-X", &mcut); 481 475 if (rc != EOK) { 482 476 printf("Error creating menu.\n"); … … 484 478 } 485 479 486 ui_menu_entry_set_cb(m exit, edit_file_exit, (void *) edit);487 488 rc = ui_menu_ dd_create(edit->menubar, "~E~dit", NULL, &medit);480 ui_menu_entry_set_cb(mcut, edit_edit_cut, (void *) edit); 481 482 rc = ui_menu_entry_create(medit, "Copy", "Ctrl-C", &mcopy); 489 483 if (rc != EOK) { 490 484 printf("Error creating menu.\n"); … … 492 486 } 493 487 494 rc = ui_menu_entry_create(medit, "Cu~t~", "Ctrl-X", &mcut); 488 ui_menu_entry_set_cb(mcopy, edit_edit_copy, (void *) edit); 489 490 rc = ui_menu_entry_create(medit, "Paste", "Ctrl-V", &mpaste); 495 491 if (rc != EOK) { 496 492 printf("Error creating menu.\n"); … … 498 494 } 499 495 500 ui_menu_entry_set_cb(m cut, edit_edit_cut, (void *) edit);501 502 rc = ui_menu_entry_create(medit, " ~C~opy", "Ctrl-C", &mcopy);496 ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit); 497 498 rc = ui_menu_entry_create(medit, "Delete", "Del", &mdelete); 503 499 if (rc != EOK) { 504 500 printf("Error creating menu.\n"); … … 506 502 } 507 503 508 ui_menu_entry_set_cb(m copy, edit_edit_copy, (void *) edit);509 510 rc = ui_menu_entry_ create(medit, "~P~aste", "Ctrl-V", &mpaste);504 ui_menu_entry_set_cb(mdelete, edit_edit_delete, (void *) edit); 505 506 rc = ui_menu_entry_sep_create(medit, &mesep); 511 507 if (rc != EOK) { 512 508 printf("Error creating menu.\n"); … … 514 510 } 515 511 516 ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit); 517 518 rc = ui_menu_entry_create(medit, "~D~elete", "Del", &mdelete); 512 rc = ui_menu_entry_create(medit, "Select All", "Ctrl-A", &mselall); 519 513 if (rc != EOK) { 520 514 printf("Error creating menu.\n"); … … 522 516 } 523 517 524 ui_menu_entry_set_cb(m delete, edit_edit_delete, (void *) edit);525 526 rc = ui_menu_ entry_sep_create(medit, &mesep);518 ui_menu_entry_set_cb(mselall, edit_edit_select_all, (void *) edit); 519 520 rc = ui_menu_create(edit->menubar, "Search", &msearch); 527 521 if (rc != EOK) { 528 522 printf("Error creating menu.\n"); … … 530 524 } 531 525 532 rc = ui_menu_entry_create(m edit, "Select ~A~ll", "Ctrl-A", &mselall);526 rc = ui_menu_entry_create(msearch, "Find", "Ctrl-F", &mfind); 533 527 if (rc != EOK) { 534 528 printf("Error creating menu.\n"); … … 536 530 } 537 531 538 ui_menu_entry_set_cb(m selall, edit_edit_select_all, (void *) edit);539 540 rc = ui_menu_ dd_create(edit->menubar, "~S~earch", NULL, &msearch);532 ui_menu_entry_set_cb(mfind, edit_search_find, (void *) edit); 533 534 rc = ui_menu_entry_create(msearch, "Reverse Find", "Ctrl-Shift-F", &mfindr); 541 535 if (rc != EOK) { 542 536 printf("Error creating menu.\n"); … … 544 538 } 545 539 546 rc = ui_menu_entry_create(msearch, "~F~ind", "Ctrl-F", &mfind); 540 ui_menu_entry_set_cb(mfindr, edit_search_reverse_find, (void *) edit); 541 542 rc = ui_menu_entry_create(msearch, "Find Next", "Ctrl-N", &mfindn); 547 543 if (rc != EOK) { 548 544 printf("Error creating menu.\n"); … … 550 546 } 551 547 552 ui_menu_entry_set_cb(mfind , edit_search_find, (void *) edit);553 554 rc = ui_menu_entry_ create(msearch, "~R~everse Find", "Ctrl-Shift-F", &mfindr);548 ui_menu_entry_set_cb(mfindn, edit_search_find_next, (void *) edit); 549 550 rc = ui_menu_entry_sep_create(msearch, &mssep); 555 551 if (rc != EOK) { 556 552 printf("Error creating menu.\n"); … … 558 554 } 559 555 560 ui_menu_entry_set_cb(mfindr, edit_search_reverse_find, (void *) edit); 561 562 rc = ui_menu_entry_create(msearch, "Find ~N~ext", "Ctrl-R", &mfindn); 563 if (rc != EOK) { 564 printf("Error creating menu.\n"); 565 return rc; 566 } 567 568 ui_menu_entry_set_cb(mfindn, edit_search_find_next, (void *) edit); 569 570 rc = ui_menu_entry_sep_create(msearch, &mssep); 571 if (rc != EOK) { 572 printf("Error creating menu.\n"); 573 return rc; 574 } 575 576 rc = ui_menu_entry_create(msearch, "Go To ~L~ine", "Ctrl-L", &mgoto); 556 rc = ui_menu_entry_create(msearch, "Go To Line", "Ctrl-L", &mgoto); 577 557 if (rc != EOK) { 578 558 printf("Error creating menu.\n"); … … 746 726 ui_quit(edit.ui); 747 727 break; 748 case KC_N:749 file_new();750 break;751 case KC_O:752 file_open();753 break;754 728 case KC_S: 755 729 if (doc.file_name != NULL) … … 785 759 search_prompt(false); 786 760 break; 787 case KC_ R:761 case KC_N: 788 762 search_repeat(); 789 763 break; … … 924 898 } 925 899 926 /** Create new document. */ 927 static errno_t file_new(void) 928 { 900 /** Save the document. */ 901 static errno_t file_save(char const *fname) 902 { 903 spt_t sp, ep; 929 904 errno_t rc; 930 sheet_t *sh; 931 932 /* Create empty sheet. */ 933 rc = sheet_create(&sh); 934 if (rc != EOK) { 935 printf("Out of memory.\n"); 936 return ENOMEM; 937 } 938 939 if (doc.sh != NULL) 940 sheet_destroy(doc.sh); 941 942 doc.sh = sh; 943 944 /* Place caret at the beginning of file. */ 945 spt_t sof; 946 pt_get_sof(&sof); 947 sheet_place_tag(doc.sh, &sof, &pane.caret_pos); 948 pane.ideal_column = 1; 949 950 doc.file_name = NULL; 951 952 /* Place selection start tag. */ 953 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 954 955 /* Move to beginning of file. */ 956 pt_get_sof(&sof); 957 958 caret_move(sof, true, true); 959 960 pane_status_display(&pane); 961 pane_caret_display(&pane); 962 pane_text_display(&pane); 963 cursor_setvis(true); 964 965 return EOK; 966 } 967 968 /** Open Open File dialog. */ 969 static void file_open(void) 905 906 status_display("Saving..."); 907 pt_get_sof(&sp); 908 pt_get_eof(&ep); 909 910 rc = file_save_range(fname, &sp, &ep); 911 912 switch (rc) { 913 case EINVAL: 914 status_display("Error opening file!"); 915 break; 916 case EIO: 917 status_display("Error writing data!"); 918 break; 919 default: 920 status_display("File saved."); 921 break; 922 } 923 924 return rc; 925 } 926 927 /** Open Save As dialog. */ 928 static void file_save_as(void) 970 929 { 971 930 const char *old_fname = (doc.file_name != NULL) ? doc.file_name : ""; … … 975 934 976 935 ui_file_dialog_params_init(&fdparams); 977 fdparams.caption = " Open File";936 fdparams.caption = "Save As"; 978 937 fdparams.ifname = old_fname; 979 938 … … 984 943 } 985 944 986 ui_file_dialog_set_cb(dialog, &open_dialog_cb, &edit);987 }988 989 /** Open exising document. */990 static errno_t file_open_file(const char *fname)991 {992 errno_t rc;993 sheet_t *sh;994 char *fn;995 996 /* Create empty sheet. */997 rc = sheet_create(&sh);998 if (rc != EOK) {999 printf("Out of memory.\n");1000 return ENOMEM;1001 }1002 1003 fn = str_dup(fname);1004 if (fn == NULL) {1005 sheet_destroy(sh);1006 return ENOMEM;1007 }1008 1009 if (doc.sh != NULL)1010 sheet_destroy(doc.sh);1011 1012 doc.sh = sh;1013 1014 /* Place caret at the beginning of file. */1015 spt_t sof;1016 pt_get_sof(&sof);1017 sheet_place_tag(doc.sh, &sof, &pane.caret_pos);1018 pane.ideal_column = 1;1019 1020 rc = file_insert(fname);1021 if (rc != EOK)1022 return rc;1023 1024 doc.file_name = fn;1025 1026 /* Place selection start tag. */1027 sheet_place_tag(doc.sh, &sof, &pane.sel_start);1028 1029 /* Move to beginning of file. */1030 pt_get_sof(&sof);1031 1032 caret_move(sof, true, true);1033 1034 pane_status_display(&pane);1035 pane_caret_display(&pane);1036 pane_text_display(&pane);1037 cursor_setvis(true);1038 1039 return EOK;1040 }1041 1042 /** Save the document. */1043 static errno_t file_save(char const *fname)1044 {1045 spt_t sp, ep;1046 errno_t rc;1047 1048 status_display("Saving...");1049 pt_get_sof(&sp);1050 pt_get_eof(&ep);1051 1052 rc = file_save_range(fname, &sp, &ep);1053 1054 switch (rc) {1055 case EINVAL:1056 status_display("Error opening file!");1057 break;1058 case EIO:1059 status_display("Error writing data!");1060 break;1061 default:1062 status_display("File saved.");1063 break;1064 }1065 1066 return rc;1067 }1068 1069 /** Open Save As dialog. */1070 static void file_save_as(void)1071 {1072 const char *old_fname = (doc.file_name != NULL) ? doc.file_name : "";1073 ui_file_dialog_params_t fdparams;1074 ui_file_dialog_t *dialog;1075 errno_t rc;1076 1077 ui_file_dialog_params_init(&fdparams);1078 fdparams.caption = "Save As";1079 fdparams.ifname = old_fname;1080 1081 rc = ui_file_dialog_create(edit.ui, &fdparams, &dialog);1082 if (rc != EOK) {1083 printf("Error creating message dialog.\n");1084 return;1085 }1086 1087 945 ui_file_dialog_set_cb(dialog, &save_as_dialog_cb, &edit); 1088 946 } … … 1093 951 * of the caret. 1094 952 */ 1095 static errno_t file_insert(c onst char *fname)953 static errno_t file_insert(char *fname) 1096 954 { 1097 955 FILE *f; … … 1120 978 1121 979 bcnt -= off; 1122 mem move(buf, buf + off, bcnt);980 memcpy(buf, buf + off, bcnt); 1123 981 1124 982 insert_char(c); … … 1401 1259 1402 1260 gfx_text_fmt_init(&fmt); 1403 fmt.font = font;1404 1261 fmt.color = pane->color; 1405 1262 … … 1461 1318 return rc; 1462 1319 1463 rc = gfx_puttext( &tpos, &fmt, cbuf);1320 rc = gfx_puttext(font, &tpos, &fmt, cbuf); 1464 1321 if (rc != EOK) 1465 1322 return rc; … … 1551 1408 */ 1552 1409 while (true) { 1553 int rc = asprintf(&text, "%d, %d (%d): File '%s'. Ctrl-Q Quit "1554 " F10 Menu", coord.row, coord.column, last_row, fname);1410 int rc = asprintf(&text, "%d, %d (%d): File '%s'. Ctrl-Q Quit Ctrl-S Save " 1411 "Ctrl-E Save As", coord.row, coord.column, last_row, fname); 1555 1412 if (rc < 0) { 1556 1413 n = 0; … … 2362 2219 } 2363 2220 2364 /** Window focus event2365 *2366 * @param window Window2367 * @param arg Argument (edit_t *)2368 * @param focus Focus number2369 */2370 static void edit_wnd_focus(ui_window_t *window, void *arg, unsigned focus)2371 {2372 edit_t *edit = (edit_t *)arg;2373 2374 (void)edit;2375 pane_caret_display(&pane);2376 cursor_setvis(true);2377 }2378 2379 2221 /** Window keyboard event 2380 2222 * … … 2387 2229 { 2388 2230 pane.keymod = event->mods; 2389 2390 if (ui_window_def_kbd(window, event) == ui_claimed)2391 return;2392 2231 2393 2232 if (event->type == KEY_PRESS) { … … 2398 2237 } 2399 2238 2400 /** Window unfocus event2401 *2402 * @param window Window2403 * @param arg Argument (edit_t *)2404 * @param focus Focus number2405 */2406 static void edit_wnd_unfocus(ui_window_t *window, void *arg, unsigned focus)2407 {2408 edit_t *edit = (edit_t *) arg;2409 2410 (void)edit;2411 cursor_setvis(false);2412 }2413 2414 /** Menu bar activate event2415 *2416 * @param mbar Menu bar2417 * @param arg Argument (edit_t *)2418 */2419 static void edit_menubar_activate(ui_menu_bar_t *mbar, void *arg)2420 {2421 edit_t *edit = (edit_t *)arg;2422 2423 (void)edit;2424 cursor_setvis(false);2425 }2426 2427 /** Menu bar deactivate event2428 *2429 * @param mbar Menu bar2430 * @param arg Argument (edit_t *)2431 */2432 static void edit_menubar_deactivate(ui_menu_bar_t *mbar, void *arg)2433 {2434 edit_t *edit = (edit_t *)arg;2435 2436 (void)edit;2437 pane_caret_display(&pane);2438 cursor_setvis(true);2439 }2440 2441 /** File / New menu entry selected.2442 *2443 * @param mentry Menu entry2444 * @param arg Argument (edit_t *)2445 */2446 static void edit_file_new(ui_menu_entry_t *mentry, void *arg)2447 {2448 edit_t *edit = (edit_t *) arg;2449 2450 (void)edit;2451 file_new();2452 (void) gfx_update(ui_window_get_gc(edit->window));2453 }2454 2455 /** File / Open menu entry selected.2456 *2457 * @param mentry Menu entry2458 * @param arg Argument (edit_t *)2459 */2460 static void edit_file_open(ui_menu_entry_t *mentry, void *arg)2461 {2462 edit_t *edit = (edit_t *) arg;2463 2464 (void)edit;2465 file_open();2466 }2467 2468 2239 /** File / Save menu entry selected. 2469 2240 * … … 2621 2392 } 2622 2393 2623 /** Open Filedialog OK button press.2624 * 2625 * @param dialog Open Filedialog2394 /** Save As dialog OK button press. 2395 * 2396 * @param dialog Save As dialog 2626 2397 * @param arg Argument (ui_demo_t *) 2627 2398 * @param fname File name 2628 2399 */ 2629 static void open_dialog_bok(ui_file_dialog_t *dialog, void *arg,2400 static void save_as_dialog_bok(ui_file_dialog_t *dialog, void *arg, 2630 2401 const char *fname) 2631 2402 { 2632 2403 edit_t *edit = (edit_t *)arg; 2404 gfx_context_t *gc = ui_window_get_gc(edit->window); 2633 2405 char *cname; 2634 2406 errno_t rc; 2635 2407 2636 (void)edit;2637 2408 ui_file_dialog_destroy(dialog); 2409 // TODO Smarter cursor management 2410 pane.rflags |= REDRAW_CARET; 2411 (void) pane_update(&pane); 2412 gfx_cursor_set_visible(gc, true); 2638 2413 2639 2414 cname = str_dup(fname); … … 2643 2418 } 2644 2419 2645 rc = file_ open_file(fname);2420 rc = file_save(fname); 2646 2421 if (rc != EOK) 2647 2422 return; … … 2651 2426 doc.file_name = cname; 2652 2427 2653 (void) gfx_update(ui_window_get_gc(edit->window)); 2654 } 2655 2656 /** Open File dialog cancel button press. 2428 } 2429 2430 /** Save As dialog cancel button press. 2657 2431 * 2658 2432 * @param dialog File dialog 2659 2433 * @param arg Argument (ui_demo_t *) 2660 2434 */ 2661 static void open_dialog_bcancel(ui_file_dialog_t *dialog, void *arg)2435 static void save_as_dialog_bcancel(ui_file_dialog_t *dialog, void *arg) 2662 2436 { 2663 2437 edit_t *edit = (edit_t *)arg; 2664 2665 (void)edit; 2438 gfx_context_t *gc = ui_window_get_gc(edit->window); 2439 2666 2440 ui_file_dialog_destroy(dialog); 2667 } 2668 2669 /** Open File dialog close request. 2441 // TODO Smarter cursor management 2442 pane.rflags |= REDRAW_CARET; 2443 (void) pane_update(&pane); 2444 gfx_cursor_set_visible(gc, true); 2445 } 2446 2447 /** Save As dialog close request. 2670 2448 * 2671 2449 * @param dialog File dialog 2672 2450 * @param arg Argument (ui_demo_t *) 2673 2451 */ 2674 static void open_dialog_close(ui_file_dialog_t *dialog, void *arg)2452 static void save_as_dialog_close(ui_file_dialog_t *dialog, void *arg) 2675 2453 { 2676 2454 edit_t *edit = (edit_t *)arg; 2677 2678 (void)edit; 2455 gfx_context_t *gc = ui_window_get_gc(edit->window); 2456 2679 2457 ui_file_dialog_destroy(dialog); 2680 } 2681 2682 /** Save As dialog OK button press. 2683 * 2684 * @param dialog Save As dialog 2685 * @param arg Argument (ui_demo_t *) 2686 * @param fname File name 2687 */ 2688 static void save_as_dialog_bok(ui_file_dialog_t *dialog, void *arg, 2689 const char *fname) 2690 { 2691 edit_t *edit = (edit_t *)arg; 2692 char *cname; 2693 errno_t rc; 2694 2695 (void)edit; 2696 ui_file_dialog_destroy(dialog); 2697 2698 cname = str_dup(fname); 2699 if (cname == NULL) { 2700 printf("Out of memory.\n"); 2701 return; 2702 } 2703 2704 rc = file_save(fname); 2705 if (rc != EOK) 2706 return; 2707 2708 if (doc.file_name != NULL) 2709 free(doc.file_name); 2710 doc.file_name = cname; 2711 2712 } 2713 2714 /** Save As dialog cancel button press. 2715 * 2716 * @param dialog File dialog 2717 * @param arg Argument (ui_demo_t *) 2718 */ 2719 static void save_as_dialog_bcancel(ui_file_dialog_t *dialog, void *arg) 2720 { 2721 edit_t *edit = (edit_t *)arg; 2722 2723 (void)edit; 2724 ui_file_dialog_destroy(dialog); 2725 } 2726 2727 /** Save As dialog close request. 2728 * 2729 * @param dialog File dialog 2730 * @param arg Argument (ui_demo_t *) 2731 */ 2732 static void save_as_dialog_close(ui_file_dialog_t *dialog, void *arg) 2733 { 2734 edit_t *edit = (edit_t *)arg; 2735 2736 (void)edit; 2737 ui_file_dialog_destroy(dialog); 2458 // TODO Smarter cursor management 2459 pane.rflags |= REDRAW_CARET; 2460 (void) pane_update(&pane); 2461 gfx_cursor_set_visible(gc, true); 2738 2462 } 2739 2463 … … 2748 2472 { 2749 2473 edit_t *edit = (edit_t *) arg; 2474 gfx_context_t *gc = ui_window_get_gc(edit->window); 2750 2475 char *endptr; 2751 2476 int line; … … 2759 2484 2760 2485 caret_move_absolute(line, pane.ideal_column, dir_before, false); 2761 (void)edit;2486 // TODO Smarter cursor management 2762 2487 (void) pane_update(&pane); 2488 gfx_cursor_set_visible(gc, true); 2489 (void) gfx_update(gc); 2763 2490 } 2764 2491 … … 2771 2498 { 2772 2499 edit_t *edit = (edit_t *) arg; 2773 2774 (void)edit; 2500 gfx_context_t *gc = ui_window_get_gc(edit->window); 2501 2775 2502 ui_prompt_dialog_destroy(dialog); 2503 // TODO Smarter cursor management 2504 pane.rflags |= REDRAW_CARET; 2505 (void) pane_update(&pane); 2506 gfx_cursor_set_visible(gc, true); 2776 2507 } 2777 2508 … … 2784 2515 { 2785 2516 edit_t *edit = (edit_t *) arg; 2786 2787 (void)edit; 2517 gfx_context_t *gc = ui_window_get_gc(edit->window); 2518 2788 2519 ui_prompt_dialog_destroy(dialog); 2520 // TODO Smarter cursor management 2521 pane.rflags |= REDRAW_CARET; 2522 (void) pane_update(&pane); 2523 gfx_cursor_set_visible(gc, true); 2789 2524 } 2790 2525 … … 2799 2534 { 2800 2535 edit_t *edit = (edit_t *) arg; 2536 gfx_context_t *gc = ui_window_get_gc(edit->window); 2801 2537 char *pattern; 2802 2538 bool reverse; 2803 2539 2804 (void)edit;2805 2540 ui_prompt_dialog_destroy(dialog); 2806 2541 … … 2819 2554 search(pattern, reverse); 2820 2555 2556 // TODO Smarter cursor management 2821 2557 (void) pane_update(&pane); 2558 gfx_cursor_set_visible(gc, true); 2559 (void) gfx_update(gc); 2822 2560 } 2823 2561 … … 2830 2568 { 2831 2569 edit_t *edit = (edit_t *) arg; 2832 2833 (void)edit; 2570 gfx_context_t *gc = ui_window_get_gc(edit->window); 2571 2834 2572 ui_prompt_dialog_destroy(dialog); 2573 // TODO Smarter cursor management 2574 pane.rflags |= REDRAW_CARET; 2575 (void) pane_update(&pane); 2576 gfx_cursor_set_visible(gc, true); 2835 2577 } 2836 2578 … … 2843 2585 { 2844 2586 edit_t *edit = (edit_t *) arg; 2845 2846 (void)edit; 2587 gfx_context_t *gc = ui_window_get_gc(edit->window); 2588 2847 2589 ui_prompt_dialog_destroy(dialog); 2590 // TODO Smarter cursor management 2591 pane.rflags |= REDRAW_CARET; 2592 (void) pane_update(&pane); 2593 gfx_cursor_set_visible(gc, true); 2848 2594 } 2849 2595
Note:
See TracChangeset
for help on using the changeset viewer.