Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_dragdrop.c
| Show All 35 Lines | |||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_math_color.h" | #include "BLI_math_color.h" | ||||
| #include "BIF_glutil.h" | #include "BIF_glutil.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_idtype.h" | #include "BKE_idtype.h" | ||||
| #include "BKE_layer.h" | |||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BLO_readfile.h" | #include "BLO_readfile.h" | ||||
| #include "ED_asset.h" | #include "ED_asset.h" | ||||
| #include "ED_outliner.h" | |||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_state.h" | #include "GPU_state.h" | ||||
| #include "GPU_viewport.h" | #include "GPU_viewport.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_interface_icons.h" | #include "UI_interface_icons.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "wm_event_system.h" | #include "wm_event_system.h" | ||||
| #include "DEG_depsgraph.h" | |||||
| #include "DEG_depsgraph_build.h" | |||||
| #include "DEG_depsgraph_query.h" | |||||
| /* ****************************************************** */ | /* ****************************************************** */ | ||||
| static ListBase dropboxes = {NULL, NULL}; | static ListBase dropboxes = {NULL, NULL}; | ||||
| static void wm_drag_free_asset_data(wmDragAsset **asset_data); | static void wm_drag_free_asset_data(wmDragAsset **asset_data); | ||||
| /* drop box maps are stored global for now */ | /* drop box maps are stored global for now */ | ||||
| /* these are part of blender's UI/space specs, and not like keymaps */ | /* these are part of blender's UI/space specs, and not like keymaps */ | ||||
| ▲ Show 20 Lines • Show All 368 Lines • ▼ Show 20 Lines | static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag) | ||||
| /* FIXME: Link/Append should happens in the operator called at the end of drop process, not from | /* FIXME: Link/Append should happens in the operator called at the end of drop process, not from | ||||
| * here. */ | * here. */ | ||||
| Main *bmain = CTX_data_main(asset_drag->evil_C); | Main *bmain = CTX_data_main(asset_drag->evil_C); | ||||
| Scene *scene = CTX_data_scene(asset_drag->evil_C); | Scene *scene = CTX_data_scene(asset_drag->evil_C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(asset_drag->evil_C); | ViewLayer *view_layer = CTX_data_view_layer(asset_drag->evil_C); | ||||
| View3D *view3d = CTX_wm_view3d(asset_drag->evil_C); | View3D *view3d = CTX_wm_view3d(asset_drag->evil_C); | ||||
| int flag = FILE_ACTIVE_COLLECTION; | |||||
| if (idtype == ID_OB) { | |||||
| /* When linking objects, select the newly added objects | |||||
| * so they can be placed at the mouse cursor using #OBJECT_OT_add_named. */ | |||||
| BKE_view_layer_base_deselect_all(view_layer); | |||||
| flag |= FILE_AUTOSELECT; | |||||
| } | |||||
Severin: Could we keep this object specific logic in `view3d_ob_drop_copy_asset()`? | |||||
| ID *id = NULL; | |||||
| switch ((eFileAssetImportType)asset_drag->import_type) { | switch ((eFileAssetImportType)asset_drag->import_type) { | ||||
| case FILE_ASSET_IMPORT_LINK: | case FILE_ASSET_IMPORT_LINK: | ||||
| return WM_file_link_datablock(bmain, | id = WM_file_link_datablock( | ||||
| scene, | bmain, scene, view_layer, view3d, asset_drag->path, idtype, name, flag); | ||||
| view_layer, | break; | ||||
| view3d, | |||||
| asset_drag->path, | |||||
| idtype, | |||||
| name, | |||||
| FILE_ACTIVE_COLLECTION); | |||||
| case FILE_ASSET_IMPORT_APPEND: | case FILE_ASSET_IMPORT_APPEND: | ||||
| return WM_file_append_datablock(bmain, | id = WM_file_append_datablock(bmain, | ||||
| scene, | scene, | ||||
| view_layer, | view_layer, | ||||
| view3d, | view3d, | ||||
| asset_drag->path, | asset_drag->path, | ||||
| idtype, | idtype, | ||||
| name, | name, | ||||
| BLO_LIBLINK_APPEND_RECURSIVE | FILE_ACTIVE_COLLECTION); | flag | BLO_LIBLINK_APPEND_RECURSIVE); | ||||
| break; | |||||
| case FILE_ASSET_IMPORT_APPEND_REUSE: | case FILE_ASSET_IMPORT_APPEND_REUSE: | ||||
| return WM_file_append_datablock(G_MAIN, | id = WM_file_append_datablock(G_MAIN, | ||||
| scene, | scene, | ||||
| view_layer, | view_layer, | ||||
| view3d, | view3d, | ||||
| asset_drag->path, | asset_drag->path, | ||||
| idtype, | idtype, | ||||
| name, | name, | ||||
| BLO_LIBLINK_APPEND_RECURSIVE | FILE_ACTIVE_COLLECTION | | flag | BLO_LIBLINK_APPEND_RECURSIVE | | ||||
| BLO_LIBLINK_APPEND_LOCAL_ID_REUSE); | BLO_LIBLINK_APPEND_LOCAL_ID_REUSE); | ||||
| break; | |||||
| default: | |||||
| BLI_assert_unreachable(); | |||||
| break; | |||||
| } | } | ||||
| BLI_assert_unreachable(); | if (idtype == ID_OB) { | ||||
SeverinUnsubmitted Done Inline ActionsWould add a comment explaining why we deal with selection here. Severin: Would add a comment explaining why we deal with selection here. | |||||
campbellbartonAuthorUnsubmitted Done Inline ActionsComment added to: view3d_ob_drop_copy_non_external_asset campbellbarton: Comment added to: `view3d_ob_drop_copy_non_external_asset` | |||||
| return NULL; | Base *base = id ? BKE_view_layer_base_find(view_layer, (Object *)id) : NULL; | ||||
| if (base != NULL) { | |||||
| BKE_view_layer_base_select_and_set_active(view_layer, base); | |||||
| WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene); | |||||
| } | |||||
| DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | |||||
| ED_outliner_select_sync_from_object_tag(asset_drag->evil_C); | |||||
| } | |||||
| return id; | |||||
| } | } | ||||
| /** | /** | ||||
| * When dragging a local ID, return that. Otherwise, if dragging an asset-handle, link or append | * When dragging a local ID, return that. Otherwise, if dragging an asset-handle, link or append | ||||
| * that depending on what was chosen by the drag-box (currently append only in fact). | * that depending on what was chosen by the drag-box (currently append only in fact). | ||||
| * | * | ||||
| * Use #WM_drag_free_imported_drag_ID() as cancel callback of the drop-box, so that the asset | * Use #WM_drag_free_imported_drag_ID() as cancel callback of the drop-box, so that the asset | ||||
| * import is rolled back if the drop operator fails. | * import is rolled back if the drop operator fails. | ||||
| */ | */ | ||||
| ID *WM_drag_get_local_ID_or_import_from_asset(const wmDrag *drag, int idcode) | ID *WM_drag_get_local_ID_or_import_from_asset(const wmDrag *drag, int idcode) | ||||
Done Inline ActionsNo strong opinion, but what I suggested was making wm_drag_asset_id_import() public and call that directly from view3d_ob_drop_copy_external_asset(). I find that nicer than an _ex() function. Severin: No strong opinion, but what I suggested was making `wm_drag_asset_id_import()` public and call… | |||||
| { | { | ||||
| if (!ELEM(drag->type, WM_DRAG_ASSET, WM_DRAG_ID)) { | if (!ELEM(drag->type, WM_DRAG_ASSET, WM_DRAG_ID)) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (drag->type == WM_DRAG_ID) { | if (drag->type == WM_DRAG_ID) { | ||||
| return WM_drag_get_local_ID(drag, idcode); | return WM_drag_get_local_ID(drag, idcode); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 257 Lines • Show Last 20 Lines | |||||
Could we keep this object specific logic in view3d_ob_drop_copy_asset()? wm_drag_asset_id_import() could become a public function that we can pass FILE_AUTOSELECT to.