add ui_document_onattach_action/ui_document_ondetach_action

Sun, 14 Jun 2026 10:52:28 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 14 Jun 2026 10:52:28 +0200
changeset 1197
4bbf0487509f
parent 1196
296b8b6eaae6
child 1198
5bb4366b0c32

add ui_document_onattach_action/ui_document_ondetach_action

ui/common/context.c file | annotate | diff | comparison | revisions
ui/common/context.h file | annotate | diff | comparison | revisions
ui/common/document.c file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Sat Jun 13 17:19:59 2026 +0200
+++ b/ui/common/context.c	Sun Jun 14 10:52:28 2026 +0200
@@ -943,3 +943,21 @@
     UiVar *var = uic_get_var_t(ctx, name, UI_VAR_GENERIC);
     return var ? var->value : NULL;
 }
+
+
+static void attachment_action_callback(UiEvent *event, void *action) {
+    if(event->document) {
+        UiContext *ctx = ui_document_context(event->document);
+        ui_call_action_on(ctx, action);
+    }
+}
+
+void ui_context_onattach_action(UiContext *ctx, const char *action) {
+    ctx->onattach = attachment_action_callback;
+    ctx->onattachdata = ui_strdup(ctx, action);
+}
+
+void ui_context_ondetach_action(UiContext *ctx, const char *action) {
+    ctx->ondetach = attachment_action_callback;
+    ctx->ondetachdata = ui_strdup(ctx, action);
+}
--- a/ui/common/context.h	Sat Jun 13 17:19:59 2026 +0200
+++ b/ui/common/context.h	Sun Jun 14 10:52:28 2026 +0200
@@ -173,6 +173,9 @@
 void uic_add_state_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *states, size_t numstates);
 void uic_remove_state_widget(UiContext *ctx, void *widget);
 
+UIEXPORT void ui_context_onattach_action(UiContext *ctx, const char *action);
+UIEXPORT void ui_context_ondetach_action(UiContext *ctx, const char *action);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/common/document.c	Sat Jun 13 17:19:59 2026 +0200
+++ b/ui/common/document.c	Sun Jun 14 10:52:28 2026 +0200
@@ -99,22 +99,13 @@
     ctx->ondetachdata = data;
 }
 
-static void attachment_action_callback(UiEvent *event, void *action) {
-    if(event->document) {
-        UiContext *ctx = ui_document_context(event->document);
-        ui_call_action_on(ctx, action);
-    }
-}
-
 void ui_document_onattach_action(void *doc, const char *action) {
     UiContext *ctx = ui_document_context(doc);
-    ctx->onattach = attachment_action_callback;
-    ctx->onattachdata = ui_strdup(ctx, action);
+    ui_context_onattach_action(ctx, action);
 }
 
 void ui_document_ondetach_action(void *doc, const char *action) {
     UiContext *ctx = ui_document_context(doc);
-    ctx->ondetach = attachment_action_callback;
-    ctx->ondetachdata = ui_strdup(ctx, action);
+    ui_context_ondetach_action(ctx, action);
 }
 

mercurial