toAction method

CarpenterActionDescriptor toAction(
  1. I input, {
  2. String? label,
  3. String? semanticLabel,
  4. CarpenterIconSource? icon,
  5. ActionColorRole? colorRole,
  6. ShortcutActivator? shortcut,
  7. CarpenterCommandExecutor? executor,
})

Creates a presentation-only action snapshot for input from the command's current visibility, availability, execution state, shortcuts, and semantic prominence.

Implementation

CarpenterActionDescriptor toAction(
  I input, {
  String? label,
  String? semanticLabel,
  CarpenterIconSource? icon,
  ActionColorRole? colorRole,
  ShortcutActivator? shortcut,
  CarpenterCommandExecutor? executor,
}) {
  final current = state.value;
  final visible = current.visibility == CarpenterCommandVisibility.visible;
  final available =
      visible &&
      current.enabled &&
      current.execution != CarpenterCommandExecution.executing;
  return CarpenterActionDescriptor(
    id: id,
    label: label ?? title,
    semanticLabel: semanticLabel,
    icon: icon,
    colorRole: colorRole ?? _commandColorRole(presentation),
    shortcut: shortcut ?? (shortcuts.isEmpty ? null : shortcuts.first),
    visible: visible,
    disabledReason: available ? null : current.disabledReason,
    onInvoke: available
        ? () {
            unawaited(_executeCommandForSurface(this, input, executor));
          }
        : null,
  );
}