Blender  V2.93
file_panels.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BLI_blenlib.h"
25 #include "BLI_utildefines.h"
26 
27 #include "BKE_context.h"
28 #include "BKE_screen.h"
29 
30 #include "BLT_translation.h"
31 
32 #include "DNA_screen_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_userdef_types.h"
35 
36 #include "MEM_guardedalloc.h"
37 
38 #include "RNA_access.h"
39 #include "RNA_define.h"
40 
41 #include "ED_fileselect.h"
42 
43 #include "UI_interface.h"
44 #include "UI_resources.h"
45 
46 #include "WM_api.h"
47 #include "WM_types.h"
48 
49 #include "file_intern.h"
50 #include "fsmenu.h"
51 
52 #include <string.h>
53 
55 {
56  SpaceFile *sfile = CTX_wm_space_file(C);
57  return (sfile && sfile->op);
58 }
59 
60 static void file_panel_operator_header(const bContext *C, Panel *panel)
61 {
62  SpaceFile *sfile = CTX_wm_space_file(C);
63  wmOperator *op = sfile->op;
64 
65  BLI_strncpy(panel->drawname, WM_operatortype_name(op->type, op->ptr), sizeof(panel->drawname));
66 }
67 
68 static void file_panel_operator(const bContext *C, Panel *panel)
69 {
70  SpaceFile *sfile = CTX_wm_space_file(C);
71  wmOperator *op = sfile->op;
72 
74 
75  /* Hack: temporary hide.*/
76  const char *hide[] = {"filepath", "files", "directory", "filename"};
77  for (int i = 0; i < ARRAY_SIZE(hide); i++) {
78  PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
79  if (prop) {
81  }
82  }
83 
86 
87  /* Hack: temporary hide.*/
88  for (int i = 0; i < ARRAY_SIZE(hide); i++) {
89  PropertyRNA *prop = RNA_struct_find_property(op->ptr, hide[i]);
90  if (prop) {
92  }
93  }
94 
96 }
97 
99 {
100  PanelType *pt;
101 
102  pt = MEM_callocN(sizeof(PanelType), "spacetype file operator properties");
103  strcpy(pt->idname, "FILE_PT_operator");
104  strcpy(pt->label, N_("Operator"));
110  BLI_addtail(&art->paneltypes, pt);
111 }
112 
114 {
115  uiLayout *row = uiLayoutRow(layout, false);
116  uiLayoutSetScaleX(row, 0.8f);
117  uiLayoutSetFixedSize(row, true);
118  uiItemO(row, IFACE_("Cancel"), ICON_NONE, "FILE_OT_cancel");
119 }
120 
121 static void file_panel_execution_execute_button(uiLayout *layout, const char *title)
122 {
123  uiLayout *row = uiLayoutRow(layout, false);
124  uiLayoutSetScaleX(row, 0.8f);
125  uiLayoutSetFixedSize(row, true);
126  /* Just a display hint. */
127  uiLayoutSetActiveDefault(row, true);
128  uiItemO(row, title, ICON_NONE, "FILE_OT_execute");
129 }
130 
132 {
133  bScreen *screen = CTX_wm_screen(C);
134  SpaceFile *sfile = CTX_wm_space_file(C);
136  uiBlock *block = uiLayoutGetBlock(panel->layout);
137  uiBut *but;
138  uiLayout *row;
139  PointerRNA params_rna_ptr, *but_extra_rna_ptr;
140 
141  const bool overwrite_alert = file_draw_check_exists(sfile);
142  const bool windows_layout =
143 #ifdef _WIN32
144  true;
145 #else
146  false;
147 #endif
148 
149  RNA_pointer_create(&screen->id, &RNA_FileSelectParams, params, &params_rna_ptr);
150 
151  row = uiLayoutRow(panel->layout, false);
152  uiLayoutSetScaleY(row, 1.3f);
153 
154  /* callbacks for operator check functions */
156 
157  but = uiDefButR(block,
159  -1,
160  "",
161  0,
162  0,
163  UI_UNIT_X * 5,
164  UI_UNIT_Y,
165  &params_rna_ptr,
166  "filename",
167  0,
168  0.0f,
169  (float)FILE_MAXFILE,
170  0,
171  0,
172  TIP_(overwrite_alert ? N_("File name, overwrite existing") : N_("File name")));
173 
175  BLI_assert(!UI_but_is_utf8(but));
176 
178  /* silly workaround calling NFunc to ensure this does not get called
179  * immediate ui_apply_but_func but only after button deactivates */
181 
182  if (params->flag & FILE_CHECK_EXISTING) {
183  but_extra_rna_ptr = UI_but_extra_operator_icon_add(
184  but, "FILE_OT_filenum", WM_OP_EXEC_REGION_WIN, ICON_REMOVE);
185  RNA_int_set(but_extra_rna_ptr, "increment", -1);
186  but_extra_rna_ptr = UI_but_extra_operator_icon_add(
187  but, "FILE_OT_filenum", WM_OP_EXEC_REGION_WIN, ICON_ADD);
188  RNA_int_set(but_extra_rna_ptr, "increment", 1);
189  }
190 
191  /* check if this overrides a file and if the operator option is used */
192  if (overwrite_alert) {
194  }
195  UI_block_func_set(block, NULL, NULL, NULL);
196 
197  {
198  uiLayout *sub = uiLayoutRow(row, false);
200 
201  if (windows_layout) {
204  }
205  else {
208  }
209  }
210 }
211 
213 {
214  PanelType *pt;
215 
216  pt = MEM_callocN(sizeof(PanelType), "spacetype file execution buttons");
217  strcpy(pt->idname, "FILE_PT_execution_buttons");
218  strcpy(pt->label, N_("Execute Buttons"));
223  BLI_addtail(&art->paneltypes, pt);
224 }
struct bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:709
struct SpaceFile * CTX_wm_space_file(const bContext *C)
Definition: context.c:818
@ PANEL_TYPE_NO_HEADER
Definition: BKE_screen.h:298
#define BLI_assert(a)
Definition: BLI_assert.h:58
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
#define FILE_MAXFILE
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define ARRAY_SIZE(arr)
#define UNUSED(x)
#define TIP_(msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define N_(msgid)
@ FILE_CHECK_EXISTING
struct FileSelectParams * ED_fileselect_get_active_params(const struct SpaceFile *sfile)
Read Guarded memory(de)allocation.
StructRNA RNA_FileSelectParams
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
#define UI_UNIT_Y
uiBlock * uiLayoutGetBlock(uiLayout *layout)
void uiTemplateOperatorPropertyButs(const struct bContext *C, uiLayout *layout, struct wmOperator *op, eButLabelAlign label_align, short flag)
void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext)
@ UI_BUT_REDALERT
Definition: UI_interface.h:204
@ UI_BUT_UNDO
Definition: UI_interface.h:208
void uiLayoutSetFixedSize(uiLayout *layout, bool fixed_size)
void uiLayoutSetScaleY(uiLayout *layout, float scale)
void uiLayoutSetActiveDefault(uiLayout *layout, bool active_default)
bool UI_but_is_utf8(const uiBut *but)
void uiLayoutSetScaleX(uiLayout *layout, float scale)
@ UI_BUT_LABEL_ALIGN_NONE
struct PointerRNA * UI_but_extra_operator_icon_add(uiBut *but, const char *opname, short opcontext, int icon)
Definition: interface.c:1650
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
uiBut * uiDefButR(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, struct PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
Definition: interface.c:5144
void UI_block_func_set(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2)
Definition: interface.c:6259
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
@ UI_TEMPLATE_OP_PROPS_SHOW_EMPTY
void UI_but_func_complete_set(uiBut *but, uiButCompleteFunc func, void *arg)
Definition: interface.c:6312
void UI_but_funcN_set(uiBut *but, uiButHandleNFunc funcN, void *argN, void *arg2)
Definition: interface.c:6301
#define UI_UNIT_X
@ UI_BTYPE_TEXT
Definition: UI_interface.h:336
void UI_but_flag_enable(uiBut *but, int flag)
Definition: interface.c:6077
bool UI_but_flag_is_set(uiBut *but, int flag)
Definition: interface.c:6087
@ WM_OP_EXEC_REGION_WIN
Definition: WM_types.h:205
int autocomplete_file(struct bContext *C, char *str, void *arg_v)
void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but)
bool file_draw_check_exists(SpaceFile *sfile)
Definition: file_ops.c:1700
void file_draw_check_cb(bContext *C, void *arg1, void *arg2)
static void file_panel_execution_execute_button(uiLayout *layout, const char *title)
Definition: file_panels.c:121
static void file_panel_execution_cancel_button(uiLayout *layout)
Definition: file_panels.c:113
void file_execute_region_panels_register(ARegionType *art)
Definition: file_panels.c:212
static void file_panel_execution_buttons_draw(const bContext *C, Panel *panel)
Definition: file_panels.c:131
static void file_panel_operator_header(const bContext *C, Panel *panel)
Definition: file_panels.c:60
static bool file_panel_operator_poll(const bContext *C, PanelType *UNUSED(pt))
Definition: file_panels.c:54
void file_tool_props_region_panels_register(ARegionType *art)
Definition: file_panels.c:98
static void file_panel_operator(const bContext *C, Panel *panel)
Definition: file_panels.c:68
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6319
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
ListBase paneltypes
Definition: BKE_screen.h:216
void(* draw)(const struct bContext *C, struct Panel *panel)
Definition: BKE_screen.h:266
bool(* poll)(const struct bContext *C, struct PanelType *pt)
Definition: BKE_screen.h:260
void(* draw_header)(const struct bContext *C, struct Panel *panel)
Definition: BKE_screen.h:262
char idname[BKE_ST_MAXNAME]
Definition: BKE_screen.h:241
char translation_context[BKE_ST_MAXNAME]
Definition: BKE_screen.h:244
char label[BKE_ST_MAXNAME]
Definition: BKE_screen.h:242
struct uiLayout * layout
char drawname[64]
struct wmOperator * op
struct wmOperatorType * type
struct PointerRNA * ptr
const char * WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *properties)