Changes in uspace/app/edit/edit.c [3c22438a:e0cf963] in mainline
- File:
-
- 1 edited
-
uspace/app/edit/edit.c (modified) (57 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r3c22438a re0cf963 1 1 /* 2 * Copyright (c) 202 6Jiri 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); … … 240 236 static void edit_ui_destroy(edit_t *); 241 237 242 static void edit_wnd_resize(ui_window_t *, void *);243 238 static void edit_wnd_close(ui_window_t *, void *); 244 static void edit_wnd_focus(ui_window_t *, void *, unsigned);245 239 static void edit_wnd_kbd_event(ui_window_t *, void *, kbd_event_t *); 246 static void edit_wnd_unfocus(ui_window_t *, void *, unsigned);247 240 248 241 static ui_window_cb_t edit_window_cb = { 249 .resize = edit_wnd_resize,250 242 .close = edit_wnd_close, 251 .focus = edit_wnd_focus, 252 .kbd = edit_wnd_kbd_event, 253 .unfocus = edit_wnd_unfocus 243 .kbd = edit_wnd_kbd_event 254 244 }; 255 245 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_deactivate262 };263 264 static void edit_file_new(ui_menu_entry_t *, void *);265 static void edit_file_open(ui_menu_entry_t *, void *);266 246 static void edit_file_save(ui_menu_entry_t *, void *); 267 247 static void edit_file_save_as(ui_menu_entry_t *, void *); … … 288 268 }; 289 269 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_close298 };299 300 270 static void save_as_dialog_bok(ui_file_dialog_t *, void *, const char *); 301 271 static void save_as_dialog_bcancel(ui_file_dialog_t *, void *); … … 330 300 int main(int argc, char *argv[]) 331 301 { 302 bool new_file; 332 303 errno_t rc; 333 304 334 305 pane.sh_row = 1; 335 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); 336 340 337 341 /* Create UI */ … … 340 344 return 1; 341 345 342 if (argc == 2) { 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 } 349 } else if (argc > 1) { 350 printf("Invalid arguments.\n"); 351 return -2; 352 } else { 353 rc = file_new(); 354 } 346 caret_move(sof, true, true); 355 347 356 348 /* Initial display */ … … 361 353 } 362 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 363 361 ui_run(edit.ui); 364 362 365 363 edit_ui_destroy(&edit); 366 364 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 Editor375 */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 Editor395 */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);406 365 } 407 366 … … 418 377 ui_menu_t *mfile = NULL; 419 378 ui_menu_t *medit = NULL; 420 ui_menu_entry_t *mnew = NULL;421 ui_menu_entry_t *mopen = NULL;422 379 ui_menu_entry_t *msave = NULL; 423 380 ui_menu_entry_t *msaveas = NULL; … … 436 393 ui_menu_entry_t *mssep = NULL; 437 394 ui_menu_entry_t *mgoto = NULL; 395 gfx_rect_t arect; 396 gfx_rect_t rect; 438 397 439 398 rc = ui_create(UI_CONSOLE_DEFAULT, &edit->ui); … … 471 430 } 472 431 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); 432 rc = ui_menu_create(edit->menubar, "File", &mfile); 476 433 if (rc != EOK) { 477 434 printf("Error creating menu.\n"); … … 479 436 } 480 437 481 rc = ui_menu_entry_create(mfile, " ~N~ew", "Ctrl-N", &mnew);438 rc = ui_menu_entry_create(mfile, "Save", "Ctrl-S", &msave); 482 439 if (rc != EOK) { 483 440 printf("Error creating menu.\n"); … … 485 442 } 486 443 487 ui_menu_entry_set_cb(m new, edit_file_new, (void *) edit);488 489 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); 490 447 if (rc != EOK) { 491 448 printf("Error creating menu.\n"); … … 493 450 } 494 451 495 ui_menu_entry_set_cb(m open, edit_file_open, (void *) edit);496 497 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); 498 455 if (rc != EOK) { 499 456 printf("Error creating menu.\n"); … … 501 458 } 502 459 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); 460 rc = ui_menu_entry_create(mfile, "Exit", "Ctrl-Q", &mexit); 506 461 if (rc != EOK) { 507 462 printf("Error creating menu.\n"); … … 509 464 } 510 465 511 ui_menu_entry_set_cb(m saveas, edit_file_save_as, (void *) edit);512 513 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); 514 469 if (rc != EOK) { 515 470 printf("Error creating menu.\n"); … … 517 472 } 518 473 519 rc = ui_menu_entry_create(m file, "E~x~it", "Ctrl-Q", &mexit);474 rc = ui_menu_entry_create(medit, "Cut", "Ctrl-X", &mcut); 520 475 if (rc != EOK) { 521 476 printf("Error creating menu.\n"); … … 523 478 } 524 479 525 ui_menu_entry_set_cb(m exit, edit_file_exit, (void *) edit);526 527 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); 528 483 if (rc != EOK) { 529 484 printf("Error creating menu.\n"); … … 531 486 } 532 487 533 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); 534 491 if (rc != EOK) { 535 492 printf("Error creating menu.\n"); … … 537 494 } 538 495 539 ui_menu_entry_set_cb(m cut, edit_edit_cut, (void *) edit);540 541 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); 542 499 if (rc != EOK) { 543 500 printf("Error creating menu.\n"); … … 545 502 } 546 503 547 ui_menu_entry_set_cb(m copy, edit_edit_copy, (void *) edit);548 549 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); 550 507 if (rc != EOK) { 551 508 printf("Error creating menu.\n"); … … 553 510 } 554 511 555 ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit); 556 557 rc = ui_menu_entry_create(medit, "~D~elete", "Del", &mdelete); 512 rc = ui_menu_entry_create(medit, "Select All", "Ctrl-A", &mselall); 558 513 if (rc != EOK) { 559 514 printf("Error creating menu.\n"); … … 561 516 } 562 517 563 ui_menu_entry_set_cb(m delete, edit_edit_delete, (void *) edit);564 565 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); 566 521 if (rc != EOK) { 567 522 printf("Error creating menu.\n"); … … 569 524 } 570 525 571 rc = ui_menu_entry_create(m edit, "Select ~A~ll", "Ctrl-A", &mselall);526 rc = ui_menu_entry_create(msearch, "Find", "Ctrl-F", &mfind); 572 527 if (rc != EOK) { 573 528 printf("Error creating menu.\n"); … … 575 530 } 576 531 577 ui_menu_entry_set_cb(m selall, edit_edit_select_all, (void *) edit);578 579 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); 580 535 if (rc != EOK) { 581 536 printf("Error creating menu.\n"); … … 583 538 } 584 539 585 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); 586 543 if (rc != EOK) { 587 544 printf("Error creating menu.\n"); … … 589 546 } 590 547 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);548 ui_menu_entry_set_cb(mfindn, edit_search_find_next, (void *) edit); 549 550 rc = ui_menu_entry_sep_create(msearch, &mssep); 594 551 if (rc != EOK) { 595 552 printf("Error creating menu.\n"); … … 597 554 } 598 555 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); 556 rc = ui_menu_entry_create(msearch, "Go To Line", "Ctrl-L", &mgoto); 602 557 if (rc != EOK) { 603 558 printf("Error creating menu.\n"); … … 605 560 } 606 561 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 621 562 ui_menu_entry_set_cb(mgoto, edit_search_go_to_line, (void *) edit); 622 563 623 edit_menubar_set_rect(edit); 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); 624 570 625 571 rc = ui_fixed_add(fixed, ui_menu_bar_ctl(edit->menubar)); … … 647 593 } 648 594 649 edit_status_set_rect(edit); 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); 650 599 651 600 rc = ui_fixed_add(fixed, ui_label_ctl(edit->status)); … … 777 726 ui_quit(edit.ui); 778 727 break; 779 case KC_N:780 file_new();781 break;782 case KC_O:783 file_open();784 break;785 728 case KC_S: 786 729 if (doc.file_name != NULL) … … 816 759 search_prompt(false); 817 760 break; 818 case KC_ R:761 case KC_N: 819 762 search_repeat(); 820 763 break; … … 955 898 } 956 899 957 /** Create new document. */ 958 static errno_t file_new(void) 959 { 900 /** Save the document. */ 901 static errno_t file_save(char const *fname) 902 { 903 spt_t sp, ep; 960 904 errno_t rc; 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) 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) 1001 929 { 1002 930 const char *old_fname = (doc.file_name != NULL) ? doc.file_name : ""; … … 1006 934 1007 935 ui_file_dialog_params_init(&fdparams); 1008 fdparams.caption = " Open File";936 fdparams.caption = "Save As"; 1009 937 fdparams.ifname = old_fname; 1010 938 … … 1015 943 } 1016 944 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);1109 fdparams.caption = "Save As";1110 fdparams.ifname = old_fname;1111 1112 rc = ui_file_dialog_create(edit.ui, &fdparams, &dialog);1113 if (rc != EOK) {1114 printf("Error creating message dialog.\n");1115 return;1116 }1117 1118 945 ui_file_dialog_set_cb(dialog, &save_as_dialog_cb, &edit); 1119 946 } … … 1124 951 * of the caret. 1125 952 */ 1126 static errno_t file_insert(c onst char *fname)953 static errno_t file_insert(char *fname) 1127 954 { 1128 955 FILE *f; … … 1151 978 1152 979 bcnt -= off; 1153 mem move(buf, buf + off, bcnt);980 memcpy(buf, buf + off, bcnt); 1154 981 1155 982 insert_char(c); … … 1233 1060 } 1234 1061 1235 static void pane_set_rect(pane_t *pane) 1236 { 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; 1237 1073 gfx_rect_t arect; 1238 1074 1239 ui_window_get_app_rect(pane->window, &arect); 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); 1240 1095 pane->rect.p0.x = arect.p0.x; 1241 1096 pane->rect.p0.y = arect.p0.y + 1; … … 1245 1100 pane->columns = pane->rect.p1.x - pane->rect.p0.x; 1246 1101 pane->rows = pane->rect.p1.y - pane->rect.p0.y; 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); 1102 1281 1103 return EOK; 1282 1104 error: … … 1292 1114 1293 1115 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);1304 1116 } 1305 1117 … … 1447 1259 1448 1260 gfx_text_fmt_init(&fmt); 1449 fmt.font = font;1450 1261 fmt.color = pane->color; 1451 1262 … … 1507 1318 return rc; 1508 1319 1509 rc = gfx_puttext( &tpos, &fmt, cbuf);1320 rc = gfx_puttext(font, &tpos, &fmt, cbuf); 1510 1321 if (rc != EOK) 1511 1322 return rc; … … 1597 1408 */ 1598 1409 while (true) { 1599 int rc = asprintf(&text, "%d, %d (%d): File '%s'. Ctrl-Q Quit "1600 " 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); 1601 1412 if (rc < 0) { 1602 1413 n = 0; … … 2396 2207 } 2397 2208 2398 /** Window was resized.2209 /** Window close request 2399 2210 * 2400 2211 * @param window Window 2401 2212 * @param arg Argument (edit_t *) 2402 2213 */ 2403 static void edit_wnd_ resize(ui_window_t *window, void *arg)2214 static void edit_wnd_close(ui_window_t *window, void *arg) 2404 2215 { 2405 2216 edit_t *edit = (edit_t *) arg; 2406 2217 2407 edit_menubar_set_rect(edit);2408 edit_status_set_rect(edit);2409 pane_resize(&pane);2410 }2411 2412 /** Window close request2413 *2414 * @param window Window2415 * @param arg Argument (edit_t *)2416 */2417 static void edit_wnd_close(ui_window_t *window, void *arg)2418 {2419 edit_t *edit = (edit_t *) arg;2420 2421 2218 ui_quit(edit->ui); 2422 }2423 2424 /** Window focus event2425 *2426 * @param window Window2427 * @param arg Argument (edit_t *)2428 * @param focus Focus number2429 */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);2437 2219 } 2438 2220 … … 2447 2229 { 2448 2230 pane.keymod = event->mods; 2449 2450 if (ui_window_def_kbd(window, event) == ui_claimed)2451 return;2452 2231 2453 2232 if (event->type == KEY_PRESS) { … … 2458 2237 } 2459 2238 2460 /** Window unfocus event2461 *2462 * @param window Window2463 * @param arg Argument (edit_t *)2464 * @param focus Focus number2465 */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 event2475 *2476 * @param mbar Menu bar2477 * @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 event2488 *2489 * @param mbar Menu bar2490 * @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 entry2504 * @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 entry2518 * @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 2528 2239 /** File / Save menu entry selected. 2529 2240 * … … 2681 2392 } 2682 2393 2683 /** Open Filedialog OK button press.2684 * 2685 * @param dialog Open Filedialog2394 /** Save As dialog OK button press. 2395 * 2396 * @param dialog Save As dialog 2686 2397 * @param arg Argument (ui_demo_t *) 2687 2398 * @param fname File name 2688 2399 */ 2689 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, 2690 2401 const char *fname) 2691 2402 { 2692 2403 edit_t *edit = (edit_t *)arg; 2404 gfx_context_t *gc = ui_window_get_gc(edit->window); 2693 2405 char *cname; 2694 2406 errno_t rc; 2695 2407 2696 (void)edit;2697 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); 2698 2413 2699 2414 cname = str_dup(fname); … … 2703 2418 } 2704 2419 2705 rc = file_ open_file(fname);2420 rc = file_save(fname); 2706 2421 if (rc != EOK) 2707 2422 return; … … 2711 2426 doc.file_name = cname; 2712 2427 2713 (void) gfx_update(ui_window_get_gc(edit->window)); 2714 } 2715 2716 /** Open File dialog cancel button press. 2428 } 2429 2430 /** Save As dialog cancel button press. 2717 2431 * 2718 2432 * @param dialog File dialog 2719 2433 * @param arg Argument (ui_demo_t *) 2720 2434 */ 2721 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) 2722 2436 { 2723 2437 edit_t *edit = (edit_t *)arg; 2724 2725 (void)edit; 2438 gfx_context_t *gc = ui_window_get_gc(edit->window); 2439 2726 2440 ui_file_dialog_destroy(dialog); 2727 } 2728 2729 /** 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. 2730 2448 * 2731 2449 * @param dialog File dialog 2732 2450 * @param arg Argument (ui_demo_t *) 2733 2451 */ 2734 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) 2735 2453 { 2736 2454 edit_t *edit = (edit_t *)arg; 2737 2738 (void)edit; 2455 gfx_context_t *gc = ui_window_get_gc(edit->window); 2456 2739 2457 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 2764 rc = file_save(fname); 2765 if (rc != EOK) 2766 return; 2767 2768 if (doc.file_name != NULL) 2769 free(doc.file_name); 2770 doc.file_name = cname; 2771 2772 } 2773 2774 /** Save As dialog cancel button press. 2775 * 2776 * @param dialog File dialog 2777 * @param arg Argument (ui_demo_t *) 2778 */ 2779 static void save_as_dialog_bcancel(ui_file_dialog_t *dialog, void *arg) 2780 { 2781 edit_t *edit = (edit_t *)arg; 2782 2783 (void)edit; 2784 ui_file_dialog_destroy(dialog); 2785 } 2786 2787 /** Save As dialog close request. 2788 * 2789 * @param dialog File dialog 2790 * @param arg Argument (ui_demo_t *) 2791 */ 2792 static void save_as_dialog_close(ui_file_dialog_t *dialog, void *arg) 2793 { 2794 edit_t *edit = (edit_t *)arg; 2795 2796 (void)edit; 2797 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); 2798 2462 } 2799 2463 … … 2808 2472 { 2809 2473 edit_t *edit = (edit_t *) arg; 2474 gfx_context_t *gc = ui_window_get_gc(edit->window); 2810 2475 char *endptr; 2811 2476 int line; … … 2819 2484 2820 2485 caret_move_absolute(line, pane.ideal_column, dir_before, false); 2821 (void)edit;2486 // TODO Smarter cursor management 2822 2487 (void) pane_update(&pane); 2488 gfx_cursor_set_visible(gc, true); 2489 (void) gfx_update(gc); 2823 2490 } 2824 2491 … … 2831 2498 { 2832 2499 edit_t *edit = (edit_t *) arg; 2833 2834 (void)edit; 2500 gfx_context_t *gc = ui_window_get_gc(edit->window); 2501 2835 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); 2836 2507 } 2837 2508 … … 2844 2515 { 2845 2516 edit_t *edit = (edit_t *) arg; 2846 2847 (void)edit; 2517 gfx_context_t *gc = ui_window_get_gc(edit->window); 2518 2848 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); 2849 2524 } 2850 2525 … … 2859 2534 { 2860 2535 edit_t *edit = (edit_t *) arg; 2536 gfx_context_t *gc = ui_window_get_gc(edit->window); 2861 2537 char *pattern; 2862 2538 bool reverse; 2863 2539 2864 (void)edit;2865 2540 ui_prompt_dialog_destroy(dialog); 2866 2541 … … 2879 2554 search(pattern, reverse); 2880 2555 2556 // TODO Smarter cursor management 2881 2557 (void) pane_update(&pane); 2558 gfx_cursor_set_visible(gc, true); 2559 (void) gfx_update(gc); 2882 2560 } 2883 2561 … … 2890 2568 { 2891 2569 edit_t *edit = (edit_t *) arg; 2892 2893 (void)edit; 2570 gfx_context_t *gc = ui_window_get_gc(edit->window); 2571 2894 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); 2895 2577 } 2896 2578 … … 2903 2585 { 2904 2586 edit_t *edit = (edit_t *) arg; 2905 2906 (void)edit; 2587 gfx_context_t *gc = ui_window_get_gc(edit->window); 2588 2907 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); 2908 2594 } 2909 2595
Note:
See TracChangeset
for help on using the changeset viewer.
