call event handler after text input in the path textfield newapi

Tue, 30 Jan 2024 12:10:41 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 30 Jan 2024 12:10:41 +0100
branch
newapi
changeset 240
9335e9bbc167
parent 239
5dd24929f9f6
child 241
c51dd0e9ecb7

call event handler after text input in the path textfield

ui/winui/text.cpp file | annotate | diff | comparison | revisions
--- a/ui/winui/text.cpp	Mon Jan 29 18:47:55 2024 +0100
+++ b/ui/winui/text.cpp	Tue Jan 30 12:10:41 2024 +0100
@@ -242,23 +242,27 @@
     return elms;
 }
 
-void ui_pathtextfield_update(UiPathTextField* pb, const char *full_path) {
+int ui_pathtextfield_update(UiPathTextField* pb, const char *full_path) {
     Grid grid = pb->grid;
 
     ui_pathelm_func getpathelm = pb->getpathelm;
     void* getpathelmdata = pb->getpathelmdata;
 
+    size_t full_path_len = full_path ? strlen(full_path) : 0;
+
+    size_t nelm = 0;
+    UiPathElm* path_elm = getpathelm(full_path, full_path_len, &nelm, getpathelmdata);
+    if (!path_elm) {
+        return 1;
+    }
+
     // hide textbox, show button panel
     pb->textbox.Visibility(Visibility::Collapsed);
     pb->buttons.Visibility(Visibility::Visible);
 
     // clear old buttons
-    ui_pathtextfield_clear(pb->buttons);
+    ui_pathtextfield_clear(pb->buttons); 
 
-    size_t full_path_len = full_path ? strlen(full_path) : 0;
-    
-    size_t nelm = 0;
-    UiPathElm* path_elm = getpathelm(full_path, full_path_len, &nelm, getpathelmdata);
     ui_pathfield_free_pathelms(pb->current_path, pb->current_path_nelms);
     pb->current_path = path_elm;
     pb->current_path_nelms = nelm;
@@ -298,6 +302,8 @@
 
         j++;
     }
+
+    return 0;
 }
 
 char* ui_path_textfield_get(UiString * str) {
@@ -436,7 +442,17 @@
                     if (update) {
                         std::wstring value(pathTextBox.Text());
                         char* full_path = wchar2utf8(value.c_str(), value.length());
-                        ui_pathtextfield_update(uipathbar, full_path);
+
+                        if (!ui_pathtextfield_update(uipathbar, full_path)) {
+                            UiEvent evt;
+                            evt.obj = obj;
+                            evt.window = obj->window;
+                            evt.document = obj->ctx->document;
+                            evt.eventdata = full_path;
+                            evt.intval = -1;
+                            args.onactivate(&evt, args.onactivatedata);
+                        } 
+
                         free(full_path);
                     }
 

mercurial