Blender V5.0
file_panels.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_listbase.h"
10#include "BLI_string_utf8.h"
11#include "BLI_utildefines.h"
12
13#include "BKE_context.hh"
14#include "BKE_screen.hh"
15
16#include "BLT_translation.hh"
17
18#include "DNA_screen_types.h"
19#include "DNA_space_types.h"
20
21#include "MEM_guardedalloc.h"
22
23#include "RNA_access.hh"
24#include "RNA_define.hh"
25#include "RNA_prototypes.hh"
26
27#include "ED_fileselect.hh"
28
29#include "UI_interface.hh"
30#include "UI_interface_icons.hh"
32#include "UI_resources.hh"
33
34#include "WM_api.hh"
35#include "WM_types.hh"
36
37#include "file_intern.hh"
38#include "filelist.hh"
39
40#include <cstring>
41
42static bool file_panel_operator_poll(const bContext *C, PanelType * /*pt*/)
43{
45 return (sfile && sfile->op);
46}
47
49{
51 return sfile && sfile->files && ED_fileselect_is_asset_browser(sfile);
52}
53
54static void file_panel_operator_header(const bContext *C, Panel *panel)
55{
57 wmOperator *op = sfile->op;
58
59 const std::string opname = WM_operatortype_name(op->type, op->ptr);
60 UI_panel_drawname_set(panel, opname);
61}
62
63static void file_panel_operator(const bContext *C, Panel *panel)
64{
66 wmOperator *op = sfile->op;
67
68 UI_block_func_set(panel->layout->block(), file_draw_check_cb, nullptr, nullptr);
69
70 /* Hack: temporary hide. */
71 const char *hide[] = {"filepath", "files", "directory", "filename"};
72 /* Track overridden properties with #PROP_HIDDEN flag. */
73 bool hidden_override[ARRAY_SIZE(hide)] = {false};
74 for (int i = 0; i < ARRAY_SIZE(hide); i++) {
75 PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
76 if (prop && !(RNA_property_flag(prop) & PROP_HIDDEN)) {
78 hidden_override[i] = true;
79 }
80 }
81
84
85 /* Hack: temporary hide. */
86 for (int i = 0; i < ARRAY_SIZE(hide); i++) {
87 PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
88 if (prop && hidden_override[i]) {
90 }
91 }
92
93 UI_block_func_set(panel->layout->block(), nullptr, nullptr, nullptr);
94}
95
97{
98 PanelType *pt;
99
100 pt = MEM_callocN<PanelType>("spacetype file operator properties");
101 STRNCPY_UTF8(pt->idname, "FILE_PT_operator");
102 STRNCPY_UTF8(pt->label, N_("Operator"));
108 BLI_addtail(&art->paneltypes, pt);
109}
110
112{
113 uiLayout *row = &layout->row(false);
114 row->scale_x_set(0.8f);
115 row->fixed_size_set(true);
116 row->op("FILE_OT_cancel", IFACE_("Cancel"), ICON_NONE);
117}
118
119static void file_panel_execution_execute_button(uiLayout *layout, const char *title)
120{
121 uiLayout *row = &layout->row(false);
122 row->scale_x_set(0.8f);
123 row->fixed_size_set(true);
124 /* Just a display hint. */
125 row->active_default_set(true);
126 row->op("FILE_OT_execute", title, ICON_NONE);
127}
128
130{
131 bScreen *screen = CTX_wm_screen(C);
132 SpaceFile *sfile = CTX_wm_space_file(C);
134 uiBlock *block = panel->layout->block();
135 uiBut *but;
136 uiLayout *row;
137 PointerRNA *but_extra_rna_ptr;
138
139 const bool overwrite_alert = file_draw_check_exists(sfile);
140 const bool windows_layout =
141#ifdef _WIN32
142 true;
143#else
144 false;
145#endif
146
148 &screen->id, &RNA_FileSelectParams, params);
149
150 row = &panel->layout->row(false);
151 row->scale_y_set(1.3f);
152
153 /* callbacks for operator check functions */
154 UI_block_func_set(block, file_draw_check_cb, nullptr, nullptr);
155
156 but = uiDefButR(block,
158 -1,
159 "",
160 0,
161 0,
162 UI_UNIT_X * 5,
163 UI_UNIT_Y,
164 &params_rna_ptr,
165 "filename",
166 0,
167 0.0f,
168 float(FILE_MAXFILE),
169 overwrite_alert ? TIP_("File name, overwrite existing") : TIP_("File name"));
170
173
175 /* silly workaround calling NFunc to ensure this does not get called
176 * immediate ui_apply_but_func but only after button deactivates */
178
179 if (params->flag & FILE_CHECK_EXISTING) {
180 but_extra_rna_ptr = UI_but_extra_operator_icon_add(
181 but, "FILE_OT_filenum", blender::wm::OpCallContext::ExecRegionWin, ICON_REMOVE);
182 RNA_int_set(but_extra_rna_ptr, "increment", -1);
183 but_extra_rna_ptr = UI_but_extra_operator_icon_add(
184 but, "FILE_OT_filenum", blender::wm::OpCallContext::ExecRegionWin, ICON_ADD);
185 RNA_int_set(but_extra_rna_ptr, "increment", 1);
186 }
187
188 /* check if this overrides a file and if the operator option is used */
189 if (overwrite_alert) {
191 }
192 UI_block_func_set(block, nullptr, nullptr, nullptr);
193
194 {
195 uiLayout *sub = &row->row(false);
197
198 if (windows_layout) {
201 }
202 else {
205 }
206 }
207}
208
210{
211 PanelType *pt;
212
213 pt = MEM_callocN<PanelType>("spacetype file execution buttons");
214 STRNCPY_UTF8(pt->idname, "FILE_PT_execution_buttons");
215 STRNCPY_UTF8(pt->label, N_("Execute Buttons"));
220 BLI_addtail(&art->paneltypes, pt);
221}
222
224{
225 bScreen *screen = CTX_wm_screen(C);
226 SpaceFile *sfile = CTX_wm_space_file(C);
227 /* May be null if the library wasn't loaded yet. */
230 BLI_assert(params != nullptr);
231
232 uiLayout *col = &panel->layout->column(false);
233 uiLayout *row = &col->row(true);
234
236 &screen->id, &RNA_FileAssetSelectParams, params);
237
238 row->prop(&params_ptr, "asset_library_reference", UI_ITEM_NONE, "", ICON_NONE);
239 if (params->asset_library_ref.type == ASSET_LIBRARY_LOCAL) {
240 bContext *mutable_ctx = CTX_copy(C);
241 if (WM_operator_name_poll(mutable_ctx, "asset.bundle_install")) {
242 col->separator();
243 col->op_menu_enum(C,
244 "asset.bundle_install",
245 "asset_library_reference",
246 IFACE_("Copy Bundle to Asset Library..."),
247 ICON_IMPORT);
248 }
249 CTX_free(mutable_ctx);
250 }
251 else {
252 row->op("ASSET_OT_library_refresh", "", ICON_FILE_REFRESH);
253 }
254
255 col->separator();
256
258 C, asset_library, col, sfile, params);
259}
260
262{
263 PanelType *pt;
264
265 pt = MEM_callocN<PanelType>("spacetype file asset catalog buttons");
266 STRNCPY_UTF8(pt->idname, "FILE_PT_asset_catalog_buttons");
267 STRNCPY_UTF8(pt->label, N_("Asset Catalogs"));
272 BLI_addtail(&art->paneltypes, pt);
273}
bScreen * CTX_wm_screen(const bContext *C)
SpaceFile * CTX_wm_space_file(const bContext *C)
bContext * CTX_copy(const bContext *C)
void CTX_free(bContext *C)
@ PANEL_TYPE_NO_HEADER
#define BLI_assert(a)
Definition BLI_assert.h:46
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
#define FILE_MAXFILE
#define STRNCPY_UTF8(dst, src)
#define ARRAY_SIZE(arr)
#define TIP_(msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
@ ASSET_LIBRARY_LOCAL
@ FILE_CHECK_EXISTING
FileSelectParams * ED_fileselect_get_active_params(const SpaceFile *sfile)
Definition filesel.cc:379
bool ED_fileselect_is_asset_browser(const SpaceFile *sfile)
Definition filesel.cc:467
FileAssetSelectParams * ED_fileselect_get_asset_params(const SpaceFile *sfile)
Definition filesel.cc:402
Read Guarded memory(de)allocation.
@ PROP_HIDDEN
Definition RNA_types.hh:338
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
uiBut * uiDefButR(uiBlock *block, ButType type, int retval, std::optional< blender::StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, blender::StringRefNull propname, int index, float min, float max, std::optional< blender::StringRef > tip)
PointerRNA * UI_but_extra_operator_icon_add(uiBut *but, blender::StringRefNull opname, blender::wm::OpCallContext opcontext, int icon)
@ UI_BUT_REDALERT
@ UI_BUT_UNDO
void UI_panel_drawname_set(Panel *panel, blender::StringRef name)
bool UI_but_is_utf8(const uiBut *but)
@ UI_BUT_LABEL_ALIGN_NONE
void uiTemplateOperatorPropertyButs(const bContext *C, uiLayout *layout, wmOperator *op, eButLabelAlign label_align, short flag)
void UI_block_func_set(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2)
void UI_but_func_complete_set(uiBut *but, uiButCompleteFunc func, void *arg)
#define UI_UNIT_X
@ UI_TEMPLATE_OP_PROPS_SHOW_EMPTY
void UI_but_funcN_set(uiBut *but, uiButHandleNFunc funcN, void *argN, void *arg2, uiButArgNFree func_argN_free_fn=MEM_freeN, uiButArgNCopy func_argN_copy_fn=MEM_dupallocN)
void UI_but_flag_enable(uiBut *but, int flag)
bool UI_but_flag_is_set(uiBut *but, int flag)
#define UI_ITEM_NONE
int autocomplete_file(bContext *C, char *str, void *arg_v)
Definition filesel.cc:1271
void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but)
Definition file_ops.cc:3008
bool file_draw_check_exists(SpaceFile *sfile)
Definition file_ops.cc:1783
void file_draw_check_cb(bContext *C, void *arg1, void *arg2)
Definition file_ops.cc:1778
static bool file_panel_operator_poll(const bContext *C, PanelType *)
static bool file_panel_asset_browsing_poll(const bContext *C, PanelType *)
static void file_panel_execution_execute_button(uiLayout *layout, const char *title)
static void file_panel_execution_cancel_button(uiLayout *layout)
void file_execute_region_panels_register(ARegionType *art)
static void file_panel_execution_buttons_draw(const bContext *C, Panel *panel)
static void file_panel_operator_header(const bContext *C, Panel *panel)
static void file_panel_asset_catalog_buttons_draw(const bContext *C, Panel *panel)
void file_tool_props_region_panels_register(ARegionType *art)
static void file_panel_operator(const bContext *C, Panel *panel)
void file_tools_region_panels_register(ARegionType *art)
blender::asset_system::AssetLibrary * filelist_asset_library(FileList *filelist)
Definition filelist.cc:1027
uint col
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void file_create_asset_catalog_tree_view_in_layout(const bContext *C, asset_system::AssetLibrary *asset_library, uiLayout *layout, SpaceFile *space_file, FileAssetSelectParams *params)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
int RNA_property_flag(PropertyRNA *prop)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
ListBase paneltypes
void(* draw)(const bContext *C, Panel *panel)
char idname[BKE_ST_MAXNAME]
bool(* poll)(const bContext *C, PanelType *pt)
char translation_context[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
void(* draw_header)(const bContext *C, Panel *panel)
struct uiLayout * layout
struct wmOperator * op
struct FileList * files
void fixed_size_set(bool fixed_size)
void active_default_set(bool active_default)
void scale_y_set(float scale)
uiBlock * block() const
void operator_context_set(blender::wm::OpCallContext opcontext)
uiLayout & column(bool align)
void scale_x_set(float scale)
uiLayout & row(bool align)
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, blender::wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
struct wmOperatorType * type
struct PointerRNA * ptr
i
Definition text_draw.cc:230
#define N_(msgid)
bool WM_operator_name_poll(bContext *C, const char *opstring)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)