Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_dragdrop.c
| Show First 20 Lines • Show All 429 Lines • ▼ Show 20 Lines | wmDragAsset *WM_drag_get_asset_data(const wmDrag *drag, int idcode) | ||||
| if (drag->type != WM_DRAG_ASSET) { | if (drag->type != WM_DRAG_ASSET) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| wmDragAsset *asset_drag = drag->poin; | wmDragAsset *asset_drag = drag->poin; | ||||
| return (ELEM(idcode, 0, asset_drag->id_type)) ? asset_drag : NULL; | return (ELEM(idcode, 0, asset_drag->id_type)) ? asset_drag : NULL; | ||||
| } | } | ||||
| static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag) | static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag, eFileSel_Params_Flag flag) | ||||
| { | { | ||||
| /* Only support passing in limited flags. */ | |||||
| BLI_assert(flag == (flag & FILE_AUTOSELECT)); | |||||
| const char *name = asset_drag->name; | const char *name = asset_drag->name; | ||||
| ID_Type idtype = asset_drag->id_type; | ID_Type idtype = asset_drag->id_type; | ||||
| /* 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); | ||||
| 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, | return WM_file_link_datablock( | ||||
| scene, | bmain, scene, view_layer, view3d, asset_drag->path, idtype, name, flag); | ||||
| view_layer, | |||||
| 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, | return WM_file_append_datablock(bmain, | ||||
| scene, | scene, | ||||
Severin: Could we keep this object specific logic in `view3d_ob_drop_copy_asset()`? | |||||
| 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_ASSET_DATA_CLEAR); | BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR); | ||||
| case FILE_ASSET_IMPORT_APPEND_REUSE: | case FILE_ASSET_IMPORT_APPEND_REUSE: | ||||
| return WM_file_append_datablock(G_MAIN, | return 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_ASSET_DATA_CLEAR | | BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR | | ||||
| BLO_LIBLINK_APPEND_LOCAL_ID_REUSE); | BLO_LIBLINK_APPEND_LOCAL_ID_REUSE); | ||||
| } | } | ||||
| BLI_assert_unreachable(); | BLI_assert_unreachable(); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /** | /** | ||||
| * 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. | ||||
| * | |||||
| * \param flag: #eFileSel_Params_Flag passed to linking code. | |||||
| */ | */ | ||||
| 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_ex(const wmDrag *drag, int idcode, int flag) | ||||
SeverinUnsubmitted 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; | ||||
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. | |||||
Done Inline ActionsComment added to: view3d_ob_drop_copy_non_external_asset campbellbarton: Comment added to: `view3d_ob_drop_copy_non_external_asset` | |||||
| } | } | ||||
| 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); | ||||
| } | } | ||||
| wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, idcode); | wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, idcode); | ||||
| if (!asset_drag) { | if (!asset_drag) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Link/append the asset. */ | /* Link/append the asset. */ | ||||
| return wm_drag_asset_id_import(asset_drag); | ID *id = wm_drag_asset_id_import(asset_drag, flag); | ||||
| return id; | |||||
| } | |||||
| ID *WM_drag_get_local_ID_or_import_from_asset(const wmDrag *drag, int idcode) | |||||
| { | |||||
| return WM_drag_get_local_ID_or_import_from_asset_ex(drag, idcode, 0); | |||||
| } | } | ||||
| /** | /** | ||||
| * \brief Free asset ID imported for canceled drop. | * \brief Free asset ID imported for canceled drop. | ||||
| * | * | ||||
| * If the asset was imported (linked/appended) using #WM_drag_get_local_ID_or_import_from_asset()` | * If the asset was imported (linked/appended) using #WM_drag_get_local_ID_or_import_from_asset()` | ||||
| * (typically via a #wmDropBox.copy() callback), we want the ID to be removed again if the drop | * (typically via a #wmDropBox.copy() callback), we want the ID to be removed again if the drop | ||||
| * operator cancels. | * operator cancels. | ||||
| ▲ Show 20 Lines • Show All 241 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.