dvStudioInspectorGroupsFor function
Which properties the inspector offers for node, grouped and ordered the
way it draws them.
Generated against dvStudioProperties and dvStudioLayoutProperties
rather than written out: the inspector used to be one flat list of the
property table, so nothing in the table could be missing from it, and
grouping must not change that. A property no group names is placed in
"Other" instead of vanishing.
Implementation
List<(String, List<String>)> dvStudioInspectorGroupsFor(DVPageNode node) {
final Set<String> known = <String>{
for (final DVStudioProperty property in dvStudioProperties) property.name,
};
final Set<String> placed = <String>{};
final List<(String, List<String>)> groups = <(String, List<String>)>[];
void add(String label, Iterable<String> names) {
final List<String> kept = <String>[
for (final String name in names)
if (placed.add(name)) name,
];
if (kept.isNotEmpty) groups.add((label, kept));
}
switch (node.type) {
case 'text' || 'button':
add('Content', <String>['text']);
case 'image':
add('Content', <String>['src', 'alt', 'fit']);
}
final bool isBox = dvStudioLeafTypeFor(node) == null;
add('Layout', <String>[
if (isBox)
for (final DVStudioLayoutProperty property in dvStudioLayoutProperties)
if (property.appliesTo(node.layout)) property.name,
if (known.contains('align')) 'align',
]);
final bool isText = node.type == 'text' || node.type == 'button';
final List<(String, List<String>)> ordered = isText
? <(String, List<String>)>[
_dvStudioGroupLayout[1],
_dvStudioGroupLayout[0],
..._dvStudioGroupLayout.skip(2),
]
: _dvStudioGroupLayout;
for (final (String label, List<String> names) in ordered) {
add(label, names.where(known.contains));
}
add('Other', <String>[
for (final DVStudioProperty property in dvStudioProperties)
if (!placed.contains(property.name)) property.name,
]);
return groups;
}