Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/asset/intern/asset_ops.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| /** \file | /** \file | ||||
| * \ingroup edasset | * \ingroup edasset | ||||
| */ | */ | ||||
| #include "BKE_asset_library.hh" | #include "AS_asset_library.h" | ||||
| #include "AS_asset_library.hh" | |||||
| #include "BKE_bpath.h" | #include "BKE_bpath.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_preferences.h" | #include "BKE_preferences.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| ▲ Show 20 Lines • Show All 424 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static int asset_catalog_new_exec(bContext *C, wmOperator *op) | static int asset_catalog_new_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| SpaceFile *sfile = CTX_wm_space_file(C); | SpaceFile *sfile = CTX_wm_space_file(C); | ||||
| struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile); | struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile); | ||||
| char *parent_path = RNA_string_get_alloc(op->ptr, "parent_path", nullptr, 0, nullptr); | char *parent_path = RNA_string_get_alloc(op->ptr, "parent_path", nullptr, 0, nullptr); | ||||
| blender::bke::AssetCatalog *new_catalog = ED_asset_catalog_add( | blender::asset_system::AssetCatalog *new_catalog = ED_asset_catalog_add( | ||||
| asset_library, "Catalog", parent_path); | asset_library, "Catalog", parent_path); | ||||
| if (sfile) { | if (sfile) { | ||||
| ED_fileselect_activate_asset_catalog(sfile, new_catalog->catalog_id); | ED_fileselect_activate_asset_catalog(sfile, new_catalog->catalog_id); | ||||
| } | } | ||||
| MEM_freeN(parent_path); | MEM_freeN(parent_path); | ||||
| Show All 22 Lines | RNA_def_string(ot->srna, | ||||
| "Optional path defining the location to put the new catalog under"); | "Optional path defining the location to put the new catalog under"); | ||||
| } | } | ||||
| static int asset_catalog_delete_exec(bContext *C, wmOperator *op) | static int asset_catalog_delete_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| SpaceFile *sfile = CTX_wm_space_file(C); | SpaceFile *sfile = CTX_wm_space_file(C); | ||||
| struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile); | struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile); | ||||
| char *catalog_id_str = RNA_string_get_alloc(op->ptr, "catalog_id", nullptr, 0, nullptr); | char *catalog_id_str = RNA_string_get_alloc(op->ptr, "catalog_id", nullptr, 0, nullptr); | ||||
| bke::CatalogID catalog_id; | asset_system::CatalogID catalog_id; | ||||
| if (!BLI_uuid_parse_string(&catalog_id, catalog_id_str)) { | if (!BLI_uuid_parse_string(&catalog_id, catalog_id_str)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ED_asset_catalog_remove(asset_library, catalog_id); | ED_asset_catalog_remove(asset_library, catalog_id); | ||||
| MEM_freeN(catalog_id_str); | MEM_freeN(catalog_id_str); | ||||
| Show All 14 Lines | static void ASSET_OT_catalog_delete(struct wmOperatorType *ot) | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = asset_catalog_delete_exec; | ot->exec = asset_catalog_delete_exec; | ||||
| ot->poll = asset_catalog_operator_poll; | ot->poll = asset_catalog_operator_poll; | ||||
| RNA_def_string(ot->srna, "catalog_id", nullptr, 0, "Catalog ID", "ID of the catalog to delete"); | RNA_def_string(ot->srna, "catalog_id", nullptr, 0, "Catalog ID", "ID of the catalog to delete"); | ||||
| } | } | ||||
| static bke::AssetCatalogService *get_catalog_service(bContext *C) | static asset_system::AssetCatalogService *get_catalog_service(bContext *C) | ||||
| { | { | ||||
| const SpaceFile *sfile = CTX_wm_space_file(C); | const SpaceFile *sfile = CTX_wm_space_file(C); | ||||
| if (!sfile) { | if (!sfile) { | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| AssetLibrary *asset_lib = ED_fileselect_active_asset_library_get(sfile); | AssetLibrary *asset_lib = ED_fileselect_active_asset_library_get(sfile); | ||||
| return BKE_asset_library_get_catalog_service(asset_lib); | return AS_asset_library_get_catalog_service(asset_lib); | ||||
| } | } | ||||
| static int asset_catalog_undo_exec(bContext *C, wmOperator * /*op*/) | static int asset_catalog_undo_exec(bContext *C, wmOperator * /*op*/) | ||||
| { | { | ||||
| bke::AssetCatalogService *catalog_service = get_catalog_service(C); | asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); | ||||
| if (!catalog_service) { | if (!catalog_service) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| catalog_service->undo(); | catalog_service->undo(); | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static bool asset_catalog_undo_poll(bContext *C) | static bool asset_catalog_undo_poll(bContext *C) | ||||
| { | { | ||||
| const bke::AssetCatalogService *catalog_service = get_catalog_service(C); | const asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); | ||||
| return catalog_service && catalog_service->is_undo_possbile(); | return catalog_service && catalog_service->is_undo_possbile(); | ||||
| } | } | ||||
| static void ASSET_OT_catalog_undo(struct wmOperatorType *ot) | static void ASSET_OT_catalog_undo(struct wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Undo Catalog Edits"; | ot->name = "Undo Catalog Edits"; | ||||
| ot->description = "Undo the last edit to the asset catalogs"; | ot->description = "Undo the last edit to the asset catalogs"; | ||||
| ot->idname = "ASSET_OT_catalog_undo"; | ot->idname = "ASSET_OT_catalog_undo"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = asset_catalog_undo_exec; | ot->exec = asset_catalog_undo_exec; | ||||
| ot->poll = asset_catalog_undo_poll; | ot->poll = asset_catalog_undo_poll; | ||||
| } | } | ||||
| static int asset_catalog_redo_exec(bContext *C, wmOperator * /*op*/) | static int asset_catalog_redo_exec(bContext *C, wmOperator * /*op*/) | ||||
| { | { | ||||
| bke::AssetCatalogService *catalog_service = get_catalog_service(C); | asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); | ||||
| if (!catalog_service) { | if (!catalog_service) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| catalog_service->redo(); | catalog_service->redo(); | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static bool asset_catalog_redo_poll(bContext *C) | static bool asset_catalog_redo_poll(bContext *C) | ||||
| { | { | ||||
| const bke::AssetCatalogService *catalog_service = get_catalog_service(C); | const asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); | ||||
| return catalog_service && catalog_service->is_redo_possbile(); | return catalog_service && catalog_service->is_redo_possbile(); | ||||
| } | } | ||||
| static void ASSET_OT_catalog_redo(struct wmOperatorType *ot) | static void ASSET_OT_catalog_redo(struct wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Redo Catalog Edits"; | ot->name = "Redo Catalog Edits"; | ||||
| ot->description = "Redo the last undone edit to the asset catalogs"; | ot->description = "Redo the last undone edit to the asset catalogs"; | ||||
| ot->idname = "ASSET_OT_catalog_redo"; | ot->idname = "ASSET_OT_catalog_redo"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = asset_catalog_redo_exec; | ot->exec = asset_catalog_redo_exec; | ||||
| ot->poll = asset_catalog_redo_poll; | ot->poll = asset_catalog_redo_poll; | ||||
| } | } | ||||
| static int asset_catalog_undo_push_exec(bContext *C, wmOperator * /*op*/) | static int asset_catalog_undo_push_exec(bContext *C, wmOperator * /*op*/) | ||||
| { | { | ||||
| bke::AssetCatalogService *catalog_service = get_catalog_service(C); | asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); | ||||
| if (!catalog_service) { | if (!catalog_service) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| catalog_service->undo_push(); | catalog_service->undo_push(); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| Show All 26 Lines | static bool asset_catalogs_save_poll(bContext *C) | ||||
| } | } | ||||
| const Main *bmain = CTX_data_main(C); | const Main *bmain = CTX_data_main(C); | ||||
| if (!bmain->filepath[0]) { | if (!bmain->filepath[0]) { | ||||
| CTX_wm_operator_poll_msg_set(C, "Cannot save asset catalogs before the Blender file is saved"); | CTX_wm_operator_poll_msg_set(C, "Cannot save asset catalogs before the Blender file is saved"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!BKE_asset_library_has_any_unsaved_catalogs()) { | if (!AS_asset_library_has_any_unsaved_catalogs()) { | ||||
| CTX_wm_operator_poll_msg_set(C, "No changes to be saved"); | CTX_wm_operator_poll_msg_set(C, "No changes to be saved"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int asset_catalogs_save_exec(bContext *C, wmOperator * /*op*/) | static int asset_catalogs_save_exec(bContext *C, wmOperator * /*op*/) | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | static int asset_bundle_install_exec(bContext *C, wmOperator *op) | ||||
| /* Check that the destination is actually contained in the selected asset library. */ | /* Check that the destination is actually contained in the selected asset library. */ | ||||
| if (!is_contained_in_selected_asset_library(op, filepath)) { | if (!is_contained_in_selected_asset_library(op, filepath)) { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "Selected path is outside of the selected asset library"); | BKE_reportf(op->reports, RPT_ERROR, "Selected path is outside of the selected asset library"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| WM_cursor_wait(true); | WM_cursor_wait(true); | ||||
| bke::AssetCatalogService *cat_service = get_catalog_service(C); | asset_system::AssetCatalogService *cat_service = get_catalog_service(C); | ||||
| /* Store undo step, such that on a failed save the 'prepare_to_merge_on_write' call can be | /* Store undo step, such that on a failed save the 'prepare_to_merge_on_write' call can be | ||||
| * un-done. */ | * un-done. */ | ||||
| cat_service->undo_push(); | cat_service->undo_push(); | ||||
| cat_service->prepare_to_merge_on_write(); | cat_service->prepare_to_merge_on_write(); | ||||
| const int operator_result = WM_operator_name_call( | const int operator_result = WM_operator_name_call( | ||||
| C, "WM_OT_save_mainfile", WM_OP_EXEC_DEFAULT, op->ptr, nullptr); | C, "WM_OT_save_mainfile", WM_OP_EXEC_DEFAULT, op->ptr, nullptr); | ||||
| WM_cursor_wait(false); | WM_cursor_wait(false); | ||||
| ▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines | |||||