10#include <fmt/format.h>
39#include "RNA_prototypes.hh"
70 U.runtime.is_dirty =
true;
77 ot->
name =
"Reset to Default Theme";
78 ot->
idname =
"PREFERENCES_OT_reset_default_theme";
79 ot->
description =
"Reset to the default theme colors";
96 bPathCompare *path_cmp = MEM_new<bPathCompare>(
"bPathCompare");
98 U.runtime.is_dirty =
true;
104 ot->
name =
"Add Auto-Execution Path";
105 ot->
idname =
"PREFERENCES_OT_autoexec_path_add";
106 ot->
description =
"Add path to exclude from auto-execution";
125 U.runtime.is_dirty =
true;
132 ot->
name =
"Remove Auto-Execution Path";
133 ot->
idname =
"PREFERENCES_OT_autoexec_path_remove";
134 ot->
description =
"Remove path to exclude from auto-execution";
160 switch (library_type) {
171 std::optional<char *> auth_token = {};
172 if (use_auth_token) {
173 auth_token = auth_token_str;
176 MEM_delete(remote_url);
177 MEM_delete(auth_token_str);
182 U.runtime.is_dirty =
true;
201 C, op, event,
IFACE_(
"Add Asset Library"),
IFACE_(
"Create"));
213 switch (library_type) {
218 const int token_icon = (use_auth_token &&
RNA_string_length(ptr,
"auth_token")) ?
224 if (use_auth_token) {
258 ot->
name =
"Add Asset Library";
259 ot->
idname =
"PREFERENCES_OT_asset_library_add";
260 ot->
description =
"Add a directory to be used by the Asset Browser as source of assets";
277 StructRNA *type_ref = RNA_UserAssetLibrary;
280 const char *prop_id =
"name";
292 const char *prop_id =
"remote_url";
303 const char *prop_id =
"use_auth_token";
313 const char *prop_id =
"auth_token";
330 "The kind of asset library to add");
343 if (
U.asset_libraries.is_empty()) {
358 if (
library->extension_id[0]) {
362 "Asset libraries defined by an extension are removed by uninstalling the extension");
367 U.runtime.is_dirty =
true;
374 ot->
name =
"Remove Asset Library";
375 ot->
idname =
"PREFERENCES_OT_asset_library_remove";
377 "Remove a path to a .blend file, so the Asset Browser will not attempt to show it anymore";
403 return "Remote Repository";
406 return "User Repository";
423 char *access_token =
nullptr;
429 if (use_custom_directory) {
437 if (use_access_token) {
456 if (name[0] ==
'\0') {
463 if (use_custom_directory) {
472 if (name[0] ==
'\0') {
477 const char *module = custom_directory[0] ?
BLI_path_basename(custom_directory) : name;
484 for (i = 0; module_buf[i]; i++) {
485 if (
ELEM(module_buf[i],
'.',
'-',
'/',
'\\')) {
490 while ((i > 0) && (module_buf[--i] ==
'_')) {
491 module_buf[i] =
'\0';
497 &
U, name, module, custom_directory);
499 if (use_sync_on_startup) {
502 if (use_custom_directory) {
510 if (use_access_token) {
520 U.runtime.is_dirty =
true;
524 nullptr, RNA_UserExtensionRepo, new_repo);
556 name_default =
nullptr;
562 C, op, event,
IFACE_(
"Add New Extension Repository"),
IFACE_(
"Create"));
582 const bool use_access_token =
RNA_boolean_get(ptr,
"use_access_token");
589 if (use_access_token) {
613 ot->
name =
"Add Extension Repository";
614 ot->
idname =
"PREFERENCES_OT_extension_repo_add";
615 ot->
description =
"Add a new repository used to store extensions";
627 "Add Remote Repository",
628 "Add a repository referencing a remote repository "
629 "with support for listing and updating extensions"},
633 "Add Local Repository",
634 "Add a repository managed manually without referencing an external repository"},
635 {0,
nullptr, 0,
nullptr,
nullptr},
649 StructRNA *type_ref = RNA_UserExtensionRepo;
652 const char *prop_id =
"name";
664 const char *prop_id =
"remote_url";
676 const char *prop_id =
"use_access_token";
687 const char *prop_id =
"access_token";
700 const char *prop_id =
"use_sync_on_startup";
711 const char *prop_id =
"use_custom_directory";
722 const char *prop_id =
"custom_directory";
734 ot->
srna,
"type", repo_type_items, 0,
"Type",
"The kind of repository to add");
746 if (
U.extension_repos.is_empty()) {
769 remove_files =
false;
781 if (dirpath[0] || user_dirpath[0]) {
782 message =
IFACE_(
"Remove all files in:");
783 const char *paths[] = {dirpath, user_dirpath};
785 if (paths[i][0] ==
'\0') {
788 message.append(fmt::format(
"\n\"{}\"", paths[i]));
792 message =
IFACE_(
"Remove, local files not found.");
793 remove_files =
false;
797 message =
IFACE_(
"Remove, keeping local files.");
800 const char *confirm_text = remove_files ?
IFACE_(
"Remove Repository & Files") :
801 IFACE_(
"Remove Repository");
825 remove_files =
false;
835 "Unable to remove files, the module name \"%.*s\" is invalid and "
836 "could remove non-repository files",
837 int(
sizeof(repo->
module)),
839 remove_files =
false;
863 if (
BLI_delete(dirpath,
true, recursive) != 0) {
866 "Unable to remove directory: %s",
867 errno ? strerror(errno) :
"unknown");
876 "Unable to remove directory: %s",
877 errno ? strerror(errno) :
"unknown");
883 const int count_remaining =
U.extension_repos.count();
885 CLAMP(
U.active_extension_repo, 0, count_remaining - 1);
886 U.runtime.is_dirty =
true;
898 ot->
name =
"Remove Extension Repository";
899 ot->
idname =
"PREFERENCES_OT_extension_repo_remove";
900 ot->
description =
"Remove an extension repository";
915 "Remove extension files when removing the repository");
930 const bool url_is_file =
STRPREFIX(url.c_str(),
"file://");
931 const bool url_is_online =
STRPREFIX(url.c_str(),
"http://") ||
933 const bool url_is_remote = url_is_file | url_is_online;
937 const char *idname_external = url_is_remote ?
"extensions.package_install" :
938 "extensions.package_install_files";
942 idname_external =
"extensions.userpref_allow_online_popup";
967 ot->
name =
"Drop Extension URL";
968 ot->
description =
"Handle dropping an extension URL";
969 ot->
idname =
"PREFERENCES_OT_extension_url_drop";
974 RNA_def_string(ot->
srna,
"url",
nullptr, 0,
"URL",
"Location of the extension to install");
991#elif defined(__APPLE__)
1000#if !defined(__APPLE__)
1007 (all_users ==
false))
1009 const char *msg = do_register ?
"Unable to register file association" :
1010 "Unable to unregister file association";
1011 MessageBox(0, msg,
"Blender", MB_OK | MB_ICONERROR);
1029 op->
reports,
RPT_ERROR,
"Registration not possible from Microsoft Store installations");
1035 char *error_msg =
nullptr;
1043 op->
reports,
RPT_ERROR, error_msg ? error_msg :
"Unable to register file association");
1045 MEM_delete(error_msg);
1058 ot->
name =
"Register File Association";
1059 ot->
description =
"Use this installation for .blend files and to display thumbnails";
1060 ot->
idname =
"PREFERENCES_OT_associate_blend";
1077 op->
reports,
RPT_ERROR,
"Unregistration not possible from Microsoft Store installations");
1083 char *error_msg =
nullptr;
1091 op->
reports,
RPT_ERROR, error_msg ? error_msg :
"Unable to unregister file association");
1093 MEM_delete(error_msg);
1106 ot->
name =
"Remove File Association";
1107 ot->
description =
"Remove this installation's associations with .blend files";
1108 ot->
idname =
"PREFERENCES_OT_unassociate_blend";
1135 const char *cstr =
str.c_str();
1141 if (
str.find(
'\n') != std::string::npos) {
1145 bool has_known_extension =
false;
1150 std::string str_strip;
1151 const char *cstr_maybe_copy = cstr;
1152 size_t param_char =
str.find(
'?');
1153 if (param_char != std::string::npos) {
1154 str_strip =
str.substr(0, param_char);
1155 cstr_maybe_copy = str_strip.c_str();
1159 if (cstr_ext &&
STRCASEEQ(cstr_ext,
".zip")) {
1160 has_known_extension =
true;
1166 if (!has_known_extension &&
1196 if (!(cstr_ext &&
STRCASEEQ(cstr_ext,
".zip"))) {
1216 "PREFERENCES_OT_extension_url_drop",
1222 "PREFERENCES_OT_extension_url_drop",
1246 ot->
name =
"Filter";
1248 ot->
idname =
"PREFERENCES_OT_start_filter";
1266 ot->
name =
"Clear Filter";
1268 ot->
idname =
"PREFERENCES_OT_clear_filter";
File and directory operations.
#define STRNCPY_UTF8(dst, src)
Compatibility-like things for windows.
#define USER_EXPERIMENTAL_TEST(userdef, member)
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
void style_init_default()
bool BKE_preferences_extension_repo_module_is_valid(const bUserExtensionRepo *repo)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
const EnumPropertyItem custom_library_type_items[]
const char * WM_drag_get_single_path(const wmDrag *drag)
static bool preferences_asset_library_remove_poll(bContext *C)
static wmOperatorStatus preferences_extension_repo_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
size_t BKE_preferences_extension_repo_user_dirpath_get(const bUserExtensionRepo *repo, char *dirpath, const int dirpath_maxncpy)
ScrArea * CTX_wm_area(const bContext *C)
void BKE_callback_exec_string(Main *bmain, const char *str, eCbEvent evt)
wmDropBox * WM_dropbox_add(ListBaseT< wmDropBox > *lb, const char *idname, bool(*poll)(bContext *C, wmDrag *drag, const wmEvent *event), void(*copy)(bContext *C, wmDrag *drag, wmDropBox *drop), void(*cancel)(Main *bmain, wmDrag *drag, wmDropBox *drop), WMDropboxTooltipFunc tooltip)
int RNA_enum_get(PointerRNA *ptr, const char *name)
bUserExtensionRepo * BKE_preferences_extension_repo_find_by_remote_url_prefix(const UserDef *userdef, const char *remote_url_full, const bool only_enabled)
static void PREFERENCES_OT_reset_default_theme(wmOperatorType *ot)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static void PREFERENCES_OT_associate_blend(wmOperatorType *ot)
static wmOperatorStatus preferences_extension_repo_remove_exec(bContext *C, wmOperator *op)
const char * RNA_property_ui_name_raw(const PropertyRNA *prop, const PointerRNA *ptr)
bool WM_platform_associate_set(bool do_register, bool all_users, char **r_error_msg)
@ BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE
@ BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST
@ BKE_CB_EVT_EXTENSION_REPOS_FILES_CLEAR
@ BKE_CB_EVT_EXTENSION_REPOS_SYNC
void BKE_callback_exec_null(Main *bmain, eCbEvent evt)
static void PREFERENCES_OT_extension_url_drop(wmOperatorType *ot)
bUserExtensionRepoAddType
static wmOperatorStatus preferences_autoexec_remove_exec(bContext *, wmOperator *op)
void WM_operator_properties_free(PointerRNA *ptr)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
int BKE_preferences_remote_scheme_end(const char *url)
void PREFERENCES_OT_clear_filter(wmOperatorType *ot)
const char * BLI_path_extension(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
SpaceUserPref * CTX_wm_space_userpref(const bContext *C)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
static bool drop_extension_path_poll(bContext *, wmDrag *drag, const wmEvent *)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
PropertyRNA * RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
void ED_region_search_filter_update(const ScrArea *area, ARegion *region)
const std::string & WM_drag_get_string(const wmDrag *drag)
static bool associate_blend(bool do_register, bool all_users, char **r_error_msg)
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)
static wmOperatorStatus associate_blend_exec(bContext *, wmOperator *op)
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
void WM_reinit_gizmomap_all(Main *bmain)
static wmOperatorStatus preferences_extension_repo_add_exec(bContext *C, wmOperator *op)
static const char * preferences_extension_repo_default_name_from_type(const bUserExtensionRepoAddType repo_type)
static bool associate_blend_poll(bContext *C)
static wmOperatorStatus preferences_extension_repo_remove_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void PREFERENCES_OT_asset_library_add(wmOperatorType *ot)
static void drop_extension_path_copy(bContext *, wmDrag *drag, wmDropBox *drop)
static const EnumPropertyItem * custom_library_type_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static wmOperatorStatus preferences_asset_library_remove_exec(bContext *C, wmOperator *op)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BKE_preferences_remote_to_name(const char *remote_url, char name[64])
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void BLI_path_slash_rstrip(char *path) ATTR_NONNULL(1)
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
void ED_operatortypes_userpref()
static void ED_dropbox_drop_extension()
void BKE_report(ReportList *reports, eReportType type, const char *message)
bool ED_operator_preferences_active(bContext *C)
static wmOperatorStatus preferences_autoexec_add_exec(bContext *, wmOperator *)
void ED_userpref_asset_library_remove(bContext *C, struct bUserAssetLibrary *asset_library)
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
struct bUserAssetLibrary * ED_userpref_asset_library_new(const struct bContext *C, const char *name, const char *dirpath, bUserAssetLibraryAddType library_type, bool is_project_defined, std::optional< UUID > uuid, std::optional< char * > auth_token)
bool BLI_windows_is_store_install(void)
@ USER_EXTENSION_REPO_SOURCE_SYSTEM
static wmOperatorStatus preferences_start_filter_exec(bContext *C, wmOperator *)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
const char * RNA_property_ui_description_raw(const PropertyRNA *prop, const PointerRNA *ptr)
static wmOperatorStatus unassociate_blend_exec(bContext *, wmOperator *op)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
static wmOperatorStatus preferences_asset_library_add_exec(bContext *C, wmOperator *op)
static bool drop_extension_url_poll(bContext *, wmDrag *drag, const wmEvent *)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
void BKE_preferences_extension_repo_remove(UserDef *userdef, bUserExtensionRepo *repo)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
int RNA_string_length(PointerRNA *ptr, const char *name)
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static void PREFERENCES_OT_extension_repo_add(wmOperatorType *ot)
static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot)
@ USER_EXTENSION_REPO_FLAG_USE_REMOTE_URL
@ USER_EXTENSION_REPO_FLAG_SYNC_ON_STARTUP
@ USER_EXTENSION_REPO_FLAG_USE_ACCESS_TOKEN
@ USER_EXTENSION_REPO_FLAG_USE_CUSTOM_DIRECTORY
static bool preferences_extension_repo_remove_poll(bContext *C)
wmOperatorStatus WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
static wmOperatorStatus preferences_extension_url_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void PREFERENCES_OT_asset_library_remove(wmOperatorType *ot)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void PREFERENCES_OT_start_filter(wmOperatorType *ot)
static void drop_extension_url_copy(bContext *, wmDrag *drag, wmDropBox *drop)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Main * CTX_data_main(const bContext *C)
bUserExtensionRepo * BKE_preferences_extension_repo_add(UserDef *userdef, const char *name, const char *module, const char *custom_dirpath)
@ USER_REGISTER_ALL_USERS
static void PREFERENCES_OT_extension_repo_remove(wmOperatorType *ot)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
static void preferences_asset_library_add_ui(bContext *, wmOperator *op)
static void preferences_extension_repo_add_ui(bContext *, wmOperator *op)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
static void PREFERENCES_OT_unassociate_blend(wmOperatorType *ot)
static wmOperatorStatus preferences_reset_default_theme_exec(bContext *C, wmOperator *)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
ListBaseT< wmDropBox > * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
void ED_region_activate_rna_prop(bContext *C, ARegion *region, const void *data, StringRefNull prop_name)
static wmOperatorStatus preferences_asset_library_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void WM_cursor_wait(bool val)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
static void PREFERENCES_OT_autoexec_path_add(wmOperatorType *ot)
void ED_area_tag_redraw(ScrArea *area)
static wmOperatorStatus preferences_clear_filter_exec(bContext *C, wmOperator *)
size_t BKE_preferences_extension_repo_dirpath_get(const bUserExtensionRepo *repo, char *dirpath, int dirpath_maxncpy)
void BKE_callback_exec(Main *bmain, PointerRNA **pointers, int pointers_num, eCbEvent evt)
std::string search_string
SpaceUserPref_Runtime * runtime
eUserExtensionRepo_Flag flag
eUserExtensionRepo_Source source
char custom_dirpath[1024]
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
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 active_set(bool active)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) ui(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports