Changes in uspace/app/edit/edit.c [3c22438a:ec50d65e] in mainline
- File:
-
- 1 edited
-
uspace/app/edit/edit.c (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r3c22438a rec50d65e 1 1 /* 2 * Copyright (c) 202 6Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * Copyright (c) 2012 Martin Sucha 4 4 * All rights reserved. … … 177 177 static void pos_handle(pos_event_t *ev); 178 178 179 static errno_t file_new(void);180 static void file_open(void);181 static errno_t file_open_file(const char *fname);182 179 static errno_t file_save(char const *fname); 183 180 static void file_save_as(void); 184 static errno_t file_insert(c onst char *fname);181 static errno_t file_insert(char *fname); 185 182 static errno_t file_save_range(char const *fname, spt_t const *spos, 186 183 spt_t const *epos); … … 240 237 static void edit_ui_destroy(edit_t *); 241 238 242 static void edit_wnd_resize(ui_window_t *, void *);243 239 static void edit_wnd_close(ui_window_t *, void *); 244 240 static void edit_wnd_focus(ui_window_t *, void *, unsigned); … … 247 243 248 244 static ui_window_cb_t edit_window_cb = { 249 .resize = edit_wnd_resize,250 245 .close = edit_wnd_close, 251 246 .focus = edit_wnd_focus, … … 262 257 }; 263 258 264 static void edit_file_new(ui_menu_entry_t *, void *);265 static void edit_file_open(ui_menu_entry_t *, void *);266 259 static void edit_file_save(ui_menu_entry_t *, void *); 267 260 static void edit_file_save_as(ui_menu_entry_t *, void *); … … 288 281 }; 289 282 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 283 static void save_as_dialog_bok(ui_file_dialog_t *, void *, const char *); 301 284 static void save_as_dialog_bcancel(ui_file_dialog_t *, void *); … … 330 313 int main(int argc, char *argv[]) 331 314 { 315 bool new_file; 332 316 errno_t rc; 333 317 334 318 pane.sh_row = 1; 335 319 pane.sh_column = 1; 320 321 /* Start with an empty sheet. */ 322 rc = sheet_create(&doc.sh); 323 if (rc != EOK) { 324 printf("Out of memory.\n"); 325 return -1; 326 } 327 328 /* Place caret at the beginning of file. */ 329 spt_t sof; 330 pt_get_sof(&sof); 331 sheet_place_tag(doc.sh, &sof, &pane.caret_pos); 332 pane.ideal_column = 1; 333 334 if (argc == 2) { 335 doc.file_name = str_dup(argv[1]); 336 } else if (argc > 1) { 337 printf("Invalid arguments.\n"); 338 return -2; 339 } else { 340 doc.file_name = NULL; 341 } 342 343 new_file = false; 344 345 if (doc.file_name == NULL || file_insert(doc.file_name) != EOK) 346 new_file = true; 347 348 /* Place selection start tag. */ 349 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 350 351 /* Move to beginning of file. */ 352 pt_get_sof(&sof); 336 353 337 354 /* Create UI */ … … 340 357 return 1; 341 358 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 } 359 caret_move(sof, true, true); 355 360 356 361 /* Initial display */ … … 361 366 } 362 367 368 pane_status_display(&pane); 369 if (new_file && doc.file_name != NULL) 370 status_display("File not found. Starting empty file."); 371 pane_caret_display(&pane); 372 cursor_setvis(true); 373 363 374 ui_run(edit.ui); 364 375 365 376 edit_ui_destroy(&edit); 366 377 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 378 } 407 379 … … 418 390 ui_menu_t *mfile = NULL; 419 391 ui_menu_t *medit = NULL; 420 ui_menu_entry_t *mnew = NULL;421 ui_menu_entry_t *mopen = NULL;422 392 ui_menu_entry_t *msave = NULL; 423 393 ui_menu_entry_t *msaveas = NULL; … … 436 406 ui_menu_entry_t *mssep = NULL; 437 407 ui_menu_entry_t *mgoto = NULL; 408 gfx_rect_t arect; 409 gfx_rect_t rect; 438 410 439 411 rc = ui_create(UI_CONSOLE_DEFAULT, &edit->ui); … … 479 451 } 480 452 481 rc = ui_menu_entry_create(mfile, "~ N~ew", "Ctrl-N", &mnew);453 rc = ui_menu_entry_create(mfile, "~S~ave", "Ctrl-S", &msave); 482 454 if (rc != EOK) { 483 455 printf("Error creating menu.\n"); … … 485 457 } 486 458 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);459 ui_menu_entry_set_cb(msave, edit_file_save, (void *) edit); 460 461 rc = ui_menu_entry_create(mfile, "Save ~A~s", "Ctrl-E", &msaveas); 490 462 if (rc != EOK) { 491 463 printf("Error creating menu.\n"); … … 493 465 } 494 466 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);467 ui_menu_entry_set_cb(msaveas, edit_file_save_as, (void *) edit); 468 469 rc = ui_menu_entry_sep_create(mfile, &mfsep); 498 470 if (rc != EOK) { 499 471 printf("Error creating menu.\n"); … … 501 473 } 502 474 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); 475 rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit); 506 476 if (rc != EOK) { 507 477 printf("Error creating menu.\n"); … … 509 479 } 510 480 511 ui_menu_entry_set_cb(m saveas, edit_file_save_as, (void *) edit);512 513 rc = ui_menu_ entry_sep_create(mfile, &mfsep);481 ui_menu_entry_set_cb(mexit, edit_file_exit, (void *) edit); 482 483 rc = ui_menu_dd_create(edit->menubar, "~E~dit", NULL, &medit); 514 484 if (rc != EOK) { 515 485 printf("Error creating menu.\n"); … … 517 487 } 518 488 519 rc = ui_menu_entry_create(m file, "E~x~it", "Ctrl-Q", &mexit);489 rc = ui_menu_entry_create(medit, "Cu~t~", "Ctrl-X", &mcut); 520 490 if (rc != EOK) { 521 491 printf("Error creating menu.\n"); … … 523 493 } 524 494 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);495 ui_menu_entry_set_cb(mcut, edit_edit_cut, (void *) edit); 496 497 rc = ui_menu_entry_create(medit, "~C~opy", "Ctrl-C", &mcopy); 528 498 if (rc != EOK) { 529 499 printf("Error creating menu.\n"); … … 531 501 } 532 502 533 rc = ui_menu_entry_create(medit, "Cu~t~", "Ctrl-X", &mcut); 503 ui_menu_entry_set_cb(mcopy, edit_edit_copy, (void *) edit); 504 505 rc = ui_menu_entry_create(medit, "~P~aste", "Ctrl-V", &mpaste); 534 506 if (rc != EOK) { 535 507 printf("Error creating menu.\n"); … … 537 509 } 538 510 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);511 ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit); 512 513 rc = ui_menu_entry_create(medit, "~D~elete", "Del", &mdelete); 542 514 if (rc != EOK) { 543 515 printf("Error creating menu.\n"); … … 545 517 } 546 518 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);519 ui_menu_entry_set_cb(mdelete, edit_edit_delete, (void *) edit); 520 521 rc = ui_menu_entry_sep_create(medit, &mesep); 550 522 if (rc != EOK) { 551 523 printf("Error creating menu.\n"); … … 553 525 } 554 526 555 ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit); 556 557 rc = ui_menu_entry_create(medit, "~D~elete", "Del", &mdelete); 527 rc = ui_menu_entry_create(medit, "Select ~A~ll", "Ctrl-A", &mselall); 558 528 if (rc != EOK) { 559 529 printf("Error creating menu.\n"); … … 561 531 } 562 532 563 ui_menu_entry_set_cb(m delete, edit_edit_delete, (void *) edit);564 565 rc = ui_menu_ entry_sep_create(medit, &mesep);533 ui_menu_entry_set_cb(mselall, edit_edit_select_all, (void *) edit); 534 535 rc = ui_menu_dd_create(edit->menubar, "~S~earch", NULL, &msearch); 566 536 if (rc != EOK) { 567 537 printf("Error creating menu.\n"); … … 569 539 } 570 540 571 rc = ui_menu_entry_create(m edit, "Select ~A~ll", "Ctrl-A", &mselall);541 rc = ui_menu_entry_create(msearch, "~F~ind", "Ctrl-F", &mfind); 572 542 if (rc != EOK) { 573 543 printf("Error creating menu.\n"); … … 575 545 } 576 546 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);547 ui_menu_entry_set_cb(mfind, edit_search_find, (void *) edit); 548 549 rc = ui_menu_entry_create(msearch, "~R~everse Find", "Ctrl-Shift-F", &mfindr); 580 550 if (rc != EOK) { 581 551 printf("Error creating menu.\n"); … … 583 553 } 584 554 585 rc = ui_menu_entry_create(msearch, "~F~ind", "Ctrl-F", &mfind); 555 ui_menu_entry_set_cb(mfindr, edit_search_reverse_find, (void *) edit); 556 557 rc = ui_menu_entry_create(msearch, "Find ~N~ext", "Ctrl-N", &mfindn); 586 558 if (rc != EOK) { 587 559 printf("Error creating menu.\n"); … … 589 561 } 590 562 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);563 ui_menu_entry_set_cb(mfindn, edit_search_find_next, (void *) edit); 564 565 rc = ui_menu_entry_sep_create(msearch, &mssep); 594 566 if (rc != EOK) { 595 567 printf("Error creating menu.\n"); … … 597 569 } 598 570 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); 571 rc = ui_menu_entry_create(msearch, "Go To ~L~ine", "Ctrl-L", &mgoto); 602 572 if (rc != EOK) { 603 573 printf("Error creating menu.\n"); … … 605 575 } 606 576 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 577 ui_menu_entry_set_cb(mgoto, edit_search_go_to_line, (void *) edit); 622 578 623 edit_menubar_set_rect(edit); 579 ui_window_get_app_rect(edit->window, &arect); 580 581 rect.p0 = arect.p0; 582 rect.p1.x = arect.p1.x; 583 rect.p1.y = arect.p0.y + 1; 584 ui_menu_bar_set_rect(edit->menubar, &rect); 624 585 625 586 rc = ui_fixed_add(fixed, ui_menu_bar_ctl(edit->menubar)); … … 647 608 } 648 609 649 edit_status_set_rect(edit); 610 rect.p0.x = arect.p0.x; 611 rect.p0.y = arect.p1.y - 1; 612 rect.p1 = arect.p1; 613 ui_label_set_rect(edit->status, &rect); 650 614 651 615 rc = ui_fixed_add(fixed, ui_label_ctl(edit->status)); … … 777 741 ui_quit(edit.ui); 778 742 break; 779 case KC_N:780 file_new();781 break;782 case KC_O:783 file_open();784 break;785 743 case KC_S: 786 744 if (doc.file_name != NULL) … … 816 774 search_prompt(false); 817 775 break; 818 case KC_ R:776 case KC_N: 819 777 search_repeat(); 820 778 break; … … 955 913 } 956 914 957 /** Create new document. */ 958 static errno_t file_new(void) 959 { 915 /** Save the document. */ 916 static errno_t file_save(char const *fname) 917 { 918 spt_t sp, ep; 960 919 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) 920 921 status_display("Saving..."); 922 pt_get_sof(&sp); 923 pt_get_eof(&ep); 924 925 rc = file_save_range(fname, &sp, &ep); 926 927 switch (rc) { 928 case EINVAL: 929 status_display("Error opening file!"); 930 break; 931 case EIO: 932 status_display("Error writing data!"); 933 break; 934 default: 935 status_display("File saved."); 936 break; 937 } 938 939 return rc; 940 } 941 942 /** Open Save As dialog. */ 943 static void file_save_as(void) 1001 944 { 1002 945 const char *old_fname = (doc.file_name != NULL) ? doc.file_name : ""; … … 1006 949 1007 950 ui_file_dialog_params_init(&fdparams); 1008 fdparams.caption = " Open File";951 fdparams.caption = "Save As"; 1009 952 fdparams.ifname = old_fname; 1010 953 … … 1015 958 } 1016 959 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 960 ui_file_dialog_set_cb(dialog, &save_as_dialog_cb, &edit); 1119 961 } … … 1124 966 * of the caret. 1125 967 */ 1126 static errno_t file_insert(c onst char *fname)968 static errno_t file_insert(char *fname) 1127 969 { 1128 970 FILE *f; … … 1233 1075 } 1234 1076 1235 static void pane_set_rect(pane_t *pane) 1236 { 1077 /** Initialize pane. 1078 * 1079 * TODO: Replace with pane_create() that allocates the pane. 1080 * 1081 * @param window Editor window 1082 * @param pane Pane 1083 * @return EOK on success or an error code 1084 */ 1085 static errno_t pane_init(ui_window_t *window, pane_t *pane) 1086 { 1087 errno_t rc; 1237 1088 gfx_rect_t arect; 1238 1089 1239 ui_window_get_app_rect(pane->window, &arect); 1090 pane->control = NULL; 1091 pane->color = NULL; 1092 pane->sel_color = NULL; 1093 1094 rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control); 1095 if (rc != EOK) 1096 goto error; 1097 1098 rc = gfx_color_new_ega(0x07, &pane->color); 1099 if (rc != EOK) 1100 goto error; 1101 1102 rc = gfx_color_new_ega(0x1e, &pane->sel_color); 1103 if (rc != EOK) 1104 goto error; 1105 1106 pane->res = ui_window_get_res(window); 1107 pane->window = window; 1108 1109 ui_window_get_app_rect(window, &arect); 1240 1110 pane->rect.p0.x = arect.p0.x; 1241 1111 pane->rect.p0.y = arect.p0.y + 1; … … 1245 1115 pane->columns = pane->rect.p1.x - pane->rect.p0.x; 1246 1116 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); 1117 1281 1118 return EOK; 1282 1119 error: … … 1292 1129 1293 1130 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 1131 } 1305 1132 … … 2396 2223 } 2397 2224 2398 /** Window was resized.2399 *2400 * @param window Window2401 * @param arg Argument (edit_t *)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 2225 /** Window close request 2413 2226 * … … 2499 2312 } 2500 2313 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 2314 /** File / Save menu entry selected. 2529 2315 * … … 2679 2465 (void) arg; 2680 2466 caret_go_to_line_ask(); 2681 }2682 2683 /** Open File dialog OK button press.2684 *2685 * @param dialog Open File dialog2686 * @param arg Argument (ui_demo_t *)2687 * @param fname File name2688 */2689 static void open_dialog_bok(ui_file_dialog_t *dialog, void *arg,2690 const char *fname)2691 {2692 edit_t *edit = (edit_t *)arg;2693 char *cname;2694 errno_t rc;2695 2696 (void)edit;2697 ui_file_dialog_destroy(dialog);2698 2699 cname = str_dup(fname);2700 if (cname == NULL) {2701 printf("Out of memory.\n");2702 return;2703 }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 dialog2719 * @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 dialog2732 * @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 2467 } 2741 2468
Note:
See TracChangeset
for help on using the changeset viewer.
