Update script to use __package__ instead of __name__ for preferences
This commit is contained in:
parent
662c47137d
commit
493e04ed05
@ -48,7 +48,7 @@ class OT_SelectTemplatePopup(Operator):
|
|||||||
project_path: StringProperty(name="Project Path", subtype="FILE_PATH")
|
project_path: StringProperty(name="Project Path", subtype="FILE_PATH")
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
prefs = context.preferences.addons[__name__].preferences
|
prefs = context.preferences.addons[__package__].preferences
|
||||||
for p in prefs.projects:
|
for p in prefs.projects:
|
||||||
if p.path == self.project_path:
|
if p.path == self.project_path:
|
||||||
already_present = True
|
already_present = True
|
||||||
@ -76,7 +76,7 @@ class OT_AddTemplatePopup(Operator):
|
|||||||
project_name: StringProperty(name="Project Name")
|
project_name: StringProperty(name="Project Name")
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
prefs = context.preferences.addons[__name__].preferences
|
prefs = context.preferences.addons[__package__].preferences
|
||||||
current_file_path = bpy.data.filepath
|
current_file_path = bpy.data.filepath
|
||||||
for p in prefs.projects:
|
for p in prefs.projects:
|
||||||
if p.path == current_file_path:
|
if p.path == current_file_path:
|
||||||
@ -106,7 +106,7 @@ class OT_AddTemplateItem(Operator):
|
|||||||
bl_description = "Add new template"
|
bl_description = "Add new template"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
prefs = context.preferences.addons[__name__].preferences
|
prefs = context.preferences.addons[__package__].preferences
|
||||||
prefs.projects.add()
|
prefs.projects.add()
|
||||||
prefs.active_template_index = len(prefs.projects) - 1
|
prefs.active_template_index = len(prefs.projects) - 1
|
||||||
self.report({'INFO'}, f"Empty template added")
|
self.report({'INFO'}, f"Empty template added")
|
||||||
@ -119,7 +119,7 @@ class OT_RemoveTemplateItem(Operator):
|
|||||||
bl_description = "Remove selected template"
|
bl_description = "Remove selected template"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
prefs = context.preferences.addons[__name__].preferences
|
prefs = context.preferences.addons[__package__].preferences
|
||||||
self.report(
|
self.report(
|
||||||
{'INFO'}, f'Template "{prefs.projects[prefs.active_template_index].name}" removed{" (`"+prefs.projects[prefs.active_template_index].path+"`)" if prefs.projects[prefs.active_template_index].path != "" else "" }')
|
{'INFO'}, f'Template "{prefs.projects[prefs.active_template_index].name}" removed{" (`"+prefs.projects[prefs.active_template_index].path+"`)" if prefs.projects[prefs.active_template_index].path != "" else "" }')
|
||||||
prefs.projects.remove(prefs.active_template_index)
|
prefs.projects.remove(prefs.active_template_index)
|
||||||
@ -134,7 +134,7 @@ class OT_MoveUpTemplateItem(bpy.types.Operator):
|
|||||||
bl_description = "Move the selected template up in the list"
|
bl_description = "Move the selected template up in the list"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
prefs = context.preferences.addons[__name__].preferences
|
prefs = context.preferences.addons[__package__].preferences
|
||||||
index = prefs.active_template_index
|
index = prefs.active_template_index
|
||||||
|
|
||||||
if index > 0:
|
if index > 0:
|
||||||
@ -153,7 +153,7 @@ class OT_MoveDownTemplateItem(bpy.types.Operator):
|
|||||||
bl_description = "Move the selected template down in the list"
|
bl_description = "Move the selected template down in the list"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
prefs = context.preferences.addons[__name__].preferences
|
prefs = context.preferences.addons[__package__].preferences
|
||||||
index = prefs.active_template_index
|
index = prefs.active_template_index
|
||||||
|
|
||||||
if index < len(prefs.projects) - 1:
|
if index < len(prefs.projects) - 1:
|
||||||
@ -178,7 +178,7 @@ class OT_OpenAddonPreferences(bpy.types.Operator):
|
|||||||
|
|
||||||
# Add-On Preferences
|
# Add-On Preferences
|
||||||
class CustomTemplatesPreferences(AddonPreferences):
|
class CustomTemplatesPreferences(AddonPreferences):
|
||||||
bl_idname = __name__
|
bl_idname = __package__
|
||||||
|
|
||||||
projects: CollectionProperty(type=TemplateItem)
|
projects: CollectionProperty(type=TemplateItem)
|
||||||
active_template_index: IntProperty(
|
active_template_index: IntProperty(
|
||||||
@ -217,7 +217,7 @@ def draw_addon_separator(layout):
|
|||||||
|
|
||||||
def draw_new_menu(self, context):
|
def draw_new_menu(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
prefs = context.preferences.addons[__name__].preferences
|
prefs = context.preferences.addons[__package__].preferences
|
||||||
|
|
||||||
if len(prefs.projects) > 0:
|
if len(prefs.projects) > 0:
|
||||||
draw_addon_separator(layout)
|
draw_addon_separator(layout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user