[Bf-blender-cvs] [c47c64734e7] temp-workspace-changes: Properties Editor: Add Workspace and organize context path

Dalai Felinto noreply at git.blender.org
Thu Sep 14 12:09:52 CEST 2017


Commit: c47c64734e7a2e4732ba7342ac598e02b9f5dde9
Author: Dalai Felinto
Date:   Fri Sep 8 22:02:16 2017 +0200
Branches: temp-workspace-changes
https://developer.blender.org/rBc47c64734e7a2e4732ba7342ac598e02b9f5dde9

Properties Editor: Add Workspace and organize context path

We now have the properties of:

Scene, Scene > Layer, Scene > World, Workspace

[Scene | Workspace] > Render Layer > Object
[Scene | Workspace] > Render Layer > Object > Data
(...)

We use Scene or Workspace depending on workspace.use_scene_settings.

Also, we no longer expose the object in the collection context.
Since this should go away (and at the very least we should get the mode
from the workspace).

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

M	release/scripts/startup/bl_ui/__init__.py
A	release/scripts/startup/bl_ui/properties_data_workspace.py
M	source/blender/editors/space_buttons/buttons_context.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index cc3d1ffc229..d7135ca202c 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -42,6 +42,7 @@ _modules = [
     "properties_data_modifier",
     "properties_data_lightprobe",
     "properties_data_speaker",
+    "properties_data_workspace",
     "properties_game",
     "properties_mask_common",
     "properties_material",
diff --git a/release/scripts/startup/bl_ui/properties_data_workspace.py b/release/scripts/startup/bl_ui/properties_data_workspace.py
new file mode 100644
index 00000000000..7095acec8f9
--- /dev/null
+++ b/release/scripts/startup/bl_ui/properties_data_workspace.py
@@ -0,0 +1,77 @@
+# ##### 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 #####
+
+# <pep8 compliant>
+import bpy
+from bpy.types import (
+        Panel,
+        )
+
+from rna_prop_ui import PropertyPanel
+
+
+class WorkSpaceButtonsPanel:
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "workspace"
+
+
+class WORKSPACE_PT_context(WorkSpaceButtonsPanel, Panel):
+    bl_label = ""
+    bl_options = {'HIDE_HEADER'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        workspace = context.workspace
+        layout.prop(workspace, "use_scene_settings", icon='SCENE')
+
+
+class WORKSPACE_PT_workspace(WorkSpaceButtonsPanel, Panel):
+    bl_label = "Workspace"
+
+    def draw(self, context):
+        layout = self.layout
+
+        workspace = context.workspace
+        scene = context.scene
+
+        layout.enabled = not workspace.use_scene_settings
+
+        layout.template_search(workspace, "render_layer", scene, "render_layers")
+
+        if workspace.has_multiple_engines:
+            layout.prop(workspace, "engine", text="")
+
+
+class WORKSPACE_PT_custom_props(WorkSpaceButtonsPanel, PropertyPanel, Panel):
+    _context_path = "workspace"
+    _property_type = bpy.types.WorkSpace
+
+
+classes = (
+    WORKSPACE_PT_context,
+    WORKSPACE_PT_workspace,
+    WORKSPACE_PT_custom_props,
+)
+
+if __name__ == "__main__":  # only for live edit.
+    from bpy.utils import register_class
+    for cls in classes:
+        register_class(cls)
+
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index f6c15f4d030..8aa4e674d11 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -57,6 +57,7 @@
 #include "BKE_screen.h"
 #include "BKE_texture.h"
 #include "BKE_linestyle.h"
+#include "BKE_workspace.h"
 
 #include "RNA_access.h"
 
@@ -168,29 +169,53 @@ static int buttons_context_path_linestyle(ButsContextPath *path)
 	return 0;
 }
 
+static int buttons_context_path_workspace(ButsContextPath *path)
+{
+	PointerRNA *ptr = &path->ptr[path->len - 1];
+
+	/* This one just verifies. */
+	return RNA_struct_is_a(ptr->type, &RNA_WorkSpace);
+}
+
+static int buttons_context_path_collection(ButsContextPath *path)
+{
+	PointerRNA *ptr = &path->ptr[path->len - 1];
+
+	/* if we already have a (pinned) Collection, we're done */
+	if (RNA_struct_is_a(ptr->type, &RNA_LayerCollection)) {
+		return 1;
+	}
+
+	SceneLayer *sl = ptr->data;
+	LayerCollection *sc = BKE_layer_collection_get_active(sl);
+
+	if (sc) {
+		RNA_pointer_create(NULL, &RNA_LayerCollection, sc, &path->ptr[path->len]);
+		path->len++;
+		return 1;
+	}
+
+	/* no path to a collection possible */
+	return 0;
+}
+
 static int buttons_context_path_object(ButsContextPath *path)
 {
-	Scene *scene;
-	Object *ob;
 	PointerRNA *ptr = &path->ptr[path->len - 1];
 
 	/* if we already have a (pinned) object, we're done */
 	if (RNA_struct_is_a(ptr->type, &RNA_Object)) {
 		return 1;
 	}
-	/* if we have a scene, use the scene's active object */
-	else if (buttons_context_path_scene(path)) {
-		scene = path->ptr[path->len - 1].data;
 
-		SceneLayer *sl = BKE_scene_layer_context_active_PLACEHOLDER(scene);
-		ob = (sl->basact) ? sl->basact->object : NULL;
+	SceneLayer *sl = ptr->data;
+	Object *ob = (sl->basact) ? sl->basact->object : NULL;
 
-		if (ob) {
-			RNA_id_pointer_create(&ob->id, &path->ptr[path->len]);
-			path->len++;
+	if (ob) {
+		RNA_id_pointer_create(&ob->id, &path->ptr[path->len]);
+		path->len++;
 
-			return 1;
-		}
+		return 1;
 	}
 
 	/* no path to a object possible */
@@ -559,39 +584,11 @@ static bool buttons_context_linestyle_pinnable(const bContext *C)
 }
 #endif
 
-static int buttons_context_path_collection(const bContext *C, ButsContextPath *path)
-{
-	PointerRNA *ptr = &path->ptr[path->len - 1];
-
-	/* if we already have a (pinned) Collection, we're done */
-	if (RNA_struct_is_a(ptr->type, &RNA_LayerCollection)) {
-		return 1;
-	}
-
-	SceneLayer *sl = CTX_data_scene_layer(C);
-	LayerCollection *sc = BKE_layer_collection_get_active(sl);
-
-	if (sc) {
-		RNA_pointer_create(NULL, &RNA_LayerCollection, sc, &path->ptr[path->len]);
-		path->len++;
-
-		/* temporary object in context path to get edit mode */
-		Object *ob = CTX_data_active_object(C);
-		if (ob) {
-			RNA_id_pointer_create(&ob->id, &path->ptr[path->len]);
-			path->len++;
-		}
-
-		return 1;
-	}
-
-	/* no path to a collection possible */
-	return 0;
-}
-
 static int buttons_context_path(const bContext *C, ButsContextPath *path, int mainb, int flag)
 {
 	SpaceButs *sbuts = CTX_wm_space_buts(C);
+	Scene *scene = CTX_data_scene(C);
+	WorkSpace *workspace = CTX_wm_workspace(C);
 	ID *id;
 	int found;
 
@@ -599,18 +596,32 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
 	path->flag = flag;
 	path->tex_ctx = sbuts->texture_context;
 
-	/* if some ID datablock is pinned, set the root pointer */
+	const bool use_scene_settings = BKE_workspace_use_scene_settings_get(workspace);
+
+	/* If some ID datablock is pinned, set the root pointer. */
 	if (sbuts->pinid) {
 		id = sbuts->pinid;
 
 		RNA_id_pointer_create(id, &path->ptr[0]);
 		path->len++;
 	}
+	/* No pinned root, use scene or workspace as initial root. */
+	else {
+		if ((mainb != BCONTEXT_WORKSPACE) && (use_scene_settings ||
+		    ELEM(mainb, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_RENDER_LAYER, BCONTEXT_WORLD)))
+		{
+			RNA_id_pointer_create(&scene->id, &path->ptr[0]);
+			path->len++;
+		}
+		else {
+			RNA_id_pointer_create(&workspace->id, &path->ptr[0]);
+			path->len++;
+		}
+	}
 
-	/* no pinned root, use scene as root */
-	if (path->len == 0) {
-		id = (ID *)CTX_data_scene(C);
-		RNA_id_pointer_create(id, &path->ptr[0]);
+	if (!ELEM(mainb, BCONTEXT_WORKSPACE, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_RENDER_LAYER, BCONTEXT_WORLD)) {
+		SceneLayer *scene_layer = BKE_scene_layer_from_workspace_get(scene, workspace);
+		RNA_pointer_create(NULL, &RNA_SceneLayer, scene_layer, &path->ptr[path->len]);
 		path->len++;
 	}
 
@@ -635,6 +646,12 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
 		case BCONTEXT_WORLD:
 			found = buttons_context_path_world(path);
 			break;
+		case BCONTEXT_WORKSPACE:
+			found = buttons_context_path_workspace(path);
+			break;
+		case BCONTEXT_COLLECTION:
+			found = buttons_context_path_collection(path);
+			break;
 		case BCONTEXT_OBJECT:
 		case BCONTEXT_PHYSICS:
 		case BCONTEXT_CONSTRAINT:
@@ -663,9 +680,6 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
 		case BCONTEXT_BONE_CONSTRAINT:
 			found = buttons_context_path_pose_bone(path);
 			break;
-		case BCONTEXT_COLLECTION:
-			found = buttons_context_path_collection(C, path);
-			break;
 		default:
 			found = 0;
 			break;
@@ -783,7 +797,7 @@ const char *buttons_context_dir[] = {
 	"texture", "texture_user", "texture_user_property", "bone", "edit_bone",
 	"pose_bone", "particle_system", "particle_system_editable", "particle_settings",
 	"cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint",
-	"line_style", "collection", NULL
+	"line_style", "collection", "workspace", NULL
 };
 
 int buttons_context(const bContext *C, const char *member, bContextDataResult *result)
@@ -812,6 +826,10 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
 		set_pointer_type(path, result, &RNA_World);
 		return 1;
 	}
+	else if (CTX_data_equals(member, "workspace")) {
+		/* Do not return one here if scene not found in path, in this case we want to get default context scene! */
+		return set_pointer_type(path, result, &RNA_WorkSpace);
+	}
 	else if (CTX_data_equals(member, "object")) {
 		set_pointer_type(path, result, &RNA_Object);
 		return 1;
@@ -1168,10 +1186,14 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
 			name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL);
 
 			if (name) {
-				if (!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_RENDER_LAYER) && ptr->type == &RNA_Scene)
+				if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_RENDER_LAYER) && ptr->type == &RNA_Scene) ||
+				    (!ELEM(sbuts->mainb, BCONTEXT_WORKSPACE) && ptr->type == &RNA_WorkSpace))
+				{
 					uiItemLDrag(row, ptr, "", icon);  /* save some space */
-				else
+				}
+				else {
 					uiItemLDrag(row, ptr, name, icon);
+				}
 
 				if (name != namebuf)
 					MEM_freeN(name);
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index 9373b3e56cf..c2b0b3cdcc0 100644
--- a/source/blender/ed

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list