diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-27 10:54:23 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-27 10:54:23 +0300 |
commit | d7a3e153e83cba0a98233fde7e173de1408dfc77 (patch) | |
tree | 48c3421ed98442699f95019db761cb0961d42ffb | |
parent | 5d147719af7122df58bbfbe9cfcd8d5271dd01cc (diff) |
InputWidget: Notify whether Enter was pressed
-rw-r--r-- | src/ui/inputwidget.c | 7 | ||||
-rw-r--r-- | src/ui/window.c | 5 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index c9be1a58..de633e3c 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -12,6 +12,7 @@ struct Impl_InputWidget { | |||
12 | iWidget widget; | 12 | iWidget widget; |
13 | enum iInputMode mode; | 13 | enum iInputMode mode; |
14 | iBool isSensitive; | 14 | iBool isSensitive; |
15 | iBool enterPressed; | ||
15 | size_t maxLen; | 16 | size_t maxLen; |
16 | iArray text; /* iChar[] */ | 17 | iArray text; /* iChar[] */ |
17 | iArray oldText; /* iChar[] */ | 18 | iArray oldText; /* iChar[] */ |
@@ -32,6 +33,7 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { | |||
32 | d->font = uiInput_FontId; | 33 | d->font = uiInput_FontId; |
33 | d->cursor = 0; | 34 | d->cursor = 0; |
34 | d->isSensitive = iFalse; | 35 | d->isSensitive = iFalse; |
36 | d->enterPressed = iFalse; | ||
35 | setMaxLen_InputWidget(d, maxLen); | 37 | setMaxLen_InputWidget(d, maxLen); |
36 | if (maxLen == 0) { | 38 | if (maxLen == 0) { |
37 | /* Caller must arrange the width. */ | 39 | /* Caller must arrange the width. */ |
@@ -118,6 +120,7 @@ void begin_InputWidget(iInputWidget *d) { | |||
118 | setFlags_Widget(w, selected_WidgetFlag, iTrue); | 120 | setFlags_Widget(w, selected_WidgetFlag, iTrue); |
119 | refresh_Widget(w); | 121 | refresh_Widget(w); |
120 | d->timer = SDL_AddTimer(REFRESH_INTERVAL, refreshTimer_, d); | 122 | d->timer = SDL_AddTimer(REFRESH_INTERVAL, refreshTimer_, d); |
123 | d->enterPressed = iFalse; | ||
121 | } | 124 | } |
122 | 125 | ||
123 | void end_InputWidget(iInputWidget *d, iBool accept) { | 126 | void end_InputWidget(iInputWidget *d, iBool accept) { |
@@ -136,7 +139,8 @@ void end_InputWidget(iInputWidget *d, iBool accept) { | |||
136 | const char *id = cstr_String(id_Widget(as_Widget(d))); | 139 | const char *id = cstr_String(id_Widget(as_Widget(d))); |
137 | if (!*id) id = "_"; | 140 | if (!*id) id = "_"; |
138 | refresh_Widget(w); | 141 | refresh_Widget(w); |
139 | postCommand_Widget(w, "input.ended id:%s arg:%d", id, accept ? 1 : 0); | 142 | postCommand_Widget( |
143 | w, "input.ended id:%s enter:%d arg:%d", id, d->enterPressed ? 1 : 0, accept ? 1 : 0); | ||
140 | } | 144 | } |
141 | 145 | ||
142 | static void insertChar_InputWidget_(iInputWidget *d, iChar chr) { | 146 | static void insertChar_InputWidget_(iInputWidget *d, iChar chr) { |
@@ -202,6 +206,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
202 | switch (key) { | 206 | switch (key) { |
203 | case SDLK_RETURN: | 207 | case SDLK_RETURN: |
204 | case SDLK_KP_ENTER: | 208 | case SDLK_KP_ENTER: |
209 | d->enterPressed = iTrue; | ||
205 | setFocus_Widget(NULL); | 210 | setFocus_Widget(NULL); |
206 | return iTrue; | 211 | return iTrue; |
207 | case SDLK_ESCAPE: | 212 | case SDLK_ESCAPE: |
diff --git a/src/ui/window.c b/src/ui/window.c index ac9cbd97..79715b6e 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -121,9 +121,10 @@ static iBool handleSearchBarCommands_(iWidget *searchBar, const char *cmd) { | |||
121 | if (equal_Command(cmd, "input.ended") && | 121 | if (equal_Command(cmd, "input.ended") && |
122 | cmp_String(string_Command(cmd, "id"), "find.input") == 0) { | 122 | cmp_String(string_Command(cmd, "id"), "find.input") == 0) { |
123 | iInputWidget *input = findChild_Widget(searchBar, "find.input"); | 123 | iInputWidget *input = findChild_Widget(searchBar, "find.input"); |
124 | if (arg_Command(cmd) && isVisible_Widget(as_Widget(input))) { | 124 | if (arg_Command(cmd) && argLabel_Command(cmd, "enter") && |
125 | isVisible_Widget(as_Widget(input))) { | ||
125 | postCommand_App("find.next"); | 126 | postCommand_App("find.next"); |
126 | /* Keep focus. */ | 127 | /* Keep focus when pressing Enter. */ |
127 | if (!isEmpty_String(text_InputWidget(input))) { | 128 | if (!isEmpty_String(text_InputWidget(input))) { |
128 | postCommand_App("focus.set id:find.input"); | 129 | postCommand_App("focus.set id:find.input"); |
129 | } | 130 | } |