Track expanded packages outside of packages themseleves

Packages now retain their expanded/collapsed state after the
packagelist has been regenerated.
This commit is contained in:
Ellwood Zwovic
2017-07-24 21:53:38 -07:00
parent 9b424b52ce
commit 5e034855c0

View File

@@ -55,7 +55,6 @@ class ConsolidatedPackage:
def __init__(self, pkg=None):
self.versions = []
self.expanded = False
if pkg is not None:
self.add_version(pkg)
@@ -600,6 +599,7 @@ class USERPREF_PT_packages(bpy.types.Panel):
available_packages = []
installed_packages = []
displayed_packages = []
expanded_packages = []
@classmethod
def poll(cls, context):
@@ -773,6 +773,7 @@ class USERPREF_PT_packages(bpy.types.Panel):
draw_version(subvbox, version)
pkg = metapkg.get_latest_version()
is_expanded = (pkg.name in self.expanded_packages)
pkgbox = layout.box()
spl = pkgbox.split(.8)
@@ -783,10 +784,9 @@ class USERPREF_PT_packages(bpy.types.Panel):
right.alignment = 'RIGHT'
right.scale_y = 1.5
# for collapse/expand button
left.operator(
WM_OT_package_toggle_expand.bl_idname,
icon='TRIA_DOWN' if metapkg.expanded else 'TRIA_RIGHT',
icon='TRIA_DOWN' if is_expanded else 'TRIA_RIGHT',
emboss=False,
).package_name=pkg.name
@@ -812,7 +812,7 @@ class USERPREF_PT_packages(bpy.types.Panel):
else:
right.label("Not installed, but no URL?")
if metapkg.expanded:
if is_expanded:
expanded()
else:
collapsed()# }}}
@@ -862,18 +862,12 @@ class WM_OT_package_toggle_expand(bpy.types.Operator):
)
def invoke(self, context, event):
global _packages
try:
pkg = _packages[self.package_name]
except KeyError:
log.error("Couldn't find package '%s'", self.package_name)
return {'CANCELLED'}
pkg.expanded = not pkg.expanded
if event.shift:
for pkgname in USERPREF_PT_packages.displayed_packages:
if not pkgname == self.package_name:
_packages[pkgname].expanded = False
USERPREF_PT_packages.expanded_packages = []
if self.package_name in USERPREF_PT_packages.expanded_packages:
USERPREF_PT_packages.expanded_packages.remove(self.package_name)
else:
USERPREF_PT_packages.expanded_packages.append(self.package_name)
return {'FINISHED'}