Blender  V2.93
userpref_ops.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 <string.h>
25 
26 #include "DNA_screen_types.h"
27 
28 #include "BLI_listbase.h"
29 
30 #include "BKE_context.h"
31 #include "BKE_main.h"
32 #include "BKE_preferences.h"
33 
34 #include "RNA_access.h"
35 #include "RNA_define.h"
36 #include "RNA_types.h"
37 
38 #include "UI_interface.h"
39 
40 #include "WM_api.h"
41 #include "WM_types.h"
42 
43 #include "ED_userpref.h"
44 
45 #include "MEM_guardedalloc.h"
46 
47 /* -------------------------------------------------------------------- */
52 {
53  Main *bmain = CTX_data_main(C);
58  U.runtime.is_dirty = true;
59  return OPERATOR_FINISHED;
60 }
61 
63 {
64  /* identifiers */
65  ot->name = "Reset to Default Theme";
66  ot->idname = "PREFERENCES_OT_reset_default_theme";
67  ot->description = "Reset to the default theme colors";
68 
69  /* callbacks */
71 
72  /* flags */
74 }
75 
78 /* -------------------------------------------------------------------- */
83 {
84  bPathCompare *path_cmp = MEM_callocN(sizeof(bPathCompare), "bPathCompare");
85  BLI_addtail(&U.autoexec_paths, path_cmp);
86  U.runtime.is_dirty = true;
87  return OPERATOR_FINISHED;
88 }
89 
91 {
92  ot->name = "Add Auto-Execution Path";
93  ot->idname = "PREFERENCES_OT_autoexec_path_add";
94  ot->description = "Add path to exclude from auto-execution";
95 
97 
99 }
100 
103 /* -------------------------------------------------------------------- */
108 {
109  const int index = RNA_int_get(op->ptr, "index");
110  bPathCompare *path_cmp = BLI_findlink(&U.autoexec_paths, index);
111  if (path_cmp) {
112  BLI_freelinkN(&U.autoexec_paths, path_cmp);
113  U.runtime.is_dirty = true;
114  }
115  return OPERATOR_FINISHED;
116 }
117 
119 {
120  ot->name = "Remove Auto-Execution Path";
121  ot->idname = "PREFERENCES_OT_autoexec_path_remove";
122  ot->description = "Remove path to exclude from auto-execution";
123 
125 
127 
128  RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
129 }
130 
133 /* -------------------------------------------------------------------- */
138 {
140  U.runtime.is_dirty = true;
141  return OPERATOR_FINISHED;
142 }
143 
145 {
146  ot->name = "Add Asset Library";
147  ot->idname = "PREFERENCES_OT_asset_library_add";
148  ot->description =
149  "Add a path to a .blend file to be used by the Asset Browser as source of assets";
150 
152 
154 }
155 
158 /* -------------------------------------------------------------------- */
163 {
164  const int index = RNA_int_get(op->ptr, "index");
165  bUserAssetLibrary *library = BLI_findlink(&U.asset_libraries, index);
166  if (library) {
168  U.runtime.is_dirty = true;
169  /* Trigger refresh for the Asset Browser. */
171  }
172  return OPERATOR_FINISHED;
173 }
174 
176 {
177  ot->name = "Remove Asset Library";
178  ot->idname = "PREFERENCES_OT_asset_library_remove";
179  ot->description =
180  "Remove a path to a .blend file, so the Asset Browser will not attempt to show it anymore";
181 
183 
185 
186  RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
187 }
188 
192 {
194 
197 
200 }
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct bUserAssetLibrary * BKE_preferences_asset_library_add(struct UserDef *userdef, const char *name, const char *path) ATTR_NONNULL(1)
Definition: preferences.c:46
void BKE_preferences_asset_library_remove(struct UserDef *userdef, struct bUserAssetLibrary *library) ATTR_NONNULL()
Definition: preferences.c:81
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:281
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define UNUSED(x)
@ OPERATOR_FINISHED
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
void UI_style_init_default(void)
Definition: resources.c:1057
void UI_theme_init_default(void)
Definition: resources.c:1041
#define NC_WINDOW
Definition: WM_types.h:277
@ OPTYPE_INTERNAL
Definition: WM_types.h:175
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_SPACE_ASSET_PARAMS
Definition: WM_types.h:420
#define NC_SPACE
Definition: WM_types.h:293
unsigned int U
Definition: btGjkEpa3.h:78
static FT_Library library
Definition: freetypefont.c:51
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
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:3585
Definition: BKE_main.h:116
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct PointerRNA * ptr
static int preferences_reset_default_theme_exec(bContext *C, wmOperator *UNUSED(op))
Definition: userpref_ops.c:51
static void PREFERENCES_OT_reset_default_theme(wmOperatorType *ot)
Definition: userpref_ops.c:62
static int preferences_autoexec_remove_exec(bContext *UNUSED(C), wmOperator *op)
Definition: userpref_ops.c:107
static int preferences_asset_library_remove_exec(bContext *UNUSED(C), wmOperator *op)
Definition: userpref_ops.c:162
void ED_operatortypes_userpref(void)
Definition: userpref_ops.c:191
static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
Definition: userpref_ops.c:137
static void PREFERENCES_OT_asset_library_remove(wmOperatorType *ot)
Definition: userpref_ops.c:175
static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot)
Definition: userpref_ops.c:118
static void PREFERENCES_OT_autoexec_path_add(wmOperatorType *ot)
Definition: userpref_ops.c:90
static void PREFERENCES_OT_asset_library_add(wmOperatorType *ot)
Definition: userpref_ops.c:144
static int preferences_autoexec_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
Definition: userpref_ops.c:82
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156
void WM_reinit_gizmomap_all(Main *bmain)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))