Merging r42533 through r42601 from trunk into soc-2011-tomato
[blender.git] / source / blender / windowmanager / intern / wm.c
index 426069245c30b4acbfb22470b6c50e08ea7daa80..c6c67e22bfd9d1b9b00a0a9ba42ca6f39c8dc43e 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/windowmanager/intern/wm.c
+ *  \ingroup wm
+ */
+
+
 #include <string.h>
 #include <stddef.h>
 
 
 #include "GHOST_C-api.h"
 
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
 #include "BLI_blenlib.h"
+#include "BLI_ghash.h"
 
 #include "BKE_blender.h"
 #include "BKE_context.h"
@@ -54,8 +61,6 @@
 #include "wm_draw.h"
 #include "wm.h"
 
-#include "MEM_guardedalloc.h"
-
 #include "ED_screen.h"
 
 #ifdef WITH_PYTHON
@@ -127,14 +132,13 @@ void wm_operator_register(bContext *C, wmOperator *op)
        }
        
        /* so the console is redrawn */
-       WM_event_add_notifier(C, NC_SPACE|ND_SPACE_CONSOLE_REPORT, NULL);
+       WM_event_add_notifier(C, NC_SPACE|ND_SPACE_INFO_REPORT, NULL);
        WM_event_add_notifier(C, NC_WM|ND_HISTORY, NULL);
 }
 
 
-void WM_operator_stack_clear(bContext *C)
+void WM_operator_stack_clear(wmWindowManager *wm)
 {
-       wmWindowManager *wm= CTX_wm_manager(C);
        wmOperator *op;
        
        while((op= wm->operators.first)) {
@@ -142,19 +146,19 @@ void WM_operator_stack_clear(bContext *C)
                WM_operator_free(op);
        }
        
-       WM_event_add_notifier(C, NC_WM|ND_HISTORY, NULL);
+       WM_main_add_notifier(NC_WM|ND_HISTORY, NULL);
 }
 
 /* ****************************************** */
 
-static ListBase menutypes = {NULL, NULL}; /* global menutype list */
+static GHash *menutypes_hash= NULL;
 
 MenuType *WM_menutype_find(const char *idname, int quiet)
 {
        MenuType* mt;
 
        if (idname[0]) {
-               mt= BLI_findstring(&menutypes, idname, offsetof(MenuType, idname));
+               mt= BLI_ghash_lookup(menutypes_hash, idname);
                if(mt)
                        return mt;
        }
@@ -167,29 +171,35 @@ MenuType *WM_menutype_find(const char *idname, int quiet)
 
 int WM_menutype_add(MenuType* mt)
 {
-       BLI_addtail(&menutypes, mt);
+       BLI_ghash_insert(menutypes_hash, (void *)mt->idname, mt);
        return 1;
 }
 
 void WM_menutype_freelink(MenuType* mt)
 {
-       BLI_freelinkN(&menutypes, mt);
+       BLI_ghash_remove(menutypes_hash, mt->idname, NULL, (GHashValFreeFP)MEM_freeN);
 }
 
-void WM_menutype_free(void)
+/* called on initialize WM_init() */
+void WM_menutype_init(void)
 {
-       MenuType* mt= menutypes.first, *mt_next;
+       menutypes_hash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "menutypes_hash gh");
+}
 
-       while(mt) {
-               mt_next= mt->next;
+void WM_menutype_free(void)
+{
+       GHashIterator *iter= BLI_ghashIterator_new(menutypes_hash);
 
-               if(mt->ext.free)
+       for( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
+               MenuType *mt= BLI_ghashIterator_getValue(iter);
+               if(mt->ext.free) {
                        mt->ext.free(mt->ext.data);
-
-               WM_menutype_freelink(mt);
-
-               mt= mt_next;
+               }
        }
+       BLI_ghashIterator_free(iter);
+
+       BLI_ghash_free(menutypes_hash, NULL, (GHashValFreeFP)MEM_freeN);
+       menutypes_hash= NULL;
 }
 
 /* ****************************************** */
@@ -198,14 +208,28 @@ void WM_keymap_init(bContext *C)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
 
+       /* create standard key configs */
        if(!wm->defaultconf)
                wm->defaultconf= WM_keyconfig_new(wm, "Blender");
+       if(!wm->addonconf)
+               wm->addonconf= WM_keyconfig_new(wm, "Blender Addon");
+       if(!wm->userconf)
+               wm->userconf= WM_keyconfig_new(wm, "Blender User");
        
-       if(wm && CTX_py_init_get(C) && (wm->initialized & WM_INIT_KEYMAP) == 0) {
-               /* create default key config */
-               wm_window_keymap(wm->defaultconf);
-               ED_spacetypes_keymap(wm->defaultconf);
-               WM_keyconfig_userdef();
+       /* initialize only after python init is done, for keymaps that
+          use python operators */
+       if(CTX_py_init_get(C) && (wm->initialized & WM_INIT_KEYMAP) == 0) {
+               /* create default key config, only initialize once,
+                  it's persistent across sessions */
+               if(!(wm->defaultconf->flag & KEYCONF_INIT_DEFAULT)) {
+                       wm_window_keymap(wm->defaultconf);
+                       ED_spacetypes_keymap(wm->defaultconf);
+
+                       wm->defaultconf->flag |= KEYCONF_INIT_DEFAULT;
+               }
+
+               WM_keyconfig_update_tag(NULL, NULL);
+               WM_keyconfig_update(wm);
 
                wm->initialized |= WM_INIT_KEYMAP;
        }
@@ -275,7 +299,7 @@ void wm_add_default(bContext *C)
        win= wm_window_new(C);
        win->screen= screen;
        screen->winid= win->winid;
-       BLI_strncpy(win->screenname, screen->id.name+2, 21);
+       BLI_strncpy(win->screenname, screen->id.name+2, sizeof(win->screenname));
        
        wm->winactive= win;
        wm->file_saved= 1;