Blender V5.3
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.hh"
10#include "BLI_string_utf8.hh"
11#include "BLI_utildefines.hh"
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_c.hh"
31#include "UI_interface_icons.hh"
33#include "UI_resources.hh"
34
35#include "WM_api.hh"
36#include "WM_types.hh"
37
38#include "file_intern.hh"
39#include "filelist.hh"
40
41#include <cstring>
42
43namespace blender {
44
45static bool file_panel_operator_poll(const bContext *C, PanelType * /*pt*/)
46{
48 return (sfile && sfile->op);
49}
50
52{
54 return sfile && sfile->files && ED_fileselect_is_asset_browser(sfile);
55}
56
57static void file_panel_operator_header(const bContext *C, Panel *panel)
58{
60 wmOperator *op = sfile->op;
61
62 const std::string opname = WM_operatortype_name(op->type, op->ptr);
63 ui::panel_drawname_set(panel, opname);
64}
65
66static void file_panel_operator(const bContext *C, Panel *panel)
67{
69 wmOperator *op = sfile->op;
70
71 block_func_set(panel->layout->block(), file_draw_check_cb, nullptr, nullptr);
72
73 /* Hack: temporary hide. */
74 const char *hide[] = {"filepath", "files", "directory", "filename"};
75 /* Track overridden properties with #PROP_HIDDEN flag. */
76 bool hidden_override[ARRAY_SIZE(hide)] = {false};
77 for (int i = 0; i < ARRAY_SIZE(hide); i++) {
79 if (prop && !(RNA_property_flag(prop) & PROP_HIDDEN)) {
81 hidden_override[i] = true;
82 }
83 }
84 /* Operator file selector window is a kind of popup, use persistent layout panel states for the
85 * active operator. */
87 op->type->idname);
88 uiTemplateOperatorPropertyButs(
90
91 /* Hack: temporary hide. */
92 for (int i = 0; i < ARRAY_SIZE(hide); i++) {
94 if (prop && hidden_override[i]) {
96 }
97 }
98
99 block_func_set(panel->layout->block(), nullptr, nullptr, nullptr);
100}
101
103{
104 PanelType *pt;
105
106 pt = MEM_new_zeroed<PanelType>("spacetype file operator properties");
107 STRNCPY_UTF8(pt->idname, "FILE_PT_operator");
108 STRNCPY_UTF8(pt->label, N_("Operator"));
114 BLI_addtail(&art->paneltypes, pt);
115}
116
118{
119 ui::Layout &row = layout.row(false);
120 row.scale_x_set(0.8f);
121 row.fixed_size_set(true);
122 row.op("FILE_OT_cancel", IFACE_("Cancel"), ICON_NONE);
123}
124
126 const char *title,
127 const bool overwrite)
128{
129 ui::Layout &row = layout.row(false);
130 row.scale_x_set(0.8f);
131 row.fixed_size_set(true);
132 /* Just a display hint. */
133 row.active_default_set(true);
134 row.red_alert_set(overwrite);
135 row.op("FILE_OT_execute", overwrite ? IFACE_("Overwrite") : title, ICON_NONE);
136}
137
139{
140 bScreen *screen = CTX_wm_screen(C);
141 SpaceFile *sfile = CTX_wm_space_file(C);
143 ui::Block *block = panel->layout->block();
144
145 PointerRNA *but_extra_rna_ptr;
146
147 const bool overwrite_alert = file_draw_check_exists(sfile);
148 const bool windows_layout =
149#ifdef _WIN32
150 true;
151#else
152 false;
153#endif
154
156 &screen->id, RNA_FileSelectParams, params);
157
158 ui::Layout &row = panel->layout->row(false);
159 row.scale_y_set(1.3f);
160
161 /* callbacks for operator check functions */
162 block_func_set(block, file_draw_check_cb, nullptr, nullptr);
163
164 ui::Button *but = uiDefButR(block,
166 "",
167 0,
168 0,
169 UI_UNIT_X * 5,
170 UI_UNIT_Y,
171 &params_rna_ptr,
172 "filename",
173 0,
174 0.0f,
175 float(FILE_MAXFILE),
176 overwrite_alert ? TIP_("File name, overwrite existing") :
177 TIP_("File name"));
178
179 BLI_assert(!button_flag_is_set(but, ui::BUT_UNDO));
180 BLI_assert(!but_is_utf8(but));
181
182 button_func_complete_set(but, autocomplete_file, nullptr);
183 /* silly workaround calling NFunc to ensure this does not get called
184 * immediate apply_but_func but only after button deactivates */
185 button_funcN_set(but, file_filename_enter_handle, nullptr, but);
186
187 if (params->flag & FILE_CHECK_EXISTING) {
188 but_extra_rna_ptr = button_extra_operator_icon_add(
189 but, "FILE_OT_filenum", wm::OpCallContext::ExecRegionWin, ICON_REMOVE);
190 RNA_int_set(but_extra_rna_ptr, "increment", -1);
191 but_extra_rna_ptr = button_extra_operator_icon_add(
192 but, "FILE_OT_filenum", wm::OpCallContext::ExecRegionWin, ICON_ADD);
193 RNA_int_set(but_extra_rna_ptr, "increment", 1);
194 }
195
196 /* check if this overrides a file and if the operator option is used */
197 if (overwrite_alert) {
198 button_flag_enable(but, ui::BUT_REDALERT);
199 }
200 block_func_set(block, nullptr, nullptr, nullptr);
201
202 {
203 ui::Layout &sub = row.row(false);
205
206 if (windows_layout) {
207 file_panel_execution_execute_button(sub, params->title, overwrite_alert);
209 }
210 else {
212 file_panel_execution_execute_button(sub, params->title, overwrite_alert);
213 }
214 }
215}
216
218{
219 PanelType *pt;
220
221 pt = MEM_new_zeroed<PanelType>("spacetype file execution buttons");
222 STRNCPY_UTF8(pt->idname, "FILE_PT_execution_buttons");
223 STRNCPY_UTF8(pt->label, N_("Execute Buttons"));
228 BLI_addtail(&art->paneltypes, pt);
229}
230
232{
233 bScreen *screen = CTX_wm_screen(C);
234 SpaceFile *sfile = CTX_wm_space_file(C);
235 /* May be null if the library wasn't loaded yet. */
238 BLI_assert(params != nullptr);
239
240 ui::Layout &col = panel->layout->column(false);
241 ui::Layout &row = col.row(true);
242
244 &screen->id, RNA_FileAssetSelectParams, params);
245
246 row.prop(&params_ptr, "asset_library_reference", UI_ITEM_NONE, "", ICON_NONE);
248 bContext *mutable_ctx = CTX_copy(C);
249 if (WM_operator_name_poll(mutable_ctx, "asset.bundle_install")) {
250 col.separator();
251 col.op_menu_enum(C,
252 "asset.bundle_install",
253 "asset_library_reference",
254 IFACE_("Copy Bundle to Asset Library..."),
255 ICON_IMPORT);
256 }
257 CTX_free(mutable_ctx);
258 }
259 else {
260 PointerRNA ptr = row.op("ASSET_OT_library_refresh", "", ICON_FILE_REFRESH);
261 RNA_boolean_set(&ptr, "use_shift_for_remote_listing", true);
262 }
263
264 col.separator();
265
267 C, asset_library, col, sfile, params);
268}
269
271{
272 PanelType *pt;
273
274 pt = MEM_new_zeroed<PanelType>("spacetype file asset catalog buttons");
275 STRNCPY_UTF8(pt->idname, "FILE_PT_asset_catalog_buttons");
276 STRNCPY_UTF8(pt->label, N_("Asset Catalogs"));
281 BLI_addtail(&art->paneltypes, pt);
282}
283
284} // namespace blender
#define FILE_MAXFILE
#define STRNCPY_UTF8(dst, src)
#define TIP_(msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
#define UI_ITEM_NONE
void file_create_asset_catalog_tree_view_in_layout(const bContext *C, asset_system::AssetLibrary *asset_library, ui::Layout &layout, SpaceFile *space_file, FileAssetSelectParams *params)
void panel_drawname_set(Panel *panel, StringRef name)
ListBaseT< LayoutPanelState > & popup_persistent_layout_panel_states(StringRef idname)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void file_draw_check_cb(bContext *C, void *arg1, void *arg2)
Definition file_ops.cc:1799
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
static void file_panel_execution_buttons_draw(const bContext *C, Panel *panel)
static void file_panel_execution_execute_button(ui::Layout &layout, const char *title, const bool overwrite)
bool ED_fileselect_is_asset_browser(const SpaceFile *sfile)
Definition filesel.cc:486
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static bool file_panel_asset_browsing_poll(const bContext *C, PanelType *)
int autocomplete_file(bContext *C, char *str, void *arg_v)
Definition filesel.cc:1315
asset_system::AssetLibrary * filelist_asset_library(FileList *filelist)
Definition filelist.cc:1050
@ ASSET_LIBRARY_LOCAL
void file_tool_props_region_panels_register(ARegionType *art)
bool WM_operator_name_poll(bContext *C, const char *opstring)
void file_execute_region_panels_register(ARegionType *art)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void file_panel_operator(const bContext *C, Panel *panel)
int RNA_property_flag(PropertyRNA *prop)
void CTX_free(bContext *C)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bContext * CTX_copy(const bContext *C)
FileSelectParams * ED_fileselect_get_active_params(const SpaceFile *sfile)
Definition filesel.cc:393
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool file_draw_check_exists(SpaceFile *sfile)
Definition file_ops.cc:1804
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
FileAssetSelectParams * ED_fileselect_get_asset_params(const SpaceFile *sfile)
Definition filesel.cc:416
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
static void file_panel_execution_cancel_button(ui::Layout &layout)
@ PANEL_TYPE_NO_HEADER
static void file_panel_operator_header(const bContext *C, Panel *panel)
static void file_panel_asset_catalog_buttons_draw(const bContext *C, Panel *panel)
@ PROP_HIDDEN
Definition RNA_types.hh:408
SpaceFile * CTX_wm_space_file(const bContext *C)
void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but)
Definition file_ops.cc:3040
bScreen * CTX_wm_screen(const bContext *C)
void file_tools_region_panels_register(ARegionType *art)
static bool file_panel_operator_poll(const bContext *C, PanelType *)
ListBaseT< PanelType > paneltypes
AssetLibraryReference asset_library_ref
eFileSel_Params_Flag flag
char translation_context[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Panel *panel)
bool(*) poll(const bContext *C, PanelType *pt)
void(*) draw_header(const bContext *C, Panel *panel)
char idname[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
ListBaseT< LayoutPanelState > * layout_panel_states_storage
ui::Layout * layout
struct Panel_Runtime * runtime
struct wmOperator * op
struct FileList * files
void fixed_size_set(bool fixed_size)
void operator_context_set(wm::OpCallContext opcontext)
PointerRNA op_menu_enum(const bContext *C, wmOperatorType *ot, StringRefNull propname, std::optional< StringRefNull > name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void scale_x_set(float scale)
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)
void red_alert_set(bool red_alert)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
void scale_y_set(float scale)
Layout & row(bool align)
void active_default_set(bool active_default)
struct wmOperatorType * type
#define N_(msgid)