Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/edit/edit.c

    r994f87b r46bd63c9  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * Copyright (c) 2012 Martin Sucha
    44 * All rights reserved.
     
    177177static void pos_handle(pos_event_t *ev);
    178178
    179 static errno_t file_new(void);
    180 static void file_open(void);
    181 static errno_t file_open_file(const char *fname);
    182179static errno_t file_save(char const *fname);
    183180static void file_save_as(void);
    184 static errno_t file_insert(const char *fname);
     181static errno_t file_insert(char *fname);
    185182static errno_t file_save_range(char const *fname, spt_t const *spos,
    186183    spt_t const *epos);
     
    241238
    242239static void edit_wnd_close(ui_window_t *, void *);
    243 static void edit_wnd_focus(ui_window_t *, void *, unsigned);
    244240static void edit_wnd_kbd_event(ui_window_t *, void *, kbd_event_t *);
    245 static void edit_wnd_unfocus(ui_window_t *, void *, unsigned);
    246241
    247242static ui_window_cb_t edit_window_cb = {
    248243        .close = edit_wnd_close,
    249         .focus = edit_wnd_focus,
    250         .kbd = edit_wnd_kbd_event,
    251         .unfocus = edit_wnd_unfocus
     244        .kbd = edit_wnd_kbd_event
    252245};
    253246
    254 static void edit_menubar_activate(ui_menu_bar_t *, void *);
    255 static void edit_menubar_deactivate(ui_menu_bar_t *, void *);
    256 
    257 static ui_menu_bar_cb_t edit_menubar_cb = {
    258         .activate = edit_menubar_activate,
    259         .deactivate = edit_menubar_deactivate
    260 };
    261 
    262 static void edit_file_new(ui_menu_entry_t *, void *);
    263 static void edit_file_open(ui_menu_entry_t *, void *);
    264247static void edit_file_save(ui_menu_entry_t *, void *);
    265248static void edit_file_save_as(ui_menu_entry_t *, void *);
     
    286269};
    287270
    288 static void open_dialog_bok(ui_file_dialog_t *, void *, const char *);
    289 static void open_dialog_bcancel(ui_file_dialog_t *, void *);
    290 static void open_dialog_close(ui_file_dialog_t *, void *);
    291 
    292 static ui_file_dialog_cb_t open_dialog_cb = {
    293         .bok = open_dialog_bok,
    294         .bcancel = open_dialog_bcancel,
    295         .close = open_dialog_close
    296 };
    297 
    298271static void save_as_dialog_bok(ui_file_dialog_t *, void *, const char *);
    299272static void save_as_dialog_bcancel(ui_file_dialog_t *, void *);
     
    328301int main(int argc, char *argv[])
    329302{
     303        bool new_file;
    330304        errno_t rc;
    331305
    332306        pane.sh_row = 1;
    333307        pane.sh_column = 1;
     308
     309        /* Start with an empty sheet. */
     310        rc = sheet_create(&doc.sh);
     311        if (rc != EOK) {
     312                printf("Out of memory.\n");
     313                return -1;
     314        }
     315
     316        /* Place caret at the beginning of file. */
     317        spt_t sof;
     318        pt_get_sof(&sof);
     319        sheet_place_tag(doc.sh, &sof, &pane.caret_pos);
     320        pane.ideal_column = 1;
     321
     322        if (argc == 2) {
     323                doc.file_name = str_dup(argv[1]);
     324        } else if (argc > 1) {
     325                printf("Invalid arguments.\n");
     326                return -2;
     327        } else {
     328                doc.file_name = NULL;
     329        }
     330
     331        new_file = false;
     332
     333        if (doc.file_name == NULL || file_insert(doc.file_name) != EOK)
     334                new_file = true;
     335
     336        /* Place selection start tag. */
     337        sheet_place_tag(doc.sh, &sof, &pane.sel_start);
     338
     339        /* Move to beginning of file. */
     340        pt_get_sof(&sof);
    334341
    335342        /* Create UI */
     
    338345                return 1;
    339346
    340         if (argc == 2) {
    341                 doc.file_name = str_dup(argv[1]);
    342                 rc = file_open_file(argv[1]);
    343                 if (rc != EOK) {
    344                         status_display("File not found. Starting empty file.");
    345                         rc = file_new();
    346                 }
    347         } else if (argc > 1) {
    348                 printf("Invalid arguments.\n");
    349                 return -2;
    350         } else {
    351                 rc = file_new();
    352         }
     347        caret_move(sof, true, true);
    353348
    354349        /* Initial display */
     
    358353                return rc;
    359354        }
     355
     356        pane_status_display(&pane);
     357        if (new_file && doc.file_name != NULL)
     358                status_display("File not found. Starting empty file.");
     359        pane_caret_display(&pane);
     360        cursor_setvis(true);
    360361
    361362        ui_run(edit.ui);
     
    377378        ui_menu_t *mfile = NULL;
    378379        ui_menu_t *medit = NULL;
    379         ui_menu_entry_t *mnew = NULL;
    380         ui_menu_entry_t *mopen = NULL;
    381380        ui_menu_entry_t *msave = NULL;
    382381        ui_menu_entry_t *msaveas = NULL;
     
    432431        }
    433432
    434         ui_menu_bar_set_cb(edit->menubar, &edit_menubar_cb, (void *) edit);
    435 
    436433        rc = ui_menu_dd_create(edit->menubar, "~F~ile", NULL, &mfile);
    437434        if (rc != EOK) {
     
    440437        }
    441438
    442         rc = ui_menu_entry_create(mfile, "~N~ew", "Ctrl-N", &mnew);
     439        rc = ui_menu_entry_create(mfile, "~S~ave", "Ctrl-S", &msave);
    443440        if (rc != EOK) {
    444441                printf("Error creating menu.\n");
     
    446443        }
    447444
    448         ui_menu_entry_set_cb(mnew, edit_file_new, (void *) edit);
    449 
    450         rc = ui_menu_entry_create(mfile, "~O~pen", "Ctrl-O", &mopen);
     445        ui_menu_entry_set_cb(msave, edit_file_save, (void *) edit);
     446
     447        rc = ui_menu_entry_create(mfile, "Save ~A~s", "Ctrl-E", &msaveas);
    451448        if (rc != EOK) {
    452449                printf("Error creating menu.\n");
     
    454451        }
    455452
    456         ui_menu_entry_set_cb(mopen, edit_file_open, (void *) edit);
    457 
    458         rc = ui_menu_entry_create(mfile, "~S~ave", "Ctrl-S", &msave);
     453        ui_menu_entry_set_cb(msaveas, edit_file_save_as, (void *) edit);
     454
     455        rc = ui_menu_entry_sep_create(mfile, &mfsep);
    459456        if (rc != EOK) {
    460457                printf("Error creating menu.\n");
     
    462459        }
    463460
    464         ui_menu_entry_set_cb(msave, edit_file_save, (void *) edit);
    465 
    466         rc = ui_menu_entry_create(mfile, "Save ~A~s", "Ctrl-E", &msaveas);
     461        rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit);
    467462        if (rc != EOK) {
    468463                printf("Error creating menu.\n");
     
    470465        }
    471466
    472         ui_menu_entry_set_cb(msaveas, edit_file_save_as, (void *) edit);
    473 
    474         rc = ui_menu_entry_sep_create(mfile, &mfsep);
     467        ui_menu_entry_set_cb(mexit, edit_file_exit, (void *) edit);
     468
     469        rc = ui_menu_dd_create(edit->menubar, "~E~dit", NULL, &medit);
    475470        if (rc != EOK) {
    476471                printf("Error creating menu.\n");
     
    478473        }
    479474
    480         rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit);
     475        rc = ui_menu_entry_create(medit, "Cu~t~", "Ctrl-X", &mcut);
    481476        if (rc != EOK) {
    482477                printf("Error creating menu.\n");
     
    484479        }
    485480
    486         ui_menu_entry_set_cb(mexit, edit_file_exit, (void *) edit);
    487 
    488         rc = ui_menu_dd_create(edit->menubar, "~E~dit", NULL, &medit);
     481        ui_menu_entry_set_cb(mcut, edit_edit_cut, (void *) edit);
     482
     483        rc = ui_menu_entry_create(medit, "~C~opy", "Ctrl-C", &mcopy);
    489484        if (rc != EOK) {
    490485                printf("Error creating menu.\n");
     
    492487        }
    493488
    494         rc = ui_menu_entry_create(medit, "Cu~t~", "Ctrl-X", &mcut);
     489        ui_menu_entry_set_cb(mcopy, edit_edit_copy, (void *) edit);
     490
     491        rc = ui_menu_entry_create(medit, "~P~aste", "Ctrl-V", &mpaste);
    495492        if (rc != EOK) {
    496493                printf("Error creating menu.\n");
     
    498495        }
    499496
    500         ui_menu_entry_set_cb(mcut, edit_edit_cut, (void *) edit);
    501 
    502         rc = ui_menu_entry_create(medit, "~C~opy", "Ctrl-C", &mcopy);
     497        ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit);
     498
     499        rc = ui_menu_entry_create(medit, "~D~elete", "Del", &mdelete);
    503500        if (rc != EOK) {
    504501                printf("Error creating menu.\n");
     
    506503        }
    507504
    508         ui_menu_entry_set_cb(mcopy, edit_edit_copy, (void *) edit);
    509 
    510         rc = ui_menu_entry_create(medit, "~P~aste", "Ctrl-V", &mpaste);
     505        ui_menu_entry_set_cb(mdelete, edit_edit_delete, (void *) edit);
     506
     507        rc = ui_menu_entry_sep_create(medit, &mesep);
    511508        if (rc != EOK) {
    512509                printf("Error creating menu.\n");
     
    514511        }
    515512
    516         ui_menu_entry_set_cb(mpaste, edit_edit_paste, (void *) edit);
    517 
    518         rc = ui_menu_entry_create(medit, "~D~elete", "Del", &mdelete);
     513        rc = ui_menu_entry_create(medit, "Select ~A~ll", "Ctrl-A", &mselall);
    519514        if (rc != EOK) {
    520515                printf("Error creating menu.\n");
     
    522517        }
    523518
    524         ui_menu_entry_set_cb(mdelete, edit_edit_delete, (void *) edit);
    525 
    526         rc = ui_menu_entry_sep_create(medit, &mesep);
     519        ui_menu_entry_set_cb(mselall, edit_edit_select_all, (void *) edit);
     520
     521        rc = ui_menu_dd_create(edit->menubar, "~S~earch", NULL, &msearch);
    527522        if (rc != EOK) {
    528523                printf("Error creating menu.\n");
     
    530525        }
    531526
    532         rc = ui_menu_entry_create(medit, "Select ~A~ll", "Ctrl-A", &mselall);
     527        rc = ui_menu_entry_create(msearch, "~F~ind", "Ctrl-F", &mfind);
    533528        if (rc != EOK) {
    534529                printf("Error creating menu.\n");
     
    536531        }
    537532
    538         ui_menu_entry_set_cb(mselall, edit_edit_select_all, (void *) edit);
    539 
    540         rc = ui_menu_dd_create(edit->menubar, "~S~earch", NULL, &msearch);
     533        ui_menu_entry_set_cb(mfind, edit_search_find, (void *) edit);
     534
     535        rc = ui_menu_entry_create(msearch, "~R~everse Find", "Ctrl-Shift-F", &mfindr);
    541536        if (rc != EOK) {
    542537                printf("Error creating menu.\n");
     
    544539        }
    545540
    546         rc = ui_menu_entry_create(msearch, "~F~ind", "Ctrl-F", &mfind);
    547         if (rc != EOK) {
    548                 printf("Error creating menu.\n");
    549                 return rc;
    550         }
    551 
    552         ui_menu_entry_set_cb(mfind, edit_search_find, (void *) edit);
    553 
    554         rc = ui_menu_entry_create(msearch, "~R~everse Find", "Ctrl-Shift-F", &mfindr);
    555         if (rc != EOK) {
    556                 printf("Error creating menu.\n");
    557                 return rc;
    558         }
    559 
    560541        ui_menu_entry_set_cb(mfindr, edit_search_reverse_find, (void *) edit);
    561542
    562         rc = ui_menu_entry_create(msearch, "Find ~N~ext", "Ctrl-R", &mfindn);
     543        rc = ui_menu_entry_create(msearch, "Find ~N~ext", "Ctrl-N", &mfindn);
    563544        if (rc != EOK) {
    564545                printf("Error creating menu.\n");
     
    746727                ui_quit(edit.ui);
    747728                break;
    748         case KC_N:
    749                 file_new();
    750                 break;
    751         case KC_O:
    752                 file_open();
    753                 break;
    754729        case KC_S:
    755730                if (doc.file_name != NULL)
     
    785760                search_prompt(false);
    786761                break;
    787         case KC_R:
     762        case KC_N:
    788763                search_repeat();
    789764                break;
     
    924899}
    925900
    926 /** Create new document. */
    927 static errno_t file_new(void)
    928 {
     901/** Save the document. */
     902static errno_t file_save(char const *fname)
     903{
     904        spt_t sp, ep;
    929905        errno_t rc;
    930         sheet_t *sh;
    931 
    932         /* Create empty sheet. */
    933         rc = sheet_create(&sh);
    934         if (rc != EOK) {
    935                 printf("Out of memory.\n");
    936                 return ENOMEM;
    937         }
    938 
    939         if (doc.sh != NULL)
    940                 sheet_destroy(doc.sh);
    941 
    942         doc.sh = sh;
    943 
    944         /* Place caret at the beginning of file. */
    945         spt_t sof;
    946         pt_get_sof(&sof);
    947         sheet_place_tag(doc.sh, &sof, &pane.caret_pos);
    948         pane.ideal_column = 1;
    949 
    950         doc.file_name = NULL;
    951 
    952         /* Place selection start tag. */
    953         sheet_place_tag(doc.sh, &sof, &pane.sel_start);
    954 
    955         /* Move to beginning of file. */
    956         pt_get_sof(&sof);
    957 
    958         caret_move(sof, true, true);
    959 
    960         pane_status_display(&pane);
    961         pane_caret_display(&pane);
    962         pane_text_display(&pane);
    963         cursor_setvis(true);
    964 
    965         return EOK;
    966 }
    967 
    968 /** Open Open File dialog. */
    969 static void file_open(void)
     906
     907        status_display("Saving...");
     908        pt_get_sof(&sp);
     909        pt_get_eof(&ep);
     910
     911        rc = file_save_range(fname, &sp, &ep);
     912
     913        switch (rc) {
     914        case EINVAL:
     915                status_display("Error opening file!");
     916                break;
     917        case EIO:
     918                status_display("Error writing data!");
     919                break;
     920        default:
     921                status_display("File saved.");
     922                break;
     923        }
     924
     925        return rc;
     926}
     927
     928/** Open Save As dialog. */
     929static void file_save_as(void)
    970930{
    971931        const char *old_fname = (doc.file_name != NULL) ? doc.file_name : "";
     
    975935
    976936        ui_file_dialog_params_init(&fdparams);
    977         fdparams.caption = "Open File";
     937        fdparams.caption = "Save As";
    978938        fdparams.ifname = old_fname;
    979939
     
    984944        }
    985945
    986         ui_file_dialog_set_cb(dialog, &open_dialog_cb, &edit);
    987 }
    988 
    989 /** Open exising document. */
    990 static errno_t file_open_file(const char *fname)
    991 {
    992         errno_t rc;
    993         sheet_t *sh;
    994         char *fn;
    995 
    996         /* Create empty sheet. */
    997         rc = sheet_create(&sh);
    998         if (rc != EOK) {
    999                 printf("Out of memory.\n");
    1000                 return ENOMEM;
    1001         }
    1002 
    1003         fn = str_dup(fname);
    1004         if (fn == NULL) {
    1005                 sheet_destroy(sh);
    1006                 return ENOMEM;
    1007         }
    1008 
    1009         if (doc.sh != NULL)
    1010                 sheet_destroy(doc.sh);
    1011 
    1012         doc.sh = sh;
    1013 
    1014         /* Place caret at the beginning of file. */
    1015         spt_t sof;
    1016         pt_get_sof(&sof);
    1017         sheet_place_tag(doc.sh, &sof, &pane.caret_pos);
    1018         pane.ideal_column = 1;
    1019 
    1020         rc = file_insert(fname);
    1021         if (rc != EOK)
    1022                 return rc;
    1023 
    1024         doc.file_name = fn;
    1025 
    1026         /* Place selection start tag. */
    1027         sheet_place_tag(doc.sh, &sof, &pane.sel_start);
    1028 
    1029         /* Move to beginning of file. */
    1030         pt_get_sof(&sof);
    1031 
    1032         caret_move(sof, true, true);
    1033 
    1034         pane_status_display(&pane);
    1035         pane_caret_display(&pane);
    1036         pane_text_display(&pane);
    1037         cursor_setvis(true);
    1038 
    1039         return EOK;
    1040 }
    1041 
    1042 /** Save the document. */
    1043 static errno_t file_save(char const *fname)
    1044 {
    1045         spt_t sp, ep;
    1046         errno_t rc;
    1047 
    1048         status_display("Saving...");
    1049         pt_get_sof(&sp);
    1050         pt_get_eof(&ep);
    1051 
    1052         rc = file_save_range(fname, &sp, &ep);
    1053 
    1054         switch (rc) {
    1055         case EINVAL:
    1056                 status_display("Error opening file!");
    1057                 break;
    1058         case EIO:
    1059                 status_display("Error writing data!");
    1060                 break;
    1061         default:
    1062                 status_display("File saved.");
    1063                 break;
    1064         }
    1065 
    1066         return rc;
    1067 }
    1068 
    1069 /** Open Save As dialog. */
    1070 static void file_save_as(void)
    1071 {
    1072         const char *old_fname = (doc.file_name != NULL) ? doc.file_name : "";
    1073         ui_file_dialog_params_t fdparams;
    1074         ui_file_dialog_t *dialog;
    1075         errno_t rc;
    1076 
    1077         ui_file_dialog_params_init(&fdparams);
    1078         fdparams.caption = "Save As";
    1079         fdparams.ifname = old_fname;
    1080 
    1081         rc = ui_file_dialog_create(edit.ui, &fdparams, &dialog);
    1082         if (rc != EOK) {
    1083                 printf("Error creating message dialog.\n");
    1084                 return;
    1085         }
    1086 
    1087946        ui_file_dialog_set_cb(dialog, &save_as_dialog_cb, &edit);
    1088947}
     
    1093952 * of the caret.
    1094953 */
    1095 static errno_t file_insert(const char *fname)
     954static errno_t file_insert(char *fname)
    1096955{
    1097956        FILE *f;
     
    23622221}
    23632222
    2364 /** Window focus event
    2365  *
    2366  * @param window Window
    2367  * @param arg Argument (edit_t *)
    2368  * @param focus Focus number
    2369  */
    2370 static void edit_wnd_focus(ui_window_t *window, void *arg, unsigned focus)
    2371 {
    2372         edit_t *edit = (edit_t *)arg;
    2373 
    2374         (void)edit;
    2375         pane_caret_display(&pane);
    2376         cursor_setvis(true);
    2377 }
    2378 
    23792223/** Window keyboard event
    23802224 *
     
    23982242}
    23992243
    2400 /** Window unfocus event
    2401  *
    2402  * @param window Window
    2403  * @param arg Argument (edit_t *)
    2404  * @param focus Focus number
    2405  */
    2406 static void edit_wnd_unfocus(ui_window_t *window, void *arg, unsigned focus)
    2407 {
    2408         edit_t *edit = (edit_t *) arg;
    2409 
    2410         (void)edit;
    2411         cursor_setvis(false);
    2412 }
    2413 
    2414 /** Menu bar activate event
    2415  *
    2416  * @param mbar Menu bar
    2417  * @param arg Argument (edit_t *)
    2418  */
    2419 static void edit_menubar_activate(ui_menu_bar_t *mbar, void *arg)
    2420 {
    2421         edit_t *edit = (edit_t *)arg;
    2422 
    2423         (void)edit;
    2424         cursor_setvis(false);
    2425 }
    2426 
    2427 /** Menu bar deactivate event
    2428  *
    2429  * @param mbar Menu bar
    2430  * @param arg Argument (edit_t *)
    2431  */
    2432 static void edit_menubar_deactivate(ui_menu_bar_t *mbar, void *arg)
    2433 {
    2434         edit_t *edit = (edit_t *)arg;
    2435 
    2436         (void)edit;
    2437         pane_caret_display(&pane);
    2438         cursor_setvis(true);
    2439 }
    2440 
    2441 /** File / New menu entry selected.
    2442  *
    2443  * @param mentry Menu entry
    2444  * @param arg Argument (edit_t *)
    2445  */
    2446 static void edit_file_new(ui_menu_entry_t *mentry, void *arg)
    2447 {
    2448         edit_t *edit = (edit_t *) arg;
    2449 
    2450         (void)edit;
    2451         file_new();
    2452         (void) gfx_update(ui_window_get_gc(edit->window));
    2453 }
    2454 
    2455 /** File / Open menu entry selected.
    2456  *
    2457  * @param mentry Menu entry
    2458  * @param arg Argument (edit_t *)
    2459  */
    2460 static void edit_file_open(ui_menu_entry_t *mentry, void *arg)
    2461 {
    2462         edit_t *edit = (edit_t *) arg;
    2463 
    2464         (void)edit;
    2465         file_open();
    2466 }
    2467 
    24682244/** File / Save menu entry selected.
    24692245 *
     
    26212397}
    26222398
    2623 /** Open File dialog OK button press.
    2624  *
    2625  * @param dialog Open File dialog
     2399/** Save As dialog OK button press.
     2400 *
     2401 * @param dialog Save As dialog
    26262402 * @param arg Argument (ui_demo_t *)
    26272403 * @param fname File name
    26282404 */
    2629 static void open_dialog_bok(ui_file_dialog_t *dialog, void *arg,
     2405static void save_as_dialog_bok(ui_file_dialog_t *dialog, void *arg,
    26302406    const char *fname)
    26312407{
    26322408        edit_t *edit = (edit_t *)arg;
     2409        gfx_context_t *gc = ui_window_get_gc(edit->window);
    26332410        char *cname;
    26342411        errno_t rc;
    26352412
    2636         (void)edit;
    26372413        ui_file_dialog_destroy(dialog);
     2414        // TODO Smarter cursor management
     2415        pane.rflags |= REDRAW_CARET;
     2416        (void) pane_update(&pane);
     2417        gfx_cursor_set_visible(gc, true);
    26382418
    26392419        cname = str_dup(fname);
     
    26432423        }
    26442424
    2645         rc = file_open_file(fname);
     2425        rc = file_save(fname);
    26462426        if (rc != EOK)
    26472427                return;
     
    26512431        doc.file_name = cname;
    26522432
    2653         (void) gfx_update(ui_window_get_gc(edit->window));
    2654 }
    2655 
    2656 /** Open File dialog cancel button press.
     2433}
     2434
     2435/** Save As dialog cancel button press.
    26572436 *
    26582437 * @param dialog File dialog
    26592438 * @param arg Argument (ui_demo_t *)
    26602439 */
    2661 static void open_dialog_bcancel(ui_file_dialog_t *dialog, void *arg)
     2440static void save_as_dialog_bcancel(ui_file_dialog_t *dialog, void *arg)
    26622441{
    26632442        edit_t *edit = (edit_t *)arg;
    2664 
    2665         (void)edit;
     2443        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2444
    26662445        ui_file_dialog_destroy(dialog);
    2667 }
    2668 
    2669 /** Open File dialog close request.
     2446        // TODO Smarter cursor management
     2447        pane.rflags |= REDRAW_CARET;
     2448        (void) pane_update(&pane);
     2449        gfx_cursor_set_visible(gc, true);
     2450}
     2451
     2452/** Save As dialog close request.
    26702453 *
    26712454 * @param dialog File dialog
    26722455 * @param arg Argument (ui_demo_t *)
    26732456 */
    2674 static void open_dialog_close(ui_file_dialog_t *dialog, void *arg)
     2457static void save_as_dialog_close(ui_file_dialog_t *dialog, void *arg)
    26752458{
    26762459        edit_t *edit = (edit_t *)arg;
    2677 
    2678         (void)edit;
     2460        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2461
    26792462        ui_file_dialog_destroy(dialog);
    2680 }
    2681 
    2682 /** Save As dialog OK button press.
    2683  *
    2684  * @param dialog Save As dialog
    2685  * @param arg Argument (ui_demo_t *)
    2686  * @param fname File name
    2687  */
    2688 static void save_as_dialog_bok(ui_file_dialog_t *dialog, void *arg,
    2689     const char *fname)
    2690 {
    2691         edit_t *edit = (edit_t *)arg;
    2692         char *cname;
    2693         errno_t rc;
    2694 
    2695         (void)edit;
    2696         ui_file_dialog_destroy(dialog);
    2697 
    2698         cname = str_dup(fname);
    2699         if (cname == NULL) {
    2700                 printf("Out of memory.\n");
    2701                 return;
    2702         }
    2703 
    2704         rc = file_save(fname);
    2705         if (rc != EOK)
    2706                 return;
    2707 
    2708         if (doc.file_name != NULL)
    2709                 free(doc.file_name);
    2710         doc.file_name = cname;
    2711 
    2712 }
    2713 
    2714 /** Save As dialog cancel button press.
    2715  *
    2716  * @param dialog File dialog
    2717  * @param arg Argument (ui_demo_t *)
    2718  */
    2719 static void save_as_dialog_bcancel(ui_file_dialog_t *dialog, void *arg)
    2720 {
    2721         edit_t *edit = (edit_t *)arg;
    2722 
    2723         (void)edit;
    2724         ui_file_dialog_destroy(dialog);
    2725 }
    2726 
    2727 /** Save As dialog close request.
    2728  *
    2729  * @param dialog File dialog
    2730  * @param arg Argument (ui_demo_t *)
    2731  */
    2732 static void save_as_dialog_close(ui_file_dialog_t *dialog, void *arg)
    2733 {
    2734         edit_t *edit = (edit_t *)arg;
    2735 
    2736         (void)edit;
    2737         ui_file_dialog_destroy(dialog);
     2463        // TODO Smarter cursor management
     2464        pane.rflags |= REDRAW_CARET;
     2465        (void) pane_update(&pane);
     2466        gfx_cursor_set_visible(gc, true);
    27382467}
    27392468
     
    27482477{
    27492478        edit_t *edit = (edit_t *) arg;
     2479        gfx_context_t *gc = ui_window_get_gc(edit->window);
    27502480        char *endptr;
    27512481        int line;
     
    27592489
    27602490        caret_move_absolute(line, pane.ideal_column, dir_before, false);
    2761         (void)edit;
     2491        // TODO Smarter cursor management
    27622492        (void) pane_update(&pane);
     2493        gfx_cursor_set_visible(gc, true);
     2494        (void) gfx_update(gc);
    27632495}
    27642496
     
    27712503{
    27722504        edit_t *edit = (edit_t *) arg;
    2773 
    2774         (void)edit;
     2505        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2506
    27752507        ui_prompt_dialog_destroy(dialog);
     2508        // TODO Smarter cursor management
     2509        pane.rflags |= REDRAW_CARET;
     2510        (void) pane_update(&pane);
     2511        gfx_cursor_set_visible(gc, true);
    27762512}
    27772513
     
    27842520{
    27852521        edit_t *edit = (edit_t *) arg;
    2786 
    2787         (void)edit;
     2522        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2523
    27882524        ui_prompt_dialog_destroy(dialog);
     2525        // TODO Smarter cursor management
     2526        pane.rflags |= REDRAW_CARET;
     2527        (void) pane_update(&pane);
     2528        gfx_cursor_set_visible(gc, true);
    27892529}
    27902530
     
    27992539{
    28002540        edit_t *edit = (edit_t *) arg;
     2541        gfx_context_t *gc = ui_window_get_gc(edit->window);
    28012542        char *pattern;
    28022543        bool reverse;
    28032544
    2804         (void)edit;
    28052545        ui_prompt_dialog_destroy(dialog);
    28062546
     
    28192559        search(pattern, reverse);
    28202560
     2561        // TODO Smarter cursor management
    28212562        (void) pane_update(&pane);
     2563        gfx_cursor_set_visible(gc, true);
     2564        (void) gfx_update(gc);
    28222565}
    28232566
     
    28302573{
    28312574        edit_t *edit = (edit_t *) arg;
    2832 
    2833         (void)edit;
     2575        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2576
    28342577        ui_prompt_dialog_destroy(dialog);
     2578        // TODO Smarter cursor management
     2579        pane.rflags |= REDRAW_CARET;
     2580        (void) pane_update(&pane);
     2581        gfx_cursor_set_visible(gc, true);
    28352582}
    28362583
     
    28432590{
    28442591        edit_t *edit = (edit_t *) arg;
    2845 
    2846         (void)edit;
     2592        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2593
    28472594        ui_prompt_dialog_destroy(dialog);
     2595        // TODO Smarter cursor management
     2596        pane.rflags |= REDRAW_CARET;
     2597        (void) pane_update(&pane);
     2598        gfx_cursor_set_visible(gc, true);
    28482599}
    28492600
Note: See TracChangeset for help on using the changeset viewer.