Merge branch 'blender-v4.2-release'

This commit is contained in:
Campbell Barton 2024-07-03 16:05:49 +10:00
commit 9da4f557f1
2 changed files with 82 additions and 16 deletions

@ -3304,6 +3304,44 @@ class EXTENSIONS_OT_repo_unlock(Operator):
return {'FINISHED'}
class EXTENSIONS_OT_userpref_tags_set(Operator):
"""Set the value of all tags"""
bl_idname = "extensions.userpref_tags_set"
bl_label = "Set Extension Tags"
bl_options = {'INTERNAL'}
value: BoolProperty(
name="Value",
description="Enable or disable all tags",
options={'SKIP_SAVE'},
)
data_path: StringProperty(
name="Data Path",
options={'SKIP_SAVE'},
)
def execute(self, context):
from .bl_extension_ui import (
tags_clear,
tags_refresh,
)
wm = context.window_manager
value = self.value
tags_attr = self.data_path
# Internal error, could happen if called from some unexpected place.
if tags_attr not in {"extension_tags", "addon_tags"}:
return {'CANCELLED'}
tags_clear(wm, tags_attr)
if self.value is False:
tags_refresh(wm, tags_attr, default_value=False)
return {'FINISHED'}
# NOTE: this is a modified version of `PREFERENCES_OT_addon_show`.
# It would make most sense to extend this operator to support showing extensions to upgrade (eventually).
class EXTENSIONS_OT_userpref_show_for_update(Operator):
@ -3476,6 +3514,7 @@ classes = (
EXTENSIONS_OT_repo_lock,
EXTENSIONS_OT_repo_unlock,
EXTENSIONS_OT_userpref_tags_set,
EXTENSIONS_OT_userpref_show_for_update,
EXTENSIONS_OT_userpref_show_online,
EXTENSIONS_OT_userpref_allow_online,

@ -2039,7 +2039,7 @@ def tags_clear(wm, tags_attr):
wm[tags_attr] = {}
def tags_refresh(wm, tags_attr):
def tags_refresh(wm, tags_attr, *, default_value):
import idprop
tags_idprop = wm.get(tags_attr)
if isinstance(tags_idprop, idprop.types.IDPropertyGroup):
@ -2059,7 +2059,7 @@ def tags_refresh(wm, tags_attr):
for tag in tags_to_rem:
del tags_idprop[tag]
for tag in tags_to_add:
tags_idprop[tag] = True
tags_idprop[tag] = default_value
return list(sorted(tags_next))
@ -2068,21 +2068,48 @@ def tags_panel_draw(layout, context, tags_attr):
from bpy.utils import escape_identifier
from bpy.app.translations import contexts as i18n_contexts
wm = context.window_manager
tags_sorted = tags_refresh(wm, tags_attr)
layout.label(text="Show Tags")
# Add one so the first row is longer in the case of an odd number.
tags_len_half = (len(tags_sorted) + 1) // 2
split = layout.split(factor=0.5)
col = split.column()
for i, t in enumerate(sorted(tags_sorted)):
if i == tags_len_half:
col = split.column()
col.prop(
getattr(wm, tags_attr),
"[\"{:s}\"]".format(escape_identifier(t)),
text=t,
text_ctxt=i18n_contexts.editor_preferences,
)
row = split.row()
row.label(text="Show Tags")
subrow = row.row()
subrow.alignment = 'RIGHT'
subrow.label(text="Select")
# NOTE: this is a workaround, as we don't have a convenient way for the UI to click on a
# single tag and de-select others (think file or outliner selection, also layers in 2.4x).
# This implements check-boxes with an awkward select All/None which has the down side that
# a single tag always takes 2 clicks instead of one.
row = split.row()
props = row.operator("extensions.userpref_tags_set", text="All")
props.value = True
props.data_path = tags_attr
props = row.operator("extensions.userpref_tags_set", text="None")
props.value = False
props.data_path = tags_attr
del split, row
layout.separator(type='LINE')
if tags_sorted := tags_refresh(wm, tags_attr, default_value=True):
# Use the `length + 1` so the first row is longer in the case of an odd number.
tags_len_half = (len(tags_sorted) + 1) // 2
split = layout.split(factor=0.5)
col = split.column()
for i, t in enumerate(sorted(tags_sorted)):
if i == tags_len_half:
col = split.column()
col.prop(
getattr(wm, tags_attr),
"[\"{:s}\"]".format(escape_identifier(t)),
text=t,
text_ctxt=i18n_contexts.editor_preferences,
)
else:
# Show some text else this seems like an error.
col = layout.column()
col.label(text="No visible tags.")
col.active = False
# -----------------------------------------------------------------------------