Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
488 lines
19 KiB
Dart
488 lines
19 KiB
Dart
import '../../shared/widgets/listenable_selector.dart';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:cutdex/l10n/l10n.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/device_experience.dart';
|
|
|
|
import 'package:cutdex_native/cutdex_native.dart';
|
|
|
|
import '../../persistence/app_settings_repositories.dart';
|
|
import '../../shared/layout/workspace_layout_metrics.dart';
|
|
|
|
import 'package:cutdex_ui/icons.dart';
|
|
import 'package:cutdex_ui/theme.dart';
|
|
|
|
import '../../workspace/timeline_provider.dart';
|
|
import '../../workspace/preview_target.dart';
|
|
import '../../workspace/projects.dart';
|
|
import '../../workspace/view_settings.dart';
|
|
import '../media/media_browser_page.dart';
|
|
import '../media/media_panel.dart';
|
|
import '../preview/preview_panel.dart';
|
|
import '../properties/properties_editor_page.dart';
|
|
import '../properties/properties_panel.dart';
|
|
import '../timeline/timeline_panel.dart';
|
|
import 'editor_presentation_controller.dart';
|
|
import 'editor_panel_defaults.dart';
|
|
import 'timeline_operation_region.dart';
|
|
import 'layouts/bounded_editor_layout.dart';
|
|
import 'layouts/expanded_editor_layout.dart';
|
|
|
|
/// The single editing surface shown beside the project/timeline navigation.
|
|
class EditorWorkspace extends ConsumerStatefulWidget {
|
|
const EditorWorkspace({
|
|
super.key,
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
required this.projectName,
|
|
required this.integratedTitlebar,
|
|
required this.headerLeading,
|
|
this.projectLoading = false,
|
|
this.timelineLoading = false,
|
|
this.showProjectName = true,
|
|
this.experience = DeviceExperience.desktop,
|
|
});
|
|
|
|
final bool projectLoading;
|
|
|
|
/// Navigation is preparing another timeline; the current content stays visible.
|
|
final bool timelineLoading;
|
|
final String projectId;
|
|
final String timelineId;
|
|
final String projectName;
|
|
final bool integratedTitlebar;
|
|
final Widget headerLeading;
|
|
final bool showProjectName;
|
|
final DeviceExperience experience;
|
|
|
|
@override
|
|
ConsumerState<EditorWorkspace> createState() => _EditorWorkspaceState();
|
|
}
|
|
|
|
class _EditorWorkspaceState extends ConsumerState<EditorWorkspace> {
|
|
final _previewKey = GlobalKey();
|
|
bool get _timelinePending => widget.projectLoading;
|
|
|
|
Widget _timelineInteraction(Widget child) => TimelineOperationRegion(
|
|
projectId: widget.projectId,
|
|
loading: widget.timelineLoading,
|
|
child: child,
|
|
);
|
|
EditorPresentationController get _presentation =>
|
|
ref.read(editorPresentationProvider(widget.projectId));
|
|
ProjectViewSettingsData get _viewSettings =>
|
|
ref.read(projectViewSettingsProvider(widget.projectId)).value ??
|
|
const ProjectViewSettingsData();
|
|
ProjectViewSettings get _viewController =>
|
|
ref.read(projectViewSettingsProvider(widget.projectId).notifier);
|
|
bool get _propertiesOpen => _viewSettings.propertiesOpen;
|
|
double? get _timelineHeight => _viewSettings.timelineHeight;
|
|
|
|
void _saveViewSettings() {
|
|
if (widget.projectId.isEmpty ||
|
|
!ref.read(projectViewSettingsProvider(widget.projectId)).hasValue) {
|
|
return;
|
|
}
|
|
unawaited(_viewController.save());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final viewSettings = ref.watch(
|
|
projectViewSettingsProvider(widget.projectId),
|
|
);
|
|
final preview = KeyedSubtree(
|
|
key: _previewKey,
|
|
child: _timelineInteraction(
|
|
EditorPreviewPanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
pending: _timelinePending,
|
|
),
|
|
),
|
|
);
|
|
final timeline = EditorTimelinePanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
pending: widget.projectLoading,
|
|
timelineLoading: widget.timelineLoading,
|
|
);
|
|
final properties = _timelineInteraction(
|
|
_timelinePending
|
|
? const EditorEmptyPanel()
|
|
: EditorPropertiesPanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
);
|
|
final media = widget.projectLoading
|
|
? const EditorEmptyPanel()
|
|
: MediaPanel(projectId: widget.projectId, projectScoped: true);
|
|
return ListenableBuilder(
|
|
listenable: ref.watch(editorPresentationProvider(widget.projectId)),
|
|
builder: (context, _) => LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final desktop = widget.experience == DeviceExperience.desktop;
|
|
final mediaOpen = desktop
|
|
? _presentation.mediaOpen
|
|
: _presentation.activeTool == EditorTool.media;
|
|
final mediaWidth = mediaOpen
|
|
? WorkspaceLayoutMetrics.mediaPanelWidth +
|
|
WorkspaceLayoutMetrics.desktopSpacing
|
|
: 0.0;
|
|
final sideWidth = (_propertiesOpen
|
|
? WorkspaceLayoutMetrics.propertiesPanelWidth +
|
|
WorkspaceLayoutMetrics.desktopSpacing
|
|
: 0);
|
|
final dockMedia =
|
|
desktop &&
|
|
mediaOpen &&
|
|
constraints.maxWidth >=
|
|
WorkspaceLayoutMetrics.previewMinimumWidth + mediaWidth;
|
|
final dockProperties =
|
|
desktop &&
|
|
_propertiesOpen &&
|
|
constraints.maxWidth >=
|
|
WorkspaceLayoutMetrics.previewMinimumWidth +
|
|
sideWidth +
|
|
(dockMedia ? mediaWidth : 0);
|
|
final desktopTool =
|
|
mediaOpen && !dockMedia && _presentation.desktopToolRequested
|
|
? _presentation.desktopTool(propertiesOpen: _propertiesOpen)
|
|
: _propertiesOpen && !dockProperties
|
|
? EditorTool.properties
|
|
: null;
|
|
final headerHeight = desktop ? AppDesktopMetrics.panelHeader : 48.0;
|
|
final propertiesOpen = desktop
|
|
? dockProperties
|
|
? _propertiesOpen
|
|
: desktopTool == EditorTool.properties
|
|
: _presentation.activeTool == EditorTool.properties;
|
|
final mediaButton = HeaderControlRegion(
|
|
child: SizedBox.square(
|
|
dimension: desktop ? AppControlSize.headerButton : 48,
|
|
child: IconButton(
|
|
key: const Key('editor-media-button'),
|
|
tooltip: context.l10n.materials,
|
|
isSelected: mediaOpen,
|
|
onPressed: () {
|
|
if (desktop) {
|
|
if (!dockMedia &&
|
|
desktopTool != EditorTool.media &&
|
|
_presentation.mediaOpen) {
|
|
_presentation.preferDesktopTool(EditorTool.media);
|
|
} else {
|
|
_presentation.toggleMedia();
|
|
}
|
|
} else {
|
|
_presentation.toggleTool(EditorTool.media);
|
|
}
|
|
},
|
|
icon: const Icon(AppIcons.mediaLibrary),
|
|
),
|
|
),
|
|
);
|
|
final header = Material(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
child: SizedBox(
|
|
key: const Key('editor-content-header'),
|
|
height: headerHeight,
|
|
child: Padding(
|
|
padding: desktop
|
|
? const EdgeInsets.symmetric(
|
|
horizontal: AppSidebarMetrics.outerPadding,
|
|
vertical: AppSpacing.tiny,
|
|
)
|
|
: EdgeInsets.zero,
|
|
child: WindowHeaderPadding(
|
|
child: Row(
|
|
children: [
|
|
widget.headerLeading,
|
|
if (desktop) mediaButton,
|
|
Expanded(
|
|
child: desktop
|
|
? _PreviewHeaderTitle(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
pending: _timelinePending,
|
|
)
|
|
: widget.showProjectName
|
|
? Row(
|
|
children: [
|
|
Flexible(
|
|
fit: FlexFit.loose,
|
|
child: Text(
|
|
widget.projectName,
|
|
key: const Key('workspace-project-title'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.titleSmall,
|
|
),
|
|
),
|
|
Flexible(
|
|
fit: FlexFit.loose,
|
|
child: _timelinePending
|
|
? const SizedBox.shrink()
|
|
: _TimelineSaveStatus(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: const SizedBox.shrink(),
|
|
),
|
|
if (!desktop) mediaButton,
|
|
if (!desktop) const SizedBox(width: AppSpacing.tiny),
|
|
HeaderControlRegion(
|
|
child: SizedBox.square(
|
|
dimension: desktop ? AppControlSize.headerButton : 48,
|
|
child: IconButton(
|
|
key: const Key('editor-properties-button'),
|
|
tooltip: propertiesOpen
|
|
? context.l10n.collapseProperties
|
|
: context.l10n.expandProperties,
|
|
isSelected: propertiesOpen,
|
|
onPressed: !viewSettings.hasValue
|
|
? null
|
|
: () {
|
|
if (desktop) {
|
|
if (dockProperties ||
|
|
desktopTool ==
|
|
EditorTool.properties ||
|
|
!_propertiesOpen) {
|
|
_viewController.setPropertiesOpen(
|
|
!_propertiesOpen,
|
|
);
|
|
_saveViewSettings();
|
|
}
|
|
_presentation.preferDesktopTool(
|
|
EditorTool.properties,
|
|
);
|
|
} else {
|
|
_presentation.toggleTool(
|
|
EditorTool.properties,
|
|
);
|
|
}
|
|
},
|
|
icon: const Icon(
|
|
AppIcons.tune,
|
|
size: AppIconSize.header,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (!desktop) const SizedBox(width: AppSpacing.compact),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
Widget dockedEditing({required bool showTools}) =>
|
|
ExpandedEditorLayout(
|
|
preview: preview,
|
|
header: header,
|
|
properties: properties,
|
|
media: media,
|
|
showMedia: dockMedia,
|
|
showProperties: showTools && dockProperties,
|
|
timelineHeight: _timelineHeight,
|
|
onTimelineHeightChanged: (height) {
|
|
if (viewSettings.hasValue) {
|
|
_viewController.setTimelineHeight(height);
|
|
}
|
|
},
|
|
onTimelineHeightChangeEnd: _saveViewSettings,
|
|
timeline: timeline,
|
|
);
|
|
return Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Column(
|
|
children: [
|
|
if (!desktop) header,
|
|
Expanded(
|
|
child: desktop && desktopTool == null
|
|
? dockedEditing(showTools: true)
|
|
: BoundedEditorLayout(
|
|
experience: widget.experience,
|
|
editing: desktop
|
|
? dockedEditing(showTools: false)
|
|
: TouchEditingLayout(
|
|
preview: preview,
|
|
timeline: timeline,
|
|
),
|
|
tool: desktop
|
|
? desktopTool
|
|
: _presentation.activeTool,
|
|
media: widget.projectLoading
|
|
? media
|
|
: switch (widget.experience) {
|
|
DeviceExperience.desktop => media,
|
|
DeviceExperience.tablet =>
|
|
MediaBrowserDrawer(
|
|
projectId: widget.projectId,
|
|
),
|
|
DeviceExperience.phone => MediaBrowserPage(
|
|
projectId: widget.projectId,
|
|
),
|
|
},
|
|
properties: _timelinePending
|
|
? properties
|
|
: switch (widget.experience) {
|
|
DeviceExperience.desktop => properties,
|
|
DeviceExperience.tablet =>
|
|
_timelineInteraction(
|
|
PropertiesToolPanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
),
|
|
DeviceExperience.phone =>
|
|
_timelineInteraction(
|
|
PropertiesEditorPage(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
),
|
|
},
|
|
onCloseTool: () {
|
|
if (!desktop) {
|
|
_presentation.closeTool();
|
|
} else if (desktopTool == EditorTool.media) {
|
|
_presentation.toggleMedia();
|
|
} else {
|
|
_viewController.setPropertiesOpen(false);
|
|
_saveViewSettings();
|
|
}
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (!desktop)
|
|
Positioned(
|
|
key: const Key('editing-top-divider'),
|
|
top: headerHeight,
|
|
left: 0,
|
|
right: 0,
|
|
height: 1,
|
|
child: const Divider(height: 1),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PreviewHeaderTitle extends ConsumerWidget {
|
|
const _PreviewHeaderTitle({
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
required this.pending,
|
|
});
|
|
|
|
final String projectId;
|
|
final String timelineId;
|
|
final bool pending;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final navigation = pending
|
|
? const PreviewTargetState.timeline()
|
|
: ref.watch(previewNavigationProvider(projectId, timelineId));
|
|
final name = pending
|
|
? context.l10n.preview
|
|
: ref.watch(
|
|
projectsProvider.select((value) {
|
|
final workspace = value.value;
|
|
return switch (navigation) {
|
|
SourcePreviewTarget(:final asset) =>
|
|
workspace?.assets
|
|
.where((item) => item.id == asset.id)
|
|
.firstOrNull
|
|
?.name ??
|
|
asset.name,
|
|
_ =>
|
|
workspace?.timeline?.id == timelineId
|
|
? workspace!.timeline!.name
|
|
: context.l10n.preview,
|
|
};
|
|
}),
|
|
);
|
|
final session = pending
|
|
? null
|
|
: ref.watch(editorTimelineProvider(projectId, timelineId)).value;
|
|
Widget title(String? saveStatus) => Tooltip(
|
|
message: saveStatus == null ? name : '$name\n$saveStatus',
|
|
child: Text(
|
|
name,
|
|
key: const Key('editor-preview-title'),
|
|
textAlign: TextAlign.center,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.titleSmall,
|
|
),
|
|
);
|
|
if (session == null) return title(null);
|
|
return ListenableSelector<(bool, bool, bool)>(
|
|
listenable: session,
|
|
select: () => (session.error != null, session.saving, session.dirty),
|
|
builder: (context, value) => title(_timelineSaveLabel(context, value)),
|
|
);
|
|
}
|
|
}
|
|
|
|
String _timelineSaveLabel(BuildContext context, (bool, bool, bool) value) =>
|
|
value.$1
|
|
? context.l10n.unsaved
|
|
: value.$2
|
|
? context.l10n.saving
|
|
: value.$3
|
|
? context.l10n.pendingSave
|
|
: context.l10n.saved;
|
|
|
|
class _TimelineSaveStatus extends ConsumerWidget {
|
|
const _TimelineSaveStatus({
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
});
|
|
|
|
final String projectId;
|
|
final String timelineId;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final session = ref
|
|
.watch(editorTimelineProvider(projectId, timelineId))
|
|
.asData
|
|
?.value;
|
|
if (session == null) return const SizedBox.shrink();
|
|
return ListenableSelector<(bool, bool, bool)>(
|
|
listenable: session,
|
|
select: () => (session.error != null, session.saving, session.dirty),
|
|
builder: (context, value) => Padding(
|
|
padding: const EdgeInsets.only(left: AppSpacing.small),
|
|
child: Text(
|
|
_timelineSaveLabel(context, value),
|
|
key: const Key('timeline-save-status'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: AppTheme.isDesktop(context)
|
|
? Theme.of(context).textTheme.bodySmall
|
|
: Theme.of(context).textTheme.bodySmall?.copyWith(fontSize: 10),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|