Merging r42533 through r42601 from trunk into soc-2011-tomato
[blender.git] / source / blender / windowmanager / intern / wm.c
index 1d5cf1cdc53b73b6934a1fd87ced440b41ce0992..c6c67e22bfd9d1b9b00a0a9ba42ca6f39c8dc43e 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
 
 #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"
@@ -59,8 +61,6 @@
 #include "wm_draw.h"
 #include "wm.h"
 
-#include "MEM_guardedalloc.h"
-
 #include "ED_screen.h"
 
 #ifdef WITH_PYTHON
@@ -151,14 +151,14 @@ void WM_operator_stack_clear(wmWindowManager *wm)
 
 /* ****************************************** */
 
-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;
        }
@@ -171,35 +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;
 }
 
-/* inefficient but only used for tooltip code */
-int WM_menutype_contains(MenuType* mt)
+void WM_menutype_freelink(MenuType* mt)
 {
-       return (mt != NULL && BLI_findindex(&menutypes, mt) != -1);
+       BLI_ghash_remove(menutypes_hash, mt->idname, NULL, (GHashValFreeFP)MEM_freeN);
 }
 
-void WM_menutype_freelink(MenuType* mt)
+/* called on initialize WM_init() */
+void WM_menutype_init(void)
 {
-       BLI_freelinkN(&menutypes, mt);
+       menutypes_hash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "menutypes_hash gh");
 }
 
 void WM_menutype_free(void)
 {
-       MenuType* mt= menutypes.first, *mt_next;
+       GHashIterator *iter= BLI_ghashIterator_new(menutypes_hash);
 
-       while(mt) {
-               mt_next= mt->next;
-
-               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;
 }
 
 /* ****************************************** */
@@ -208,6 +208,7 @@ 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)
@@ -215,10 +216,17 @@ void WM_keymap_init(bContext *C)
        if(!wm->userconf)
                wm->userconf= WM_keyconfig_new(wm, "Blender User");
        
+       /* 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 */
-               wm_window_keymap(wm->defaultconf);
-               ED_spacetypes_keymap(wm->defaultconf);
+               /* 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);