Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 8e253ac in mainline


Ignore:
Timestamp:
2021-09-25T21:01:28Z (4 weeks ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
b4b5f6a4
Parents:
45b7d4d
Message:

Save As file dialog

File:
1 edited

Legend:

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

    r45b7d4d r8e253ac  
    5555#include <types/common.h>
    5656#include <ui/control.h>
     57#include <ui/filedialog.h>
    5758#include <ui/fixed.h>
    5859#include <ui/label.h>
     
    255256        .paint = pane_ctl_paint,
    256257        .pos_event = pane_ctl_pos_event
     258};
     259
     260static void save_as_dialog_bok(ui_file_dialog_t *, void *, const char *);
     261static void save_as_dialog_bcancel(ui_file_dialog_t *, void *);
     262static void save_as_dialog_close(ui_file_dialog_t *, void *);
     263
     264static ui_file_dialog_cb_t save_as_dialog_cb = {
     265        .bok = save_as_dialog_bok,
     266        .bcancel = save_as_dialog_bcancel,
     267        .close = save_as_dialog_close
    257268};
    258269
     
    783794}
    784795
    785 /** Change document name and save. */
     796/** Open Save As dialog. */
    786797static void file_save_as(void)
    787798{
    788         const char *old_fname = (doc.file_name != NULL) ? doc.file_name : "";
    789         char *fname;
    790 
    791         fname = prompt("Save As", old_fname);
    792         if (fname == NULL) {
    793                 status_display("Save cancelled.");
     799//      const char *old_fname = (doc.file_name != NULL) ? doc.file_name : "";
     800        ui_file_dialog_params_t fdparams;
     801        ui_file_dialog_t *dialog;
     802        errno_t rc;
     803
     804        ui_file_dialog_params_init(&fdparams);
     805        fdparams.caption = "Save As";
     806        // TODO: Set initial file name to old_fname
     807
     808        rc = ui_file_dialog_create(edit.ui, &fdparams, &dialog);
     809        if (rc != EOK) {
     810                printf("Error creating message dialog.\n");
    794811                return;
    795812        }
    796813
    797         errno_t rc = file_save(fname);
    798         if (rc != EOK)
    799                 return;
    800 
    801         if (doc.file_name != NULL)
    802                 free(doc.file_name);
    803         doc.file_name = fname;
     814        ui_file_dialog_set_cb(dialog, &save_as_dialog_cb, &edit);
    804815}
    805816
     
    21112122}
    21122123
     2124/** Save As dialog OK button press.
     2125 *
     2126 * @param dialog Save As dialog
     2127 * @param arg Argument (ui_demo_t *)
     2128 * @param fname File name
     2129 */
     2130static void save_as_dialog_bok(ui_file_dialog_t *dialog, void *arg,
     2131    const char *fname)
     2132{
     2133        char *cname;
     2134        errno_t rc;
     2135
     2136        ui_file_dialog_destroy(dialog);
     2137
     2138        cname = str_dup(fname);
     2139        if (cname == NULL) {
     2140                printf("Out of memory.\n");
     2141                return;
     2142        }
     2143
     2144        rc = file_save(fname);
     2145        if (rc != EOK)
     2146                return;
     2147
     2148        if (doc.file_name != NULL)
     2149                free(doc.file_name);
     2150        doc.file_name = cname;
     2151
     2152}
     2153
     2154/** Save As dialog cancel button press.
     2155 *
     2156 * @param dialog File dialog
     2157 * @param arg Argument (ui_demo_t *)
     2158 */
     2159static void save_as_dialog_bcancel(ui_file_dialog_t *dialog, void *arg)
     2160{
     2161        edit_t *edit = (edit_t *)arg;
     2162
     2163        (void)edit;
     2164        ui_file_dialog_destroy(dialog);
     2165}
     2166
     2167/** Save As dialog close request.
     2168 *
     2169 * @param dialog File dialog
     2170 * @param arg Argument (ui_demo_t *)
     2171 */
     2172static void save_as_dialog_close(ui_file_dialog_t *dialog, void *arg)
     2173{
     2174        edit_t *edit = (edit_t *)arg;
     2175
     2176        (void)edit;
     2177        ui_file_dialog_destroy(dialog);
     2178}
     2179
    21132180/** @}
    21142181 */
Note: See TracChangeset for help on using the changeset viewer.