Blender V4.5
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.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"
31#include "UI_resources.hh"
32
33#include "WM_api.hh"
34#include "WM_types.hh"
35
36#include "file_intern.hh"
37#include "filelist.hh"
38
39#include <cstring>
40
41static bool file_panel_operator_poll(const bContext *C, PanelType * /*pt*/)
42{
44 return (sfile && sfile->op);
45}
46
48{
50 return sfile && sfile->files && ED_fileselect_is_asset_browser(sfile);
51}
52
53static void file_panel_operator_header(const bContext *C, Panel *panel)
54{
56 wmOperator *op = sfile->op;
57
58 const std::string opname = WM_operatortype_name(op->type, op->ptr);
59 UI_panel_drawname_set(panel, opname);
60}
61
62static void file_panel_operator(const bContext *C, Panel *panel)
63{
65 wmOperator *op = sfile->op;
66
68
69 /* Hack: temporary hide. */
70 const char *hide[] = {"filepath", "files", "directory", "filename"};
71 /* Track overridden properties with #PROP_HIDDEN flag. */
72 bool hidden_override[ARRAY_SIZE(hide)] = {false};
73 for (int i = 0; i < ARRAY_SIZE(hide); i++) {
74 PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
75 if (prop && !(RNA_property_flag(prop) & PROP_HIDDEN)) {
77 hidden_override[i] = true;
78 }
79 }
80
83
84 /* Hack: temporary hide. */
85 for (int i = 0; i < ARRAY_SIZE(hide); i++) {
86 PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
87 if (prop && hidden_override[i]) {
89 }
90 }
91
92 UI_block_func_set(uiLayoutGetBlock(panel->layout), nullptr, nullptr, nullptr);
93}
94
96{
97 PanelType *pt;
98
99 pt = MEM_callocN<PanelType>("spacetype file operator properties");
100 STRNCPY(pt->idname, "FILE_PT_operator");
101 STRNCPY(pt->label, N_("Operator"));
107 BLI_addtail(&art->paneltypes, pt);
108}
109
111{
112 uiLayout *row = &layout->row(false);
113 uiLayoutSetScaleX(row, 0.8f);
114 uiLayoutSetFixedSize(row, true);
115 row->op("FILE_OT_cancel", IFACE_("Cancel"), ICON_NONE);
116}
117
118static void file_panel_execution_execute_button(uiLayout *layout, const char *title)
119{
120 uiLayout *row = &layout->row(false);
121 uiLayoutSetScaleX(row, 0.8f);
122 uiLayoutSetFixedSize(row, true);
123 /* Just a display hint. */
124 uiLayoutSetActiveDefault(row, true);
125 row->op("FILE_OT_execute", title, ICON_NONE);
126}
127
129{
130 bScreen *screen = CTX_wm_screen(C);
131 SpaceFile *sfile = CTX_wm_space_file(C);
133 uiBlock *block = uiLayoutGetBlock(panel->layout);
134 uiBut *but;
135 uiLayout *row;
136 PointerRNA *but_extra_rna_ptr;
137
138 const bool overwrite_alert = file_draw_check_exists(sfile);
139 const bool windows_layout =
140#ifdef _WIN32
141 true;
142#else
143 false;
144#endif
145
147 &screen->id, &RNA_FileSelectParams, params);
148
149 row = &panel->layout->row(false);
150 uiLayoutSetScaleY(row, 1.3f);
151
152 /* callbacks for operator check functions */
153 UI_block_func_set(block, file_draw_check_cb, nullptr, nullptr);
154
155 but = uiDefButR(block,
157 -1,
158 "",
159 0,
160 0,
161 UI_UNIT_X * 5,
162 UI_UNIT_Y,
163 &params_rna_ptr,
164 "filename",
165 0,
166 0.0f,
167 float(FILE_MAXFILE),
168 overwrite_alert ? TIP_("File name, overwrite existing") : TIP_("File name"));
169
172
174 /* silly workaround calling NFunc to ensure this does not get called
175 * immediate ui_apply_but_func but only after button deactivates */
177
178 if (params->flag & FILE_CHECK_EXISTING) {
179 but_extra_rna_ptr = UI_but_extra_operator_icon_add(
180 but, "FILE_OT_filenum", WM_OP_EXEC_REGION_WIN, ICON_REMOVE);
181 RNA_int_set(but_extra_rna_ptr, "increment", -1);
182 but_extra_rna_ptr = UI_but_extra_operator_icon_add(
183 but, "FILE_OT_filenum", WM_OP_EXEC_REGION_WIN, ICON_ADD);
184 RNA_int_set(but_extra_rna_ptr, "increment", 1);
185 }
186
187 /* check if this overrides a file and if the operator option is used */
188 if (overwrite_alert) {
190 }
191 UI_block_func_set(block, nullptr, nullptr, nullptr);
192
193 {
194 uiLayout *sub = &row->row(false);
196
197 if (windows_layout) {
200 }
201 else {
204 }
205 }
206}
207
209{
210 PanelType *pt;
211
212 pt = MEM_callocN<PanelType>("spacetype file execution buttons");
213 STRNCPY(pt->idname, "FILE_PT_execution_buttons");
214 STRNCPY(pt->label, N_("Execute Buttons"));
219 BLI_addtail(&art->paneltypes, pt);
220}
221
223{
224 bScreen *screen = CTX_wm_screen(C);
225 SpaceFile *sfile = CTX_wm_space_file(C);
226 /* May be null if the library wasn't loaded yet. */
229 BLI_assert(params != nullptr);
230
231 uiLayout *col = &panel->layout->column(false);
232 uiLayout *row = &col->row(true);
233
235 &screen->id, &RNA_FileAssetSelectParams, params);
236
237 row->prop(&params_ptr, "asset_library_reference", UI_ITEM_NONE, "", ICON_NONE);
238 if (params->asset_library_ref.type == ASSET_LIBRARY_LOCAL) {
239 bContext *mutable_ctx = CTX_copy(C);
240 if (WM_operator_name_poll(mutable_ctx, "asset.bundle_install")) {
241 col->separator();
243 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(pt->idname, "FILE_PT_asset_catalog_buttons");
267 STRNCPY(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
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
#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:382
bool ED_fileselect_is_asset_browser(const SpaceFile *sfile)
Definition filesel.cc:470
FileAssetSelectParams * ED_fileselect_get_asset_params(const SpaceFile *sfile)
Definition filesel.cc:405
Read Guarded memory(de)allocation.
@ PROP_HIDDEN
Definition RNA_types.hh:324
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
void UI_panel_drawname_set(Panel *panel, blender::StringRef name)
bool UI_but_is_utf8(const uiBut *but)
PointerRNA * UI_but_extra_operator_icon_add(uiBut *but, blender::StringRefNull opname, wmOperatorCallContext opcontext, int icon)
@ UI_TEMPLATE_OP_PROPS_SHOW_EMPTY
@ 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_BTYPE_TEXT
uiBut * uiDefButR(uiBlock *block, int 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)
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)
@ UI_BUT_REDALERT
@ UI_BUT_UNDO
void UI_but_flag_enable(uiBut *but, int flag)
bool UI_but_flag_is_set(uiBut *but, int flag)
void uiLayoutSetFixedSize(uiLayout *layout, bool fixed_size)
void uiLayoutSetScaleY(uiLayout *layout, float scale)
void uiLayoutSetActiveDefault(uiLayout *layout, bool active_default)
uiBlock * uiLayoutGetBlock(uiLayout *layout)
void uiLayoutSetScaleX(uiLayout *layout, float scale)
#define UI_ITEM_NONE
void uiItemMenuEnumO(uiLayout *layout, const bContext *C, blender::StringRefNull opname, blender::StringRefNull propname, blender::StringRefNull name, int icon)
void uiLayoutSetOperatorContext(uiLayout *layout, wmOperatorCallContext opcontext)
@ WM_OP_EXEC_REGION_WIN
Definition WM_types.hh:246
int autocomplete_file(bContext *C, char *str, void *arg_v)
Definition filesel.cc:1278
void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but)
Definition file_ops.cc:2975
bool file_draw_check_exists(SpaceFile *sfile)
Definition file_ops.cc:1777
void file_draw_check_cb(bContext *C, void *arg1, void *arg2)
Definition file_ops.cc:1772
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:1997
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
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, wmOperatorCallContext context, eUI_Item_Flag flag)
uiLayout & column(bool align)
uiLayout & row(bool align)
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)