refactor(desktop): reorganize workspace panels and navigation
This commit is contained in:
1 parent
826745b407
commit
1f73765745
92 files changed
+5811
-2650
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
import 'dart:async';
|
||||
@@ -352,9 +353,12 @@ class TimelineExternalDropTargetState
|
||||
);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(context.l10n.errorMessage(e))));
|
||||
ErrorNotificationHost.of(context).show(
|
||||
ErrorNotification(
|
||||
content: Text(context.l10n.errorMessage(e)),
|
||||
details: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted && g == generation) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_sdk/timeline/layout.dart';
|
||||
@@ -7,6 +8,7 @@ import 'package:cutdex_sdk/project.dart';
|
||||
|
||||
import 'package:cutdex_sdk/timeline_ui.dart';
|
||||
|
||||
import '../../shared/widgets/listenable_selector.dart';
|
||||
import '../../workspace/timeline_provider.dart';
|
||||
import '../../workspace/projects.dart';
|
||||
|
||||
@@ -20,6 +22,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import '../editor/editor_panel_defaults.dart';
|
||||
import '../media/transcription_dialog.dart';
|
||||
import '../media/background_removal_dialog.dart';
|
||||
import '../projects/widgets/name_dialog.dart';
|
||||
@@ -28,86 +31,121 @@ import '../../workspace/preview_target.dart';
|
||||
import 'timeline_asset_drop_target.dart';
|
||||
import 'timeline_speed_editor.dart';
|
||||
|
||||
class EditorTimelinePanel extends ConsumerWidget {
|
||||
class EditorTimelinePanel extends StatelessWidget {
|
||||
const EditorTimelinePanel({
|
||||
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) => Theme(
|
||||
data: AppTheme.timelinePanelTheme(Theme.of(context)),
|
||||
child: pending
|
||||
? const EditorTimelineDefaults()
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_TimelineTabsContent(
|
||||
projectId: projectId,
|
||||
timelineId: timelineId,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: _TimelineSessionContent(
|
||||
projectId: projectId,
|
||||
timelineId: timelineId,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _TimelineTabsContent extends ConsumerWidget {
|
||||
const _TimelineTabsContent({
|
||||
required this.projectId,
|
||||
required this.timelineId,
|
||||
});
|
||||
final String projectId;
|
||||
final String timelineId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final provider = editorTimelineProvider(projectId, timelineId);
|
||||
final timeline = ref.watch(provider);
|
||||
final projectState = ref.watch(projectsProvider).asData?.value;
|
||||
final timelines = projectState?.activeProject?.id == projectId
|
||||
? projectState!.timelines
|
||||
: const <TimelineSummary>[];
|
||||
return Theme(
|
||||
data: AppTheme.timelinePanelTheme(Theme.of(context)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_TimelineTabsBar(
|
||||
projectId: projectId,
|
||||
timelineId: timelineId,
|
||||
timelines: timelines,
|
||||
creating: projectState?.creatingTimeline ?? false,
|
||||
openingTimelineId: projectState?.openingTimelineId,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: timeline.when(
|
||||
loading: () => const WorkspacePanel(
|
||||
key: Key('timeline-pending'),
|
||||
child: SizedBox.expand(),
|
||||
),
|
||||
error: (_, _) => WorkspacePanel(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
primary: false,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.openTimelineFailed,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => ref.invalidate(provider),
|
||||
child: Text(context.l10n.retry),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
return _TimelineTabsBar(
|
||||
projectId: projectId,
|
||||
timelineId: timelineId,
|
||||
timelines: timelines,
|
||||
creating: projectState?.creatingTimeline ?? false,
|
||||
openingTimelineId: projectState?.openingTimelineId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TimelineSessionContent extends ConsumerWidget {
|
||||
const _TimelineSessionContent({
|
||||
required this.projectId,
|
||||
required this.timelineId,
|
||||
});
|
||||
final String projectId;
|
||||
final String timelineId;
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final provider = editorTimelineProvider(projectId, timelineId);
|
||||
final watched = ref.watch(provider);
|
||||
final cached = watched.isLoading && !watched.hasError
|
||||
? ref
|
||||
.read(projectsProvider.notifier)
|
||||
.cachedTimelineSession(projectId, timelineId)
|
||||
: null;
|
||||
final timeline = cached == null ? watched : AsyncData(cached);
|
||||
return timeline.when(
|
||||
loading: () => const EditorTimelineDefaults(
|
||||
key: Key('timeline-pending'),
|
||||
showTabs: false,
|
||||
),
|
||||
error: (_, _) => WorkspacePanel(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
primary: false,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.openTimelineFailed,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
data: (session) => Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (_) {
|
||||
if (const bool.fromEnvironment('CUTDEX_PREVIEW_TRACE')) {
|
||||
debugPrint(
|
||||
'CUTDEX_PREVIEW '
|
||||
'${DateTime.now().millisecondsSinceEpoch} '
|
||||
'dart pointer-down',
|
||||
);
|
||||
}
|
||||
ref
|
||||
.read(
|
||||
previewNavigationProvider(
|
||||
projectId,
|
||||
timelineId,
|
||||
).notifier,
|
||||
)
|
||||
.showTimeline();
|
||||
},
|
||||
child: _TimelineEditor(session: session, projectId: projectId),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => ref.invalidate(provider),
|
||||
child: Text(context.l10n.retry),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
data: (session) => Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (_) {
|
||||
if (const bool.fromEnvironment('CUTDEX_PREVIEW_TRACE')) {
|
||||
debugPrint(
|
||||
'CUTDEX_PREVIEW '
|
||||
'${DateTime.now().millisecondsSinceEpoch} '
|
||||
'dart pointer-down',
|
||||
);
|
||||
}
|
||||
ref
|
||||
.read(previewNavigationProvider(projectId, timelineId).notifier)
|
||||
.showTimeline();
|
||||
},
|
||||
child: _TimelineEditor(session: session, projectId: projectId),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -241,8 +279,8 @@ class _TimelineTabsBarState extends ConsumerState<_TimelineTabsBar> {
|
||||
Future<void> _createTimeline() async {
|
||||
if (_operationsBusy) return;
|
||||
if (widget.timelines.length >= Projects.maxTimelineCount) {
|
||||
ScaffoldMessenger.maybeOf(context)?.showSnackBar(
|
||||
SnackBar(
|
||||
ErrorNotificationHost.maybeOf(context)?.show(
|
||||
ErrorNotification(
|
||||
content: Text(
|
||||
context.l10n.timelineLimitReached(Projects.maxTimelineCount),
|
||||
),
|
||||
@@ -494,60 +532,13 @@ class _TimelineEditor extends StatefulWidget {
|
||||
class _TimelineEditorState extends State<_TimelineEditor> {
|
||||
EditorTimelineSession get session => widget.session;
|
||||
String get projectId => widget.projectId;
|
||||
late RuntimeTimelineThumbnails _thumbnails;
|
||||
late RuntimeTimelineWaveforms _waveforms;
|
||||
RuntimeTimelineThumbnails get _thumbnails => session.thumbnails;
|
||||
RuntimeTimelineWaveforms get _waveforms => session.waveforms;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_createMediaCaches();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _TimelineEditor oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!identical(oldWidget.session, widget.session)) {
|
||||
_thumbnails.dispose();
|
||||
_waveforms.dispose();
|
||||
_createMediaCaches();
|
||||
}
|
||||
}
|
||||
|
||||
void _createMediaCaches() {
|
||||
_thumbnails = RuntimeTimelineThumbnails(
|
||||
resolveTrackSelection: (ref) => session.mediaBinding(ref)?.videoSelection,
|
||||
resolveMedia: (ref) {
|
||||
final binding = session.mediaBinding(ref);
|
||||
if (session.unavailableAssets.containsKey(binding?.media.id)) {
|
||||
return null;
|
||||
}
|
||||
return binding?.videoTrackIndex == null ? null : binding!.media;
|
||||
},
|
||||
);
|
||||
_waveforms = RuntimeTimelineWaveforms(
|
||||
resolveTrackSelection: (ref) => session.mediaBinding(ref)?.audioSelection,
|
||||
resolveGain: session.waveformGain,
|
||||
gainChanges: session.audioGainPreview,
|
||||
resolveMedia: (ref) {
|
||||
final binding = session.mediaBinding(ref);
|
||||
if (session.unavailableAssets.containsKey(binding?.media.id)) {
|
||||
return null;
|
||||
}
|
||||
return binding?.audioTrackIndex == null ? null : binding!.media;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_thumbnails.dispose();
|
||||
_waveforms.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListenableBuilder(
|
||||
Widget build(BuildContext context) => ListenableSelector(
|
||||
listenable: session,
|
||||
select: () => session.activeSequenceId,
|
||||
builder: (context, _) => _build(context),
|
||||
);
|
||||
|
||||
@@ -662,8 +653,8 @@ class _TimelineEditorState extends State<_TimelineEditor> {
|
||||
try {
|
||||
edit();
|
||||
} on CommandRejected catch (error) {
|
||||
ScaffoldMessenger.maybeOf(context)?.showSnackBar(
|
||||
SnackBar(
|
||||
ErrorNotificationHost.maybeOf(context)?.show(
|
||||
ErrorNotification(
|
||||
content: Text(
|
||||
error.code == 'staleVersion'
|
||||
? context.l10n.captionChanged
|
||||
@@ -706,107 +697,121 @@ class _TimelineEditorState extends State<_TimelineEditor> {
|
||||
);
|
||||
}
|
||||
final controller = session.view(sequenceId);
|
||||
final captionCues = _selectedCaptionCues(controller);
|
||||
final canSplitCaption = _canSplitCaption(controller, captionCues);
|
||||
return WorkspacePanel(
|
||||
headerHeight: 32,
|
||||
headerPadding: EdgeInsets.zero,
|
||||
controls: ListenableBuilder(
|
||||
controls: ListenableSelector(
|
||||
listenable: Listenable.merge([
|
||||
controller.contentChanges,
|
||||
controller.playheadChanges,
|
||||
session,
|
||||
]),
|
||||
builder: (context, _) => SizedBox(
|
||||
key: const Key('timeline-toolbar'),
|
||||
height: 32,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.gap),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||
child: IntrinsicWidth(
|
||||
child: Row(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: AppSpacing.tiny,
|
||||
children: [
|
||||
_toolbarButton(
|
||||
tooltip: context.l10n.undo,
|
||||
onPressed: controller.canUndo
|
||||
? controller.undo
|
||||
: null,
|
||||
icon: Icons.undo,
|
||||
),
|
||||
_toolbarButton(
|
||||
tooltip: context.l10n.redo,
|
||||
onPressed: controller.canRedo
|
||||
? controller.redo
|
||||
: null,
|
||||
icon: Icons.redo,
|
||||
),
|
||||
_toolbarButton(
|
||||
tooltip: context.l10n.splitAtPlayhead,
|
||||
onPressed: canSplitCaption
|
||||
? () => _runCaptionEdit(
|
||||
context,
|
||||
() => _splitCaption(
|
||||
sequenceId,
|
||||
controller,
|
||||
captionCues.single,
|
||||
),
|
||||
)
|
||||
: controller.canCutSelection
|
||||
? controller.cutSelectionAtPlayhead
|
||||
: null,
|
||||
icon: Icons.content_cut,
|
||||
),
|
||||
_toolbarButton(
|
||||
key: const ValueKey('timeline-trim-left'),
|
||||
tooltip: context.l10n.trimLeftTooltip,
|
||||
onPressed: controller.canCutSelection
|
||||
? controller.trimLeftAtPlayhead
|
||||
: null,
|
||||
icon: Icons.align_horizontal_left,
|
||||
semanticLabel: context.l10n.trimLeft,
|
||||
),
|
||||
_toolbarButton(
|
||||
key: const ValueKey('timeline-trim-right'),
|
||||
tooltip: context.l10n.trimRightTooltip,
|
||||
onPressed: controller.canCutSelection
|
||||
? controller.trimRightAtPlayhead
|
||||
: null,
|
||||
icon: Icons.align_horizontal_right,
|
||||
semanticLabel: context.l10n.trimRight,
|
||||
),
|
||||
_toolbarButton(
|
||||
key: const ValueKey('timeline-delete-selection'),
|
||||
tooltip: context.l10n.deleteSelectedClips,
|
||||
onPressed: () {
|
||||
if (!controller.canDeleteSelection) return;
|
||||
controller.deleteSelection();
|
||||
},
|
||||
icon: Icons.delete_outline,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
if (controller.commandRejection != null)
|
||||
Tooltip(
|
||||
message: controller.commandRejection!,
|
||||
child: const Icon(Icons.info_outline),
|
||||
select: () => (
|
||||
controller.canUndo,
|
||||
controller.canRedo,
|
||||
controller.canCutSelection,
|
||||
controller.canDeleteSelection,
|
||||
controller.commandRejection,
|
||||
_canSplitCaption(controller, _selectedCaptionCues(controller)),
|
||||
_selectedCaptionCues(controller).singleOrNull,
|
||||
controller.version.kernelVersion,
|
||||
),
|
||||
builder: (context, _) {
|
||||
final captionCues = _selectedCaptionCues(controller);
|
||||
final canSplitCaption = _canSplitCaption(controller, captionCues);
|
||||
return SizedBox(
|
||||
key: const Key('timeline-toolbar'),
|
||||
height: 32,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.gap),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||
child: IntrinsicWidth(
|
||||
child: Row(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: AppSpacing.tiny,
|
||||
children: [
|
||||
_toolbarButton(
|
||||
tooltip: context.l10n.undo,
|
||||
onPressed: controller.canUndo
|
||||
? controller.undo
|
||||
: null,
|
||||
icon: Icons.undo,
|
||||
),
|
||||
_toolbarButton(
|
||||
tooltip: context.l10n.redo,
|
||||
onPressed: controller.canRedo
|
||||
? controller.redo
|
||||
: null,
|
||||
icon: Icons.redo,
|
||||
),
|
||||
_toolbarButton(
|
||||
tooltip: context.l10n.splitAtPlayhead,
|
||||
onPressed: canSplitCaption
|
||||
? () => _runCaptionEdit(
|
||||
context,
|
||||
() => _splitCaption(
|
||||
sequenceId,
|
||||
controller,
|
||||
captionCues.single,
|
||||
),
|
||||
)
|
||||
: controller.canCutSelection
|
||||
? controller.cutSelectionAtPlayhead
|
||||
: null,
|
||||
icon: Icons.content_cut,
|
||||
),
|
||||
_toolbarButton(
|
||||
key: const ValueKey('timeline-trim-left'),
|
||||
tooltip: context.l10n.trimLeftTooltip,
|
||||
onPressed: controller.canCutSelection
|
||||
? controller.trimLeftAtPlayhead
|
||||
: null,
|
||||
icon: Icons.align_horizontal_left,
|
||||
semanticLabel: context.l10n.trimLeft,
|
||||
),
|
||||
_toolbarButton(
|
||||
key: const ValueKey('timeline-trim-right'),
|
||||
tooltip: context.l10n.trimRightTooltip,
|
||||
onPressed: controller.canCutSelection
|
||||
? controller.trimRightAtPlayhead
|
||||
: null,
|
||||
icon: Icons.align_horizontal_right,
|
||||
semanticLabel: context.l10n.trimRight,
|
||||
),
|
||||
_toolbarButton(
|
||||
key: const ValueKey(
|
||||
'timeline-delete-selection',
|
||||
),
|
||||
tooltip: context.l10n.deleteSelectedClips,
|
||||
onPressed: () {
|
||||
if (!controller.canDeleteSelection) return;
|
||||
controller.deleteSelection();
|
||||
},
|
||||
icon: Icons.delete_outline,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
if (controller.commandRejection != null)
|
||||
Tooltip(
|
||||
message: controller.commandRejection!,
|
||||
child: const Icon(Icons.info_outline),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: ListenableBuilder(
|
||||
listenable: controller.contentChanges,
|
||||
@@ -860,9 +865,10 @@ class _TimelineEditorState extends State<_TimelineEditor> {
|
||||
session.detachAudio(sequenceId, detachTarget);
|
||||
}
|
||||
} catch (error) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
ErrorNotificationHost.of(context).show(
|
||||
ErrorNotification(
|
||||
content: Text(context.l10n.errorMessage(error)),
|
||||
details: error.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
@@ -315,9 +317,12 @@ class _ClipSpeedEditorState extends State<_ClipSpeedEditor> {
|
||||
|
||||
void _showError(Object error) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(context.l10n.errorMessage(error))));
|
||||
ErrorNotificationHost.of(context).show(
|
||||
ErrorNotification(
|
||||
content: Text(context.l10n.errorMessage(error)),
|
||||
details: error.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _clearDrag() {
|
||||
|
||||
Reference in new issue
Block a user