# HG changeset patch # User Olaf Wintermann # Date 1781427148 -7200 # Node ID 4bbf0487509fa44a1b58bb3c4a1fe094350ea78f # Parent 296b8b6eaae6dde98176a0aff5c5224e740912fc add ui_document_onattach_action/ui_document_ondetach_action diff -r 296b8b6eaae6 -r 4bbf0487509f ui/common/context.c --- 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); +} diff -r 296b8b6eaae6 -r 4bbf0487509f ui/common/context.h --- 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 diff -r 296b8b6eaae6 -r 4bbf0487509f ui/common/document.c --- 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); }