WorkSpace: show/hode opt-out support for addons
In some cases it doesn't make sense for add-ons to be listed for hiding. Especially for import/export which use minimal UI space. This adds `bl_info["use_owner"]` to add-ons, currently defaulting to True for all non Import-Export add-ons.
This commit is contained in:
@@ -352,10 +352,11 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
|
|||||||
# 2) try register collected modules
|
# 2) try register collected modules
|
||||||
# removed, addons need to handle own registration now.
|
# removed, addons need to handle own registration now.
|
||||||
|
|
||||||
|
use_owner = mod.bl_info.get("use_owner", True)
|
||||||
from _bpy import _bl_owner_id_get, _bl_owner_id_set
|
if use_owner:
|
||||||
owner_id_prev = _bl_owner_id_get()
|
from _bpy import _bl_owner_id_get, _bl_owner_id_set
|
||||||
_bl_owner_id_set(module_name)
|
owner_id_prev = _bl_owner_id_get()
|
||||||
|
_bl_owner_id_set(module_name)
|
||||||
|
|
||||||
# 3) try run the modules register function
|
# 3) try run the modules register function
|
||||||
try:
|
try:
|
||||||
@@ -369,7 +370,8 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
|
|||||||
_addon_remove(module_name)
|
_addon_remove(module_name)
|
||||||
return None
|
return None
|
||||||
finally:
|
finally:
|
||||||
_bl_owner_id_set(owner_id_prev)
|
if use_owner:
|
||||||
|
_bl_owner_id_set(owner_id_prev)
|
||||||
|
|
||||||
# * OK loaded successfully! *
|
# * OK loaded successfully! *
|
||||||
mod.__addon_enabled__ = True
|
mod.__addon_enabled__ = True
|
||||||
@@ -480,6 +482,7 @@ def module_bl_info(mod, info_basis=None):
|
|||||||
"category": "",
|
"category": "",
|
||||||
"warning": "",
|
"warning": "",
|
||||||
"show_expanded": False,
|
"show_expanded": False,
|
||||||
|
"use_owner": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
addon_info = getattr(mod, "bl_info", {})
|
addon_info = getattr(mod, "bl_info", {})
|
||||||
@@ -497,5 +500,9 @@ def module_bl_info(mod, info_basis=None):
|
|||||||
if not addon_info["name"]:
|
if not addon_info["name"]:
|
||||||
addon_info["name"] = mod.__name__
|
addon_info["name"] = mod.__name__
|
||||||
|
|
||||||
|
# Temporary auto-magic, don't use_owner for import export menus.
|
||||||
|
if mod.bl_info["category"] == "Import-Export":
|
||||||
|
mod.bl_info["use_owner"] = False
|
||||||
|
|
||||||
addon_info["_init"] = None
|
addon_info["_init"] = None
|
||||||
return addon_info
|
return addon_info
|
||||||
|
|||||||
@@ -80,15 +80,14 @@ class WORKSPACE_PT_owner_ids(WorkSpaceButtonsPanel, Panel):
|
|||||||
col.active = workspace.use_filter_by_owner
|
col.active = workspace.use_filter_by_owner
|
||||||
|
|
||||||
import addon_utils
|
import addon_utils
|
||||||
addon_map = {
|
addon_map = {mod.__name__: mod for mod in addon_utils.modules()}
|
||||||
mod.__name__: ("%s: %s" % (mod.bl_info["category"], mod.bl_info["name"]))
|
|
||||||
for mod in addon_utils.modules()
|
|
||||||
}
|
|
||||||
owner_ids = {owner_id.name for owner_id in workspace.owner_ids}
|
owner_ids = {owner_id.name for owner_id in workspace.owner_ids}
|
||||||
|
|
||||||
for addon in userpref.addons:
|
for addon in userpref.addons:
|
||||||
module_name = addon.module
|
module_name = addon.module
|
||||||
text = addon_map[module_name]
|
info = addon_utils.module_bl_info(addon_map[module_name])
|
||||||
|
if not info["use_owner"]:
|
||||||
|
continue
|
||||||
is_enabled = module_name in owner_ids
|
is_enabled = module_name in owner_ids
|
||||||
row = col.row()
|
row = col.row()
|
||||||
row.operator(
|
row.operator(
|
||||||
@@ -97,7 +96,7 @@ class WORKSPACE_PT_owner_ids(WorkSpaceButtonsPanel, Panel):
|
|||||||
text="",
|
text="",
|
||||||
emboss=False,
|
emboss=False,
|
||||||
).owner_id = module_name
|
).owner_id = module_name
|
||||||
row.label(text)
|
row.label("%s: %s" % (info["category"], info["name"]))
|
||||||
if is_enabled:
|
if is_enabled:
|
||||||
owner_ids.remove(module_name)
|
owner_ids.remove(module_name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user