Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_buttons/buttons_context.c
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_texture.h" | #include "BKE_texture.h" | ||||
| #include "BKE_linestyle.h" | #include "BKE_linestyle.h" | ||||
| #include "BKE_workspace.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "ED_buttons.h" | #include "ED_buttons.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_physics.h" | #include "ED_physics.h" | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (linestyle) { | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| /* no path to a linestyle possible */ | /* no path to a linestyle possible */ | ||||
| return 0; | 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) | static int buttons_context_path_object(ButsContextPath *path) | ||||
| { | { | ||||
| Scene *scene; | |||||
| Object *ob; | |||||
| PointerRNA *ptr = &path->ptr[path->len - 1]; | PointerRNA *ptr = &path->ptr[path->len - 1]; | ||||
| /* if we already have a (pinned) object, we're done */ | /* if we already have a (pinned) object, we're done */ | ||||
| if (RNA_struct_is_a(ptr->type, &RNA_Object)) { | if (RNA_struct_is_a(ptr->type, &RNA_Object)) { | ||||
| return 1; | 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); | SceneLayer *sl = ptr->data; | ||||
| ob = (sl->basact) ? sl->basact->object : NULL; | Object *ob = (sl->basact) ? sl->basact->object : NULL; | ||||
| if (ob) { | if (ob) { | ||||
| RNA_id_pointer_create(&ob->id, &path->ptr[path->len]); | RNA_id_pointer_create(&ob->id, &path->ptr[path->len]); | ||||
| path->len++; | path->len++; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | |||||
| /* no path to a object possible */ | /* no path to a object possible */ | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static int buttons_context_path_data(ButsContextPath *path, int type) | static int buttons_context_path_data(ButsContextPath *path, int type) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| ▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Lines | static bool buttons_context_linestyle_pinnable(const bContext *C) | ||||
| sbuts = CTX_wm_space_buts(C); | sbuts = CTX_wm_space_buts(C); | ||||
| if (sbuts->pinid && sbuts->pinid == &scene->id) { | if (sbuts->pinid && sbuts->pinid == &scene->id) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| #endif | #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) | static int buttons_context_path(const bContext *C, ButsContextPath *path, int mainb, int flag) | ||||
| { | { | ||||
| SpaceButs *sbuts = CTX_wm_space_buts(C); | SpaceButs *sbuts = CTX_wm_space_buts(C); | ||||
| Scene *scene = CTX_data_scene(C); | |||||
| WorkSpace *workspace = CTX_wm_workspace(C); | |||||
| ID *id; | ID *id; | ||||
| int found; | int found; | ||||
| memset(path, 0, sizeof(*path)); | memset(path, 0, sizeof(*path)); | ||||
| path->flag = flag; | path->flag = flag; | ||||
| path->tex_ctx = sbuts->texture_context; | 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) { | if (sbuts->pinid) { | ||||
| id = sbuts->pinid; | id = sbuts->pinid; | ||||
| RNA_id_pointer_create(id, &path->ptr[0]); | RNA_id_pointer_create(id, &path->ptr[0]); | ||||
| path->len++; | 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 (!ELEM(mainb, BCONTEXT_WORKSPACE, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_RENDER_LAYER, BCONTEXT_WORLD)) { | ||||
| if (path->len == 0) { | SceneLayer *scene_layer = BKE_scene_layer_from_workspace_get(scene, workspace); | ||||
| id = (ID *)CTX_data_scene(C); | RNA_pointer_create(NULL, &RNA_SceneLayer, scene_layer, &path->ptr[path->len]); | ||||
| RNA_id_pointer_create(id, &path->ptr[0]); | |||||
| path->len++; | path->len++; | ||||
| } | } | ||||
| /* now for each buttons context type, we try to construct a path, | /* now for each buttons context type, we try to construct a path, | ||||
| * tracing back recursively */ | * tracing back recursively */ | ||||
| switch (mainb) { | switch (mainb) { | ||||
| case BCONTEXT_SCENE: | case BCONTEXT_SCENE: | ||||
| case BCONTEXT_RENDER: | case BCONTEXT_RENDER: | ||||
| found = buttons_context_path_scene(path); | found = buttons_context_path_scene(path); | ||||
| break; | break; | ||||
| case BCONTEXT_RENDER_LAYER: | case BCONTEXT_RENDER_LAYER: | ||||
| #ifdef WITH_FREESTYLE | #ifdef WITH_FREESTYLE | ||||
| if (buttons_context_linestyle_pinnable(C)) { | if (buttons_context_linestyle_pinnable(C)) { | ||||
| found = buttons_context_path_linestyle(path); | found = buttons_context_path_linestyle(path); | ||||
| if (found) { | if (found) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| found = buttons_context_path_scene(path); | found = buttons_context_path_scene(path); | ||||
| break; | break; | ||||
| case BCONTEXT_WORLD: | case BCONTEXT_WORLD: | ||||
| found = buttons_context_path_world(path); | found = buttons_context_path_world(path); | ||||
| break; | 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_OBJECT: | ||||
| case BCONTEXT_PHYSICS: | case BCONTEXT_PHYSICS: | ||||
| case BCONTEXT_CONSTRAINT: | case BCONTEXT_CONSTRAINT: | ||||
| found = buttons_context_path_object(path); | found = buttons_context_path_object(path); | ||||
| break; | break; | ||||
| case BCONTEXT_MODIFIER: | case BCONTEXT_MODIFIER: | ||||
| found = buttons_context_path_modifier(path); | found = buttons_context_path_modifier(path); | ||||
| break; | break; | ||||
| Show All 12 Lines | #endif | ||||
| case BCONTEXT_BONE: | case BCONTEXT_BONE: | ||||
| found = buttons_context_path_bone(path); | found = buttons_context_path_bone(path); | ||||
| if (!found) | if (!found) | ||||
| found = buttons_context_path_data(path, OB_ARMATURE); | found = buttons_context_path_data(path, OB_ARMATURE); | ||||
| break; | break; | ||||
| case BCONTEXT_BONE_CONSTRAINT: | case BCONTEXT_BONE_CONSTRAINT: | ||||
| found = buttons_context_path_pose_bone(path); | found = buttons_context_path_pose_bone(path); | ||||
| break; | break; | ||||
| case BCONTEXT_COLLECTION: | |||||
| found = buttons_context_path_collection(C, path); | |||||
| break; | |||||
| default: | default: | ||||
| found = 0; | found = 0; | ||||
| break; | break; | ||||
| } | } | ||||
| return found; | return found; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
| /************************* Context Callback ************************/ | /************************* Context Callback ************************/ | ||||
| const char *buttons_context_dir[] = { | const char *buttons_context_dir[] = { | ||||
| "texture_slot", "scene", "world", "object", "mesh", "armature", "lattice", "curve", | "texture_slot", "scene", "world", "object", "mesh", "armature", "lattice", "curve", | ||||
| "meta_ball", "lamp", "speaker", "lightprobe", "camera", "material", "material_slot", | "meta_ball", "lamp", "speaker", "lightprobe", "camera", "material", "material_slot", | ||||
| "texture", "texture_user", "texture_user_property", "bone", "edit_bone", | "texture", "texture_user", "texture_user_property", "bone", "edit_bone", | ||||
| "pose_bone", "particle_system", "particle_system_editable", "particle_settings", | "pose_bone", "particle_system", "particle_system_editable", "particle_settings", | ||||
| "cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint", | "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) | int buttons_context(const bContext *C, const char *member, bContextDataResult *result) | ||||
| { | { | ||||
| SpaceButs *sbuts = CTX_wm_space_buts(C); | SpaceButs *sbuts = CTX_wm_space_buts(C); | ||||
| ButsContextPath *path = sbuts ? sbuts->path : NULL; | ButsContextPath *path = sbuts ? sbuts->path : NULL; | ||||
| if (!path) | if (!path) | ||||
| Show All 12 Lines | int buttons_context(const bContext *C, const char *member, bContextDataResult *result) | ||||
| else if (CTX_data_equals(member, "scene")) { | else if (CTX_data_equals(member, "scene")) { | ||||
| /* Do not return one here if scene not found in path, in this case we want to get default context scene! */ | /* 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_Scene); | return set_pointer_type(path, result, &RNA_Scene); | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "world")) { | else if (CTX_data_equals(member, "world")) { | ||||
| set_pointer_type(path, result, &RNA_World); | set_pointer_type(path, result, &RNA_World); | ||||
| return 1; | 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")) { | else if (CTX_data_equals(member, "object")) { | ||||
| set_pointer_type(path, result, &RNA_Object); | set_pointer_type(path, result, &RNA_Object); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "mesh")) { | else if (CTX_data_equals(member, "mesh")) { | ||||
| set_pointer_type(path, result, &RNA_Mesh); | set_pointer_type(path, result, &RNA_Mesh); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | for (a = 0; a < path->len; a++) { | ||||
| if (a != 0) | if (a != 0) | ||||
| uiItemL(row, "", VICO_SMALL_TRI_RIGHT_VEC); | uiItemL(row, "", VICO_SMALL_TRI_RIGHT_VEC); | ||||
| if (ptr->data) { | if (ptr->data) { | ||||
| icon = RNA_struct_ui_icon(ptr->type); | icon = RNA_struct_ui_icon(ptr->type); | ||||
| name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL); | name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL); | ||||
| if (name) { | 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 */ | uiItemLDrag(row, ptr, "", icon); /* save some space */ | ||||
| else | } | ||||
| else { | |||||
| uiItemLDrag(row, ptr, name, icon); | uiItemLDrag(row, ptr, name, icon); | ||||
| } | |||||
| if (name != namebuf) | if (name != namebuf) | ||||
| MEM_freeN(name); | MEM_freeN(name); | ||||
| } | } | ||||
| else | else | ||||
| uiItemL(row, "", icon); | uiItemL(row, "", icon); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines | |||||