setCollapsed method

EditResult setCollapsed(
  1. String id,
  2. bool collapsed
)

Changes frame presentation without rewriting its expanded geometry.

Implementation

EditResult setCollapsed(String id, bool collapsed) {
  if (store.isInteracting) {
    return const EditResult.denied(reason: 'Finish the active edit first.');
  }
  final document = store.state.document;
  final before = document.shapeById(id);
  if (before == null ||
      store.diagram.resolver.registry.require(before.type).collapse == null) {
    return const EditResult.denied(reason: 'Choose a collapsible frame.');
  }
  if (!store.scene.isVisible(id)) {
    return const EditResult.denied(
      reason: 'Expand the containing frame first.',
    );
  }
  if (before.isCollapsed == collapsed) {
    return const EditResult.allow();
  }
  return store.edits.dispatch(
    DiagramTransaction(
      label: collapsed ? 'Collapse frame' : 'Expand frame',
      steps: [
        ReplaceElementStep(
          before: before,
          after: before.copyWith(isCollapsed: collapsed),
        ),
      ],
      selectionAfter: ElementSelection({id}),
    ),
    expectedRevision: document.revision,
  );
}