RNA: move the read-only extension "directory" to RNA
This allows it to be exposed in the user interface when the custom-directory is disabled without having to use a label which can't handle non UTF-8 characters which file-paths can contain.
This commit is contained in:
@@ -1312,24 +1312,6 @@ class RenderEngine(StructRNA, metaclass=RNAMeta):
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
class UserExtensionRepo(StructRNA):
|
||||
__slots__ = ()
|
||||
|
||||
@property
|
||||
def directory(self):
|
||||
"""Return ``directory`` or a default path derived from the users scripts path."""
|
||||
if self.use_custom_directory:
|
||||
return self.custom_directory
|
||||
import bpy
|
||||
import os
|
||||
# TODO: this should eventually be accessed via `bpy.utils.user_resource('EXTENSIONS')`
|
||||
# which points to the same location (by default).
|
||||
if (path := bpy.utils.resource_path('USER')):
|
||||
return os.path.join(path, "extensions", self.module)
|
||||
# Unlikely this is ever encountered.
|
||||
return ""
|
||||
|
||||
|
||||
class HydraRenderEngine(RenderEngine):
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include "BLI_compiler_attrs.h"
|
||||
#include "BLI_sys_types.h"
|
||||
|
||||
struct UserDef;
|
||||
struct bUserExtensionRepo;
|
||||
@@ -95,9 +96,9 @@ void BKE_preferences_extension_repo_module_set(UserDef *userdef,
|
||||
const char *module);
|
||||
|
||||
void BKE_preferences_extension_repo_custom_dirpath_set(bUserExtensionRepo *repo, const char *path);
|
||||
void BKE_preferences_extension_repo_dirpath_get(const bUserExtensionRepo *repo,
|
||||
char *dirpath,
|
||||
int dirpath_maxncpy);
|
||||
size_t BKE_preferences_extension_repo_dirpath_get(const bUserExtensionRepo *repo,
|
||||
char *dirpath,
|
||||
int dirpath_maxncpy);
|
||||
|
||||
bUserExtensionRepo *BKE_preferences_extension_repo_find_index(const UserDef *userdef, int index);
|
||||
bUserExtensionRepo *BKE_preferences_extension_repo_find_by_module(const UserDef *userdef,
|
||||
|
||||
@@ -247,13 +247,12 @@ void BKE_preferences_extension_repo_custom_dirpath_set(bUserExtensionRepo *repo,
|
||||
STRNCPY(repo->custom_dirpath, path);
|
||||
}
|
||||
|
||||
void BKE_preferences_extension_repo_dirpath_get(const bUserExtensionRepo *repo,
|
||||
char *dirpath,
|
||||
const int dirpath_maxncpy)
|
||||
size_t BKE_preferences_extension_repo_dirpath_get(const bUserExtensionRepo *repo,
|
||||
char *dirpath,
|
||||
const int dirpath_maxncpy)
|
||||
{
|
||||
if (repo->flag & USER_EXTENSION_REPO_FLAG_USE_CUSTOM_DIRECTORY) {
|
||||
BLI_strncpy(dirpath, repo->custom_dirpath, dirpath_maxncpy);
|
||||
return;
|
||||
return BLI_strncpy_rlen(dirpath, repo->custom_dirpath, dirpath_maxncpy);
|
||||
}
|
||||
|
||||
/* TODO: support `BLENDER_USER_EXTENSIONS`, until then add to user resource. */
|
||||
@@ -261,9 +260,9 @@ void BKE_preferences_extension_repo_dirpath_get(const bUserExtensionRepo *repo,
|
||||
/* Highly unlikely to fail as the directory doesn't have to exist. */
|
||||
if (!path) {
|
||||
dirpath[0] = '\0';
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
BLI_path_join(dirpath, dirpath_maxncpy, path.value().c_str(), "extensions", repo->module);
|
||||
return BLI_path_join(dirpath, dirpath_maxncpy, path.value().c_str(), "extensions", repo->module);
|
||||
}
|
||||
|
||||
bUserExtensionRepo *BKE_preferences_extension_repo_find_index(const UserDef *userdef, int index)
|
||||
|
||||
@@ -373,7 +373,7 @@ static void rna_userdef_extension_repo_module_set(PointerRNA *ptr, const char *v
|
||||
BKE_callback_exec_null(bmain, BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST);
|
||||
}
|
||||
|
||||
static void rna_userdef_extension_repo_directory_set(PointerRNA *ptr, const char *value)
|
||||
static void rna_userdef_extension_repo_custom_directory_set(PointerRNA *ptr, const char *value)
|
||||
{
|
||||
Main *bmain = G.main;
|
||||
bUserExtensionRepo *repo = (bUserExtensionRepo *)ptr->data;
|
||||
@@ -382,6 +382,19 @@ static void rna_userdef_extension_repo_directory_set(PointerRNA *ptr, const char
|
||||
BKE_callback_exec_null(bmain, BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST);
|
||||
}
|
||||
|
||||
static void rna_userdef_extension_repo_directory_get(PointerRNA *ptr, char *value)
|
||||
{
|
||||
const bUserExtensionRepo *repo = (bUserExtensionRepo *)ptr->data;
|
||||
BKE_preferences_extension_repo_dirpath_get(repo, value, FILE_MAX);
|
||||
}
|
||||
|
||||
static int rna_userdef_extension_repo_directory_length(PointerRNA *ptr)
|
||||
{
|
||||
const bUserExtensionRepo *repo = (bUserExtensionRepo *)ptr->data;
|
||||
char dirpath[FILE_MAX];
|
||||
return BKE_preferences_extension_repo_dirpath_get(repo, dirpath, sizeof(dirpath));
|
||||
}
|
||||
|
||||
static void rna_userdef_extension_repo_generic_flag_set_impl(PointerRNA *ptr,
|
||||
const bool value,
|
||||
const int flag)
|
||||
@@ -6604,9 +6617,18 @@ static void rna_def_userdef_filepaths_extension_repo(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Custom Directory", "The local directory containing extensions");
|
||||
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_EDITOR_FILEBROWSER);
|
||||
RNA_def_property_string_funcs(
|
||||
prop, nullptr, nullptr, "rna_userdef_extension_repo_directory_set");
|
||||
prop, nullptr, nullptr, "rna_userdef_extension_repo_custom_directory_set");
|
||||
RNA_def_property_update(prop, 0, "rna_userdef_update");
|
||||
|
||||
prop = RNA_def_property(srna, "directory", PROP_STRING, PROP_DIRPATH);
|
||||
RNA_def_property_ui_text(prop, "Directory", "The local directory containing extensions");
|
||||
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_EDITOR_FILEBROWSER);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_string_funcs(prop,
|
||||
"rna_userdef_extension_repo_directory_get",
|
||||
"rna_userdef_extension_repo_directory_length",
|
||||
nullptr);
|
||||
|
||||
prop = RNA_def_property(srna, "remote_path", PROP_STRING, PROP_NONE);
|
||||
RNA_def_property_string_sdna(prop, nullptr, "remote_path");
|
||||
RNA_def_property_ui_text(prop, "URL", "Remote URL or path for extension repository");
|
||||
|
||||
Reference in New Issue
Block a user