Blender V4.3
io_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <fmt/format.h>
6
7#include "BLI_path_utils.hh"
8
9#include "BLT_translation.hh"
10
11#include "BKE_context.hh"
12#include "BKE_main.hh"
13
14#include "DNA_space_types.h"
15
16#include "RNA_access.hh"
17#include "RNA_prototypes.hh"
18
19#include "WM_api.hh"
20
21#include "io_utils.hh"
22
23namespace blender::ed::io {
24
26{
27
28 PropertyRNA *filepath_prop = RNA_struct_find_property(op->ptr, "filepath");
29 PropertyRNA *directory_prop = RNA_struct_find_property(op->ptr, "directory");
30 if ((filepath_prop && RNA_property_is_set(op->ptr, filepath_prop)) ||
31 (directory_prop && RNA_property_is_set(op->ptr, directory_prop)))
32 {
33 std::string title;
34 PropertyRNA *files_prop = RNA_struct_find_property(op->ptr, "files");
35 if (directory_prop && files_prop) {
36 const auto files = paths_from_operator_properties(op->ptr);
37 if (files.size() == 1) {
38 title = files[0];
39 }
40 else {
41 title = fmt::format(TIP_("Import {} files"), files.size());
42 }
43 }
44 else {
45 char filepath[FILE_MAX];
46 RNA_string_get(op->ptr, "filepath", filepath);
47 title = filepath;
48 }
50 C, op, 350, std::move(title), WM_operatortype_name(op->type, op->ptr));
51 }
52
55}
56
58{
59 View3D *v3d = CTX_wm_view3d(C);
60 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
61 ARegion *region = CTX_wm_region(C);
62 if (!region || region->regiontype != RGN_TYPE_WINDOW) {
63 return false;
64 }
65 if (v3d) {
66 return true;
67 }
68 if (space_outliner && space_outliner->outlinevis == SO_VIEW_LAYER) {
69 return true;
70 }
71 return false;
72}
73
75{
77 PropertyRNA *directory_prop = RNA_struct_find_property(ptr, "directory");
78 PropertyRNA *relative_path_prop = RNA_struct_find_property(ptr, "relative_path");
79 const bool is_relative_path = relative_path_prop ?
80 RNA_property_boolean_get(ptr, relative_path_prop) :
81 false;
82 if (RNA_property_is_set(ptr, directory_prop)) {
83 char directory[FILE_MAX], name[FILE_MAX];
84
85 RNA_string_get(ptr, "directory", directory);
86 if (is_relative_path && !BLI_path_is_rel(directory)) {
88 }
89
91 *ptr, "files", &RNA_OperatorFileListElement);
92
93 BLI_assert(files_prop);
94
95 RNA_PROP_BEGIN (ptr, file_ptr, files_prop) {
96 RNA_string_get(&file_ptr, "name", name);
97 char path[FILE_MAX];
98 BLI_path_join(path, sizeof(path), directory, name);
99 paths.append_non_duplicates(path);
100 }
102 }
103 PropertyRNA *filepath_prop = RNA_struct_find_property(ptr, "filepath");
104 if (filepath_prop && RNA_property_is_set(ptr, filepath_prop)) {
105 char filepath[FILE_MAX];
106 RNA_string_get(ptr, "filepath", filepath);
107 if (is_relative_path && !BLI_path_is_rel(filepath)) {
109 }
110 paths.append_non_duplicates(filepath);
111 }
112 return paths;
113}
114} // namespace blender::ed::io
SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:837
#define BLI_assert(a)
Definition BLI_assert.h:50
#define FILE_MAX
#define BLI_path_join(...)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
#define TIP_(msgid)
@ RGN_TYPE_WINDOW
@ SO_VIEW_LAYER
@ OPERATOR_RUNNING_MODAL
#define RNA_PROP_END
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
bool poll_file_object_drop(const bContext *C, blender::bke::FileHandlerType *)
Definition io_utils.cc:57
Vector< std::string > paths_from_operator_properties(PointerRNA *ptr)
Definition io_utils.cc:74
int filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition io_utils.cc:25
PropertyRNA * RNA_struct_find_collection_property_check(PointerRNA &props, const char *name, const StructRNA *struct_type_check)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
struct wmOperatorType * type
struct PointerRNA * ptr
void WM_event_add_fileselect(bContext *C, wmOperator *op)
PointerRNA * ptr
Definition wm_files.cc:4126
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
int 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)