Changeset View
Standalone View
source/blender/editors/space_view3d/space_view3d.c
| Show First 20 Lines • Show All 513 Lines • ▼ Show 20 Lines | static bool view3d_drop_id_in_main_region_poll(bContext *C, | ||||
| return WM_drag_is_ID_type(drag, id_type); | return WM_drag_is_ID_type(drag, id_type); | ||||
| } | } | ||||
| static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB); | return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB); | ||||
| } | } | ||||
| static bool view3d_ob_drop_poll_asset(bContext *C, wmDrag *drag, const wmEvent *event) | |||||
| { | |||||
| if (!view3d_ob_drop_poll(C, drag, event) || (drag->type != WM_DRAG_ASSET)) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static bool view3d_ob_drop_poll_non_asset(bContext *C, wmDrag *drag, const wmEvent *event) | |||||
Severin: The distinction here isn't if something is an asset or not, but if something is an external… | |||||
Done Inline ActionsWould suggest view3d_ob_drop_poll_local_id(), since not every ID is an asset. This will also be the version executed when dragging from the Outliner, which of course isn't asset specific at all. Just note in a comment that this local ID may also be an asset. Severin: Would suggest `view3d_ob_drop_poll_local_id()`, since not every ID is an asset. This will also… | |||||
Done Inline ActionsRenamed to local_id to avoid too many iterations on this patch, I'm concerned this would be confused with local-id / linked-id terminology which is used throughout the code-base. While non_external_asset reads awkwardly, at least it's clear whats happening. campbellbarton: Renamed to `local_id` to avoid too many iterations on this patch, I'm concerned this would be… | |||||
Not Done Inline Actions
I'd argue against that. non_external_asset to me means an asset that isn't external, so local. However this is also used for IDs that are not marked as assets. Severin: > While `non_external_asset` reads awkwardly, at least it's clear whats happening.
I'd argue… | |||||
| { | |||||
| if (!view3d_ob_drop_poll(C, drag, event) || (drag->type == WM_DRAG_ASSET)) { | |||||
Done Inline ActionsTogether with the suggested naming change, I'd change this to check drag->type != WM_DRAG_ID. Severin: Together with the suggested naming change, I'd change this to check `drag->type != WM_DRAG_ID`. | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static bool view3d_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | static bool view3d_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| return view3d_drop_id_in_main_region_poll(C, drag, event, ID_GR); | return view3d_drop_id_in_main_region_poll(C, drag, event, ID_GR); | ||||
| } | } | ||||
| static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
| static bool view3d_volume_drop_poll(bContext *UNUSED(C), | static bool view3d_volume_drop_poll(bContext *UNUSED(C), | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *UNUSED(event)) | const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| return (drag->type == WM_DRAG_PATH) && (drag->icon == ICON_FILE_VOLUME); | return (drag->type == WM_DRAG_PATH) && (drag->icon == ICON_FILE_VOLUME); | ||||
| } | } | ||||
| static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop) | static void view3d_ob_drop_copy_non_asset(wmDrag *drag, wmDropBox *drop) | ||||
Not Done Inline Actionsview3d_ob_drop_copy_local_id()? Severin: `view3d_ob_drop_copy_local_id()`? | |||||
| { | { | ||||
| BLI_assert(drag->type != WM_DRAG_ASSET); | |||||
| ID *id = WM_drag_get_local_ID(drag, ID_OB); | |||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | |||||
| } | |||||
| static void view3d_ob_drop_copy_asset(wmDrag *drag, wmDropBox *drop) | |||||
| { | |||||
| BLI_assert(drag->type == WM_DRAG_ASSET); | |||||
| ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_OB); | ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_OB); | ||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | RNA_string_set(drop->ptr, "name", id->name + 2); | ||||
| /* Don't duplicate ID's which were just imported. Only do that for existing, local IDs. */ | |||||
| const bool is_imported_id = drag->type == WM_DRAG_ASSET; | |||||
| RNA_boolean_set(drop->ptr, "duplicate", !is_imported_id); | |||||
| } | } | ||||
| static void view3d_collection_drop_copy(wmDrag *drag, wmDropBox *drop) | static void view3d_collection_drop_copy(wmDrag *drag, wmDropBox *drop) | ||||
| { | { | ||||
| ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR); | ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR); | ||||
| RNA_string_set(drop->ptr, "name", id->name + 2); | RNA_string_set(drop->ptr, "name", id->name + 2); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | static void view3d_lightcache_update(bContext *C) | ||||
| WM_operator_properties_free(&op_ptr); | WM_operator_properties_free(&op_ptr); | ||||
| } | } | ||||
| /* region dropbox definition */ | /* region dropbox definition */ | ||||
| static void view3d_dropboxes(void) | static void view3d_dropboxes(void) | ||||
| { | { | ||||
| ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW); | ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW); | ||||
| /* Assets have separate logic. */ | |||||
| WM_dropbox_add(lb, | WM_dropbox_add(lb, | ||||
| "OBJECT_OT_add_named", | "OBJECT_OT_add_named", | ||||
| view3d_ob_drop_poll, | view3d_ob_drop_poll_non_asset, | ||||
| view3d_ob_drop_copy, | view3d_ob_drop_copy_non_asset, | ||||
| WM_drag_free_imported_drag_ID, | |||||
| NULL); | |||||
| WM_dropbox_add(lb, | |||||
| "OBJECT_OT_transform_to_mouse", | |||||
| view3d_ob_drop_poll_asset, | |||||
| view3d_ob_drop_copy_asset, | |||||
| WM_drag_free_imported_drag_ID, | WM_drag_free_imported_drag_ID, | ||||
| NULL); | NULL); | ||||
| WM_dropbox_add(lb, | WM_dropbox_add(lb, | ||||
| "OBJECT_OT_drop_named_material", | "OBJECT_OT_drop_named_material", | ||||
| view3d_mat_drop_poll, | view3d_mat_drop_poll, | ||||
| view3d_id_drop_copy, | view3d_id_drop_copy, | ||||
| WM_drag_free_imported_drag_ID, | WM_drag_free_imported_drag_ID, | ||||
| view3d_mat_drop_tooltip); | view3d_mat_drop_tooltip); | ||||
| ▲ Show 20 Lines • Show All 1,095 Lines • Show Last 20 Lines | |||||
The distinction here isn't if something is an asset or not, but if something is an external asset that has to be imported first, or a local ID, which may well be marked as asset too.
In hindsight, I find WM_DRAG_ASSET to be named badly, and reusing WM_DRAG_ID for local ID asset makes things even more confusing. Instead there should be WM_DRAG_ASSET_EXTERNAL and WM_DRAG_ASSET_LOCAL_ID or similar, but that's a separate cleanup.