Use DIR_PATH subtype for properties

It adds this option to open directory in system browser using alt+click and we don't need anymore a special operator `bim.select_dir` to fill these props.

Example - https://files.catbox.moe/t8ejrs.png
This commit is contained in:
Andrej730
2025-08-08 16:45:49 +05:00
parent 12c795a482
commit f2f28f8ba6
2 changed files with 13 additions and 12 deletions
+3
View File
@@ -236,6 +236,9 @@ class SelectIfcFile(bpy.types.Operator, IFCFileSelector, ImportHelper):
return ImportHelper.invoke(self, context, event)
# TODO: Unused operator.
# Is there a need for this or 'DIR_PATH' propety subtype does almost the same,
# but also has alt+click?
class SelectDir(bpy.types.Operator, ImportHelper):
bl_idname = "bim.select_dir"
bl_label = "Select Directory"
+10 -12
View File
@@ -370,6 +370,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
tmp_dir: StringProperty(
name="Temporary Directory",
description="Path to create and store temporary files. If left blank, a system default will be used.",
subtype="DIR_PATH",
)
spatial_elements_unselectable: BoolProperty(
name="Make Spatial Elements Unselectable By Default",
@@ -469,14 +470,19 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
default=(platformdirs.user_data_path("bonsai", roaming=True, ensure_exists=True) / "data").__str__(),
name="Data Directory",
update=update_data_dir,
subtype="DIR_PATH",
)
cache_dir: StringProperty(
default=platformdirs.user_cache_dir("bonsai"), name="Cache Directory", update=update_cache_dir
default=platformdirs.user_cache_dir("bonsai"),
name="Cache Directory",
update=update_cache_dir,
subtype="DIR_PATH",
)
pset_dir: StringProperty(
default=os.path.join("psets") + os.path.sep,
name="Default Psets Directory",
subtype="DIR_PATH",
)
doc: bpy.props.PointerProperty(type=DocPreferences)
@@ -561,17 +567,9 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
layout.prop(self, "occurrence_name_function")
def draw_directories(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None:
row = layout.row(align=True)
row.prop(self, "data_dir")
row.operator("bim.select_dir", icon="FILE_FOLDER", text="").data_path = "preferences.data_dir"
row = layout.row(align=True)
row.prop(self, "cache_dir")
row.operator("bim.select_dir", icon="FILE_FOLDER", text="").data_path = "preferences.cache_dir"
row = layout.row(align=True)
row.prop(self, "tmp_dir")
row.operator("bim.select_dir", icon="FILE_FOLDER", text="").data_path = "preferences.tmp_dir"
layout.prop(self, "data_dir")
layout.prop(self, "cache_dir")
layout.prop(self, "tmp_dir")
def draw_drawing_settings(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None:
layout.prop(self, "pset_dir")