Refactor addon preferences to make it cleaner as per developer's feedback

This commit is contained in:
falken10vdl
2025-12-08 09:25:49 +01:00
parent 9f6e92eefd
commit c4da1dda4d
2 changed files with 20 additions and 45 deletions
+10 -17
View File
@@ -132,23 +132,16 @@ class BIM_PT_spatial_decomposition(Panel):
op = col.operator("bim.set_default_container", icon="OUTLINER_COLLECTION", text="Set Default")
op.container = ifc_definition_id
# Only show container visibility operators if the preference is enabled
from bonsai.bim.ui import BIM_ADDON_preferences
addon = BIM_ADDON_preferences.get_addon_instance()
if addon and getattr(addon, "preferences", None):
prefs = addon.preferences
value = getattr(prefs, "container_hide_show_isolate", None)
if value:
op = row.operator("bim.set_container_visibility", icon="FULLSCREEN_EXIT", text="")
op.mode = "ISOLATE"
op.container = ifc_definition_id
op = row.operator("bim.set_container_visibility", icon="HIDE_OFF", text="")
op.mode = "SHOW"
op.container = ifc_definition_id
op = row.operator("bim.set_container_visibility", icon="HIDE_ON", text="")
op.mode = "HIDE"
op.container = ifc_definition_id
if tool.Blender.get_addon_preferences().container_hide_show_isolate:
op = row.operator("bim.set_container_visibility", icon="FULLSCREEN_EXIT", text="")
op.mode = "ISOLATE"
op.container = ifc_definition_id
op = row.operator("bim.set_container_visibility", icon="HIDE_OFF", text="")
op.mode = "SHOW"
op.container = ifc_definition_id
op = row.operator("bim.set_container_visibility", icon="HIDE_ON", text="")
op.mode = "HIDE"
op.container = ifc_definition_id
# The only operator that's enabled for IfcProject.
col = row.column(align=True)
+10 -28
View File
@@ -678,34 +678,6 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
description="Default parameters for BIM elements",
)
addon_instance = None
@classmethod
def set_addon_instance(cls):
import bpy
instance = None
for key in bpy.context.preferences.addons.keys():
if ".bonsai" in key:
instance = bpy.context.preferences.addons.get(key)
break
cls.addon_instance = instance
@classmethod
def get_addon_instance(cls):
if cls.addon_instance is None:
cls.set_addon_instance()
return cls.addon_instance
def draw_extras_settings(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None:
layout.prop(self, "container_hide_show_isolate")
container_hide_show_isolate: BoolProperty(
name="Container hide/show/isolate",
description="Enable container hide/show/isolate feature in the UI",
default=False,
)
if TYPE_CHECKING:
svg2pdf_command: str
svg2dxf_command: str
@@ -921,6 +893,16 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
layout.prop(self, "bsdd_load_test_dictionaries")
def draw_extras_settings(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None:
layout.prop(self, "container_hide_show_isolate")
container_hide_show_isolate: BoolProperty(
name="Container hide/show/isolate",
description="Enable container hide/show/isolate feature in the UI",
default=False,
)
# Scene panel groups
class BIM_PT_tabs(Panel):
bl_label = "Bonsai"