Changeset 11662bd in mainline for uspace/lib/ui/src/filedialog.c


Ignore:
Timestamp:
2022-05-31T08:38:28Z (23 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03fc3a9
Parents:
5877de74
git-author:
Jiri Svoboda <jiri@…> (2022-05-30 17:38:13)
git-committer:
Jiri Svoboda <jiri@…> (2022-05-31 08:38:28)
Message:

File list control

File dialogs now allow browsing files/directories using the new
file list control. This is essentialy a copy of the Panel class
from Navigator, modified and extended to work in graphics mode as well.
Later Panel should be re-implemented using file list to prevent
duplication.

Note that this is not 100% done, it needs, for example, a scrollbar
(instead of scrolling by clicking the edges).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/filedialog.c

    r5877de74 r11662bd  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141#include <ui/label.h>
    4242#include <ui/filedialog.h>
     43#include <ui/filelist.h>
    4344#include <ui/pbutton.h>
    4445#include <ui/resource.h>
     
    5354        .close = ui_file_dialog_wnd_close,
    5455        .kbd = ui_file_dialog_wnd_kbd
     56};
     57
     58static void ui_file_dialog_flist_activate_req(ui_file_list_t *, void *);
     59static void ui_file_dialog_flist_selected(ui_file_list_t *, void *,
     60    const char *);
     61
     62ui_file_list_cb_t ui_file_dialog_flist_cb = {
     63        .activate_req = ui_file_dialog_flist_activate_req,
     64        .selected = ui_file_dialog_flist_selected
    5565};
    5666
     
    96106        ui_label_t *label = NULL;
    97107        ui_entry_t *entry = NULL;
     108        ui_file_list_t *flist = NULL;
    98109        ui_pbutton_t *bok = NULL;
    99110        ui_pbutton_t *bcancel = NULL;
     
    115126                wparams.rect.p0.y = 0;
    116127                wparams.rect.p1.x = 40;
    117                 wparams.rect.p1.y = 9;
     128                wparams.rect.p1.y = 20;
    118129        } else {
    119130                wparams.rect.p0.x = 0;
    120131                wparams.rect.p0.y = 0;
    121132                wparams.rect.p1.x = 300;
    122                 wparams.rect.p1.y = 135;
     133                wparams.rect.p1.y = 335;
    123134        }
    124135
     
    167178        if (ui_is_textmode(ui)) {
    168179                rect.p0.x = 3;
    169                 rect.p0.y = 4;
     180                rect.p0.y = 3;
    170181                rect.p1.x = 37;
    171                 rect.p1.y = 5;
     182                rect.p1.y = 4;
    172183        } else {
    173184                rect.p0.x = 10;
     
    192203        entry = NULL;
    193204
     205        /* Files label */
     206        rc = ui_label_create(ui_res, "Files:", &label);
     207        if (rc != EOK)
     208                goto error;
     209
     210        /* FIXME: Auto layout */
     211        if (ui_is_textmode(ui)) {
     212                rect.p0.x = 3;
     213                rect.p0.y = 5;
     214                rect.p1.x = 17;
     215                rect.p1.y = 6;
     216        } else {
     217                rect.p0.x = 10;
     218                rect.p0.y = 90;
     219                rect.p1.x = 190;
     220                rect.p1.y = 105;
     221        }
     222
     223        ui_label_set_rect(label, &rect);
     224
     225        rc = ui_fixed_add(fixed, ui_label_ctl(label));
     226        if (rc != EOK)
     227                goto error;
     228
     229        label = NULL;
     230
     231        /* File list */
     232
     233        rc = ui_file_list_create(window, false, &flist);
     234        if (rc != EOK)
     235                goto error;
     236
     237        /* FIXME: Auto layout */
     238        if (ui_is_textmode(ui)) {
     239                rect.p0.x = 3;
     240                rect.p0.y = 6;
     241                rect.p1.x = 37;
     242                rect.p1.y = 16;
     243        } else {
     244                rect.p0.x = 10;
     245                rect.p0.y = 110;
     246                rect.p1.x = 290;
     247                rect.p1.y = 280;
     248        }
     249
     250        ui_file_list_set_rect(flist, &rect);
     251        ui_file_list_set_cb(flist, &ui_file_dialog_flist_cb, dialog);
     252
     253        rc = ui_fixed_add(fixed, ui_file_list_ctl(flist));
     254        if (rc != EOK)
     255                goto error;
     256
     257        dialog->flist = flist;
     258        flist = NULL;
     259
     260        rc = ui_file_list_read_dir(dialog->flist, ".");
     261        if (rc != EOK)
     262                goto error;
     263
     264        /* OK button */
     265
    194266        rc = ui_pbutton_create(ui_res, "OK", &bok);
    195267        if (rc != EOK)
     
    201273        if (ui_is_textmode(ui)) {
    202274                rect.p0.x = 10;
    203                 rect.p0.y = 6;
     275                rect.p0.y = 17;
    204276                rect.p1.x = 20;
    205                 rect.p1.y = 7;
     277                rect.p1.y = 18;
    206278        } else {
    207279                rect.p0.x = 55;
    208                 rect.p0.y = 90;
     280                rect.p0.y = 290;
    209281                rect.p1.x = 145;
    210                 rect.p1.y = 118;
     282                rect.p1.y = 318;
    211283        }
    212284
     
    222294        bok = NULL;
    223295
     296        /* Cancel button */
     297
    224298        rc = ui_pbutton_create(ui_res, "Cancel", &bcancel);
    225299        if (rc != EOK)
     
    231305        if (ui_is_textmode(ui)) {
    232306                rect.p0.x = 22;
    233                 rect.p0.y = 6;
     307                rect.p0.y = 17;
    234308                rect.p1.x = 32;
    235                 rect.p1.y = 7;
     309                rect.p1.y = 18;
    236310        } else {
    237311                rect.p0.x = 155;
    238                 rect.p0.y = 90;
     312                rect.p0.y = 290;
    239313                rect.p1.x = 245;
    240                 rect.p1.y = 118;
     314                rect.p1.y = 318;
    241315        }
    242316
     
    263337        if (entry != NULL)
    264338                ui_entry_destroy(entry);
     339        if (flist != NULL)
     340                ui_file_list_destroy(flist);
    265341        if (bok != NULL)
    266342                ui_pbutton_destroy(bok);
     
    328404        ui_file_dialog_t *dialog = (ui_file_dialog_t *) arg;
    329405        const char *fname;
     406        ui_evclaim_t claim;
     407
     408        claim = ui_window_def_kbd(window, event);
     409        if (claim == ui_claimed)
     410                return;
    330411
    331412        if (event->type == KEY_PRESS &&
     
    347428        }
    348429
    349         ui_window_def_kbd(window, event);
     430}
     431
     432static void ui_file_dialog_flist_activate_req(ui_file_list_t *flist, void *arg)
     433{
     434        ui_file_dialog_t *dialog = (ui_file_dialog_t *) arg;
     435
     436        ui_file_list_activate(dialog->flist);
     437        ui_entry_deactivate(dialog->ename);
     438}
     439
     440static void ui_file_dialog_flist_selected(ui_file_list_t *flist, void *arg,
     441    const char *fname)
     442{
     443        ui_file_dialog_t *dialog = (ui_file_dialog_t *) arg;
     444
     445        dialog->cb->bok(dialog, dialog->arg, fname);
    350446}
    351447
Note: See TracChangeset for help on using the changeset viewer.