Changes in uspace/app/edit/edit.c [e0cf963:3c22438a] in mainline
- File:
-
- 1 edited
-
uspace/app/edit/edit.c (modified) (58 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
re0cf963 r3c22438a 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2026 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> 62 63 #include <ui/menuentry.h> 63 64 #include <ui/promptdialog.h> … … 176 177 static void pos_handle(pos_event_t *ev); 177 178 179 static errno_t file_new(void); 180 static void file_open(void); 181 static errno_t file_open_file(const char *fname); 178 182 static errno_t file_save(char const *fname); 179 183 static void file_save_as(void); 180 static errno_t file_insert(c har *fname);184 static errno_t file_insert(const char *fname); 181 185 static errno_t file_save_range(char const *fname, spt_t const *spos, 182 186 spt_t const *epos); … … 236 240 static void edit_ui_destroy(edit_t *); 237 241 242 static void edit_wnd_resize(ui_window_t *, void *); 238 243 static void edit_wnd_close(ui_window_t *, void *); 244 static void edit_wnd_focus(ui_window_t *, void *, unsigned); 239 245 static void edit_wnd_kbd_event(ui_window_t *, void *, kbd_event_t *); 246 static void edit_wnd_unfocus(ui_window_t *, void *, unsigned); 240 247 241 248 static ui_window_cb_t edit_window_cb = { 249 .resize = edit_wnd_resize, 242 250 .close = edit_wnd_close, 243 .kbd = edit_wnd_kbd_event 251 .focus = edit_wnd_focus, 252 .kbd = edit_wnd_kbd_event, 253 .unfocus = edit_wnd_unfocus 244 254 }; 245 255 256 static void edit_menubar_activate(ui_menu_bar_t *, void *); 257 static void edit_menubar_deactivate(ui_menu_bar_t *, void *); 258 259 static ui_menu_bar_cb_t edit_menubar_cb = { 260 .activate = edit_menubar_activate, 261 .deactivate = edit_menubar_deactivate 262 }; 263 264 static void edit_file_new(ui_menu_entry_t *, void *); 265 static void edit_file_open(ui_menu_entry_t *, void *); 246 266 static void edit_file_save(ui_menu_entry_t *, void *); 247 267 static void edit_file_save_as(ui_menu_entry_t *, void *); … … 268 288 }; 269 289 290 static void open_dialog_bok(ui_file_dialog_t *, void *, const char *); 291 static void open_dialog_bcancel(ui_file_dialog_t *, void *); 292 static void open_dialog_close(ui_file_dialog_t *, void *); 293 294 static ui_file_dialog_cb_t open_dialog_cb = { 295 .bok = open_dialog_bok, 296 .bcancel = open_dialog_bcancel, 297 .close = open_dialog_close 298 }; 299 270 300 static void save_as_dialog_bok(ui_file_dialog_t *, void *, const char *); 271 301 static void save_as_dialog_bcancel(ui_file_dialog_t *, void *); … … 300 330 int main(int argc, char *argv[]) 301 331 { 302 bool new_file;303 332 errno_t rc; 304 333 … … 306 335 pane.sh_column = 1; 307 336 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; 337 /* Create UI */ 338 rc = edit_ui_create(&edit); 339 if (rc != EOK) 340 return 1; 320 341 321 342 if (argc == 2) { 322 343 doc.file_name = str_dup(argv[1]); 344 rc = file_open_file(argv[1]); 345 if (rc != EOK) { 346 status_display("File not found. Starting empty file."); 347 rc = file_new(); 348 } 323 349 } else if (argc > 1) { 324 350 printf("Invalid arguments.\n"); 325 351 return -2; 326 352 } 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); 340 341 /* Create UI */ 342 rc = edit_ui_create(&edit); 343 if (rc != EOK) 344 return 1; 345 346 caret_move(sof, true, true); 353 rc = file_new(); 354 } 347 355 348 356 /* Initial display */ … … 353 361 } 354 362 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 361 363 ui_run(edit.ui); 362 364 363 365 edit_ui_destroy(&edit); 364 366 return 0; 367 } 368 369 /** Set menu bar rectangle. 370 * 371 * Set the menu bar rectangle based on editor window dimensions. 372 * Used when window is created or resized. 373 * 374 * @param edit Editor 375 */ 376 static void edit_menubar_set_rect(edit_t *edit) 377 { 378 gfx_rect_t arect; 379 gfx_rect_t rect; 380 381 ui_window_get_app_rect(edit->window, &arect); 382 383 rect.p0 = arect.p0; 384 rect.p1.x = arect.p1.x; 385 rect.p1.y = arect.p0.y + 1; 386 ui_menu_bar_set_rect(edit->menubar, &rect); 387 } 388 389 /** Set status bar rectangle. 390 * 391 * Set the status bar rectangle based on editor window dimensions. 392 * Used when window is created or resized. 393 * 394 * @param edit Editor 395 */ 396 static void edit_status_set_rect(edit_t *edit) 397 { 398 gfx_rect_t arect; 399 gfx_rect_t rect; 400 401 ui_window_get_app_rect(edit->window, &arect); 402 rect.p0.x = arect.p0.x; 403 rect.p0.y = arect.p1.y - 1; 404 rect.p1 = arect.p1; 405 ui_label_set_rect(edit->status, &rect); 365 406 } 366 407 … … 377 418 ui_menu_t *mfile = NULL; 378 419 ui_menu_t *medit = NULL; 420 ui_menu_entry_t *mnew = NULL; 421 ui_menu_entry_t *mopen = NULL; 379 422 ui_menu_entry_t *msave = NULL; 380 423 ui_menu_entry_t *msaveas = NULL; … … 393 436 ui_menu_entry_t *mssep = NULL; 394 437 ui_menu_entry_t *mgoto = NULL; 395 gfx_rect_t arect;396 gfx_rect_t rect;397 438 398 439 rc = ui_create(UI_CONSOLE_DEFAULT, &edit->ui); … … 430 471 } 431 472 432 rc = ui_menu_create(edit->menubar, "File", &mfile); 473 ui_menu_bar_set_cb(edit->menubar, &edit_menubar_cb, (void *) edit); 474 475 rc = ui_menu_dd_create(edit->menubar, "~F~ile", NULL, &mfile); 433 476 if (rc != EOK) { 434 477 printf("Error creating menu.\n"); … … 436 479 } 437 480 438 rc = ui_menu_entry_create(mfile, " Save", "Ctrl-S", &msave);481 rc = ui_menu_entry_create(mfile, "~N~ew", "Ctrl-N", &mnew); 439 482 if (rc != EOK) { 440 483 printf("Error creating menu.\n"); … … 442 485 } 443 486 444 ui_menu_entry_set_cb(m save, edit_file_save, (void *) edit);445 446 rc = ui_menu_entry_create(mfile, " Save As", "Ctrl-E", &msaveas);487 ui_menu_entry_set_cb(mnew, edit_file_new, (void *) edit); 488 489 rc = ui_menu_entry_create(mfile, "~O~pen", "Ctrl-O", &mopen); 447 490 if (rc != EOK) { 448 491 printf("Error creating menu.\n"); … … 450 493 } 451 494 452 ui_menu_entry_set_cb(m saveas, edit_file_save_as, (void *) edit);453 454 rc = ui_menu_entry_ sep_create(mfile, &mfsep);495 ui_menu_entry_set_cb(mopen, edit_file_open, (void *) edit); 496 497 rc = ui_menu_entry_create(mfile, "~S~ave", "Ctrl-S", &msave); 455 498 if (rc != EOK) { 456 499 printf("Error creating menu.\n"); … … 458 501 } 459 502 460 rc = ui_menu_entry_create(mfile, "Exit", "Ctrl-Q", &mexit); 503 ui_menu_entry_set_cb(msave, edit_file_save, (void *) edit); 504 505 rc = ui_menu_entry_create(mfile, "Save ~A~s", "Ctrl-E", &msaveas); 461 506 if (rc != EOK) { 462 507 printf("Error creating menu.\n"); … … 464 509 } 465 510 466 ui_menu_entry_set_cb(m exit, edit_file_exit, (void *) edit);467 468 rc = ui_menu_ create(edit->menubar, "Edit", &medit);511 ui_menu_entry_set_cb(msaveas, edit_file_save_as, (void *) edit); 512 513 rc = ui_menu_entry_sep_create(mfile, &mfsep); 469 514 if (rc != EOK) { 470 515 printf("Error creating menu.\n"); … … 472 517 } 473 518 474 rc = ui_menu_entry_create(m edit, "Cut", "Ctrl-X", &mcut);519 rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit); 475 520 if (rc != EOK) { 476 521 printf("Error creating menu.\n"); … … 478 523 } 479 524 480 ui_menu_entry_set_cb(m cut, edit_edit_cut, (void *) edit);481 482 rc = ui_menu_ entry_create(medit, "Copy", "Ctrl-C", &mcopy);525 ui_menu_entry_set_cb(mexit, edit_file_exit, (void *) edit); 526 527 rc = ui_menu_dd_create(edit->menubar, "~E~dit", NULL, &medit); 483 528 if (rc != EOK) { 484 529 printf("Error creating menu.\n"); … … 486 531 } 487 532 488 ui_menu_entry_set_cb(mcopy, edit_edit_copy, (void *) edit); 489 490 rc = ui_menu_entry_create(medit, "Paste", "Ctrl-V", &mpaste); 533 rc = ui_menu_entry_create(medit, "Cu~t~", "Ctrl-X", &mcut); 491 534 if (rc != EOK) { 492 535 printf("Error creating menu.\n"); … … 494 537 } 495 538 496 ui_menu_entry_set_cb(m paste, edit_edit_paste, (void *) edit);497 498 rc = ui_menu_entry_create(medit, " Delete", "Del", &mdelete);539 ui_menu_entry_set_cb(mcut, edit_edit_cut, (void *) edit); 540 541 rc = ui_menu_entry_create(medit, "~C~opy", "Ctrl-C", &mcopy); 499 542 if (rc != EOK) { 500 543 printf("Error creating menu.\n"); … … 502 545 } 503 546 504 ui_menu_entry_set_cb(m delete, edit_edit_delete, (void *) edit);505 506 rc = ui_menu_entry_ sep_create(medit, &mesep);547 ui_menu_entry_set_cb(mcopy, edit_edit_copy, (void *) edit); 548 549 rc = ui_menu_entry_create(medit, "~P~aste", "Ctrl-V", &mpaste); 507 550 if (rc != EOK) { 508 551 printf("Error creating menu.\n"); … … 510 553 } 511 554 512 rc = ui_menu_entry_create(medit, "Select All", "Ctrl-A", &mselall); 555 ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit); 556 557 rc = ui_menu_entry_create(medit, "~D~elete", "Del", &mdelete); 513 558 if (rc != EOK) { 514 559 printf("Error creating menu.\n"); … … 516 561 } 517 562 518 ui_menu_entry_set_cb(m selall, edit_edit_select_all, (void *) edit);519 520 rc = ui_menu_ create(edit->menubar, "Search", &msearch);563 ui_menu_entry_set_cb(mdelete, edit_edit_delete, (void *) edit); 564 565 rc = ui_menu_entry_sep_create(medit, &mesep); 521 566 if (rc != EOK) { 522 567 printf("Error creating menu.\n"); … … 524 569 } 525 570 526 rc = ui_menu_entry_create(m search, "Find", "Ctrl-F", &mfind);571 rc = ui_menu_entry_create(medit, "Select ~A~ll", "Ctrl-A", &mselall); 527 572 if (rc != EOK) { 528 573 printf("Error creating menu.\n"); … … 530 575 } 531 576 532 ui_menu_entry_set_cb(m find, edit_search_find, (void *) edit);533 534 rc = ui_menu_ entry_create(msearch, "Reverse Find", "Ctrl-Shift-F", &mfindr);577 ui_menu_entry_set_cb(mselall, edit_edit_select_all, (void *) edit); 578 579 rc = ui_menu_dd_create(edit->menubar, "~S~earch", NULL, &msearch); 535 580 if (rc != EOK) { 536 581 printf("Error creating menu.\n"); … … 538 583 } 539 584 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); 585 rc = ui_menu_entry_create(msearch, "~F~ind", "Ctrl-F", &mfind); 543 586 if (rc != EOK) { 544 587 printf("Error creating menu.\n"); … … 546 589 } 547 590 548 ui_menu_entry_set_cb(mfind n, edit_search_find_next, (void *) edit);549 550 rc = ui_menu_entry_ sep_create(msearch, &mssep);591 ui_menu_entry_set_cb(mfind, edit_search_find, (void *) edit); 592 593 rc = ui_menu_entry_create(msearch, "~R~everse Find", "Ctrl-Shift-F", &mfindr); 551 594 if (rc != EOK) { 552 595 printf("Error creating menu.\n"); … … 554 597 } 555 598 556 rc = ui_menu_entry_create(msearch, "Go To Line", "Ctrl-L", &mgoto); 599 ui_menu_entry_set_cb(mfindr, edit_search_reverse_find, (void *) edit); 600 601 rc = ui_menu_entry_create(msearch, "Find ~N~ext", "Ctrl-R", &mfindn); 557 602 if (rc != EOK) { 558 603 printf("Error creating menu.\n"); … … 560 605 } 561 606 607 ui_menu_entry_set_cb(mfindn, edit_search_find_next, (void *) edit); 608 609 rc = ui_menu_entry_sep_create(msearch, &mssep); 610 if (rc != EOK) { 611 printf("Error creating menu.\n"); 612 return rc; 613 } 614 615 rc = ui_menu_entry_create(msearch, "Go To ~L~ine", "Ctrl-L", &mgoto); 616 if (rc != EOK) { 617 printf("Error creating menu.\n"); 618 return rc; 619 } 620 562 621 ui_menu_entry_set_cb(mgoto, edit_search_go_to_line, (void *) edit); 563 622 564 ui_window_get_app_rect(edit->window, &arect); 565 566 rect.p0 = arect.p0; 567 rect.p1.x = arect.p1.x; 568 rect.p1.y = arect.p0.y + 1; 569 ui_menu_bar_set_rect(edit->menubar, &rect); 623 edit_menubar_set_rect(edit); 570 624 571 625 rc = ui_fixed_add(fixed, ui_menu_bar_ctl(edit->menubar)); … … 593 647 } 594 648 595 rect.p0.x = arect.p0.x; 596 rect.p0.y = arect.p1.y - 1; 597 rect.p1 = arect.p1; 598 ui_label_set_rect(edit->status, &rect); 649 edit_status_set_rect(edit); 599 650 600 651 rc = ui_fixed_add(fixed, ui_label_ctl(edit->status)); … … 726 777 ui_quit(edit.ui); 727 778 break; 779 case KC_N: 780 file_new(); 781 break; 782 case KC_O: 783 file_open(); 784 break; 728 785 case KC_S: 729 786 if (doc.file_name != NULL) … … 759 816 search_prompt(false); 760 817 break; 761 case KC_ N:818 case KC_R: 762 819 search_repeat(); 763 820 break; … … 898 955 } 899 956 900 /** Save the document. */ 901 static errno_t file_save(char const *fname) 902 { 903 spt_t sp, ep; 957 /** Create new document. */ 958 static errno_t file_new(void) 959 { 904 960 errno_t rc; 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) 961 sheet_t *sh; 962 963 /* Create empty sheet. */ 964 rc = sheet_create(&sh); 965 if (rc != EOK) { 966 printf("Out of memory.\n"); 967 return ENOMEM; 968 } 969 970 if (doc.sh != NULL) 971 sheet_destroy(doc.sh); 972 973 doc.sh = sh; 974 975 /* Place caret at the beginning of file. */ 976 spt_t sof; 977 pt_get_sof(&sof); 978 sheet_place_tag(doc.sh, &sof, &pane.caret_pos); 979 pane.ideal_column = 1; 980 981 doc.file_name = NULL; 982 983 /* Place selection start tag. */ 984 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 985 986 /* Move to beginning of file. */ 987 pt_get_sof(&sof); 988 989 caret_move(sof, true, true); 990 991 pane_status_display(&pane); 992 pane_caret_display(&pane); 993 pane_text_display(&pane); 994 cursor_setvis(true); 995 996 return EOK; 997 } 998 999 /** Open Open File dialog. */ 1000 static void file_open(void) 929 1001 { 930 1002 const char *old_fname = (doc.file_name != NULL) ? doc.file_name : ""; … … 934 1006 935 1007 ui_file_dialog_params_init(&fdparams); 1008 fdparams.caption = "Open File"; 1009 fdparams.ifname = old_fname; 1010 1011 rc = ui_file_dialog_create(edit.ui, &fdparams, &dialog); 1012 if (rc != EOK) { 1013 printf("Error creating message dialog.\n"); 1014 return; 1015 } 1016 1017 ui_file_dialog_set_cb(dialog, &open_dialog_cb, &edit); 1018 } 1019 1020 /** Open exising document. */ 1021 static errno_t file_open_file(const char *fname) 1022 { 1023 errno_t rc; 1024 sheet_t *sh; 1025 char *fn; 1026 1027 /* Create empty sheet. */ 1028 rc = sheet_create(&sh); 1029 if (rc != EOK) { 1030 printf("Out of memory.\n"); 1031 return ENOMEM; 1032 } 1033 1034 fn = str_dup(fname); 1035 if (fn == NULL) { 1036 sheet_destroy(sh); 1037 return ENOMEM; 1038 } 1039 1040 if (doc.sh != NULL) 1041 sheet_destroy(doc.sh); 1042 1043 doc.sh = sh; 1044 1045 /* Place caret at the beginning of file. */ 1046 spt_t sof; 1047 pt_get_sof(&sof); 1048 sheet_place_tag(doc.sh, &sof, &pane.caret_pos); 1049 pane.ideal_column = 1; 1050 1051 rc = file_insert(fname); 1052 if (rc != EOK) 1053 return rc; 1054 1055 doc.file_name = fn; 1056 1057 /* Place selection start tag. */ 1058 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 1059 1060 /* Move to beginning of file. */ 1061 pt_get_sof(&sof); 1062 1063 caret_move(sof, true, true); 1064 1065 pane_status_display(&pane); 1066 pane_caret_display(&pane); 1067 pane_text_display(&pane); 1068 cursor_setvis(true); 1069 1070 return EOK; 1071 } 1072 1073 /** Save the document. */ 1074 static errno_t file_save(char const *fname) 1075 { 1076 spt_t sp, ep; 1077 errno_t rc; 1078 1079 status_display("Saving..."); 1080 pt_get_sof(&sp); 1081 pt_get_eof(&ep); 1082 1083 rc = file_save_range(fname, &sp, &ep); 1084 1085 switch (rc) { 1086 case EINVAL: 1087 status_display("Error opening file!"); 1088 break; 1089 case EIO: 1090 status_display("Error writing data!"); 1091 break; 1092 default: 1093 status_display("File saved."); 1094 break; 1095 } 1096 1097 return rc; 1098 } 1099 1100 /** Open Save As dialog. */ 1101 static void file_save_as(void) 1102 { 1103 const char *old_fname = (doc.file_name != NULL) ? doc.file_name : ""; 1104 ui_file_dialog_params_t fdparams; 1105 ui_file_dialog_t *dialog; 1106 errno_t rc; 1107 1108 ui_file_dialog_params_init(&fdparams); 936 1109 fdparams.caption = "Save As"; 937 1110 fdparams.ifname = old_fname; … … 951 1124 * of the caret. 952 1125 */ 953 static errno_t file_insert(c har *fname)1126 static errno_t file_insert(const char *fname) 954 1127 { 955 1128 FILE *f; … … 978 1151 979 1152 bcnt -= off; 980 mem cpy(buf, buf + off, bcnt);1153 memmove(buf, buf + off, bcnt); 981 1154 982 1155 insert_char(c); … … 1060 1233 } 1061 1234 1062 /** Initialize pane. 1063 * 1064 * TODO: Replace with pane_create() that allocates the pane. 1065 * 1066 * @param window Editor window 1067 * @param pane Pane 1068 * @return EOK on success or an error code 1069 */ 1070 static errno_t pane_init(ui_window_t *window, pane_t *pane) 1071 { 1072 errno_t rc; 1235 static void pane_set_rect(pane_t *pane) 1236 { 1073 1237 gfx_rect_t arect; 1074 1238 1075 pane->control = NULL; 1076 pane->color = NULL; 1077 pane->sel_color = NULL; 1078 1079 rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control); 1080 if (rc != EOK) 1081 goto error; 1082 1083 rc = gfx_color_new_ega(0x07, &pane->color); 1084 if (rc != EOK) 1085 goto error; 1086 1087 rc = gfx_color_new_ega(0x1e, &pane->sel_color); 1088 if (rc != EOK) 1089 goto error; 1090 1091 pane->res = ui_window_get_res(window); 1092 pane->window = window; 1093 1094 ui_window_get_app_rect(window, &arect); 1239 ui_window_get_app_rect(pane->window, &arect); 1095 1240 pane->rect.p0.x = arect.p0.x; 1096 1241 pane->rect.p0.y = arect.p0.y + 1; … … 1100 1245 pane->columns = pane->rect.p1.x - pane->rect.p0.x; 1101 1246 pane->rows = pane->rect.p1.y - pane->rect.p0.y; 1102 1247 } 1248 1249 /** Initialize pane. 1250 * 1251 * TODO: Replace with pane_create() that allocates the pane. 1252 * 1253 * @param window Editor window 1254 * @param pane Pane 1255 * @return EOK on success or an error code 1256 */ 1257 static errno_t pane_init(ui_window_t *window, pane_t *pane) 1258 { 1259 errno_t rc; 1260 1261 pane->control = NULL; 1262 pane->color = NULL; 1263 pane->sel_color = NULL; 1264 1265 rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control); 1266 if (rc != EOK) 1267 goto error; 1268 1269 rc = gfx_color_new_ega(0x07, &pane->color); 1270 if (rc != EOK) 1271 goto error; 1272 1273 rc = gfx_color_new_ega(0x1e, &pane->sel_color); 1274 if (rc != EOK) 1275 goto error; 1276 1277 pane->res = ui_window_get_res(window); 1278 pane->window = window; 1279 1280 pane_set_rect(pane); 1103 1281 return EOK; 1104 1282 error: … … 1114 1292 1115 1293 return rc; 1294 } 1295 1296 static void pane_resize(pane_t *pane) 1297 { 1298 pane_set_rect(pane); 1299 1300 /* Scroll in case cursor is now outside of the editor pane. */ 1301 caret_move_relative(0, 0, dir_before, true); 1302 1303 pane_caret_display(pane); 1116 1304 } 1117 1305 … … 1259 1447 1260 1448 gfx_text_fmt_init(&fmt); 1449 fmt.font = font; 1261 1450 fmt.color = pane->color; 1262 1451 … … 1318 1507 return rc; 1319 1508 1320 rc = gfx_puttext( font,&tpos, &fmt, cbuf);1509 rc = gfx_puttext(&tpos, &fmt, cbuf); 1321 1510 if (rc != EOK) 1322 1511 return rc; … … 1408 1597 */ 1409 1598 while (true) { 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);1599 int rc = asprintf(&text, "%d, %d (%d): File '%s'. Ctrl-Q Quit " 1600 "F10 Menu", coord.row, coord.column, last_row, fname); 1412 1601 if (rc < 0) { 1413 1602 n = 0; … … 2207 2396 } 2208 2397 2209 /** Window close request2398 /** Window was resized. 2210 2399 * 2211 2400 * @param window Window 2212 2401 * @param arg Argument (edit_t *) 2213 2402 */ 2403 static void edit_wnd_resize(ui_window_t *window, void *arg) 2404 { 2405 edit_t *edit = (edit_t *) arg; 2406 2407 edit_menubar_set_rect(edit); 2408 edit_status_set_rect(edit); 2409 pane_resize(&pane); 2410 } 2411 2412 /** Window close request 2413 * 2414 * @param window Window 2415 * @param arg Argument (edit_t *) 2416 */ 2214 2417 static void edit_wnd_close(ui_window_t *window, void *arg) 2215 2418 { … … 2217 2420 2218 2421 ui_quit(edit->ui); 2422 } 2423 2424 /** Window focus event 2425 * 2426 * @param window Window 2427 * @param arg Argument (edit_t *) 2428 * @param focus Focus number 2429 */ 2430 static void edit_wnd_focus(ui_window_t *window, void *arg, unsigned focus) 2431 { 2432 edit_t *edit = (edit_t *)arg; 2433 2434 (void)edit; 2435 pane_caret_display(&pane); 2436 cursor_setvis(true); 2219 2437 } 2220 2438 … … 2229 2447 { 2230 2448 pane.keymod = event->mods; 2449 2450 if (ui_window_def_kbd(window, event) == ui_claimed) 2451 return; 2231 2452 2232 2453 if (event->type == KEY_PRESS) { … … 2237 2458 } 2238 2459 2460 /** Window unfocus event 2461 * 2462 * @param window Window 2463 * @param arg Argument (edit_t *) 2464 * @param focus Focus number 2465 */ 2466 static void edit_wnd_unfocus(ui_window_t *window, void *arg, unsigned focus) 2467 { 2468 edit_t *edit = (edit_t *) arg; 2469 2470 (void)edit; 2471 cursor_setvis(false); 2472 } 2473 2474 /** Menu bar activate event 2475 * 2476 * @param mbar Menu bar 2477 * @param arg Argument (edit_t *) 2478 */ 2479 static void edit_menubar_activate(ui_menu_bar_t *mbar, void *arg) 2480 { 2481 edit_t *edit = (edit_t *)arg; 2482 2483 (void)edit; 2484 cursor_setvis(false); 2485 } 2486 2487 /** Menu bar deactivate event 2488 * 2489 * @param mbar Menu bar 2490 * @param arg Argument (edit_t *) 2491 */ 2492 static void edit_menubar_deactivate(ui_menu_bar_t *mbar, void *arg) 2493 { 2494 edit_t *edit = (edit_t *)arg; 2495 2496 (void)edit; 2497 pane_caret_display(&pane); 2498 cursor_setvis(true); 2499 } 2500 2501 /** File / New menu entry selected. 2502 * 2503 * @param mentry Menu entry 2504 * @param arg Argument (edit_t *) 2505 */ 2506 static void edit_file_new(ui_menu_entry_t *mentry, void *arg) 2507 { 2508 edit_t *edit = (edit_t *) arg; 2509 2510 (void)edit; 2511 file_new(); 2512 (void) gfx_update(ui_window_get_gc(edit->window)); 2513 } 2514 2515 /** File / Open menu entry selected. 2516 * 2517 * @param mentry Menu entry 2518 * @param arg Argument (edit_t *) 2519 */ 2520 static void edit_file_open(ui_menu_entry_t *mentry, void *arg) 2521 { 2522 edit_t *edit = (edit_t *) arg; 2523 2524 (void)edit; 2525 file_open(); 2526 } 2527 2239 2528 /** File / Save menu entry selected. 2240 2529 * … … 2392 2681 } 2393 2682 2394 /** Save Asdialog OK button press.2395 * 2396 * @param dialog Save Asdialog2683 /** Open File dialog OK button press. 2684 * 2685 * @param dialog Open File dialog 2397 2686 * @param arg Argument (ui_demo_t *) 2398 2687 * @param fname File name 2399 2688 */ 2400 static void save_as_dialog_bok(ui_file_dialog_t *dialog, void *arg,2689 static void open_dialog_bok(ui_file_dialog_t *dialog, void *arg, 2401 2690 const char *fname) 2402 2691 { 2403 2692 edit_t *edit = (edit_t *)arg; 2404 gfx_context_t *gc = ui_window_get_gc(edit->window);2405 2693 char *cname; 2406 2694 errno_t rc; 2407 2695 2696 (void)edit; 2408 2697 ui_file_dialog_destroy(dialog); 2409 // TODO Smarter cursor management2410 pane.rflags |= REDRAW_CARET;2411 (void) pane_update(&pane);2412 gfx_cursor_set_visible(gc, true);2413 2698 2414 2699 cname = str_dup(fname); … … 2418 2703 } 2419 2704 2705 rc = file_open_file(fname); 2706 if (rc != EOK) 2707 return; 2708 2709 if (doc.file_name != NULL) 2710 free(doc.file_name); 2711 doc.file_name = cname; 2712 2713 (void) gfx_update(ui_window_get_gc(edit->window)); 2714 } 2715 2716 /** Open File dialog cancel button press. 2717 * 2718 * @param dialog File dialog 2719 * @param arg Argument (ui_demo_t *) 2720 */ 2721 static void open_dialog_bcancel(ui_file_dialog_t *dialog, void *arg) 2722 { 2723 edit_t *edit = (edit_t *)arg; 2724 2725 (void)edit; 2726 ui_file_dialog_destroy(dialog); 2727 } 2728 2729 /** Open File dialog close request. 2730 * 2731 * @param dialog File dialog 2732 * @param arg Argument (ui_demo_t *) 2733 */ 2734 static void open_dialog_close(ui_file_dialog_t *dialog, void *arg) 2735 { 2736 edit_t *edit = (edit_t *)arg; 2737 2738 (void)edit; 2739 ui_file_dialog_destroy(dialog); 2740 } 2741 2742 /** Save As dialog OK button press. 2743 * 2744 * @param dialog Save As dialog 2745 * @param arg Argument (ui_demo_t *) 2746 * @param fname File name 2747 */ 2748 static void save_as_dialog_bok(ui_file_dialog_t *dialog, void *arg, 2749 const char *fname) 2750 { 2751 edit_t *edit = (edit_t *)arg; 2752 char *cname; 2753 errno_t rc; 2754 2755 (void)edit; 2756 ui_file_dialog_destroy(dialog); 2757 2758 cname = str_dup(fname); 2759 if (cname == NULL) { 2760 printf("Out of memory.\n"); 2761 return; 2762 } 2763 2420 2764 rc = file_save(fname); 2421 2765 if (rc != EOK) … … 2436 2780 { 2437 2781 edit_t *edit = (edit_t *)arg; 2438 gfx_context_t *gc = ui_window_get_gc(edit->window); 2439 2782 2783 (void)edit; 2440 2784 ui_file_dialog_destroy(dialog); 2441 // TODO Smarter cursor management2442 pane.rflags |= REDRAW_CARET;2443 (void) pane_update(&pane);2444 gfx_cursor_set_visible(gc, true);2445 2785 } 2446 2786 … … 2453 2793 { 2454 2794 edit_t *edit = (edit_t *)arg; 2455 gfx_context_t *gc = ui_window_get_gc(edit->window); 2456 2795 2796 (void)edit; 2457 2797 ui_file_dialog_destroy(dialog); 2458 // TODO Smarter cursor management2459 pane.rflags |= REDRAW_CARET;2460 (void) pane_update(&pane);2461 gfx_cursor_set_visible(gc, true);2462 2798 } 2463 2799 … … 2472 2808 { 2473 2809 edit_t *edit = (edit_t *) arg; 2474 gfx_context_t *gc = ui_window_get_gc(edit->window);2475 2810 char *endptr; 2476 2811 int line; … … 2484 2819 2485 2820 caret_move_absolute(line, pane.ideal_column, dir_before, false); 2486 // TODO Smarter cursor management2821 (void)edit; 2487 2822 (void) pane_update(&pane); 2488 gfx_cursor_set_visible(gc, true);2489 (void) gfx_update(gc);2490 2823 } 2491 2824 … … 2498 2831 { 2499 2832 edit_t *edit = (edit_t *) arg; 2500 gfx_context_t *gc = ui_window_get_gc(edit->window); 2501 2833 2834 (void)edit; 2502 2835 ui_prompt_dialog_destroy(dialog); 2503 // TODO Smarter cursor management2504 pane.rflags |= REDRAW_CARET;2505 (void) pane_update(&pane);2506 gfx_cursor_set_visible(gc, true);2507 2836 } 2508 2837 … … 2515 2844 { 2516 2845 edit_t *edit = (edit_t *) arg; 2517 gfx_context_t *gc = ui_window_get_gc(edit->window); 2518 2846 2847 (void)edit; 2519 2848 ui_prompt_dialog_destroy(dialog); 2520 // TODO Smarter cursor management2521 pane.rflags |= REDRAW_CARET;2522 (void) pane_update(&pane);2523 gfx_cursor_set_visible(gc, true);2524 2849 } 2525 2850 … … 2534 2859 { 2535 2860 edit_t *edit = (edit_t *) arg; 2536 gfx_context_t *gc = ui_window_get_gc(edit->window);2537 2861 char *pattern; 2538 2862 bool reverse; 2539 2863 2864 (void)edit; 2540 2865 ui_prompt_dialog_destroy(dialog); 2541 2866 … … 2554 2879 search(pattern, reverse); 2555 2880 2556 // TODO Smarter cursor management2557 2881 (void) pane_update(&pane); 2558 gfx_cursor_set_visible(gc, true);2559 (void) gfx_update(gc);2560 2882 } 2561 2883 … … 2568 2890 { 2569 2891 edit_t *edit = (edit_t *) arg; 2570 gfx_context_t *gc = ui_window_get_gc(edit->window); 2571 2892 2893 (void)edit; 2572 2894 ui_prompt_dialog_destroy(dialog); 2573 // TODO Smarter cursor management2574 pane.rflags |= REDRAW_CARET;2575 (void) pane_update(&pane);2576 gfx_cursor_set_visible(gc, true);2577 2895 } 2578 2896 … … 2585 2903 { 2586 2904 edit_t *edit = (edit_t *) arg; 2587 gfx_context_t *gc = ui_window_get_gc(edit->window); 2588 2905 2906 (void)edit; 2589 2907 ui_prompt_dialog_destroy(dialog); 2590 // TODO Smarter cursor management2591 pane.rflags |= REDRAW_CARET;2592 (void) pane_update(&pane);2593 gfx_cursor_set_visible(gc, true);2594 2908 } 2595 2909
Note:
See TracChangeset
for help on using the changeset viewer.
