refactor(desktop): reorganize workspace panels and navigation
Gitea CI / Windows x64 and Android (pull_request) Successful in 16m21s
Gitea CI / Gitea CI passed (pull_request) Successful in 3s

This commit is contained in:
lingjhf committed 2026-10-06 12:11:59 +08:00
1 parent 826745b407
commit 1f73765745
92 files changed
+5811 -2650

No files matched your search

+420 -304
View File
@@ -1,3 +1,5 @@
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import '../../diagnostics/app_diagnostics.dart';
import 'dart:async';
@@ -17,6 +19,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import '../../shared/widgets/listenable_selector.dart';
import '../../workspace/media_availability.dart';
import '../../workspace/preview_controller_registry.dart';
import '../../workspace/preview_target.dart';
@@ -148,13 +151,19 @@ class EditorPreviewPanel extends StatelessWidget {
super.key,
required this.projectId,
required this.timelineId,
this.pending = false,
});
final String projectId;
final String timelineId;
final bool pending;
@override
Widget build(BuildContext context) => PreviewFullscreenHost(
child: _EditorPreviewContent(projectId: projectId, timelineId: timelineId),
child: _EditorPreviewContent(
projectId: projectId,
timelineId: timelineId,
pending: pending,
),
);
}
@@ -162,199 +171,256 @@ class _EditorPreviewContent extends ConsumerWidget {
const _EditorPreviewContent({
required this.projectId,
required this.timelineId,
this.pending = false,
});
final String projectId;
final String timelineId;
final bool pending;
@override
Widget build(BuildContext context, WidgetRef ref) {
final provider = editorPreviewProvider(projectId, timelineId);
final state = ref.watch(provider);
final watched = pending
? const AsyncData<PreviewController?>(null)
: ref.watch(provider);
final cached = watched.isLoading && !watched.hasError
? ref.read(previewControllerRegistryProvider).cached((
projectId,
timelineId,
))
: null;
final state = cached == null
? watched
: AsyncData<PreviewController?>(cached);
final controller = state.asData?.value;
Widget panel() {
final activeController = controller;
final showCanvas =
state.hasError ||
(activeController != null &&
(activeController.durationTick > 0 ||
activeController.error != null));
final overlayBuilder =
activeController != null &&
PreviewFullscreenScope.of(context)?.fullscreen != true &&
activeController.session != null &&
activeController.error == null
? (Rect rect) => ListenableBuilder(
listenable: activeController.positionChanges,
builder: (context, _) => Theme(
data: AppTheme.previewCanvasTheme,
child:
activeController.maskEditingElement != null ||
activeController.obscureEditingElement != null
? MaskInteractionOverlay(
controller: activeController,
canvasRect: rect,
obscure: activeController.obscureEditingElement != null,
)
: PreviewInteractionOverlay(
onError: (_) => ScaffoldMessenger.maybeOf(context)
?.showSnackBar(
SnackBar(
content: Text(
context.l10n.canvasTransformFailed,
),
),
),
controller: activeController,
canvasRect: rect,
),
),
)
: null;
return WorkspacePanel(
headerHeight: 0,
showHeaderDivider: false,
child: PreviewFullscreenLayout(
canvas: showCanvas
? Padding(
padding:
PreviewFullscreenScope.of(context)?.fullscreen == true
? EdgeInsets.zero
: AppSpacing.panelSection,
child: PreviewCanvas(
alignment: Alignment.center,
horizontalPadding: 0,
backgroundColor: AppSurfaces.of(context).previewBackground,
overlayBuilder: overlayBuilder,
aspectRatio:
(activeController?.canvas ?? ProjectCanvas.widescreen)
.aspectRatio,
child: Theme(
Widget panel() => WorkspacePanel(
headerHeight: 0,
showHeaderDivider: false,
child: PreviewFullscreenLayout(
canvas: ListenableSelector(
listenable: controller,
select: () => (
controller?.canvas,
controller?.session,
controller?.error,
(controller?.durationTick ?? 0) > 0,
),
builder: (context, _) {
final activeController = controller;
final defaultCanvas =
pending ||
(state.isLoading && !state.hasError && controller == null);
final showCanvas =
defaultCanvas ||
state.hasError ||
(activeController != null &&
(activeController.durationTick > 0 ||
activeController.error != null));
final overlayBuilder =
activeController != null &&
PreviewFullscreenScope.of(context)?.fullscreen != true &&
activeController.session != null &&
activeController.error == null
? (Rect rect) => ListenableBuilder(
listenable: activeController.positionChanges,
builder: (context, _) => Theme(
data: AppTheme.previewCanvasTheme,
child: Builder(
builder: (context) => state.when(
loading: () => const DelayedLoadingIndicator(
child: Center(child: CircularProgressIndicator()),
),
error: (error, _) => Center(
child: SingleChildScrollView(
primary: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
error is EditorSessionStartupException
? context.l10n.editorSessionStartFailed
: error is RuntimeException &&
error.code == 'unsupported'
? context.l10n.nativePreviewUnsupported
: context.l10n.previewStartFailed,
textAlign: TextAlign.center,
child:
activeController.maskEditingElement != null ||
activeController.obscureEditingElement != null
? MaskInteractionOverlay(
controller: activeController,
canvasRect: rect,
obscure:
activeController.obscureEditingElement !=
null,
)
: PreviewInteractionOverlay(
onError: (error) =>
ErrorNotificationHost.maybeOf(context)?.show(
ErrorNotification(
content: Text(
context.l10n.canvasTransformFailed,
),
details: error.toString(),
),
),
TextButton(
onPressed: () {
if (error
is EditorSessionStartupException) {
ref.invalidate(
editorTimelineProvider(
projectId,
timelineId,
),
);
} else {
unawaited(
ref
.read(
previewControllerRegistryProvider,
)
.invalidate((
projectId,
timelineId,
)),
);
ref.invalidate(provider);
}
},
child: Text(context.l10n.retry),
),
],
),
controller: activeController,
canvasRect: rect,
),
),
data: (preview) {
if (preview == null) {
return const SizedBox.expand(
key: Key('empty-preview-area'),
);
}
return Stack(
fit: StackFit.expand,
children: [
if (preview.session case final session?)
RuntimePreview(session: session),
ListenableBuilder(
listenable: preview.positionChanges,
builder: (context, _) {
final unavailable =
preview.unavailableAtPlayhead;
if (preview.error != null ||
unavailable.isEmpty) {
return const SizedBox.shrink();
}
return IgnorePointer(
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(
AppSpacing.medium,
),
child: Text(
context.l10n.mediaOffline(
unavailable.join(', '),
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
)
: null;
return showCanvas
? Padding(
padding:
PreviewFullscreenScope.of(context)?.fullscreen == true
? EdgeInsets.zero
: AppSpacing.panelSection,
child: PreviewCanvas(
alignment: Alignment.center,
horizontalPadding: 0,
backgroundColor: AppSurfaces.of(context)
.previewBackground,
overlayBuilder: overlayBuilder,
aspectRatio:
(activeController?.canvas ?? ProjectCanvas.widescreen)
.aspectRatio,
child: Theme(
data: AppTheme.previewCanvasTheme,
child: Builder(
builder: (context) => defaultCanvas
? const ColoredBox(
key: Key('preview-default-frame'),
color: Colors.black,
)
: state.when(
skipLoadingOnReload: true,
loading: () => const ColoredBox(
key: Key('preview-default-frame'),
color: Colors.black,
),
error: (error, _) => Center(
child: SingleChildScrollView(
primary: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
error is EditorSessionStartupException
? context
.l10n
.editorSessionStartFailed
: error is RuntimeException &&
error.code ==
'unsupported'
? context
.l10n
.nativePreviewUnsupported
: context.l10n.previewStartFailed,
textAlign: TextAlign.center,
),
),
),
);
},
),
if (preview.error != null ||
preview.durationTick == 0)
ColoredBox(
color: AppSurfaces.of(context)
.previewBackground,
child: Center(
child: Padding(
padding: const EdgeInsets.all(
AppSpacing.medium,
),
child: Text(
preview.error == null
? context.l10n.noPreviewContent
: previewErrorMessage(
preview.error!,
context.l10n,
),
textAlign: TextAlign.center,
),
TextButton(
onPressed: () {
if (error
is EditorSessionStartupException) {
ref.invalidate(
editorTimelineProvider(
projectId,
timelineId,
),
);
} else {
unawaited(
ref
.read(
previewControllerRegistryProvider,
)
.invalidate((
projectId,
timelineId,
)),
);
ref.invalidate(provider);
}
},
child: Text(context.l10n.retry),
),
],
),
),
),
],
);
},
data: (preview) {
if (preview == null) {
return const SizedBox.expand(
key: Key('empty-preview-area'),
);
}
return Stack(
fit: StackFit.expand,
children: [
if (preview.session case final session?)
RuntimePreview(session: session),
ListenableSelector(
listenable: Listenable.merge([
preview,
preview.positionChanges,
]),
select: () => (
preview.error,
preview.unavailableAtPlayhead.join(
', ',
),
),
builder: (context, _) {
final unavailable =
preview.unavailableAtPlayhead;
if (preview.error != null ||
unavailable.isEmpty) {
return const SizedBox.shrink();
}
return IgnorePointer(
child: Align(
alignment:
Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(
AppSpacing.medium,
),
child: Text(
context.l10n.mediaOffline(
unavailable.join(', '),
),
maxLines: 2,
overflow:
TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
),
),
);
},
),
if (preview.error != null ||
preview.durationTick == 0)
ColoredBox(
color: AppSurfaces.of(context)
.previewBackground,
child: Center(
child: Padding(
padding: const EdgeInsets.all(
AppSpacing.medium,
),
child: Text(
preview.error == null
? context
.l10n
.noPreviewContent
: previewErrorMessage(
preview.error!,
context.l10n,
),
textAlign: TextAlign.center,
),
),
),
),
],
);
},
),
),
),
),
),
)
: const SizedBox.expand(key: Key('empty-preview-area')),
toolbar: _PreviewToolbar(controller: controller),
)
: const SizedBox.expand(key: Key('empty-preview-area'));
},
),
);
}
toolbar: _PreviewToolbar(controller: controller),
),
);
if (pending) return panel();
final target = ref.watch(previewTargetProvider(projectId, timelineId));
final navigation = ref.watch(
@@ -381,12 +447,7 @@ class _EditorPreviewContent extends ConsumerWidget {
target.togglePlayback = controller == null
? null
: () => unawaited(controller.togglePlayback());
return controller == null
? panel()
: ListenableBuilder(
listenable: controller,
builder: (_, _) => panel(),
);
return panel();
},
),
},
@@ -410,34 +471,40 @@ class _SourcePreviewPanel extends ConsumerWidget {
.watch(mediaAvailabilityProvider(projectId, asset))
.asData
?.value;
return ListenableBuilder(
listenable: source,
builder: (context, _) {
// The availability probe can finish while a newly dropped file is
// still switching security-scoped leases. Once the runtime has opened
// the source, that live session is stronger evidence than the stale
// probe result and must not be covered by an unavailable placeholder.
final unavailable =
availability != null &&
availability != MediaAvailability.available &&
source.session == null &&
source.image == null;
return CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.space):
source.togglePlayback,
},
child: Focus(
autofocus: true,
child: WorkspacePanel(
title: asset.name,
showHeaderDivider: false,
headerHeight:
PreviewFullscreenScope.of(context)?.fullscreen == true
? 0
: AppControlSize.panelHeader,
child: PreviewFullscreenLayout(
canvas: Padding(
return CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.space): source.togglePlayback,
},
child: Focus(
autofocus: true,
child: WorkspacePanel(
title: asset.name,
showHeaderDivider: false,
headerHeight: PreviewFullscreenScope.of(context)?.fullscreen == true
? 0
: AppControlSize.panelHeader,
child: PreviewFullscreenLayout(
canvas: ListenableSelector(
listenable: source,
select: () => (
source.session,
source.image,
source.error,
source.busy,
source.aspectRatio,
source.audioOnly,
),
builder: (context, _) {
// The availability probe can finish while a newly dropped file is
// still switching security-scoped leases. Once the runtime has opened
// the source, that live session is stronger evidence than the stale
// probe result and must not be covered by an unavailable placeholder.
final unavailable =
availability != null &&
availability != MediaAvailability.available &&
source.session == null &&
source.image == null;
return Padding(
padding:
PreviewFullscreenScope.of(context)?.fullscreen == true
? EdgeInsets.zero
@@ -508,13 +575,13 @@ class _SourcePreviewPanel extends ConsumerWidget {
),
),
),
),
toolbar: _PreviewToolbar(controller: null, source: source),
),
);
},
),
toolbar: _PreviewToolbar(controller: null, source: source),
),
);
},
),
),
);
}
}
@@ -527,18 +594,33 @@ class _PreviewToolbar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final listenable = source == null && controller != null
? Listenable.merge([controller!, controller!.positionChanges])
: source;
if (listenable != null) {
return ListenableBuilder(
listenable: listenable,
if (PreviewFullscreenScope.of(context)?.fullscreen == true) {
return ListenableSelector(
listenable: _clock,
select: () => (
source?.positionTick ?? controller?.positionTick ?? 0,
source?.durationTick ?? controller?.durationTick ?? 0,
source?.frameDuration ?? controller?.frameDuration,
source?.playing ?? controller?.playing ?? false,
source?.canPlay ?? controller?.canPlay ?? false,
),
builder: (context, _) => _build(context),
);
}
return _build(context);
}
Listenable? get _clock =>
source ??
(controller == null
? null
: Listenable.merge([controller!, controller!.positionChanges]));
RationalTime get _frameDuration =>
source?.frameDuration ??
controller?.frameDuration ??
TimelineFormat.fps30.frameDuration;
Widget _build(BuildContext context) {
final preview = controller;
final playing = source?.playing ?? preview?.playing ?? false;
@@ -569,8 +651,10 @@ class _PreviewToolbar extends StatelessWidget {
}
} catch (error) {
if (context.mounted) {
ScaffoldMessenger.maybeOf(context)?.showSnackBar(
SnackBar(content: Text(previewErrorMessage(error, context.l10n))),
ErrorNotificationHost.maybeOf(context)?.show(
ErrorNotification(
content: Text(previewErrorMessage(error, context.l10n)),
),
);
}
}
@@ -618,96 +702,128 @@ class _PreviewToolbar extends StatelessWidget {
child: Row(
children: [
Expanded(
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: _time(
source?.positionTick ?? preview?.positionTick ?? 0,
frameDuration,
),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
),
),
TextSpan(
text:
' / ${_time(source?.durationTick ?? preview?.durationTick ?? 0, frameDuration)}',
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
child: ListenableSelector(
key: const Key('preview-time'),
listenable: _clock,
select: () => (
source?.positionTick ?? preview?.positionTick ?? 0,
source?.durationTick ?? preview?.durationTick ?? 0,
_frameDuration,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontFeatures: [const FontFeature.tabularFigures()],
builder: (context, _) => Text.rich(
TextSpan(
children: [
TextSpan(
text: _time(
source?.positionTick ?? preview?.positionTick ?? 0,
_frameDuration,
),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
),
),
TextSpan(
text:
' / ${_time(source?.durationTick ?? preview?.durationTick ?? 0, _frameDuration)}',
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontFeatures: [const FontFeature.tabularFigures()],
),
),
),
),
IconButton(
tooltip: playing ? context.l10n.pause : context.l10n.play,
onPressed: source != null
? (source!.canPlay ? source!.togglePlayback : null)
: preview != null && preview.canPlay
? preview.togglePlayback
: null,
icon: Icon(playing ? Icons.pause : Icons.play_arrow),
ListenableSelector(
listenable: source ?? preview,
select: () => (
source?.playing ?? preview?.playing ?? false,
source?.canPlay ?? preview?.canPlay ?? false,
),
builder: (context, value) {
final playing = value.$1;
return IconButton(
tooltip: playing ? context.l10n.pause : context.l10n.play,
onPressed: source != null
? (source!.canPlay ? source!.togglePlayback : null)
: preview != null && preview.canPlay
? preview.togglePlayback
: null,
icon: Icon(playing ? Icons.pause : Icons.play_arrow),
);
},
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (preview != null &&
(preview.error != null ||
preview.hasUnavailableMedia)) ...[
IconButton(
tooltip: context.l10n.retryPreview,
onPressed: preview.busy ? null : preview.retry,
icon: const Icon(Icons.refresh),
),
const SizedBox(width: AppSpacing.gap),
child: ListenableSelector(
listenable: source ?? preview,
select: () => (
preview?.canvas,
preview?.error,
preview?.hasUnavailableMedia,
preview?.busy,
preview?.session,
source?.session,
source?.image,
),
builder: (context, _) => Align(
alignment: Alignment.centerRight,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (preview != null &&
(preview.error != null ||
preview.hasUnavailableMedia)) ...[
IconButton(
tooltip: context.l10n.retryPreview,
onPressed: preview.busy ? null : preview.retry,
icon: const Icon(Icons.refresh),
),
const SizedBox(width: AppSpacing.gap),
],
if (source == null &&
PreviewFullscreenScope.of(context)?.fullscreen !=
true)
Flexible(
child: AppSelect<ProjectCanvas>(
emptyLabel: context.l10n.noMatchingOptions,
label: context.l10n.canvasRatio,
outlined: false,
value: preview?.canvas ?? ProjectCanvas.widescreen,
onChanged: preview?.setCanvas,
options: [
for (final entry
in ProjectCanvasPresets.values.entries)
AppSelectOption(entry.value, entry.key),
],
),
),
if (PreviewFullscreenScope.of(context)
case final fullscreen?)
IconButton(
key: const Key('preview-fullscreen'),
tooltip: fullscreen.fullscreen
? context.l10n.exitPreviewFullscreen
: context.l10n.previewFullscreen,
onPressed:
fullscreen.fullscreen ||
source?.session != null ||
source?.image != null ||
preview?.session != null
? fullscreen.toggle
: null,
icon: Icon(
fullscreen.fullscreen
? Icons.fullscreen_exit
: Icons.fullscreen,
),
),
],
if (source == null &&
PreviewFullscreenScope.of(context)?.fullscreen != true)
Flexible(
child: AppSelect<ProjectCanvas>(
emptyLabel: context.l10n.noMatchingOptions,
label: context.l10n.canvasRatio,
outlined: false,
value: preview?.canvas ?? ProjectCanvas.widescreen,
onChanged: preview?.setCanvas,
options: [
for (final entry
in ProjectCanvasPresets.values.entries)
AppSelectOption(entry.value, entry.key),
],
),
),
if (PreviewFullscreenScope.of(context)
case final fullscreen?)
IconButton(
key: const Key('preview-fullscreen'),
tooltip: fullscreen.fullscreen
? context.l10n.exitPreviewFullscreen
: context.l10n.previewFullscreen,
onPressed:
fullscreen.fullscreen ||
source?.session != null ||
source?.image != null ||
preview?.session != null
? fullscreen.toggle
: null,
icon: Icon(
fullscreen.fullscreen
? Icons.fullscreen_exit
: Icons.fullscreen,
),
),
],
),
),
),
),