# HG changeset patch # User Olaf Wintermann # Date 1765105161 -3600 # Node ID e88ca7dfa94362b883b80151296ba804f5cbdfc4 # Parent 4b2202df31ece692fbb299ef4d9cc9ec52586d9e add single-document-mode to UiContext diff -r 4b2202df31ec -r e88ca7dfa943 ui/common/context.c --- a/ui/common/context.c Sun Dec 07 11:51:01 2025 +0100 +++ b/ui/common/context.c Sun Dec 07 11:59:21 2025 +0100 @@ -97,6 +97,12 @@ } void uic_context_attach_document(UiContext *ctx, void *document) { + if(ctx->single_document_mode) { + if(ctx->document) { + uic_context_detach_document(ctx, ctx->document); + } + } + cxListAdd(ctx->documents, document); ctx->document = document; @@ -485,6 +491,14 @@ // public API +void* ui_context_get_document(UiContext *ctx) { + return ctx->document; +} + +void ui_context_single_attachment_mode(UiContext *ctx, UiBool enable) { + ctx->single_document_mode = enable; +} + void ui_attach_document(UiContext *ctx, void *document) { uic_context_attach_document(ctx, document); } diff -r 4b2202df31ec -r e88ca7dfa943 ui/common/context.h --- a/ui/common/context.h Sun Dec 07 11:51:01 2025 +0100 +++ b/ui/common/context.h Sun Dec 07 11:59:21 2025 +0100 @@ -84,8 +84,10 @@ GtkAccelGroup *accel_group; #endif #endif - - + + // allow only one document to be attached + // attaching a document will automatically detach the current document + UiBool single_document_mode; ui_callback close_callback; void *close_data; diff -r 4b2202df31ec -r e88ca7dfa943 ui/ui/toolkit.h --- a/ui/ui/toolkit.h Sun Dec 07 11:51:01 2025 +0100 +++ b/ui/ui/toolkit.h Sun Dec 07 11:59:21 2025 +0100 @@ -565,6 +565,8 @@ UIEXPORT UiContext* ui_document_context(void *doc); +UIEXPORT void* ui_context_get_document(UiContext *ctx); +UIEXPORT void ui_context_single_attachment_mode(UiContext *ctx, UiBool enable); UIEXPORT void ui_attach_document(UiContext *ctx, void *document); UIEXPORT void ui_detach_document(UiContext *ctx, void *document);