Changes in uspace/app/edit/edit.c [ec50d65e:3c22438a] in mainline
- File:
-
- 1 edited
-
uspace/app/edit/edit.c (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
rec50d65e r3c22438a 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2026 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); 179 182 static errno_t file_save(char const *fname); 180 183 static void file_save_as(void); 181 static errno_t file_insert(c har *fname);184 static errno_t file_insert(const char *fname); 182 185 static errno_t file_save_range(char const *fname, spt_t const *spos, 183 186 spt_t const *epos); … … 237 240 static void edit_ui_destroy(edit_t *); 238 241 242 static void edit_wnd_resize(ui_window_t *, void *); 239 243 static void edit_wnd_close(ui_window_t *, void *); 240 244 static void edit_wnd_focus(ui_window_t *, void *, unsigned); … … 243 247 244 248 static ui_window_cb_t edit_window_cb = { 249 .resize = edit_wnd_resize, 245 250 .close = edit_wnd_close, 246 251 .focus = edit_wnd_focus, … … 257 262 }; 258 263 264 static void edit_file_new(ui_menu_entry_t *, void *); 265 static void edit_file_open(ui_menu_entry_t *, void *); 259 266 static void edit_file_save(ui_menu_entry_t *, void *); 260 267 static void edit_file_save_as(ui_menu_entry_t *, void *); … … 281 288 }; 282 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 283 300 static void save_as_dialog_bok(ui_file_dialog_t *, void *, const char *); 284 301 static void save_as_dialog_bcancel(ui_file_dialog_t *, void *); … … 313 330 int main(int argc, char *argv[]) 314 331 { 315 bool new_file;316 332 errno_t rc; 317 333 … … 319 335 pane.sh_column = 1; 320 336 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; 337 /* Create UI */ 338 rc = edit_ui_create(&edit); 339 if (rc != EOK) 340 return 1; 333 341 334 342 if (argc == 2) { 335 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 } 336 349 } else if (argc > 1) { 337 350 printf("Invalid arguments.\n"); 338 351 return -2; 339 352 } 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); 353 354 /* Create UI */ 355 rc = edit_ui_create(&edit); 356 if (rc != EOK) 357 return 1; 358 359 caret_move(sof, true, true); 353 rc = file_new(); 354 } 360 355 361 356 /* Initial display */ … … 366 361 } 367 362 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 374 363 ui_run(edit.ui); 375 364 376 365 edit_ui_destroy(&edit); 377 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); 378 406 } 379 407 … … 390 418 ui_menu_t *mfile = NULL; 391 419 ui_menu_t *medit = NULL; 420 ui_menu_entry_t *mnew = NULL; 421 ui_menu_entry_t *mopen = NULL; 392 422 ui_menu_entry_t *msave = NULL; 393 423 ui_menu_entry_t *msaveas = NULL; … … 406 436 ui_menu_entry_t *mssep = NULL; 407 437 ui_menu_entry_t *mgoto = NULL; 408 gfx_rect_t arect;409 gfx_rect_t rect;410 438 411 439 rc = ui_create(UI_CONSOLE_DEFAULT, &edit->ui); … … 451 479 } 452 480 453 rc = ui_menu_entry_create(mfile, "~ S~ave", "Ctrl-S", &msave);481 rc = ui_menu_entry_create(mfile, "~N~ew", "Ctrl-N", &mnew); 454 482 if (rc != EOK) { 455 483 printf("Error creating menu.\n"); … … 457 485 } 458 486 459 ui_menu_entry_set_cb(m save, edit_file_save, (void *) edit);460 461 rc = ui_menu_entry_create(mfile, " Save ~A~s", "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); 462 490 if (rc != EOK) { 463 491 printf("Error creating menu.\n"); … … 465 493 } 466 494 467 ui_menu_entry_set_cb(m saveas, edit_file_save_as, (void *) edit);468 469 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); 470 498 if (rc != EOK) { 471 499 printf("Error creating menu.\n"); … … 473 501 } 474 502 475 rc = ui_menu_entry_create(mfile, "E~x~it", "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); 476 506 if (rc != EOK) { 477 507 printf("Error creating menu.\n"); … … 479 509 } 480 510 481 ui_menu_entry_set_cb(m exit, edit_file_exit, (void *) edit);482 483 rc = ui_menu_ dd_create(edit->menubar, "~E~dit", NULL, &medit);511 ui_menu_entry_set_cb(msaveas, edit_file_save_as, (void *) edit); 512 513 rc = ui_menu_entry_sep_create(mfile, &mfsep); 484 514 if (rc != EOK) { 485 515 printf("Error creating menu.\n"); … … 487 517 } 488 518 489 rc = ui_menu_entry_create(m edit, "Cu~t~", "Ctrl-X", &mcut);519 rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit); 490 520 if (rc != EOK) { 491 521 printf("Error creating menu.\n"); … … 493 523 } 494 524 495 ui_menu_entry_set_cb(m cut, edit_edit_cut, (void *) edit);496 497 rc = ui_menu_ entry_create(medit, "~C~opy", "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); 498 528 if (rc != EOK) { 499 529 printf("Error creating menu.\n"); … … 501 531 } 502 532 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); 533 rc = ui_menu_entry_create(medit, "Cu~t~", "Ctrl-X", &mcut); 506 534 if (rc != EOK) { 507 535 printf("Error creating menu.\n"); … … 509 537 } 510 538 511 ui_menu_entry_set_cb(m paste, edit_edit_paste, (void *) edit);512 513 rc = ui_menu_entry_create(medit, "~ D~elete", "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); 514 542 if (rc != EOK) { 515 543 printf("Error creating menu.\n"); … … 517 545 } 518 546 519 ui_menu_entry_set_cb(m delete, edit_edit_delete, (void *) edit);520 521 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); 522 550 if (rc != EOK) { 523 551 printf("Error creating menu.\n"); … … 525 553 } 526 554 527 rc = ui_menu_entry_create(medit, "Select ~A~ll", "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); 528 558 if (rc != EOK) { 529 559 printf("Error creating menu.\n"); … … 531 561 } 532 562 533 ui_menu_entry_set_cb(m selall, edit_edit_select_all, (void *) edit);534 535 rc = ui_menu_ dd_create(edit->menubar, "~S~earch", NULL, &msearch);563 ui_menu_entry_set_cb(mdelete, edit_edit_delete, (void *) edit); 564 565 rc = ui_menu_entry_sep_create(medit, &mesep); 536 566 if (rc != EOK) { 537 567 printf("Error creating menu.\n"); … … 539 569 } 540 570 541 rc = ui_menu_entry_create(m search, "~F~ind", "Ctrl-F", &mfind);571 rc = ui_menu_entry_create(medit, "Select ~A~ll", "Ctrl-A", &mselall); 542 572 if (rc != EOK) { 543 573 printf("Error creating menu.\n"); … … 545 575 } 546 576 547 ui_menu_entry_set_cb(m find, edit_search_find, (void *) edit);548 549 rc = ui_menu_ entry_create(msearch, "~R~everse 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); 550 580 if (rc != EOK) { 551 581 printf("Error creating menu.\n"); … … 553 583 } 554 584 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); 585 rc = ui_menu_entry_create(msearch, "~F~ind", "Ctrl-F", &mfind); 558 586 if (rc != EOK) { 559 587 printf("Error creating menu.\n"); … … 561 589 } 562 590 563 ui_menu_entry_set_cb(mfind n, edit_search_find_next, (void *) edit);564 565 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); 566 594 if (rc != EOK) { 567 595 printf("Error creating menu.\n"); … … 569 597 } 570 598 571 rc = ui_menu_entry_create(msearch, "Go To ~L~ine", "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); 572 602 if (rc != EOK) { 573 603 printf("Error creating menu.\n"); … … 575 605 } 576 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 577 621 ui_menu_entry_set_cb(mgoto, edit_search_go_to_line, (void *) edit); 578 622 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); 623 edit_menubar_set_rect(edit); 585 624 586 625 rc = ui_fixed_add(fixed, ui_menu_bar_ctl(edit->menubar)); … … 608 647 } 609 648 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); 649 edit_status_set_rect(edit); 614 650 615 651 rc = ui_fixed_add(fixed, ui_label_ctl(edit->status)); … … 741 777 ui_quit(edit.ui); 742 778 break; 779 case KC_N: 780 file_new(); 781 break; 782 case KC_O: 783 file_open(); 784 break; 743 785 case KC_S: 744 786 if (doc.file_name != NULL) … … 774 816 search_prompt(false); 775 817 break; 776 case KC_ N:818 case KC_R: 777 819 search_repeat(); 778 820 break; … … 913 955 } 914 956 915 /** Save the document. */ 916 static errno_t file_save(char const *fname) 917 { 918 spt_t sp, ep; 957 /** Create new document. */ 958 static errno_t file_new(void) 959 { 919 960 errno_t rc; 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) 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) 944 1001 { 945 1002 const char *old_fname = (doc.file_name != NULL) ? doc.file_name : ""; … … 949 1006 950 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); 951 1109 fdparams.caption = "Save As"; 952 1110 fdparams.ifname = old_fname; … … 966 1124 * of the caret. 967 1125 */ 968 static errno_t file_insert(c har *fname)1126 static errno_t file_insert(const char *fname) 969 1127 { 970 1128 FILE *f; … … 1075 1233 } 1076 1234 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; 1235 static void pane_set_rect(pane_t *pane) 1236 { 1088 1237 gfx_rect_t arect; 1089 1238 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); 1239 ui_window_get_app_rect(pane->window, &arect); 1110 1240 pane->rect.p0.x = arect.p0.x; 1111 1241 pane->rect.p0.y = arect.p0.y + 1; … … 1115 1245 pane->columns = pane->rect.p1.x - pane->rect.p0.x; 1116 1246 pane->rows = pane->rect.p1.y - pane->rect.p0.y; 1117 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); 1118 1281 return EOK; 1119 1282 error: … … 1129 1292 1130 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); 1131 1304 } 1132 1305 … … 2223 2396 } 2224 2397 2398 /** Window was resized. 2399 * 2400 * @param window Window 2401 * @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 2225 2412 /** Window close request 2226 2413 * … … 2312 2499 } 2313 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 2314 2528 /** File / Save menu entry selected. 2315 2529 * … … 2465 2679 (void) arg; 2466 2680 caret_go_to_line_ask(); 2681 } 2682 2683 /** Open File dialog OK button press. 2684 * 2685 * @param dialog Open File dialog 2686 * @param arg Argument (ui_demo_t *) 2687 * @param fname File name 2688 */ 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 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); 2467 2740 } 2468 2741
Note:
See TracChangeset
for help on using the changeset viewer.
