Blender  V3.3
userpref_ops.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2009 Blender Foundation. All rights reserved. */
3 
8 #include <string.h>
9 
10 #include "DNA_screen_types.h"
11 #include "DNA_space_types.h"
12 
13 #include "BLI_listbase.h"
14 #ifdef WIN32
15 # include "BLI_winstuff.h"
16 #endif
17 #include "BLI_path_util.h"
18 
19 #include "BKE_context.h"
20 #include "BKE_main.h"
21 #include "BKE_preferences.h"
22 
23 #include "BKE_report.h"
24 
25 #include "RNA_access.h"
26 #include "RNA_define.h"
27 #include "RNA_types.h"
28 
29 #include "UI_interface.h"
30 
31 #include "WM_api.h"
32 #include "WM_types.h"
33 
34 #include "ED_userpref.h"
35 
36 #include "MEM_guardedalloc.h"
37 
38 /* -------------------------------------------------------------------- */
43 {
44  Main *bmain = CTX_data_main(C);
49  U.runtime.is_dirty = true;
50  return OPERATOR_FINISHED;
51 }
52 
54 {
55  /* identifiers */
56  ot->name = "Reset to Default Theme";
57  ot->idname = "PREFERENCES_OT_reset_default_theme";
58  ot->description = "Reset to the default theme colors";
59 
60  /* callbacks */
62 
63  /* flags */
65 }
66 
69 /* -------------------------------------------------------------------- */
74 {
75  bPathCompare *path_cmp = MEM_callocN(sizeof(bPathCompare), "bPathCompare");
76  BLI_addtail(&U.autoexec_paths, path_cmp);
77  U.runtime.is_dirty = true;
78  return OPERATOR_FINISHED;
79 }
80 
82 {
83  ot->name = "Add Auto-Execution Path";
84  ot->idname = "PREFERENCES_OT_autoexec_path_add";
85  ot->description = "Add path to exclude from auto-execution";
86 
88 
90 }
91 
94 /* -------------------------------------------------------------------- */
99 {
100  const int index = RNA_int_get(op->ptr, "index");
101  bPathCompare *path_cmp = BLI_findlink(&U.autoexec_paths, index);
102  if (path_cmp) {
103  BLI_freelinkN(&U.autoexec_paths, path_cmp);
104  U.runtime.is_dirty = true;
105  }
106  return OPERATOR_FINISHED;
107 }
108 
110 {
111  ot->name = "Remove Auto-Execution Path";
112  ot->idname = "PREFERENCES_OT_autoexec_path_remove";
113  ot->description = "Remove path to exclude from auto-execution";
114 
116 
118 
119  RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
120 }
121 
124 /* -------------------------------------------------------------------- */
129 {
130  char *path = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL);
131  char dirname[FILE_MAXFILE];
132 
133  BLI_path_slash_rstrip(path);
134  BLI_split_file_part(path, dirname, sizeof(dirname));
135 
136  /* NULL is a valid directory path here. A library without path will be created then. */
138  U.runtime.is_dirty = true;
139 
140  /* There's no dedicated notifier for the Preferences. */
142 
143  MEM_freeN(path);
144  return OPERATOR_FINISHED;
145 }
146 
148  wmOperator *op,
149  const wmEvent *UNUSED(event))
150 {
151  if (!RNA_struct_property_is_set(op->ptr, "directory")) {
153  return OPERATOR_RUNNING_MODAL;
154  }
155 
157 }
158 
160 {
161  ot->name = "Add Asset Library";
162  ot->idname = "PREFERENCES_OT_asset_library_add";
163  ot->description = "Add a directory to be used by the Asset Browser as source of assets";
164 
167 
169 
172  FILE_SPECIAL,
177 }
178 
181 /* -------------------------------------------------------------------- */
186 {
187  const int index = RNA_int_get(op->ptr, "index");
188  bUserAssetLibrary *library = BLI_findlink(&U.asset_libraries, index);
189  if (library) {
191  U.runtime.is_dirty = true;
192  /* Trigger refresh for the Asset Browser. */
194  }
195  return OPERATOR_FINISHED;
196 }
197 
199 {
200  ot->name = "Remove Asset Library";
201  ot->idname = "PREFERENCES_OT_asset_library_remove";
202  ot->description =
203  "Remove a path to a .blend file, so the Asset Browser will not attempt to show it anymore";
204 
206 
208 
209  RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
210 }
211 
214 /* -------------------------------------------------------------------- */
219 {
220 #ifdef WIN32
221  UNUSED_VARS(C);
222  return true;
223 #else
224  CTX_wm_operator_poll_msg_set(C, "Windows-only operator");
225  return false;
226 #endif
227 }
228 
230 {
231 #ifdef WIN32
232  WM_cursor_wait(true);
234  BKE_report(op->reports, RPT_INFO, "File association registered");
235  WM_cursor_wait(false);
236  return OPERATOR_FINISHED;
237  }
238  else {
239  BKE_report(op->reports, RPT_ERROR, "Unable to register file association");
240  WM_cursor_wait(false);
241  return OPERATOR_CANCELLED;
242  }
243 #else
244  UNUSED_VARS(op);
246  return OPERATOR_CANCELLED;
247 #endif
248 }
249 
251 {
252  /* identifiers */
253  ot->name = "Register File Association";
254  ot->description = "Use this installation for .blend files and to display thumbnails";
255  ot->idname = "PREFERENCES_OT_associate_blend";
256 
257  /* api callbacks */
260 }
261 
265 {
267 
270 
273 
275 }
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg)
Definition: context.c:1042
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct bUserAssetLibrary * BKE_preferences_asset_library_add(struct UserDef *userdef, const char *name, const char *path) ATTR_NONNULL(1)
Definition: preferences.c:33
void BKE_preferences_asset_library_remove(struct UserDef *userdef, struct bUserAssetLibrary *library) ATTR_NONNULL()
Definition: preferences.c:51
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:239
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define FILE_MAXFILE
void BLI_path_slash_rstrip(char *string) ATTR_NONNULL()
Definition: path_util.c:1791
void BLI_split_file_part(const char *string, char *file, size_t filelen)
Definition: path_util.c:1495
#define UNUSED_VARS(...)
#define UNUSED(x)
Compatibility-like things for windows.
bool BLI_windows_register_blend_extension(bool background)
const char * dirname(char *path)
@ FILE_SORT_DEFAULT
@ FILE_SPECIAL
@ FILE_TYPE_FOLDER
@ FILE_DEFAULTDISPLAY
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:25
void UI_style_init_default(void)
Definition: resources.c:1038
void UI_theme_init_default(void)
Definition: resources.c:1022
@ WM_FILESEL_DIRECTORY
Definition: WM_api.h:753
@ FILE_OPENFILE
Definition: WM_api.h:764
@ OPTYPE_INTERNAL
Definition: WM_types.h:168
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_WINDOW
Definition: WM_types.h:325
#define ND_SPACE_ASSET_PARAMS
Definition: WM_types.h:468
#define NC_SPACE
Definition: WM_types.h:342
unsigned int U
Definition: btGjkEpa3.h:78
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4910
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:5129
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:5301
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
Definition: BKE_main.h:121
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct PointerRNA * ptr
static bool associate_blend_poll(bContext *C)
Definition: userpref_ops.c:218
static int preferences_reset_default_theme_exec(bContext *C, wmOperator *UNUSED(op))
Definition: userpref_ops.c:42
static void PREFERENCES_OT_associate_blend(struct wmOperatorType *ot)
Definition: userpref_ops.c:250
static void PREFERENCES_OT_reset_default_theme(wmOperatorType *ot)
Definition: userpref_ops.c:53
static int associate_blend_exec(bContext *UNUSED(C), wmOperator *op)
Definition: userpref_ops.c:229
static int preferences_autoexec_remove_exec(bContext *UNUSED(C), wmOperator *op)
Definition: userpref_ops.c:98
static int preferences_asset_library_remove_exec(bContext *UNUSED(C), wmOperator *op)
Definition: userpref_ops.c:185
static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *op)
Definition: userpref_ops.c:128
static int preferences_asset_library_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: userpref_ops.c:147
void ED_operatortypes_userpref(void)
Definition: userpref_ops.c:264
static void PREFERENCES_OT_asset_library_remove(wmOperatorType *ot)
Definition: userpref_ops.c:198
static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot)
Definition: userpref_ops.c:109
static void PREFERENCES_OT_autoexec_path_add(wmOperatorType *ot)
Definition: userpref_ops.c:81
static void PREFERENCES_OT_asset_library_add(wmOperatorType *ot)
Definition: userpref_ops.c:159
static int preferences_autoexec_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
Definition: userpref_ops.c:73
static FT_Library library
void WM_cursor_wait(bool val)
Definition: wm_cursors.c:209
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479
void WM_reinit_gizmomap_all(Main *bmain)
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))