Blender  V3.3
asset_ops.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BKE_asset_library.hh"
8 #include "BKE_bpath.h"
9 #include "BKE_context.h"
10 #include "BKE_global.h"
11 #include "BKE_lib_id.h"
12 #include "BKE_main.h"
13 #include "BKE_preferences.h"
14 #include "BKE_report.h"
15 
16 #include "BLI_fileops.h"
17 #include "BLI_fnmatch.h"
18 #include "BLI_path_util.h"
19 #include "BLI_set.hh"
20 
21 #include "ED_asset.h"
22 #include "ED_asset_catalog.hh"
23 #include "ED_screen.h"
24 #include "ED_util.h"
25 /* XXX needs access to the file list, should all be done via the asset system in future. */
26 #include "ED_fileselect.h"
27 
28 #include "BLT_translation.h"
29 
30 #include "RNA_access.h"
31 #include "RNA_define.h"
32 #include "RNA_prototypes.h"
33 
34 #include "WM_api.h"
35 
36 #include "DNA_space_types.h"
37 
38 #include "BLO_writefile.h"
39 
40 using namespace blender;
41 
42 /* -------------------------------------------------------------------- */
43 
45 
51 {
52  PointerRNAVec ids;
53 
54  PointerRNA idptr = CTX_data_pointer_get_type(C, "id", &RNA_ID);
55  if (idptr.data) {
56  /* Single ID. */
57  ids.append(idptr);
58  }
59  else {
60  ListBase list;
61  CTX_data_selected_ids(C, &list);
62  LISTBASE_FOREACH (CollectionPointerLink *, link, &list) {
63  ids.append(link->ptr);
64  }
65  BLI_freelistN(&list);
66  }
67 
68  return ids;
69 }
70 
75 struct IDVecStats {
76  bool has_asset = false;
77  bool has_supported_type = false;
78  bool is_single = false;
79 };
80 
86 {
88  IDVecStats stats;
89 
90  stats.is_single = pointers.size() == 1;
91 
92  for (PointerRNA &ptr : pointers) {
94 
95  ID *id = static_cast<ID *>(ptr.data);
97  stats.has_supported_type = true;
98  }
99  if (ID_IS_ASSET(id)) {
100  stats.has_asset = true;
101  }
102  }
103 
104  return stats;
105 }
106 
107 static const char *asset_operation_unsupported_type_msg(const bool is_single)
108 {
109  const char *msg_single =
110  "Data-block does not support asset operations - must be "
112  const char *msg_multiple =
113  "No data-block selected that supports asset operations - select at least "
115  return is_single ? msg_single : msg_multiple;
116 }
117 
118 /* -------------------------------------------------------------------- */
119 
121  public:
122  void operator()(const bContext &C, PointerRNAVec &ids);
123 
124  void reportResults(ReportList &reports) const;
125  bool wasSuccessful() const;
126 
127  private:
128  struct Stats {
129  int tot_created = 0;
130  int tot_already_asset = 0;
131  ID *last_id = nullptr;
132  };
133 
134  Stats stats;
135 };
136 
138 {
139  for (PointerRNA &ptr : ids) {
141 
142  ID *id = static_cast<ID *>(ptr.data);
143  if (id->asset_data) {
144  stats.tot_already_asset++;
145  continue;
146  }
147 
148  if (ED_asset_mark_id(id)) {
150 
151  stats.last_id = id;
152  stats.tot_created++;
153  }
154  }
155 }
156 
158 {
159  return stats.tot_created > 0;
160 }
161 
163 {
164  /* User feedback on failure. */
165  if (!wasSuccessful()) {
166  if (stats.tot_already_asset > 0) {
167  BKE_report(&reports,
168  RPT_ERROR,
169  "Selected data-blocks are already assets (or do not support use as assets)");
170  }
171  else {
172  BKE_report(&reports,
173  RPT_ERROR,
174  "No data-blocks to create assets for found (or do not support use as assets)");
175  }
176  }
177  /* User feedback on success. */
178  else if (stats.tot_created == 1) {
179  /* If only one data-block: Give more useful message by printing asset name. */
180  BKE_reportf(&reports, RPT_INFO, "Data-block '%s' is now an asset", stats.last_id->name + 2);
181  }
182  else {
183  BKE_reportf(&reports, RPT_INFO, "%i data-blocks are now assets", stats.tot_created);
184  }
185 }
186 
188 {
190 
191  AssetMarkHelper mark_helper;
192  mark_helper(*C, ids);
193  mark_helper.reportResults(*op->reports);
194 
195  if (!mark_helper.wasSuccessful()) {
196  return OPERATOR_CANCELLED;
197  }
198 
201 
202  return OPERATOR_FINISHED;
203 }
204 
205 static bool asset_mark_poll(bContext *C)
206 {
208 
209  if (!ctx_stats.has_supported_type) {
211  return false;
212  }
213 
214  return true;
215 }
216 
218 {
219  ot->name = "Mark as Asset";
220  ot->description =
221  "Enable easier reuse of selected data-blocks through the Asset Browser, with the help of "
222  "customizable metadata (like previews, descriptions and tags)";
223  ot->idname = "ASSET_OT_mark";
224 
227 
229 }
230 
231 /* -------------------------------------------------------------------- */
232 
234  const bool set_fake_user_;
235 
236  public:
237  AssetClearHelper(const bool set_fake_user) : set_fake_user_(set_fake_user)
238  {
239  }
240 
241  void operator()(PointerRNAVec &ids);
242 
243  void reportResults(const bContext *C, ReportList &reports) const;
244  bool wasSuccessful() const;
245 
246  private:
247  struct Stats {
248  int tot_cleared = 0;
249  ID *last_id = nullptr;
250  };
251 
252  Stats stats;
253 };
254 
256 {
257  for (PointerRNA &ptr : ids) {
259 
260  ID *id = static_cast<ID *>(ptr.data);
261  if (!id->asset_data) {
262  continue;
263  }
264 
265  if (!ED_asset_clear_id(id)) {
266  continue;
267  }
268 
269  if (set_fake_user_) {
270  id_fake_user_set(id);
271  }
272 
273  stats.tot_cleared++;
274  stats.last_id = id;
275  }
276 }
277 
279 {
280  if (!wasSuccessful()) {
281  bool is_valid;
282  /* Dedicated error message for when there is an active asset detected, but it's not an ID local
283  * to this file. Helps users better understanding what's going on. */
284  if (AssetHandle active_asset = CTX_wm_asset_handle(C, &is_valid);
285  is_valid && !ED_asset_handle_get_local_id(&active_asset)) {
286  BKE_report(&reports,
287  RPT_ERROR,
288  "No asset data-blocks from the current file selected (assets must be stored in "
289  "the current file to be able to edit or clear them)");
290  }
291  else {
292  BKE_report(&reports, RPT_ERROR, "No asset data-blocks selected/focused");
293  }
294  }
295  else if (stats.tot_cleared == 1) {
296  /* If only one data-block: Give more useful message by printing asset name. */
297  BKE_reportf(
298  &reports, RPT_INFO, "Data-block '%s' is not an asset anymore", stats.last_id->name + 2);
299  }
300  else {
301  BKE_reportf(&reports, RPT_INFO, "%i data-blocks are no assets anymore", stats.tot_cleared);
302  }
303 }
304 
306 {
307  return stats.tot_cleared > 0;
308 }
309 
311 {
313 
314  const bool set_fake_user = RNA_boolean_get(op->ptr, "set_fake_user");
315  AssetClearHelper clear_helper(set_fake_user);
316  clear_helper(ids);
317  clear_helper.reportResults(C, *op->reports);
318 
319  if (!clear_helper.wasSuccessful()) {
320  return OPERATOR_CANCELLED;
321  }
322 
325 
326  return OPERATOR_FINISHED;
327 }
328 
329 static bool asset_clear_poll(bContext *C)
330 {
332 
333  if (!ctx_stats.has_asset) {
334  const char *msg_single = TIP_("Data-block is not marked as asset");
335  const char *msg_multiple = TIP_("No data-block selected that is marked as asset");
336  CTX_wm_operator_poll_msg_set(C, ctx_stats.is_single ? msg_single : msg_multiple);
337  return false;
338  }
339  if (!ctx_stats.has_supported_type) {
341  return false;
342  }
343 
344  return true;
345 }
346 
348  struct wmOperatorType *UNUSED(op),
349  struct PointerRNA *values)
350 {
351  const bool set_fake_user = RNA_boolean_get(values, "set_fake_user");
352  if (!set_fake_user) {
353  return nullptr;
354  }
355 
356  return BLI_strdup(
357  TIP_("Delete all asset metadata, turning the selected asset data-blocks back into normal "
358  "data-blocks, and set Fake User to ensure the data-blocks will still be saved"));
359 }
360 
362 {
363  ot->name = "Clear Asset";
364  ot->description =
365  "Delete all asset metadata and turn the selected asset data-blocks back into normal "
366  "data-blocks";
368  ot->idname = "ASSET_OT_clear";
369 
372 
374 
376  "set_fake_user",
377  false,
378  "Set Fake User",
379  "Ensure the data-block is saved, even when it is no longer marked as asset");
380 }
381 
382 /* -------------------------------------------------------------------- */
383 
385 {
387  return true;
388  }
389 
390  /* While not inside an Asset Browser, check if there's a asset list stored for the active asset
391  * library (stored in the workspace, obtained via context). */
393  if (!library) {
394  return false;
395  }
396 
398 }
399 
401 {
402  /* Execution mode #1: Inside the Asset Browser. */
404  SpaceFile *sfile = CTX_wm_space_file(C);
407  }
408  else {
409  /* Execution mode #2: Outside the Asset Browser, use the asset list. */
412  }
413 
414  return OPERATOR_FINISHED;
415 }
416 
423 {
424  /* identifiers */
425  ot->name = "Refresh Asset Library";
426  ot->description = "Reread assets and asset catalogs from the asset library on disk";
427  ot->idname = "ASSET_OT_library_refresh";
428 
429  /* api callbacks */
432 }
433 
434 /* -------------------------------------------------------------------- */
435 
437 {
438  const SpaceFile *sfile = CTX_wm_space_file(C);
439  return sfile && ED_fileselect_active_asset_library_get(sfile);
440 }
441 
443 {
444  SpaceFile *sfile = CTX_wm_space_file(C);
445  struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
446  char *parent_path = RNA_string_get_alloc(op->ptr, "parent_path", nullptr, 0, nullptr);
447 
449  asset_library, "Catalog", parent_path);
450 
451  if (sfile) {
453  }
454 
455  MEM_freeN(parent_path);
456 
459 
460  return OPERATOR_FINISHED;
461 }
462 
464 {
465  /* identifiers */
466  ot->name = "New Asset Catalog";
467  ot->description = "Create a new catalog to put assets in";
468  ot->idname = "ASSET_OT_catalog_new";
469 
470  /* api callbacks */
473 
475  "parent_path",
476  nullptr,
477  0,
478  "Parent Path",
479  "Optional path defining the location to put the new catalog under");
480 }
481 
483 {
484  SpaceFile *sfile = CTX_wm_space_file(C);
485  struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
486  char *catalog_id_str = RNA_string_get_alloc(op->ptr, "catalog_id", nullptr, 0, nullptr);
487  bke::CatalogID catalog_id;
488  if (!BLI_uuid_parse_string(&catalog_id, catalog_id_str)) {
489  return OPERATOR_CANCELLED;
490  }
491 
492  ED_asset_catalog_remove(asset_library, catalog_id);
493 
494  MEM_freeN(catalog_id_str);
495 
498 
499  return OPERATOR_FINISHED;
500 }
501 
503 {
504  /* identifiers */
505  ot->name = "Delete Asset Catalog";
506  ot->description =
507  "Remove an asset catalog from the asset library (contained assets will not be affected and "
508  "show up as unassigned)";
509  ot->idname = "ASSET_OT_catalog_delete";
510 
511  /* api callbacks */
514 
515  RNA_def_string(ot->srna, "catalog_id", nullptr, 0, "Catalog ID", "ID of the catalog to delete");
516 }
517 
519 {
520  const SpaceFile *sfile = CTX_wm_space_file(C);
521  if (!sfile) {
522  return nullptr;
523  }
524 
526  return BKE_asset_library_get_catalog_service(asset_lib);
527 }
528 
530 {
531  bke::AssetCatalogService *catalog_service = get_catalog_service(C);
532  if (!catalog_service) {
533  return OPERATOR_CANCELLED;
534  }
535 
536  catalog_service->undo();
538  return OPERATOR_FINISHED;
539 }
540 
542 {
543  const bke::AssetCatalogService *catalog_service = get_catalog_service(C);
544  return catalog_service && catalog_service->is_undo_possbile();
545 }
546 
548 {
549  /* identifiers */
550  ot->name = "Undo Catalog Edits";
551  ot->description = "Undo the last edit to the asset catalogs";
552  ot->idname = "ASSET_OT_catalog_undo";
553 
554  /* api callbacks */
557 }
558 
560 {
561  bke::AssetCatalogService *catalog_service = get_catalog_service(C);
562  if (!catalog_service) {
563  return OPERATOR_CANCELLED;
564  }
565 
566  catalog_service->redo();
568  return OPERATOR_FINISHED;
569 }
570 
572 {
573  const bke::AssetCatalogService *catalog_service = get_catalog_service(C);
574  return catalog_service && catalog_service->is_redo_possbile();
575 }
576 
578 {
579  /* identifiers */
580  ot->name = "Redo Catalog Edits";
581  ot->description = "Redo the last undone edit to the asset catalogs";
582  ot->idname = "ASSET_OT_catalog_redo";
583 
584  /* api callbacks */
587 }
588 
590 {
591  bke::AssetCatalogService *catalog_service = get_catalog_service(C);
592  if (!catalog_service) {
593  return OPERATOR_CANCELLED;
594  }
595 
596  catalog_service->undo_push();
597  return OPERATOR_FINISHED;
598 }
599 
601 {
602  return get_catalog_service(C) != nullptr;
603 }
604 
606 {
607  /* identifiers */
608  ot->name = "Store undo snapshot for asset catalog edits";
609  ot->description = "Store the current state of the asset catalogs in the undo buffer";
610  ot->idname = "ASSET_OT_catalog_undo_push";
611 
612  /* api callbacks */
615 
616  /* Generally artists don't need to find & use this operator, it's meant for scripts only. */
618 }
619 
620 /* -------------------------------------------------------------------- */
621 
623 {
625  return false;
626  }
627 
628  const Main *bmain = CTX_data_main(C);
629  if (!bmain->filepath[0]) {
630  CTX_wm_operator_poll_msg_set(C, "Cannot save asset catalogs before the Blender file is saved");
631  return false;
632  }
633 
635  CTX_wm_operator_poll_msg_set(C, "No changes to be saved");
636  return false;
637  }
638 
639  return true;
640 }
641 
643 {
644  const SpaceFile *sfile = CTX_wm_space_file(C);
646 
648 
651 
652  return OPERATOR_FINISHED;
653 }
654 
656 {
657  /* identifiers */
658  ot->name = "Save Asset Catalogs";
659  ot->description =
660  "Make any edits to any catalogs permanent by writing the current set up to the asset "
661  "library";
662  ot->idname = "ASSET_OT_catalogs_save";
663 
664  /* api callbacks */
667 }
668 
669 /* -------------------------------------------------------------------- */
670 
671 static bool could_be_asset_bundle(const Main *bmain);
672 static const bUserAssetLibrary *selected_asset_library(struct wmOperator *op);
673 static bool is_contained_in_selected_asset_library(struct wmOperator *op, const char *filepath);
674 static bool set_filepath_for_asset_lib(const Main *bmain, struct wmOperator *op);
675 static bool has_external_files(Main *bmain, struct ReportList *reports);
676 
678 {
679  /* This operator only works when the asset browser is set to Current File. */
680  const SpaceFile *sfile = CTX_wm_space_file(C);
681  if (sfile == nullptr) {
682  return false;
683  }
685  return false;
686  }
687 
688  const Main *bmain = CTX_data_main(C);
689  if (!could_be_asset_bundle(bmain)) {
690  return false;
691  }
692 
693  /* Check whether this file is already located inside any asset library. */
695  &U, bmain->filepath);
696  if (asset_lib) {
697  return false;
698  }
699 
700  return true;
701 }
702 
704  struct wmOperator *op,
705  const struct wmEvent * /*event*/)
706 {
707  Main *bmain = CTX_data_main(C);
708  if (has_external_files(bmain, op->reports)) {
709  return OPERATOR_CANCELLED;
710  }
711 
713 
714  /* Make the "Save As" dialog box default to "${ASSET_LIB_ROOT}/${CURRENT_FILE}.blend". */
715  if (!set_filepath_for_asset_lib(bmain, op)) {
716  return OPERATOR_CANCELLED;
717  }
718 
719  return OPERATOR_RUNNING_MODAL;
720 }
721 
723 {
724  Main *bmain = CTX_data_main(C);
725  if (has_external_files(bmain, op->reports)) {
726  return OPERATOR_CANCELLED;
727  }
728 
729  /* Check file path, copied from #wm_file_write(). */
730  char filepath[PATH_MAX];
731  RNA_string_get(op->ptr, "filepath", filepath);
732  const size_t len = strlen(filepath);
733 
734  if (len == 0) {
735  BKE_report(op->reports, RPT_ERROR, "Path is empty, cannot save");
736  return OPERATOR_CANCELLED;
737  }
738 
739  if (len >= FILE_MAX) {
740  BKE_report(op->reports, RPT_ERROR, "Path too long, cannot save");
741  return OPERATOR_CANCELLED;
742  }
743 
744  /* Check that the destination is actually contained in the selected asset library. */
745  if (!is_contained_in_selected_asset_library(op, filepath)) {
746  BKE_reportf(op->reports, RPT_ERROR, "Selected path is outside of the selected asset library");
747  return OPERATOR_CANCELLED;
748  }
749 
750  WM_cursor_wait(true);
752  /* Store undo step, such that on a failed save the 'prepare_to_merge_on_write' call can be
753  * un-done. */
754  cat_service->undo_push();
755  cat_service->prepare_to_merge_on_write();
756 
757  const int operator_result = WM_operator_name_call(
758  C, "WM_OT_save_mainfile", WM_OP_EXEC_DEFAULT, op->ptr, nullptr);
759  WM_cursor_wait(false);
760 
761  if (operator_result != OPERATOR_FINISHED) {
762  cat_service->undo();
763  return operator_result;
764  }
765 
767  BLI_assert_msg(lib, "If the asset library is not known, how did we get here?");
768  BKE_reportf(op->reports,
769  RPT_INFO,
770  R"(Saved "%s" to asset library "%s")",
771  BLI_path_basename(bmain->filepath),
772  lib->name);
773  return OPERATOR_FINISHED;
774 }
775 
778  PropertyRNA *UNUSED(prop),
779  bool *r_free)
780 {
782  if (!items) {
783  *r_free = false;
784  }
785 
786  *r_free = true;
787  return items;
788 }
789 
791 {
792  /* identifiers */
793  ot->name = "Copy to Asset Library";
794  ot->description =
795  "Copy the current .blend file into an Asset Library. Only works on standalone .blend files "
796  "(i.e. when no other files are referenced)";
797  ot->idname = "ASSET_OT_bundle_install";
798 
799  /* api callbacks */
803 
804  ot->prop = RNA_def_property(ot->srna, "asset_library_ref", PROP_ENUM, PROP_NONE);
807 
810  FILE_BLENDER,
811  FILE_SAVE,
815 }
816 
817 /* Cheap check to see if this is an "asset bundle" just by checking main file name.
818  * A proper check will be done in the exec function, to ensure that no external files will be
819  * referenced. */
820 static bool could_be_asset_bundle(const Main *bmain)
821 {
822  return fnmatch("*_bundle.blend", bmain->filepath, FNM_CASEFOLD) == 0;
823 }
824 
826 {
827  const int enum_value = RNA_enum_get(op->ptr, "asset_library_ref");
830  &U, lib_ref.custom_library_index);
831  return lib;
832 }
833 
834 static bool is_contained_in_selected_asset_library(struct wmOperator *op, const char *filepath)
835 {
837  if (!lib) {
838  return false;
839  }
840  return BLI_path_contains(lib->path, filepath);
841 }
842 
847 static bool set_filepath_for_asset_lib(const Main *bmain, struct wmOperator *op)
848 {
849  /* Find the directory path of the selected asset library. */
851  if (lib == nullptr) {
852  return false;
853  }
854 
855  /* Concatenate the filename of the current blend file. */
856  const char *blend_filename = BLI_path_basename(bmain->filepath);
857  if (blend_filename == nullptr || blend_filename[0] == '\0') {
858  return false;
859  }
860 
861  char file_path[PATH_MAX];
862  BLI_join_dirfile(file_path, sizeof(file_path), lib->path, blend_filename);
863  RNA_string_set(op->ptr, "filepath", file_path);
864 
865  return true;
866 }
867 
871 };
872 
874  char * /*path_dst*/,
875  const char *path_src)
876 {
877  FileCheckCallbackInfo *callback_info = static_cast<FileCheckCallbackInfo *>(
878  bpath_data->user_data);
879  callback_info->external_files.add(std::string(path_src));
880  return false;
881 }
882 
890 static bool has_external_files(Main *bmain, struct ReportList *reports)
891 {
892  struct FileCheckCallbackInfo callback_info = {reports, Set<std::string>()};
893 
894  eBPathForeachFlag flag = static_cast<eBPathForeachFlag>(
895  BKE_BPATH_FOREACH_PATH_SKIP_PACKED /* Packed files are fine. */
896  | BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE /* Only report multi-files once, it's enough. */
897  | BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES); /* Only care about actually used files. */
898 
899  BPathForeachPathData bpath_data = {
900  /* bmain */ bmain,
901  /* callback_function */ &external_file_check_callback,
902  /* flag */ flag,
903  /* user_data */ &callback_info,
904  /* absolute_base_path */ nullptr,
905  };
906  BKE_bpath_foreach_path_main(&bpath_data);
907 
908  if (callback_info.external_files.is_empty()) {
909  /* No external dependencies. */
910  return false;
911  }
912 
913  if (callback_info.external_files.size() == 1) {
914  /* Only one external dependency, report it directly. */
915  BKE_reportf(callback_info.reports,
916  RPT_ERROR,
917  "Unable to copy bundle due to external dependency: \"%s\"",
918  callback_info.external_files.begin()->c_str());
919  return true;
920  }
921 
922  /* Multiple external dependencies, report the aggregate and put details on console. */
923  BKE_reportf(
924  callback_info.reports,
925  RPT_ERROR,
926  "Unable to copy bundle due to %zu external dependencies; more details on the console",
927  (size_t)callback_info.external_files.size());
928  printf("Unable to copy bundle due to %zu external dependencies:\n",
929  (size_t)callback_info.external_files.size());
930  for (const std::string &path : callback_info.external_files) {
931  printf(" \"%s\"\n", path.c_str());
932  }
933  return true;
934 }
935 
936 /* -------------------------------------------------------------------- */
937 
939 {
942 
950 
952 }
bool BKE_asset_library_has_any_unsaved_catalogs(void)
struct AssetLibrary AssetLibrary
blender::bke::AssetCatalogService * BKE_asset_library_get_catalog_service(const ::AssetLibrary *library)
eBPathForeachFlag
Definition: BKE_bpath.h:27
@ BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES
Definition: BKE_bpath.h:45
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
Definition: BKE_bpath.h:37
@ BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE
Definition: BKE_bpath.h:55
void BKE_bpath_foreach_path_main(BPathForeachPathData *bpath_data)
Definition: bpath.c:112
const struct AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
Definition: context.c:1475
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:473
int CTX_data_selected_ids(const bContext *C, ListBase *list)
Definition: context.c:1293
struct AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid)
Definition: context.c:1480
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg)
Definition: context.c:1042
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct SpaceFile * CTX_wm_space_file(const bContext *C)
Definition: context.c:842
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:723
void id_fake_user_set(struct ID *id)
Definition: lib_id.c:343
struct bUserAssetLibrary * BKE_preferences_asset_library_find_from_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
struct bUserAssetLibrary * BKE_preferences_asset_library_containing_path(const struct UserDef *userdef, const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
File and directory operations.
#define PATH_MAX
Definition: BLI_fileops.h:29
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1653
#define FILE_MAX
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_WARN_UNUSED_RESULT
Definition: path_util.c:1717
void BLI_join_dirfile(char *__restrict dst, size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1531
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:42
#define UNUSED(x)
bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL()
Definition: uuid.cc:103
external writefile.c function prototypes.
#define TIP_(msgid)
#define ID_IS_ASSET(_id)
Definition: DNA_ID.h:598
@ FILE_SORT_DEFAULT
@ FILE_BLENDER
@ FILE_TYPE_BLENDER
@ FILE_TYPE_FOLDER
@ FILE_DEFAULTDISPLAY
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
void ED_asset_catalogs_save_from_main_path(struct AssetLibrary *library, const struct Main *bmain)
void ED_asset_catalog_remove(AssetLibrary *library, const blender::bke::CatalogID &catalog_id)
blender::bke::AssetCatalog * ED_asset_catalog_add(AssetLibrary *library, blender::StringRefNull name, blender::StringRef parent_path=nullptr)
struct ID * ED_asset_handle_get_local_id(const struct AssetHandle *asset)
AssetLibraryReference ED_asset_library_reference_from_enum_value(int value)
const struct EnumPropertyItem * ED_asset_library_reference_to_rna_enum_itemf(bool include_local_library)
void ED_assetlist_clear(const struct AssetLibraryReference *library_reference, struct bContext *C)
bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference)
Definition: asset_list.cc:442
bool ED_asset_clear_id(struct ID *id)
bool ED_asset_mark_id(struct ID *id)
void ED_asset_generate_preview(const struct bContext *C, struct ID *id)
bool ED_asset_type_is_supported(const ID *id)
Definition: asset_type.cc:22
#define ED_ASSET_TYPE_IDS_NON_EXPERIMENTAL_UI_STRING
Definition: ED_asset_type.h:41
void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile)
Definition: filesel.c:1213
void ED_fileselect_activate_asset_catalog(const struct SpaceFile *sfile, bUUID catalog_id)
struct AssetLibrary * ED_fileselect_active_asset_library_get(const struct SpaceFile *sfile)
bool ED_fileselect_is_local_asset_library(const struct SpaceFile *sfile)
bool ED_operator_asset_browsing_active(struct bContext *C)
Definition: screen_ops.c:284
@ PROP_ENUM
Definition: RNA_types.h:63
@ PROP_HIDDEN
Definition: RNA_types.h:216
@ PROP_NONE
Definition: RNA_types.h:126
#define C
Definition: RandGen.cpp:25
@ WM_FILESEL_FILEPATH
Definition: WM_api.h:755
@ FILE_SAVE
Definition: WM_api.h:765
@ OPTYPE_INTERNAL
Definition: WM_types.h:168
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_ID
Definition: WM_types.h:345
#define ND_SPACE_ASSET_PARAMS
Definition: WM_types.h:468
#define NA_ADDED
Definition: WM_types.h:525
#define NA_EDITED
Definition: WM_types.h:523
#define NC_ASSET
Definition: WM_types.h:354
#define NA_REMOVED
Definition: WM_types.h:526
@ WM_OP_EXEC_DEFAULT
Definition: WM_types.h:208
#define ND_ASSET_CATALOGS
Definition: WM_types.h:495
#define NC_SPACE
Definition: WM_types.h:342
#define ND_SPACE_FILE_LIST
Definition: WM_types.h:467
static int asset_catalog_undo_push_exec(bContext *C, wmOperator *)
Definition: asset_ops.cc:589
static int asset_bundle_install_exec(bContext *C, wmOperator *op)
Definition: asset_ops.cc:722
static bool external_file_check_callback(BPathForeachPathData *bpath_data, char *, const char *path_src)
Definition: asset_ops.cc:873
static bool asset_catalog_undo_push_poll(bContext *C)
Definition: asset_ops.cc:600
static int asset_catalog_delete_exec(bContext *C, wmOperator *op)
Definition: asset_ops.cc:482
static bool asset_clear_poll(bContext *C)
Definition: asset_ops.cc:329
void ED_operatortypes_asset()
Definition: asset_ops.cc:938
static int asset_catalog_new_exec(bContext *C, wmOperator *op)
Definition: asset_ops.cc:442
static void ASSET_OT_mark(wmOperatorType *ot)
Definition: asset_ops.cc:217
static void ASSET_OT_catalog_undo_push(struct wmOperatorType *ot)
Definition: asset_ops.cc:605
static int asset_catalog_undo_exec(bContext *C, wmOperator *)
Definition: asset_ops.cc:529
static IDVecStats asset_operation_get_id_vec_stats_from_context(const bContext *C)
Definition: asset_ops.cc:85
static bool asset_catalog_undo_poll(bContext *C)
Definition: asset_ops.cc:541
static char * asset_clear_get_description(struct bContext *UNUSED(C), struct wmOperatorType *UNUSED(op), struct PointerRNA *values)
Definition: asset_ops.cc:347
static void ASSET_OT_catalogs_save(struct wmOperatorType *ot)
Definition: asset_ops.cc:655
static int asset_bundle_install_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *)
Definition: asset_ops.cc:703
static void ASSET_OT_catalog_redo(struct wmOperatorType *ot)
Definition: asset_ops.cc:577
static const EnumPropertyItem * rna_asset_library_reference_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
Definition: asset_ops.cc:776
static bool asset_catalog_operator_poll(bContext *C)
Definition: asset_ops.cc:436
static bool asset_library_refresh_poll(bContext *C)
Definition: asset_ops.cc:384
static void ASSET_OT_catalog_delete(struct wmOperatorType *ot)
Definition: asset_ops.cc:502
static void ASSET_OT_catalog_undo(struct wmOperatorType *ot)
Definition: asset_ops.cc:547
static bool set_filepath_for_asset_lib(const Main *bmain, struct wmOperator *op)
Definition: asset_ops.cc:847
static int asset_library_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
Definition: asset_ops.cc:400
static bool asset_catalog_redo_poll(bContext *C)
Definition: asset_ops.cc:571
static const bUserAssetLibrary * selected_asset_library(struct wmOperator *op)
Definition: asset_ops.cc:825
static int asset_catalogs_save_exec(bContext *C, wmOperator *)
Definition: asset_ops.cc:642
static int asset_clear_exec(bContext *C, wmOperator *op)
Definition: asset_ops.cc:310
static PointerRNAVec asset_operation_get_ids_from_context(const bContext *C)
Definition: asset_ops.cc:50
static int asset_catalog_redo_exec(bContext *C, wmOperator *)
Definition: asset_ops.cc:559
static bool asset_mark_poll(bContext *C)
Definition: asset_ops.cc:205
static int asset_mark_exec(bContext *C, wmOperator *op)
Definition: asset_ops.cc:187
static void ASSET_OT_clear(wmOperatorType *ot)
Definition: asset_ops.cc:361
static void ASSET_OT_library_refresh(struct wmOperatorType *ot)
Definition: asset_ops.cc:422
static const char * asset_operation_unsupported_type_msg(const bool is_single)
Definition: asset_ops.cc:107
static bool has_external_files(Main *bmain, struct ReportList *reports)
Definition: asset_ops.cc:890
static void ASSET_OT_catalog_new(struct wmOperatorType *ot)
Definition: asset_ops.cc:463
static bke::AssetCatalogService * get_catalog_service(bContext *C)
Definition: asset_ops.cc:518
static bool could_be_asset_bundle(const Main *bmain)
Definition: asset_ops.cc:820
static void ASSET_OT_bundle_install(struct wmOperatorType *ot)
Definition: asset_ops.cc:790
static bool asset_catalogs_save_poll(bContext *C)
Definition: asset_ops.cc:622
static bool is_contained_in_selected_asset_library(struct wmOperator *op, const char *filepath)
Definition: asset_ops.cc:834
static bool asset_bundle_install_poll(bContext *C)
Definition: asset_ops.cc:677
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition: btTransform.h:90
bool wasSuccessful() const
Definition: asset_ops.cc:305
void operator()(PointerRNAVec &ids)
Definition: asset_ops.cc:255
AssetClearHelper(const bool set_fake_user)
Definition: asset_ops.cc:237
void reportResults(const bContext *C, ReportList &reports) const
Definition: asset_ops.cc:278
bool wasSuccessful() const
Definition: asset_ops.cc:157
void operator()(const bContext &C, PointerRNAVec &ids)
Definition: asset_ops.cc:137
void reportResults(ReportList &reports) const
Definition: asset_ops.cc:162
Stats()
Definition: util/stats.h:16
Iterator begin() const
Definition: BLI_set.hh:466
int64_t size() const
Definition: BLI_set.hh:539
bool add(const Key &key)
Definition: BLI_set.hh:253
bool is_empty() const
Definition: BLI_set.hh:547
int64_t size() const
Definition: BLI_vector.hh:694
void append(const T &value)
Definition: BLI_vector.hh:433
bool is_valid
int len
Definition: draw_manager.c:108
DRWShaderLibrary * lib
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
Definition: rna_access.c:5155
bool RNA_struct_is_ID(const StructRNA *type)
Definition: rna_access.c:655
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:5116
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:5129
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3687
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3830
Set< std::string > external_files
Definition: asset_ops.cc:870
struct ReportList * reports
Definition: asset_ops.cc:869
bool is_single
Definition: asset_ops.cc:78
bool has_asset
Definition: asset_ops.cc:76
bool has_supported_type
Definition: asset_ops.cc:77
Definition: DNA_ID.h:368
struct AssetMetaData * asset_data
Definition: DNA_ID.h:375
Definition: BKE_main.h:121
char filepath[1024]
Definition: BKE_main.h:124
struct StructRNA * type
Definition: RNA_types.h:37
void * data
Definition: RNA_types.h:38
Universally Unique Identifier according to RFC4122.
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
char *(* get_description)(struct bContext *C, struct wmOperatorType *, struct PointerRNA *)
Definition: WM_types.h:966
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
PropertyRNA * prop
Definition: WM_types.h:981
struct ReportList * reports
struct PointerRNA * ptr
static FT_Library library
void WM_cursor_wait(bool val)
Definition: wm_cursors.c:209
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
int WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
PointerRNA * ptr
Definition: wm_files.c:3480
wmOperatorType * ot
Definition: wm_files.c:3479
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))