[Bf-blender-cvs] [8ff3f7f6013] master: Cleanup: move WM type registration into own files

Campbell Barton noreply at git.blender.org
Fri Jul 13 12:21:26 CEST 2018


Commit: 8ff3f7f6013f730f5325dbcbbfcb4e78fae19bbb
Author: Campbell Barton
Date:   Fri Jul 13 12:15:18 2018 +0200
Branches: master
https://developer.blender.org/rB8ff3f7f6013f730f5325dbcbbfcb4e78fae19bbb

Cleanup: move WM type registration into own files

Type registration is mostly boiler plate logic,
which can be separated from other API's.

===================================================================

M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/intern/wm.c
M	source/blender/windowmanager/intern/wm_init_exit.c
A	source/blender/windowmanager/intern/wm_menu_type.c
A	source/blender/windowmanager/intern/wm_operator_type.c
M	source/blender/windowmanager/intern/wm_operators.c
A	source/blender/windowmanager/intern/wm_uilist_type.c
M	source/blender/windowmanager/wm.h

===================================================================

diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 50f99251489..810cceb5fc3 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -53,7 +53,6 @@ set(INC_SYS
 
 set(SRC
 	intern/wm.c
-	intern/wm_playanim.c
 	intern/wm_cursors.c
 	intern/wm_dragdrop.c
 	intern/wm_draw.c
@@ -65,12 +64,16 @@ set(SRC
 	intern/wm_init_exit.c
 	intern/wm_jobs.c
 	intern/wm_keymap.c
+	intern/wm_menu_type.c
 	intern/wm_operator_props.c
+	intern/wm_operator_type.c
 	intern/wm_operators.c
+	intern/wm_playanim.c
+	intern/wm_stereo.c
 	intern/wm_subwindow.c
 	intern/wm_tooltip.c
+	intern/wm_uilist_type.c
 	intern/wm_window.c
-	intern/wm_stereo.c
 
 	WM_api.h
 	WM_keymap.h
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index b3b8bf5734d..132789aade4 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -222,130 +222,6 @@ void WM_operator_handlers_clear(wmWindowManager *wm, wmOperatorType *ot)
 }
 
 /* ************ uiListType handling ************** */
-
-static GHash *uilisttypes_hash = NULL;
-
-uiListType *WM_uilisttype_find(const char *idname, bool quiet)
-{
-	uiListType *ult;
-
-	if (idname[0]) {
-		ult = BLI_ghash_lookup(uilisttypes_hash, idname);
-		if (ult) {
-			return ult;
-		}
-	}
-
-	if (!quiet) {
-		printf("search for unknown uilisttype %s\n", idname);
-	}
-
-	return NULL;
-}
-
-bool WM_uilisttype_add(uiListType *ult)
-{
-	BLI_ghash_insert(uilisttypes_hash, ult->idname, ult);
-	return 1;
-}
-
-void WM_uilisttype_freelink(uiListType *ult)
-{
-	bool ok;
-
-	ok = BLI_ghash_remove(uilisttypes_hash, ult->idname, NULL, MEM_freeN);
-
-	BLI_assert(ok);
-	(void)ok;
-}
-
-/* called on initialize WM_init() */
-void WM_uilisttype_init(void)
-{
-	uilisttypes_hash = BLI_ghash_str_new_ex("uilisttypes_hash gh", 16);
-}
-
-void WM_uilisttype_free(void)
-{
-	GHashIterator gh_iter;
-
-	GHASH_ITER (gh_iter, uilisttypes_hash) {
-		uiListType *ult = BLI_ghashIterator_getValue(&gh_iter);
-		if (ult->ext.free) {
-			ult->ext.free(ult->ext.data);
-		}
-	}
-
-	BLI_ghash_free(uilisttypes_hash, NULL, MEM_freeN);
-	uilisttypes_hash = NULL;
-}
-
-/* ************ MenuType handling ************** */
-
-static GHash *menutypes_hash = NULL;
-
-MenuType *WM_menutype_find(const char *idname, bool quiet)
-{
-	MenuType *mt;
-
-	if (idname[0]) {
-		mt = BLI_ghash_lookup(menutypes_hash, idname);
-		if (mt)
-			return mt;
-	}
-
-	if (!quiet)
-		printf("search for unknown menutype %s\n", idname);
-
-	return NULL;
-}
-
-bool WM_menutype_add(MenuType *mt)
-{
-	BLI_ghash_insert(menutypes_hash, mt->idname, mt);
-	return true;
-}
-
-void WM_menutype_freelink(MenuType *mt)
-{
-	bool ok;
-
-	ok = BLI_ghash_remove(menutypes_hash, mt->idname, NULL, MEM_freeN);
-
-	BLI_assert(ok);
-	(void)ok;
-}
-
-/* called on initialize WM_init() */
-void WM_menutype_init(void)
-{
-	/* reserve size is set based on blender default setup */
-	menutypes_hash = BLI_ghash_str_new_ex("menutypes_hash gh", 512);
-}
-
-void WM_menutype_free(void)
-{
-	GHashIterator gh_iter;
-
-	GHASH_ITER (gh_iter, menutypes_hash) {
-		MenuType *mt = BLI_ghashIterator_getValue(&gh_iter);
-		if (mt->ext.free) {
-			mt->ext.free(mt->ext.data);
-		}
-	}
-
-	BLI_ghash_free(menutypes_hash, NULL, MEM_freeN);
-	menutypes_hash = NULL;
-}
-
-bool WM_menutype_poll(bContext *C, MenuType *mt)
-{
-	if (mt->poll != NULL) {
-		return mt->poll(C, mt);
-	}
-	return true;
-}
-
 /* ****************************************** */
 
 void WM_keymap_init(bContext *C)
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 449a0a91a01..088327fa611 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -166,6 +166,8 @@ void WM_init(bContext *C, int argc, const char **argv)
 	BKE_addon_pref_type_init();
 
 	wm_operatortype_init();
+	wm_operatortypes_register();
+
 	WM_menutype_init();
 	WM_uilisttype_init();
 
diff --git a/source/blender/windowmanager/intern/wm_menu_type.c b/source/blender/windowmanager/intern/wm_menu_type.c
new file mode 100644
index 00000000000..58e85716bf1
--- /dev/null
+++ b/source/blender/windowmanager/intern/wm_menu_type.c
@@ -0,0 +1,105 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/intern/wm_menu_type.c
+ *  \ingroup wm
+ *
+ * Menu Registry.
+ */
+
+#include "BLI_sys_types.h"
+
+#include "DNA_windowmanager_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+
+#include "BKE_context.h"
+#include "BKE_library.h"
+#include "BKE_screen.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+static GHash *menutypes_hash = NULL;
+
+MenuType *WM_menutype_find(const char *idname, bool quiet)
+{
+	MenuType *mt;
+
+	if (idname[0]) {
+		mt = BLI_ghash_lookup(menutypes_hash, idname);
+		if (mt)
+			return mt;
+	}
+
+	if (!quiet)
+		printf("search for unknown menutype %s\n", idname);
+
+	return NULL;
+}
+
+bool WM_menutype_add(MenuType *mt)
+{
+	BLI_ghash_insert(menutypes_hash, mt->idname, mt);
+	return true;
+}
+
+void WM_menutype_freelink(MenuType *mt)
+{
+	bool ok;
+
+	ok = BLI_ghash_remove(menutypes_hash, mt->idname, NULL, MEM_freeN);
+
+	BLI_assert(ok);
+	(void)ok;
+}
+
+/* called on initialize WM_init() */
+void WM_menutype_init(void)
+{
+	/* reserve size is set based on blender default setup */
+	menutypes_hash = BLI_ghash_str_new_ex("menutypes_hash gh", 512);
+}
+
+void WM_menutype_free(void)
+{
+	GHashIterator gh_iter;
+
+	GHASH_ITER (gh_iter, menutypes_hash) {
+		MenuType *mt = BLI_ghashIterator_getValue(&gh_iter);
+		if (mt->ext.free) {
+			mt->ext.free(mt->ext.data);
+		}
+	}
+
+	BLI_ghash_free(menutypes_hash, NULL, MEM_freeN);
+	menutypes_hash = NULL;
+}
+
+bool WM_menutype_poll(bContext *C, MenuType *mt)
+{
+	if (mt->poll != NULL) {
+		return mt->poll(C, mt);
+	}
+	return true;
+}
diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c
new file mode 100644
index 00000000000..35efdb2c4a2
--- /dev/null
+++ b/source/blender/windowmanager/intern/wm_operator_type.c
@@ -0,0 +1,483 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/intern/wm_operator_type.c
+ *  \ingroup wm
+ *
+ * Operator Registry.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "CLG_log.h"
+
+#include "DNA_ID.h"
+#include "DNA_screen_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BLT_translation.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+
+#include "BKE_context.h"
+#include "BKE_idprop.h"
+#include "BKE_library.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "wm.h"
+#include "wm_event_system.h"
+
+#define UNDOCUMENTED_OPERATOR_TIP N_("(undocumented operator)")
+
+static void wm_operatortype_free_macro(wmOperatorType *ot);
+
+/* -------------------------------------------------------------------- */
+/** \name Operator Type Registry
+ * \{ */
+
+static GHash *global_ops_hash = NULL;
+
+wmOperatorType *WM_operatortype_find(const char *idname, bool quiet)
+{
+	if (idname[0]) {
+		wmOperatorType *ot;
+
+		/* needed to support python style names without the _OT_ syntax */
+		char idname_bl[OP_MAX_TYPENAME];
+		WM_operator_bl_idname(idname_bl, idname);
+
+		ot = BLI_ghash_lookup(global_ops_hash, idname_bl);
+		if (ot) {
+			return ot;
+		}
+
+		if (!quiet) {
+			CLOG_INFO(WM_LOG_OPERATORS, 0, "search for unknown operator '%s', '%s'\n", idname_bl, idname);
+		}
+	}
+	else {
+		if (!quiet) {
+			CLOG_INFO(WM_LOG_OPERATORS, 0, "search for empty operator");
+		}
+	}
+
+	return NULL;
+}
+
+/* caller must free */
+void WM_operatortype_iter(GHashIterator *ghi)
+{
+	BLI_ghashIterator_init(ghi, global_ops_hash);
+}
+
+/* all ops in 1 list (for time being... needs evaluation later) */
+void WM_operatortype_append(void (*opfunc)(wmOperatorType *))
+{
+	wmOperatorType *ot;
+
+	ot = MEM_callocN(sizeof(wmOperatorType), "operatortype");
+	ot->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_OperatorProperties);
+	/* Set the default i18n context now, so that opfunc can redefine it if needed! */
+	RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
+	ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
+	opfunc(ot);
+
+	if (ot->name == NULL) {
+		CLOG_ERROR(WM_LOG_OPERATORS, "Operator '%s' has no name property", ot->idname);
+	}
+
+	/* XXX All ops s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list