ui/common/context.c

changeset 167
161511838ea6
parent 164
1d912f78fd1d
child 168
1b99acacc5bb
--- a/ui/common/context.c	Tue Dec 08 15:19:31 2020 +0100
+++ b/ui/common/context.c	Thu Dec 10 13:42:25 2020 +0100
@@ -36,6 +36,16 @@
 #include "document.h"
 #include "types.h"
 
+static UiContext* global_context;
+
+void uic_init_global_context(void) {
+    UcxMempool *mp = ucx_mempool_new(32);
+    global_context = uic_context(NULL, mp);
+}
+
+UiContext* ui_global_context(void) {
+    return global_context;
+}
 
 UiContext* uic_context(UiObject *toplevel, UcxMempool *mp) {
     UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext));
@@ -48,7 +58,7 @@
     ctx->detach_document2 = uic_context_detach_document2;
     
 #ifdef UI_GTK
-    if(toplevel->widget) {
+    if(toplevel && toplevel->widget) {
         ctx->accel_group = gtk_accel_group_new();
         gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group);
     }
@@ -156,12 +166,12 @@
     return var;
 }
 
-UiVar* uic_get_var(UiContext *ctx, char *name) {
+UiVar* uic_get_var(UiContext *ctx, const char *name) {
     UcxKey key = ucx_key(name, strlen(name));
     return ctx_getvar(ctx, key);
 }
 
-UiVar* uic_create_var(UiContext *ctx, char *name, UiVarType type) {
+UiVar* uic_create_var(UiContext *ctx, const char *name, UiVarType type) {
     UiVar *var = uic_get_var(ctx, name);
     if(var) {
         if(var->type == type) {

mercurial