Changeset 6c0766b in mainline


Ignore:
Timestamp:
2021-09-29T14:07:36Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e0cf963
Parents:
8603145
git-author:
Jiri Svoboda <jiri@…> (2021-09-28 14:06:29)
git-committer:
Jiri Svoboda <jiri@…> (2021-09-29 14:07:36)
Message:

Confirm / cancel file and prompt dialogs using Enter / Escape

Location:
uspace/lib/ui/src
Files:
2 edited

Legend:

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

    r8603145 r6c0766b  
    4848
    4949static void ui_file_dialog_wnd_close(ui_window_t *, void *);
     50static void ui_file_dialog_wnd_kbd(ui_window_t *, void *, kbd_event_t *);
    5051
    5152ui_window_cb_t ui_file_dialog_wnd_cb = {
    52         .close = ui_file_dialog_wnd_close
     53        .close = ui_file_dialog_wnd_close,
     54        .kbd = ui_file_dialog_wnd_kbd
    5355};
    5456
     
    310312}
    311313
     314/** File dialog window keyboard event handler.
     315 *
     316 * @param window Window
     317 * @param arg Argument (ui_prompt_dialog_t *)
     318 * @param event Keyboard event
     319 */
     320static void ui_file_dialog_wnd_kbd(ui_window_t *window, void *arg,
     321    kbd_event_t *event)
     322{
     323        ui_file_dialog_t *dialog = (ui_file_dialog_t *) arg;
     324        const char *fname;
     325
     326        if (event->type == KEY_PRESS &&
     327            (event->mods & (KM_CTRL | KM_SHIFT | KM_ALT)) == 0) {
     328                if (event->key == KC_ENTER) {
     329                        /* Confirm */
     330                        if (dialog->cb != NULL && dialog->cb->bok != NULL) {
     331                                fname = ui_entry_get_text(dialog->ename);
     332                                dialog->cb->bok(dialog, dialog->arg, fname);
     333                                return;
     334                        }
     335                } else if (event->key == KC_ESCAPE) {
     336                        /* Cancel */
     337                        if (dialog->cb != NULL && dialog->cb->bcancel != NULL) {
     338                                dialog->cb->bcancel(dialog, dialog->arg);
     339                                return;
     340                        }
     341                }
     342        }
     343
     344        ui_window_def_kbd(window, event);
     345}
     346
    312347/** File dialog OK button click handler.
    313348 *
  • uspace/lib/ui/src/promptdialog.c

    r8603145 r6c0766b  
    4848
    4949static void ui_prompt_dialog_wnd_close(ui_window_t *, void *);
     50static void ui_prompt_dialog_wnd_kbd(ui_window_t *, void *, kbd_event_t *);
    5051
    5152ui_window_cb_t ui_prompt_dialog_wnd_cb = {
    52         .close = ui_prompt_dialog_wnd_close
     53        .close = ui_prompt_dialog_wnd_close,
     54        .kbd = ui_prompt_dialog_wnd_kbd
    5355};
    5456
     
    310312}
    311313
     314/** Prompt dialog window keyboard event handler.
     315 *
     316 * @param window Window
     317 * @param arg Argument (ui_prompt_dialog_t *)
     318 * @param event Keyboard event
     319 */
     320static void ui_prompt_dialog_wnd_kbd(ui_window_t *window, void *arg,
     321    kbd_event_t *event)
     322{
     323        ui_prompt_dialog_t *dialog = (ui_prompt_dialog_t *) arg;
     324        const char *fname;
     325
     326        if (event->type == KEY_PRESS &&
     327            (event->mods & (KM_CTRL | KM_SHIFT | KM_ALT)) == 0) {
     328                if (event->key == KC_ENTER) {
     329                        /* Confirm */
     330                        if (dialog->cb != NULL && dialog->cb->bok != NULL) {
     331                                fname = ui_entry_get_text(dialog->ename);
     332                                dialog->cb->bok(dialog, dialog->arg, fname);
     333                                return;
     334                        }
     335                } else if (event->key == KC_ESCAPE) {
     336                        /* Cancel */
     337                        if (dialog->cb != NULL && dialog->cb->bcancel != NULL) {
     338                                dialog->cb->bcancel(dialog, dialog->arg);
     339                                return;
     340                        }
     341                }
     342        }
     343
     344        ui_window_def_kbd(window, event);
     345}
     346
    312347/** Prompt dialog OK button click handler.
    313348 *
Note: See TracChangeset for help on using the changeset viewer.