Просмотр исходного кода

Make keyboard able to be dismissed with back key.

antirez 3 лет назад
Родитель
Сommit
88a43ece0e
2 измененных файлов с 23 добавлено и 0 удалено
  1. 22 0
      app.c
  2. 1 0
      view_info.c

+ 22 - 0
app.c

@@ -245,6 +245,22 @@ static void timer_callback(void *ctx) {
     scan_for_signal(app);
 }
 
+/* This is the navigation callback we use in the view dispatcher used
+ * to display the "text input" widget, that is the keyboard to get text.
+ * The text input view is implemented to ignore the "back" short press,
+ * so the event is not consumed and is handled by the view dispatcher.
+ * However the view dispatcher implementation has the strange behavior that
+ * if no navigation callback is set, it will not stop when handling back.
+ *
+ * We just need a dummy callback returning false. We believe the
+ * implementation should be changed and if no callback is set, it should be
+ * the same as returning false. */
+static bool keyboard_view_dispatcher_navigation_callback(void *ctx) {
+    UNUSED(ctx);
+    return false;
+}
+
+/* App entry point, as specified in application.fam. */
 int32_t protoview_app_entry(void* p) {
     UNUSED(p);
     ProtoViewApp *app = protoview_app_alloc();
@@ -335,6 +351,12 @@ int32_t protoview_app_entry(void* p) {
              * and activate it. */
             app->view_dispatcher = view_dispatcher_alloc();
             view_dispatcher_enable_queue(app->view_dispatcher);
+            /* We need to set a navigation callback for the view dispatcher
+             * otherwise when the user presses back on the keyboard to
+             * abort, the dispatcher will not stop. */
+            view_dispatcher_set_navigation_event_callback(
+                app->view_dispatcher,
+                keyboard_view_dispatcher_navigation_callback);
             app->text_input = text_input_alloc();
             view_dispatcher_set_event_callback_context(app->view_dispatcher,app);
             view_dispatcher_add_view(app->view_dispatcher, 0, text_input_get_view(app->text_input));

+ 1 - 0
view_info.c

@@ -187,6 +187,7 @@ void text_input_done_callback(void* context) {
 
     free(privdata->filename);
     ui_dismiss_keyboard(app);
+    ui_show_alert(app, "Signal saved", 1500);
 }
 
 /* Replace all the occurrences of character c1 with c2 in the specified