Files
cutdex/lib/features/properties/properties_inspector_controller.dart
T
lingjhf 06f1c26681
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

143 lines
4.6 KiB
Dart

import 'package:cutdex_core/timeline/engine.dart';
import 'package:cutdex_core/timeline/layout.dart';
import 'package:cutdex_core/timeline/model.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../workspace/timeline_provider.dart';
import '../../workspace/timeline_session.dart';
import 'properties_presentation_state.dart';
final propertiesInspectorProvider = Provider.autoDispose
.family<PropertiesInspectorController?, (String, String)>((ref, identity) {
final session = ref
.watch(editorTimelineProvider(identity.$1, identity.$2))
.value;
if (session == null) return null;
final controller = PropertiesInspectorController(session);
ref.onDispose(controller.dispose);
return controller;
});
/// Resolves the shared editing selection without prescribing a device layout.
class PropertiesInspectorController extends ChangeNotifier {
PropertiesInspectorController(this.session) {
session.addListener(_sessionChanged);
_bindView();
_captureSelection();
}
final EditorTimelineSession session;
Listenable? _editingChanges;
SequenceId? _lastSequence;
Object? _lastVersion;
Set<Object> _lastSelection = {};
List<Object> _lastShell = const [];
SequenceId? get sequence => session.activeSequenceId;
void _bindView() {
final id = sequence;
final next = id == null ? null : session.view(id).editingChanges;
if (identical(next, _editingChanges)) return;
_editingChanges?.removeListener(_viewChanged);
_editingChanges = next;
_editingChanges?.addListener(_viewChanged);
}
bool _captureSelection({bool force = false}) {
final id = sequence;
final view = id == null ? null : session.view(id);
final version = view?.version.kernelVersion;
final selected = view?.selectedIdentities ?? const <Object>{};
if (!force &&
id == _lastSequence &&
identical(version, _lastVersion) &&
setEquals(selected, _lastSelection)) {
return false;
}
final shell = <Object>[
for (final clip in selectedClips)
(
clip.id,
clip.structure,
clip.enabled,
clip.payloadRef == null
? null
: session.payloadFor(clip.payloadRef!)?.type,
clip.payloadRef == null
? null
: session.mediaBinding(clip.payloadRef!)?.audioSelection,
clip.payloadRef == null
? null
: session.mediaBinding(clip.payloadRef!)?.videoTrackIndex,
),
];
final changed = id != _lastSequence || !listEquals(shell, _lastShell);
_lastSequence = id;
_lastVersion = version;
_lastSelection = selected.toSet();
_lastShell = shell;
return changed;
}
void _viewChanged() {
// The inspector's selection shell does not depend on the playhead. Its
// property editors subscribe separately to position and live edit changes.
if (_captureSelection()) notifyListeners();
}
void _sessionChanged() {
_bindView();
if (_captureSelection(force: true)) notifyListeners();
}
List<ElementRecord> get selectedClips {
final id = sequence;
if (id == null) return const [];
final view = session.view(id);
final query = view.version.kernelVersion.query();
final handles = <ElementHandle>{};
for (final identity in view.selectedIdentities) {
final handle = switch (identity) {
ElementHandle handle => handle,
LayoutBodyId body => view.elementForIdentity(body),
_ => null,
};
if (handle != null && query.ownerOf(handle) != null) handles.add(handle);
}
final clips = [for (final handle in handles) query.element(handle)];
return clips.any((clip) => clip.structure != ElementStructure.gap)
? clips
: const [];
}
@override
void dispose() {
session.removeListener(_sessionChanged);
_editingChanges?.removeListener(_viewChanged);
super.dispose();
}
}
List<PropertyCategory> categoriesForClip(ElementRecord clip, String? type) {
if (clip.structure != ElementStructure.content) {
return [PropertyCategory.basic];
}
return switch (type) {
'video' => [
PropertyCategory.picture,
PropertyCategory.color,
PropertyCategory.mask,
PropertyCategory.audio,
PropertyCategory.speed,
PropertyCategory.animation,
],
'audio' => [PropertyCategory.audio, PropertyCategory.speed],
'image' => [
PropertyCategory.picture,
PropertyCategory.mask,
PropertyCategory.animation,
],
_ => [PropertyCategory.basic],
};
}