Blender V5.3
project_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <fmt/format.h>
10
11#include "BKE_appdir.hh"
13#include "BKE_context.hh"
14#include "BKE_global.hh"
15#include "BKE_main.hh"
16#include "BKE_report.hh"
17
18#include "BLI_fileops.hh"
20#include "BLI_path_utils.hh"
21#include "BLI_string.hh"
22
23#include "BLT_translation.hh"
24
25#include "DNA_userdef_types.h"
27
28#include "ED_userpref.hh"
29
30#include "RNA_access.hh"
31#include "RNA_define.hh"
32#include "RNA_enum_types.hh"
33#include "RNA_prototypes.hh"
34
35#include "UI_interface_c.hh"
37#include "UI_resources.hh"
38
39#include "WM_api.hh"
40#include "WM_types.hh"
41
42#include "project_intern.hh"
43#include "wm_files.hh"
44
45namespace blender {
46
47/* -------------------------------------------------------------------- */
50
52{
53 Main *bmain = CTX_data_main(C);
54 return BKE_blender_project_get(bmain) != nullptr;
55}
56
57static void project_mark_dirty(Main *bmain)
58{
60 if (project) {
61 project->is_dirty = true;
62 };
63 });
64}
65
67
68/* -------------------------------------------------------------------- */
71
72static std::string new_project_name_get(PointerRNA *ptr)
73{
74 return RNA_struct_property_is_set(ptr, "name") ? StringRef(RNA_string_get(ptr, "name")).trim() :
75 DATA_("Untitled Project");
76}
77
78static std::string new_project_default_parent()
79{
80 char documents_path[FILE_MAXDIR];
81 const char *base_path = BKE_appdir_folder_documents(documents_path) ? documents_path :
83 char path[FILE_MAX];
84 BLI_path_join(path, sizeof(path), base_path ? base_path : "", "Blender", "Projects");
85 return path;
86}
87
93{
94 Vector<std::string> directories;
95 const char *blendfile_path = BKE_main_blendfile_path(bmain);
96 if (blendfile_path[0] == '\0') {
97 return directories;
98 }
99
100 const char *home_path = BLI_dir_home();
101 char directory[FILE_MAX];
102 BLI_path_split_dir_part(blendfile_path, directory, sizeof(directory));
103
104 while (!(home_path && BLI_path_contains(directory, home_path))) {
105 char parent[FILE_MAX];
106 STRNCPY(parent, directory);
107 if (!BLI_path_parent_dir(parent) || !BLI_path_is_abs_from_cwd(parent)) {
108 break;
109 }
110 BLI_path_slash_rstrip(directory);
111 directories.append(directory);
112 STRNCPY(directory, parent);
113 }
114 return directories;
115}
116
119{
120 return RNA_string_length(ptr, "directory") == 0 &&
122}
123
125static std::string new_project_root_path(const Main *bmain, PointerRNA *ptr)
126{
127 char path[FILE_MAX];
128 if (new_project_use_existing_directory(bmain, ptr)) {
130 const int index = RNA_enum_get(ptr, "existing_directory");
131 if (!directories.index_range().contains(index)) {
132 return "";
133 }
134 STRNCPY(path, directories[index].c_str());
135 }
136 else {
137 RNA_string_get(ptr, "directory", path);
139 }
140
141 if (!BLI_path_is_abs_from_cwd(path)) {
142 return "";
143 }
144 BLI_path_normalize(path);
146 return path;
147}
148
150static std::string new_project_find_root(const StringRefNull directory)
151{
152 char path[FILE_MAX];
153 STRNCPY(path, directory.c_str());
154 while (!BLI_is_dir(path)) {
155 if (!BLI_path_parent_dir(path)) {
156 return "";
157 }
158 }
160}
161
163{
164 /* Propose the folder name as project name. */
165 char path[FILE_MAX];
166 STRNCPY(path, directory.c_str());
168 const char *name = BLI_path_basename(path);
169 if (name && name[0]) {
170 RNA_string_set(ptr, "name", name);
171 }
172}
173
176{
177 char directory[FILE_MAX];
178 RNA_string_get(ptr, "directory", directory);
179 BLI_path_slash_rstrip(directory);
180 RNA_boolean_set(ptr,
181 "update_directory_from_name",
182 BLI_path_basename(directory) == new_project_name_get(ptr));
183}
184
185static void new_project_name_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
186{
187 /* Rename the directory along with the project. */
188 const std::string name = new_project_name_get(ptr);
189 if (!RNA_boolean_get(ptr, "update_directory_from_name")) {
190 return;
191 }
192 if (name.empty() || name.find_first_of("/\\") != StringRef::not_found) {
193 /* Can't use as directory name. */
194 return;
195 }
196
197 char directory[FILE_MAX];
198 RNA_string_get(ptr, "directory", directory);
199 BLI_path_slash_rstrip(directory);
200 BLI_path_parent_dir(directory);
201 BLI_path_append(directory, sizeof(directory), name.c_str());
202 RNA_string_set(ptr, "directory", directory);
203}
204
205static void new_project_directory_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
206{
208}
209
210static void new_project_existing_directory_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
211{
213 const int index = RNA_enum_get(ptr, "existing_directory");
214 if (directories.index_range().contains(index)) {
215 new_project_name_from_directory(ptr, directories[index]);
216 }
217}
218
220 PointerRNA * /*ptr*/,
221 PropertyRNA * /*prop*/,
222 bool *r_free)
223{
224 /* Item strings must remain valid after returning, keep them until they change. */
225 static Vector<std::string> directories;
227 G_MAIN);
228 if (new_directories != directories) {
229 directories = std::move(new_directories);
230 }
231
232 EnumPropertyItem *items = nullptr;
233 int totitem = 0;
234 for (const int i : directories.index_range()) {
235 EnumPropertyItem item = {};
236 item.value = i;
237 item.identifier = directories[i].c_str();
238 item.name = directories[i].c_str();
239 RNA_enum_item_add(&items, &totitem, &item);
240 }
241 RNA_enum_item_end(&items, &totitem);
242 *r_free = true;
243 return items;
244}
245
247{
248 Main *bmain = CTX_data_main(C);
249 if (BKE_blender_project_get(bmain) != nullptr) {
250 CTX_wm_operator_poll_msg_set(C, IFACE_("Close the current project before creating a new one"));
251 return false;
252 }
253
254 return true;
255}
256
258{
259 Main *bmain = CTX_data_main(C);
260
261 const std::string root_path = new_project_root_path(bmain, op->ptr);
262 if (root_path.empty()) {
263 BKE_report(op->reports, RPT_ERROR, "Invalid project root folder");
264 return OPERATOR_CANCELLED;
265 }
266
267 if (!RNA_struct_property_is_set(op->ptr, "name")) {
268 new_project_name_from_directory(op->ptr, root_path);
269 }
270
271 const std::string name = new_project_name_get(op->ptr);
272 if (name.empty()) {
273 BKE_report(op->reports, RPT_ERROR, "Missing project name");
274 return OPERATOR_CANCELLED;
275 }
276
277 /* Don't allow nesting inside or replacing a project. Nested does not have
278 * well defined semantics so is not supported for now. */
279 if (!BKE_is_path_inside_blender_project(root_path.c_str()).empty()) {
280 BKE_report(op->reports, RPT_ERROR, "Folder already part of a project");
281 return OPERATOR_CANCELLED;
282 }
283
284 if (!BLI_dir_create_recursive(root_path.c_str())) {
285 BKE_reportf(op->reports, RPT_ERROR, "Failed to create folder \"%s\"", root_path.c_str());
286 return OPERATOR_CANCELLED;
287 }
288
290
291 BKE_blender_project_init(name, root_path);
295 op->reports, RPT_ERROR, "Failed to write project config in \"%s\"", root_path.c_str());
296 return OPERATOR_CANCELLED;
297 }
298 /* Force full redraw of all windows, and refresh their title. */
301
302 /* Show the project settings when used from the user interface. */
303 if (op->flag & OP_IS_INVOKE) {
305 C, "SCREEN_OT_project_settings_show", wm::OpCallContext::ExecDefault, nullptr, nullptr);
306 }
307
308 return OPERATOR_FINISHED;
309}
310
312{
313 Main *bmain = CTX_data_main(C);
314
315 if (RNA_string_length(op->ptr, "directory") == 0) {
316 if (BKE_main_blendfile_path(bmain)[0] != '\0') {
317 /* Saved file, use an existing parent directory. */
318 Vector<std::string> suggested_directories = new_project_suggested_directories(bmain);
319 if (suggested_directories.is_empty()) {
321 RPT_ERROR,
322 "Can not create project for a blend file in the home or root folder");
323 return OPERATOR_CANCELLED;
324 }
325
326 RNA_enum_set(op->ptr, "existing_directory", 0);
327 new_project_name_from_directory(op->ptr, suggested_directories[0]);
328 }
329 else {
330 /* Not saved, suggest a default project name and path. */
331 const std::string projects_dir = new_project_default_parent();
332 const std::string base_name = new_project_name_get(op->ptr);
333 std::string name = base_name;
334 char directory[FILE_MAX];
335 BLI_path_join(directory, sizeof(directory), projects_dir.c_str(), name.c_str());
336 /* Make the name unique. */
337 for (int number = 2; BLI_exists(directory); number++) {
338 name = fmt::format("{} {}", base_name, number);
339 BLI_path_join(directory, sizeof(directory), projects_dir.c_str(), name.c_str());
340 }
341
342 RNA_string_set(op->ptr, "name", name.c_str());
343 RNA_string_set(op->ptr, "directory", directory);
344 }
345 }
346
348
350 C,
351 op,
352 600,
353 std::nullopt,
354 IFACE_("Create Project"),
355 false,
356 RPT_("A Blender Project is a directory that provides a shared environment for related "
357 ".blend files, textures, and other files, with project-specific settings such as "
358 "Asset Libraries, custom variables, and other configuration options.\n"
359 "\n"
360 "This is a structured way to organize files and settings across complex pipelines "
361 "and team projects."));
362}
363
365static void new_project_draw_folder_info(ui::Layout &layout, const std::string &root_path)
366{
367 const std::string parent_root = new_project_find_root(root_path);
368 if (!parent_root.empty()) {
369 if (BLI_path_cmp_normalized(parent_root.c_str(), root_path.c_str()) == 0) {
370 layout.label(IFACE_("Folder already contains a project."), ICON_STATUS_WARNING);
371 return;
372 }
373 layout.label(IFACE_("Folder is inside another project."), ICON_STATUS_WARNING);
374 }
375}
376
378{
379 ui::Layout &layout = *op->layout;
380 const Main *bmain = CTX_data_main(C);
381 PointerRNA *ptr = op->ptr;
382
383 /* Narrower label column than usual, to leave more space for long paths. */
384 constexpr float label_factor = 0.25f;
385 auto labeled_row = [&](const StringRef text) -> ui::Layout & {
386 ui::Layout &split = layout.split(label_factor, false);
387 ui::Layout &col = split.column(false);
389 col.label(text, ICON_NONE);
390 return split.row(true);
391 };
392
393 /* Name and path. */
394 labeled_row(IFACE_("Name")).prop(ptr, "name", UI_ITEM_NONE, "", ICON_NONE);
395
396 if (new_project_use_existing_directory(bmain, ptr)) {
397 ui::Layout &row = labeled_row(IFACE_("Project Root Folder"));
398 row.prop(ptr, "existing_directory", UI_ITEM_NONE, "", ICON_NONE);
399
400 ui::Layout &button_row = row.row(true);
401 button_row.enabled_set(false);
402 button_row.button(
403 "",
404 ICON_FILEBROWSER,
405 [](bContext &) {},
406 TIP_("The current file needs to be inside of the project's path.\n"
407 "To pick a different folder, move the current file there first, or create a new "
408 "project from a new unsaved file."));
409 }
410 else {
411 ui::template_filepath(&labeled_row(IFACE_("Project Root Folder")),
412 C,
413 ptr,
414 "directory",
415 nullptr,
416 nullptr,
417 "",
418 std::nullopt,
419 true);
420 }
421
422 /* Path info. */
423 const std::string root_path = new_project_root_path(bmain, ptr);
424 if (!root_path.empty()) {
425 ui::Layout &split = layout.split(label_factor, false);
426 split.column(false);
427 new_project_draw_folder_info(split.column(false), root_path);
428 }
429}
430
432{
433 ot->name = "New Project";
434 ot->idname = "PROJECT_OT_new";
435 ot->description = "Create a new project";
436
440 ot->ui = project_new_ui;
441
442 PropertyRNA *prop;
443 prop = RNA_def_string(ot->srna, "name", "Untitled Project", 0, "Name", "Name of the project");
446
447 prop = RNA_def_string_dir_path(ot->srna,
448 "directory",
449 nullptr,
450 FILE_MAX,
451 "Project Root Folder",
452 "Project folder, created if missing");
455
456 prop = RNA_def_boolean(
457 ot->srna, "update_directory_from_name", false, "Update Directory From Name", "");
460
461 /* Choice of folder when a blend file is open, used if `directory` is not set. */
462 prop = RNA_def_enum(ot->srna,
463 "existing_directory",
465 0,
466 "Project Root Folder",
467 "Folder of the current file or one of its parents, to turn into a project");
472}
473
475
476/* -------------------------------------------------------------------- */
479
481{
482 char dirpath[FILE_MAX];
483 RNA_string_get(op->ptr, "directory", dirpath);
484 std::string project_root_path = BKE_is_path_inside_blender_project(dirpath);
485
486 if (project_root_path == "") {
487 BKE_reportf(op->reports, RPT_ERROR, "Folder '%s' does not belong to a project", dirpath);
488 return OPERATOR_CANCELLED;
489 }
490
491 /* Initialize project before blend file, so it is taken into account. */
495 project_root_path);
496
498 C, "WM_OT_read_homefile", wm::OpCallContext::ExecDefault, nullptr, nullptr);
499
500 if (!success) {
502 op->reports, RPT_ERROR, "Failed to load project from path: %s", project_root_path.c_str());
503 return OPERATOR_CANCELLED;
504 }
505
506 /* Force full redraw of all windows, and refresh their title. */
509
510 if (!G.background) {
512 }
513
514 if (op->flag & OP_IS_INVOKE) {
516 }
517
518 return OPERATOR_FINISHED;
519}
520
521static void project_open_after_dialog_callback(bContext *C, void *user_data)
522{
524 "PROJECT_OT_open",
526 static_cast<IDProperty *>(user_data),
527 nullptr);
528}
529
531{
532 if (!RNA_boolean_get(op->ptr, "skip_save_check")) {
533 RNA_boolean_set(op->ptr, "skip_save_check", true);
535 return OPERATOR_INTERFACE;
536 }
537 }
538
539 /* Open directly when the folder is given, for example for recent projects. */
540 if (RNA_struct_property_is_set(op->ptr, "directory")) {
541 return project_open_exec(C, op);
542 }
543
546}
547
549{
550 ot->name = "Open Project...";
551 ot->idname = "PROJECT_OT_open";
552 ot->description = "Open a project, starting a new file in it";
553
556
564
565 PropertyRNA *prop = RNA_def_boolean(ot->srna,
566 "skip_save_check",
567 false,
568 "Skip check to prevent unsaved changes from being lost",
569 "");
572}
573
575
576/* -------------------------------------------------------------------- */
579
581{
585 C, "WM_OT_read_homefile", wm::OpCallContext::ExecDefault, nullptr, nullptr);
586
587 /* Force full redraw of all windows, and refresh their title. */
590
591 if (op->flag & OP_IS_INVOKE) {
593 }
594
595 return OPERATOR_FINISHED;
596}
597
598static void project_close_after_dialog_callback(bContext *C, void *user_data)
599{
601 "PROJECT_OT_close",
603 static_cast<IDProperty *>(user_data),
604 nullptr);
605}
606
608 wmOperator *op,
609 const wmEvent * /*event*/)
610{
611 if (!RNA_boolean_get(op->ptr, "skip_save_check")) {
612 RNA_boolean_set(op->ptr, "skip_save_check", true);
614 return OPERATOR_INTERFACE;
615 }
616 }
617 return project_close_exec(C, op);
618}
619
621{
622 ot->name = "Close Project";
623 ot->idname = "PROJECT_OT_close";
624 ot->description = "Close the active project, starting a new file";
625
629
630 PropertyRNA *prop = RNA_def_boolean(ot->srna,
631 "skip_save_check",
632 false,
633 "Skip check to prevent unsaved changes from being lost",
634 "");
637}
638
640
642{
643 Main *bmain = CTX_data_main(C);
645 return OPERATOR_FINISHED;
646 }
647
648 return OPERATOR_CANCELLED;
649}
650
652{
653 ot->name = "Save Project Config";
654 ot->idname = "PROJECT_OT_config_save";
655 ot->description = "Save the current project config to disk";
656
659}
660/* -------------------------------------------------------------------- */
663
665{
667 RNA_enum_get(op->ptr, "type"));
668
669 char name[sizeof(bUserAssetLibrary::name)] = "";
670 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "name");
671 if (RNA_property_is_set(op->ptr, prop)) {
672 RNA_property_string_get(op->ptr, prop, name);
673 }
674
675 switch (library_type) {
677 char *dirpath = RNA_string_get_alloc(op->ptr, "directory", nullptr, 0, nullptr);
678 /* Store directories inside the project relative to the project root. */
679 const std::string dirpath_str = BKE_blender_project_read_callback(
681 return project ? BKE_blender_project_path_make_relative(dirpath, false, *project) :
682 std::string(dirpath);
683 });
684 ED_userpref_asset_library_new(C, name, dirpath_str.c_str(), library_type, true, {}, {});
685 MEM_delete(dirpath);
686 break;
687 }
689 char *remote_url = RNA_string_get_alloc(op->ptr, "remote_url", nullptr, 0, nullptr);
690 ED_userpref_asset_library_new(C, name, remote_url, library_type, true, {}, {});
691 MEM_delete(remote_url);
692 break;
693 }
694 }
695
696 U.runtime.is_dirty = true;
697 Main *bmain = CTX_data_main(C);
698 project_mark_dirty(bmain);
699 return OPERATOR_FINISHED;
700}
701
703 wmOperator *op,
704 const wmEvent *event)
705{
707 RNA_enum_get(op->ptr, "type"));
708
709 if ((library_type == bUserAssetLibraryAddType::Local) &&
710 !RNA_struct_property_is_set(op->ptr, "directory"))
711 {
714 }
715
717 C, op, event, IFACE_("Add Asset Library"), IFACE_("Create"));
718}
719
721{
722 blender::ui::Layout *layout = op->layout;
723 layout->use_property_split_set(true);
724 layout->use_property_decorate_set(false);
725
726 PointerRNA *ptr = op->ptr;
728 RNA_enum_get(ptr, "type"));
729 switch (library_type) {
731 layout->prop(op->ptr, "remote_url", ui::ITEM_R_IMMEDIATE, std::nullopt, ICON_NONE);
732 break;
733 }
735 layout->prop(op->ptr, "name", ui::ITEM_R_IMMEDIATE, std::nullopt, ICON_NONE);
736 break;
737 }
738 }
739}
740
742 PointerRNA * /*ptr*/,
743 PropertyRNA * /*prop*/,
744 bool *r_free)
745{
746 *r_free = false;
747
748 if (USER_EXPERIMENTAL_TEST(&U, use_remote_asset_libraries)) {
749 /* Experimental flag is enabled, just return all items. */
751 }
752
753 /* Since the Remote item is the first in the list, we can just return a pointer to
754 * the 2nd item in the list, when remote asset libraries should be hidden. */
756 return custom_library_type_items + 1;
757}
758
760{
761 ot->name = "Add Asset Library";
762 ot->idname = "PROJECT_OT_asset_library_add";
763 ot->description = "Add a directory to be used by the Project as source of assets";
764
769
771
779
780 /* Copy the RNA values are copied into the operator to avoid repetition. */
781 StructRNA *type_ref = RNA_UserAssetLibrary;
782
783 { /* Name. */
784 const char *prop_id = "name";
785 const PropertyRNA *prop_ref = RNA_struct_type_find_property(type_ref, prop_id);
786 PropertyRNA *prop = RNA_def_string(ot->srna,
787 prop_id,
788 nullptr,
790 RNA_property_ui_name_raw(prop_ref),
793 }
794
795 { /* Remote Path. */
796 const char *prop_id = "remote_url";
797 const PropertyRNA *prop_ref = RNA_struct_type_find_property(type_ref, prop_id);
798 PropertyRNA *prop = RNA_def_string(ot->srna,
799 prop_id,
800 nullptr,
802 RNA_property_ui_name_raw(prop_ref),
805 }
806
807 ot->prop = RNA_def_enum(ot->srna,
808 "type",
811 "Type",
812 "The kind of asset library to add");
815}
816
818
819/* -------------------------------------------------------------------- */
822
824{
825 int num_assets = 0;
826 for (bUserAssetLibrary &library : U.asset_libraries) {
828 num_assets++;
829 }
830 }
831 if (num_assets == 0) {
832 CTX_wm_operator_poll_msg_set(C, "There is no asset library to remove");
833 return false;
834 }
835 return true;
836}
837
839{
840 const int index = RNA_int_get(op->ptr, "index");
841 int num_assets = 0;
842 bUserAssetLibrary *library_ptr = nullptr;
843 for (bUserAssetLibrary &library : U.asset_libraries) {
845 if (num_assets == index) {
846 library_ptr = &library;
847 }
848 num_assets++;
849 }
850 }
851 if (!library_ptr) {
852 return OPERATOR_CANCELLED;
853 }
854 if (library_ptr->extension_id[0]) {
856 op->reports,
857 RPT_ERROR,
858 "Asset libraries defined by an extension are removed by uninstalling the extension");
859 return OPERATOR_CANCELLED;
860 }
861
863
864 Main *bmain = CTX_data_main(C);
866 /* num_assets - 2 because we removed one item (-1) and then adjust from size to last possible
867 * index.
868 */
869 CLAMP(project->active_asset_library_index, 0, num_assets - 2);
870 });
871
872 U.runtime.is_dirty = true;
873 project_mark_dirty(bmain);
874
875 /* Force full redraw of all windows. */
877
878 return OPERATOR_FINISHED;
879}
880
882{
883 ot->name = "Remove Asset Library";
884 ot->idname = "PROJECT_OT_asset_library_remove";
885 ot->description =
886 "Remove a path to a .blend file, so the Asset Browser will not attempt to show it anymore";
887
890
891 ot->flag = OPTYPE_INTERNAL;
892
893 RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
894}
895
897
898/* -------------------------------------------------------------------- */
901
908
910 {VariableType::STRING, "STRING", 0, "String Variable", ""},
911 {VariableType::FILEPATH, "FILEPATH", 0, "Filepath Variable", ""},
912 {VariableType::INTEGER, "INTEGER", 0, "Integer Variable", ""},
913 {VariableType::FLOAT, "FLOAT", 0, "Float Variable", ""},
914 {0, nullptr, 0, nullptr, nullptr},
915};
916
918{
919 const VariableType variable_type = VariableType(RNA_enum_get(op->ptr, "variable_type"));
920 Main *bmain = CTX_data_main(C);
922 std::string variable_name;
923 bke::ProjectVariableType proj_var_type;
924 switch (variable_type) {
926 variable_name = "string_variable";
927 proj_var_type = bke::ProjectVariableType::STRING;
928 break;
930 variable_name = "filepath_variable";
931 proj_var_type = bke::ProjectVariableType::STRING;
932 break;
934 variable_name = "integer_variable";
935 proj_var_type = bke::ProjectVariableType::INT;
936 break;
938 variable_name = "float_variable";
939 proj_var_type = bke::ProjectVariableType::FLOAT;
940 break;
941 default:
943 break;
944 }
945 bke::ProjectVariable *new_var = project->new_variable(variable_name, proj_var_type);
946 if (variable_type == VariableType::FILEPATH) {
948 }
949 project->active_variable_index = project->variables.size() - 1;
950 });
951 /* Force full redraw of all windows. */
953
954 return OPERATOR_FINISHED;
955}
956
958{
959 ot->name = "Add Variable";
960 ot->idname = "PROJECT_OT_variable_add";
961 ot->description = "Add a new variable to the current project";
962
965
966 ot->flag = OPTYPE_INTERNAL;
967
968 ot->prop = RNA_def_enum(ot->srna,
969 "variable_type",
972 "Variable Type",
973 "The kind of variable type to add");
975}
976
978
979/* -------------------------------------------------------------------- */
983{
984 Main *bmain = CTX_data_main(C);
986 return project != nullptr && project->active_variable_index >= 0 &&
987 project->active_variable_index < project->variables.size();
988 });
989}
990
992{
993 Main *bmain = CTX_data_main(C);
995 project->remove_variable(project->variables[project->active_variable_index].get());
996 });
997 /* Force full redraw of all windows. */
999 return OPERATOR_FINISHED;
1000}
1001
1003{
1004 ot->name = "Remove Variable";
1005 ot->idname = "PROJECT_OT_variable_remove";
1006 ot->description = "Remove the active variable from the current project";
1007
1010
1011 ot->flag = OPTYPE_INTERNAL;
1012}
1013
1015
1016/* -------------------------------------------------------------------- */
1020 UP = 0,
1021 DOWN = 1,
1022};
1023
1025 {DirectionType::UP, "UP", 0, "Move Up", ""},
1026 {DirectionType::DOWN, "DOWN", 0, "Move Down", ""},
1027 {0, nullptr, 0, nullptr, nullptr},
1028};
1030{
1031 const DirectionType direction = DirectionType(RNA_enum_get(op->ptr, "direction"));
1032 Main *bmain = CTX_data_main(C);
1034 int index = project->active_variable_index;
1035 if (direction == UP && index > 0) {
1036 project->move_variable(index, index - 1);
1037 project->active_variable_index -= 1;
1038 }
1039 else if (direction == DOWN && (index + 1) < project->variables.size()) {
1040 project->move_variable(index, index + 1);
1041 project->active_variable_index += 1;
1042 }
1043 });
1044 /* Force full redraw of all windows. */
1046 return OPERATOR_FINISHED;
1047}
1048
1050{
1051 ot->name = "Move Variable";
1052 ot->idname = "PROJECT_OT_variable_move";
1053 ot->description = "Move the active variable up or down in the list of variables";
1054
1057
1058 ot->flag = OPTYPE_INTERNAL;
1059
1060 ot->prop = RNA_def_enum(ot->srna,
1061 "direction",
1063 0,
1064 "Move Direction",
1065 "Which direction to move the variable");
1067}
1068
1070
1071} // namespace blender
#define G_MAIN
File and directory operations.
#define FILE_MAX
#define BLI_path_join(...)
#define FILE_MAXDIR
#define RPT_(msgid)
#define TIP_(msgid)
#define IFACE_(msgid)
#define DATA_(msgid)
#define USER_EXPERIMENTAL_TEST(userdef, member)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_PROJECT_CHANGED
Definition WM_types.hh:436
#define NC_WM
Definition WM_types.hh:387
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
constexpr const char * c_str() const
constexpr StringRef()
void append(const T &value)
bool is_empty() const
IndexRange index_range() const
void string_subtype_set(ProjectVariableStringSubtype type)
constexpr bool contains(int64_t value) const
static constexpr int64_t not_found
#define INT_MAX
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
void template_filepath(Layout *layout, const bContext *C, PointerRNA *ptr, const StringRefNull propname, const char *pathselect_op, const char *filter_glob, const std::optional< StringRef > name, const std::optional< StringRef > placeholder, bool split_name=false)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static constexpr EnumPropertyItem project_variable_type_items[]
bUserAssetLibraryAddType
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
const EnumPropertyItem custom_library_type_items[]
static Vector< std::string > new_project_suggested_directories(const Main *bmain)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
static wmOperatorStatus project_asset_library_add_exec(bContext *C, wmOperator *op)
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static bool project_new_poll(bContext *C)
const char * RNA_property_ui_name_raw(const PropertyRNA *prop, const PointerRNA *ptr)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void BKE_blender_project_config_autosave(Main *bmain)
bool wm_operator_close_file_dialog_if_needed(bContext *C, wmOperator *op, wmGenericCallbackFn post_action_fn)
Definition wm_files.cc:5331
static std::string new_project_find_root(const StringRefNull directory)
@ ASSET_LIBRARY_PROJECT_DEFINED
void PROJECT_OT_open(wmOperatorType *ot)
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
Definition fileops_c.cc:416
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bke::BlenderProject * BKE_blender_project_get(const Main *bmain)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
void PROJECT_OT_variable_remove(wmOperatorType *ot)
static wmOperatorStatus project_new_exec(bContext *C, wmOperator *op)
void PROJECT_OT_close(wmOperatorType *ot)
static void project_close_after_dialog_callback(bContext *C, void *user_data)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void project_new_ui(bContext *C, wmOperator *op)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
static void new_project_name_update(Main *, Scene *, PointerRNA *ptr)
PropertyRNA * RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus project_open_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem * new_project_existing_directory_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file) ATTR_NONNULL(1
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
static void new_project_name_from_directory(PointerRNA *ptr, const StringRefNull directory)
void PROJECT_OT_config_save(wmOperatorType *ot)
static wmOperatorStatus project_open_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool project_variable_remove_poll(bContext *C)
static wmOperatorStatus project_variable_move_exec(bContext *C, wmOperator *op)
static bool has_vaild_project_poll(bContext *C)
static std::string new_project_name_get(PointerRNA *ptr)
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)
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
void WM_init_splash(bContext *C)
void BKE_blender_project_clear()
const char * BLI_dir_home()
Definition storage.cc:99
Global G
Definition blender.cc:57
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
static void project_mark_dirty(Main *bmain)
static const EnumPropertyItem * custom_library_type_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static void new_project_directory_update(Main *, Scene *, PointerRNA *ptr)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
static void new_project_draw_folder_info(ui::Layout &layout, const std::string &root_path)
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1)
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
static bool project_asset_library_remove_poll(bContext *C)
void BKE_blender_project_recent_update(const Main *bmain)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
@ WM_FILESEL_DIRECTORY
Definition WM_api.hh:1330
void ED_userpref_asset_library_remove(bContext *C, struct bUserAssetLibrary *asset_library)
bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
struct bUserAssetLibrary * ED_userpref_asset_library_new(const struct bContext *C, const char *name, const char *dirpath, bUserAssetLibraryAddType library_type, bool is_project_defined, std::optional< UUID > uuid, std::optional< char * > auth_token)
void PROJECT_OT_asset_library_add(wmOperatorType *ot)
static constexpr EnumPropertyItem project_variable_move_items[]
const char * RNA_property_ui_description_raw(const PropertyRNA *prop, const PointerRNA *ptr)
bool BKE_blender_project_config_file_write(Main *bmain)
static wmOperatorStatus project_close_exec(bContext *C, wmOperator *op)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
bool BKE_appdir_folder_documents(char *dir) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:174
int BLI_path_normalize(char *path) ATTR_NONNULL(1)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void PROJECT_OT_new(wmOperatorType *ot)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
static wmOperatorStatus project_new_invoke(bContext *C, wmOperator *op, const wmEvent *)
int RNA_string_length(PointerRNA *ptr, const char *name)
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:457
static void new_project_existing_directory_update(Main *bmain, Scene *, PointerRNA *ptr)
std::string BKE_is_path_inside_blender_project(const char *path)
bool BKE_blender_project_init(blender::StringRef name, blender::StringRef root_path)
wmOperatorStatus WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message)
wmOperatorStatus WM_operator_name_call_with_properties(bContext *C, const char *opstring, wm::OpCallContext context, IDProperty *properties, const wmEvent *event)
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ FILE_OPENFILE
Definition WM_api.hh:1341
void PROJECT_OT_variable_move(wmOperatorType *ot)
Main * CTX_data_main(const bContext *C)
static wmOperatorStatus project_variable_add_exec(bContext *C, wmOperator *op)
static void new_project_update_directory_from_name_set(PointerRNA *ptr)
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
void PROJECT_OT_asset_library_remove(wmOperatorType *ot)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
@ PROP_HIDDEN
Definition RNA_types.hh:408
static void project_open_after_dialog_callback(bContext *C, void *user_data)
static wmOperatorStatus project_asset_library_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
static wmOperatorStatus project_asset_library_remove_exec(bContext *C, wmOperator *op)
static wmOperatorStatus project_config_save_exec(bContext *C, wmOperator *)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
std::string RNA_string_get(PointerRNA *ptr, const char *name)
static std::string new_project_default_parent()
static std::string new_project_root_path(const Main *bmain, PointerRNA *ptr)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus project_close_invoke(bContext *C, wmOperator *op, const wmEvent *)
void PROJECT_OT_variable_add(wmOperatorType *ot)
static bool new_project_use_existing_directory(const Main *bmain, PointerRNA *ptr)
bool BKE_blender_project_init_from_root_path(Main *bmain, std::string project_root_path)
static wmOperatorStatus project_variable_remove_exec(bContext *C, wmOperator *)
static void project_asset_library_add_ui(bContext *, wmOperator *op)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
auto BKE_blender_project_write_callback(const Main *bmain, Fn lambda)
std::string BKE_blender_project_path_make_relative(StringRef path, bool path_is_template, const bke::BlenderProject &project)
void enabled_set(bool enabled)
void alignment_set(LayoutAlign alignment)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & split(float percentage, bool align)
Layout & row(bool align)
Button * button(StringRef name, int icon, std::function< void(bContext &)> func, std::optional< StringRef > tooltip=std::nullopt)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports