feat: initial Cutdex application
Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,282 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../../integrations/agent/conversation_repository.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
import '../../workspace/projects.dart';
|
||||
import '../assistant/agent_conversation_service.dart';
|
||||
import '../assistant/agent_composer_store.dart';
|
||||
|
||||
part 'conversation_sidebar.g.dart';
|
||||
part 'conversation_sidebar.freezed.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ConversationSnapshot with _$ConversationSnapshot {
|
||||
const factory ConversationSnapshot({
|
||||
String? projectId,
|
||||
@Default({}) Map<String, List<ConversationMetadata>> groups,
|
||||
@Default([]) List<ConversationMetadata> trashed,
|
||||
String? selectedId,
|
||||
@Default(false) bool reloadFailed,
|
||||
}) = _ConversationSnapshot;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class ConversationWorkspaceKey with _$ConversationWorkspaceKey {
|
||||
const factory ConversationWorkspaceKey({
|
||||
String? projectId,
|
||||
required List<String> projectIds,
|
||||
}) = _ConversationWorkspaceKey;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class ConversationSelectionState with _$ConversationSelectionState {
|
||||
const factory ConversationSelectionState({
|
||||
String? selectedId,
|
||||
required String draftKey,
|
||||
@Default(false) bool initialized,
|
||||
}) = _ConversationSelectionState;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Future<String?> savedConversationSelection(Ref ref, String? projectId) async {
|
||||
if (projectId == null) return null;
|
||||
ref.watch(projectsProvider.select((value) => value.value?.activeProject?.id));
|
||||
final repository = await ref.watch(conversationRepositoryProvider.future);
|
||||
return repository.selected(projectId);
|
||||
}
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
@Riverpod(keepAlive: true)
|
||||
class ConversationSelection extends _$ConversationSelection {
|
||||
String? _draftKey;
|
||||
@override
|
||||
ConversationSelectionState build(String? projectId) {
|
||||
final composers = ref.read(agentComposerStoreProvider);
|
||||
ref.onDispose(() {
|
||||
if (_draftKey case final key?) composers.removeDraft(projectId, key);
|
||||
});
|
||||
ref.watch(
|
||||
projectsProvider.select((value) => value.value?.activeProject?.id),
|
||||
);
|
||||
final saved = savedConversationSelectionProvider(projectId);
|
||||
ref.listen(saved, (_, next) {
|
||||
if (!state.initialized &&
|
||||
next.hasValue &&
|
||||
!next.isLoading &&
|
||||
!next.hasError) {
|
||||
state = state.copyWith(selectedId: next.value, initialized: true);
|
||||
}
|
||||
});
|
||||
final selected = ref.read(saved);
|
||||
final initialized =
|
||||
selected.hasValue && !selected.isLoading && !selected.hasError;
|
||||
_draftKey = const Uuid().v4();
|
||||
return ConversationSelectionState(
|
||||
draftKey: _draftKey!,
|
||||
selectedId: initialized ? selected.value : null,
|
||||
initialized: initialized,
|
||||
);
|
||||
}
|
||||
|
||||
void newConversation() {
|
||||
ref.read(agentComposerStoreProvider).removeDraft(projectId, state.draftKey);
|
||||
_draftKey = const Uuid().v4();
|
||||
state = ConversationSelectionState(draftKey: _draftKey!, initialized: true);
|
||||
}
|
||||
|
||||
void select(String id) =>
|
||||
state = state.copyWith(selectedId: id, initialized: true);
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class ConversationSidebar extends _$ConversationSidebar {
|
||||
int _revision = 0;
|
||||
|
||||
@override
|
||||
Future<ConversationSnapshot> build() async {
|
||||
await ref.watch(
|
||||
projectsProvider.selectAsync(
|
||||
(workspace) => ConversationWorkspaceKey(
|
||||
projectId: workspace.activeProject?.id,
|
||||
projectIds: [for (final project in workspace.recent) project.id],
|
||||
),
|
||||
),
|
||||
);
|
||||
_revision++;
|
||||
final workspace = ref.read(projectsProvider).requireValue;
|
||||
return _load(workspace);
|
||||
}
|
||||
|
||||
Future<ConversationSnapshot> _load(ProjectState workspace) async {
|
||||
final projectId = workspace.activeProject?.id;
|
||||
if (projectId == null && workspace.recent.isEmpty) {
|
||||
return const ConversationSnapshot();
|
||||
}
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
final lists = await Future.wait([
|
||||
for (final project in workspace.recent) repository.list(project.id),
|
||||
]);
|
||||
return ConversationSnapshot(
|
||||
projectId: projectId,
|
||||
groups: {
|
||||
for (var index = 0; index < workspace.recent.length; index++)
|
||||
workspace.recent[index].id: List.unmodifiable(lists[index]),
|
||||
},
|
||||
trashed: projectId == null
|
||||
? const []
|
||||
: List.unmodifiable(await repository.list(projectId, trash: true)),
|
||||
selectedId: await ref.read(
|
||||
savedConversationSelectionProvider(projectId).future,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> reload() async {
|
||||
final revision = ++_revision;
|
||||
final workspace = ref.read(projectsProvider).requireValue;
|
||||
try {
|
||||
final next = await _load(workspace);
|
||||
if (!ref.mounted ||
|
||||
revision != _revision ||
|
||||
ref.read(projectsProvider).value?.activeProject?.id !=
|
||||
next.projectId) {
|
||||
return;
|
||||
}
|
||||
state = AsyncData(next);
|
||||
} catch (error, stack) {
|
||||
if (ref.mounted && revision == _revision) {
|
||||
state = state.value == null
|
||||
? AsyncError(error, stack)
|
||||
: AsyncData(state.requireValue.copyWith(reloadFailed: true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void newConversation() => ref
|
||||
.read(
|
||||
conversationSelectionProvider(
|
||||
ref.read(projectsProvider).value?.activeProject?.id,
|
||||
).notifier,
|
||||
)
|
||||
.newConversation();
|
||||
|
||||
Future<void> rememberSelection(ConversationMetadata item) async {
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.select(item.projectId, item.id);
|
||||
if (ref.mounted) {
|
||||
ref.invalidate(savedConversationSelectionProvider(item.projectId));
|
||||
}
|
||||
}
|
||||
|
||||
void activate(ConversationMetadata item) => ref
|
||||
.read(conversationSelectionProvider(item.projectId).notifier)
|
||||
.select(item.id);
|
||||
|
||||
Future<void> updateListing(
|
||||
ConversationMetadata item, {
|
||||
String? selectIfDraftKey,
|
||||
}) async {
|
||||
if (ref.read(projectsProvider).value?.activeProject?.id != item.projectId) {
|
||||
return;
|
||||
}
|
||||
final current = state.value ?? await future;
|
||||
if (!ref.mounted) return;
|
||||
_revision++;
|
||||
if (ref.read(projectsProvider).value?.activeProject?.id != item.projectId) {
|
||||
return;
|
||||
}
|
||||
final selection = ref.read(conversationSelectionProvider(item.projectId));
|
||||
final selectCreated =
|
||||
selectIfDraftKey != null &&
|
||||
selection.selectedId == null &&
|
||||
selection.draftKey == selectIfDraftKey;
|
||||
state = AsyncData(
|
||||
current.copyWith(
|
||||
groups: {
|
||||
...current.groups,
|
||||
item.projectId: [
|
||||
item,
|
||||
...?current.groups[item.projectId]?.where(
|
||||
(existing) => existing.id != item.id,
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
);
|
||||
if (selectCreated) {
|
||||
ref
|
||||
.read(agentComposerStoreProvider)
|
||||
.promoteDraft(item.projectId, selectIfDraftKey, item.id);
|
||||
activate(item);
|
||||
await rememberSelection(item);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> rename(ConversationMetadata item, String title) =>
|
||||
updateMetadata(item.copyWith(title: title));
|
||||
Future<void> updateMetadata(ConversationMetadata item) async {
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.update(item);
|
||||
if (ref.mounted) await reload();
|
||||
}
|
||||
|
||||
Future<void> trash(ConversationMetadata item) async {
|
||||
await ref
|
||||
.read(agentConversationRegistryProvider)
|
||||
.cancel(item.projectId, item.id);
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.trash(item.projectId, item.id);
|
||||
if (!ref.mounted) return;
|
||||
_forgetRemovedSelection(item);
|
||||
await reload();
|
||||
}
|
||||
|
||||
Future<void> restore(ConversationMetadata item) async {
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.restore(item.projectId, item.id);
|
||||
if (ref.mounted) {
|
||||
ref.invalidate(savedConversationSelectionProvider(item.projectId));
|
||||
await reload();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> delete(ConversationMetadata item) async {
|
||||
await ref
|
||||
.read(agentConversationRegistryProvider)
|
||||
.cancel(item.projectId, item.id);
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
await repository.deletePermanently(item.projectId, item.id);
|
||||
if (!ref.mounted) return;
|
||||
_forgetRemovedSelection(item);
|
||||
ref
|
||||
.read(agentComposerStoreProvider)
|
||||
.removeConversation(item.projectId, item.id);
|
||||
await reload();
|
||||
}
|
||||
|
||||
void _forgetRemovedSelection(ConversationMetadata item) {
|
||||
ref.invalidate(savedConversationSelectionProvider(item.projectId));
|
||||
if (ref.read(projectsProvider).value?.activeProject?.id == item.projectId &&
|
||||
ref.read(conversationSelectionProvider(item.projectId)).selectedId ==
|
||||
item.id) {
|
||||
newConversation();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> emptyTrash() async {
|
||||
final items = state.value?.trashed ?? const <ConversationMetadata>[];
|
||||
final repository = await ref.read(conversationRepositoryProvider.future);
|
||||
for (final item in items) {
|
||||
await repository.deletePermanently(item.projectId, item.id);
|
||||
if (!ref.mounted) return;
|
||||
_forgetRemovedSelection(item);
|
||||
ref
|
||||
.read(agentComposerStoreProvider)
|
||||
.removeConversation(item.projectId, item.id);
|
||||
}
|
||||
if (ref.mounted) await reload();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,247 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'conversation_sidebar.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(savedConversationSelection)
|
||||
final savedConversationSelectionProvider = SavedConversationSelectionFamily._();
|
||||
|
||||
final class SavedConversationSelectionProvider
|
||||
extends $FunctionalProvider<AsyncValue<String?>, String?, FutureOr<String?>>
|
||||
with $FutureModifier<String?>, $FutureProvider<String?> {
|
||||
SavedConversationSelectionProvider._({
|
||||
required SavedConversationSelectionFamily super.from,
|
||||
required String? super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'savedConversationSelectionProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$savedConversationSelectionHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'savedConversationSelectionProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<String?> $createElement($ProviderPointer pointer) =>
|
||||
$FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<String?> create(Ref ref) {
|
||||
final argument = this.argument as String?;
|
||||
return savedConversationSelection(ref, argument);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is SavedConversationSelectionProvider &&
|
||||
other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$savedConversationSelectionHash() =>
|
||||
r'849182ed07f7227ba041f611ccdb3cbb1423f95e';
|
||||
|
||||
final class SavedConversationSelectionFamily extends $Family
|
||||
with $FunctionalFamilyOverride<FutureOr<String?>, String?> {
|
||||
SavedConversationSelectionFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'savedConversationSelectionProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: false,
|
||||
);
|
||||
|
||||
SavedConversationSelectionProvider call(String? projectId) =>
|
||||
SavedConversationSelectionProvider._(argument: projectId, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'savedConversationSelectionProvider';
|
||||
}
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
|
||||
@ProviderFor(ConversationSelection)
|
||||
final conversationSelectionProvider = ConversationSelectionFamily._();
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
final class ConversationSelectionProvider
|
||||
extends
|
||||
$NotifierProvider<ConversationSelection, ConversationSelectionState> {
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
ConversationSelectionProvider._({
|
||||
required ConversationSelectionFamily super.from,
|
||||
required String? super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'conversationSelectionProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$conversationSelectionHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'conversationSelectionProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ConversationSelection create() => ConversationSelection();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(ConversationSelectionState value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<ConversationSelectionState>(value),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ConversationSelectionProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$conversationSelectionHash() =>
|
||||
r'eef3c6c95f86b017e73d3244adccc257f717699b';
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
|
||||
final class ConversationSelectionFamily extends $Family
|
||||
with
|
||||
$ClassFamilyOverride<
|
||||
ConversationSelection,
|
||||
ConversationSelectionState,
|
||||
ConversationSelectionState,
|
||||
ConversationSelectionState,
|
||||
String?
|
||||
> {
|
||||
ConversationSelectionFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'conversationSelectionProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: false,
|
||||
);
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
|
||||
ConversationSelectionProvider call(String? projectId) =>
|
||||
ConversationSelectionProvider._(argument: projectId, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'conversationSelectionProvider';
|
||||
}
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
|
||||
abstract class _$ConversationSelection
|
||||
extends $Notifier<ConversationSelectionState> {
|
||||
late final _$args = ref.$arg as String?;
|
||||
String? get projectId => _$args;
|
||||
|
||||
ConversationSelectionState build(String? projectId);
|
||||
@$mustCallSuper
|
||||
@override
|
||||
WhenComplete runBuild() {
|
||||
final ref =
|
||||
this.ref
|
||||
as $Ref<ConversationSelectionState, ConversationSelectionState>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<
|
||||
ConversationSelectionState,
|
||||
ConversationSelectionState
|
||||
>,
|
||||
ConversationSelectionState,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
return element.handleCreate(ref, () => build(_$args));
|
||||
}
|
||||
}
|
||||
|
||||
@ProviderFor(ConversationSidebar)
|
||||
final conversationSidebarProvider = ConversationSidebarProvider._();
|
||||
|
||||
final class ConversationSidebarProvider
|
||||
extends $AsyncNotifierProvider<ConversationSidebar, ConversationSnapshot> {
|
||||
ConversationSidebarProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'conversationSidebarProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$conversationSidebarHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ConversationSidebar create() => ConversationSidebar();
|
||||
}
|
||||
|
||||
String _$conversationSidebarHash() =>
|
||||
r'13122a844ce87622c8d4919042e4dbefc69b790f';
|
||||
|
||||
abstract class _$ConversationSidebar
|
||||
extends $AsyncNotifier<ConversationSnapshot> {
|
||||
FutureOr<ConversationSnapshot> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
WhenComplete runBuild() {
|
||||
final ref =
|
||||
this.ref
|
||||
as $Ref<AsyncValue<ConversationSnapshot>, ConversationSnapshot>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<
|
||||
AsyncValue<ConversationSnapshot>,
|
||||
ConversationSnapshot
|
||||
>,
|
||||
AsyncValue<ConversationSnapshot>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
return element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
class EmptyEditor extends StatelessWidget {
|
||||
const EmptyEditor({
|
||||
super.key,
|
||||
required this.state,
|
||||
required this.headerLeading,
|
||||
required this.showProjectName,
|
||||
});
|
||||
|
||||
final ProjectState state;
|
||||
final Widget headerLeading;
|
||||
final bool showProjectName;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: AppControlSize.panelHeader,
|
||||
child: WindowHeaderPadding(
|
||||
child: Row(
|
||||
children: [
|
||||
headerLeading,
|
||||
if (showProjectName)
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.activeProject?.name ?? '',
|
||||
key: const Key('workspace-project-title'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppSpacing.page),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.movie_outlined,
|
||||
size: AppIconSize.project,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
Text(
|
||||
state.activeProject == null
|
||||
? context.l10n.projectsEmpty
|
||||
: context.l10n.projectNoTimelines,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
if (state.activeProject != null) ...[
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Text(
|
||||
context.l10n.createTimelineHint,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
class ProjectLoadingRegion extends StatelessWidget {
|
||||
const ProjectLoadingRegion({
|
||||
super.key,
|
||||
required this.loading,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool loading;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
ExcludeFocus(
|
||||
excluding: loading,
|
||||
child: IgnorePointer(ignoring: loading, child: child),
|
||||
),
|
||||
if (loading)
|
||||
DelayedLoadingIndicator(
|
||||
child: Positioned.fill(
|
||||
child: ColoredBox(
|
||||
key: const Key('editor-project-loading'),
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: const Center(
|
||||
child: SizedBox.square(
|
||||
dimension: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,664 @@
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../app/adaptive/desktop_workspace_controller.dart';
|
||||
import '../../app/adaptive/workspace_layout_policy.dart';
|
||||
import '../../app/shells/phone_workspace_shell.dart';
|
||||
import '../../app/shells/desktop_workspace_shell.dart';
|
||||
import '../../app/shells/tablet_workspace_shell.dart';
|
||||
import '../../integrations/platform/device_experience.dart';
|
||||
import '../../integrations/platform/editor_window_chrome.dart';
|
||||
import '../../integrations/platform/file_picker.dart';
|
||||
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
|
||||
import '../../persistence/app_settings_repositories.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
import '../../workspace/project_state.dart';
|
||||
import '../../workspace/projects.dart';
|
||||
import '../../workspace/view_settings.dart';
|
||||
import '../../workspace/workspace_mode.dart';
|
||||
import '../../workspace/workspace_navigation.dart';
|
||||
import '../../workspace/workspace_session_scope.dart';
|
||||
import '../assistant/workspace_agent_surface.dart';
|
||||
import '../editor/background_tasks_button.dart';
|
||||
import '../editor/editor_page.dart';
|
||||
import '../settings/settings_dialog.dart';
|
||||
import 'editor_loading_region.dart';
|
||||
import 'project_sidebar.dart';
|
||||
import 'widgets/name_dialog.dart';
|
||||
|
||||
/// The single application surface: project navigation beside the editor.
|
||||
|
||||
class EditingPage extends ConsumerStatefulWidget {
|
||||
const EditingPage({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<EditingPage> createState() => _EditingPageState();
|
||||
}
|
||||
|
||||
class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
final _desktopSplits = DesktopWorkspaceController();
|
||||
final _editorKey = GlobalKey();
|
||||
final _agentKey = GlobalKey();
|
||||
final _navigationKey = GlobalKey();
|
||||
final _drawerNavigationKey = GlobalKey();
|
||||
final _desktopScaffoldKey = GlobalKey<ScaffoldState>();
|
||||
WorkspaceViewSettingsData get _viewSettings =>
|
||||
ref.read(workspaceViewSettingsProvider).value ??
|
||||
const WorkspaceViewSettingsData();
|
||||
WorkspaceViewSettings get _viewController =>
|
||||
ref.read(workspaceViewSettingsProvider.notifier);
|
||||
WorkspaceMode get _mode => _viewSettings.mode;
|
||||
set _mode(WorkspaceMode value) => _viewController.setMode(value);
|
||||
bool get _sidebarCollapsed => _viewSettings.sidebarCollapsed;
|
||||
set _sidebarCollapsed(bool value) =>
|
||||
_viewController.setSidebarCollapsed(value);
|
||||
double? get _sidebarWidthOverride => _viewSettings.sidebarWidth;
|
||||
set _sidebarWidthOverride(double? value) =>
|
||||
_viewController.setSidebarWidth(value);
|
||||
bool get _startupReady => ref.read(workspaceNavigationProvider).ready;
|
||||
bool get _switchingProject =>
|
||||
ref.read(workspaceNavigationProvider).switchingProject;
|
||||
String? get _selectedProjectId =>
|
||||
ref.read(workspaceNavigationProvider).selectedProjectId;
|
||||
|
||||
void _saveViewState({String? activeProjectId}) {
|
||||
if (!_startupReady) return;
|
||||
final current = ref.read(projectsProvider).value;
|
||||
unawaited(
|
||||
_viewController.save(
|
||||
activeProjectId: activeProjectId ?? current?.activeProject?.id,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _selectProject(
|
||||
BuildContext context,
|
||||
WidgetRef ref, {
|
||||
required bool create,
|
||||
}) async {
|
||||
if (ref.read(projectsProvider).value?.projectBusy == true) return;
|
||||
try {
|
||||
if (create) {
|
||||
final name = await askName(
|
||||
context,
|
||||
title: context.l10n.newProject,
|
||||
label: context.l10n.projectName,
|
||||
);
|
||||
if (name == null || !context.mounted) return;
|
||||
final created = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.createProject(
|
||||
name,
|
||||
initialTimelineName: context.l10n.defaultTimelineName(1),
|
||||
);
|
||||
if (!created && context.mounted) {
|
||||
final error = ref.read(projectsProvider).value?.error;
|
||||
if (error?.requiresProjectLocation == true) {
|
||||
await showSettingsDialog(context);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
final directory = await ref
|
||||
.read(filePickerProvider)
|
||||
.pickDirectory(confirmButtonText: context.l10n.openProject);
|
||||
if (directory == null || !context.mounted) return;
|
||||
await ref.read(projectsProvider.notifier).open(directory);
|
||||
} catch (_) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(context.l10n.selectDirectoryFailed)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openProject(WidgetRef ref, RecentProject project) =>
|
||||
ref.read(workspaceNavigationProvider.notifier).openProject(project);
|
||||
|
||||
Future<bool> _renameProject(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
RecentProject project,
|
||||
) async {
|
||||
if (ref.read(projectsProvider).value?.projectBusy == true) return false;
|
||||
final name = await askName(
|
||||
context,
|
||||
title: context.l10n.rename,
|
||||
label: context.l10n.projectName,
|
||||
initialValue: project.name,
|
||||
submitLabel: context.l10n.rename,
|
||||
);
|
||||
if (name == null || !context.mounted || name == project.name) return false;
|
||||
return ref.read(projectsProvider.notifier).renameProject(project, name);
|
||||
}
|
||||
|
||||
Future<void> _relocateProject(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
RecentProject project,
|
||||
) async {
|
||||
if (ref.read(projectsProvider).value?.projectBusy == true) return;
|
||||
final directory = await ref
|
||||
.read(filePickerProvider)
|
||||
.pickDirectory(confirmButtonText: context.l10n.openProject);
|
||||
if (directory == null || !context.mounted) return;
|
||||
await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.open(directory, expectedId: project.id);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_desktopSplits.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _setMode(WorkspaceMode mode) {
|
||||
_mode = mode;
|
||||
_saveViewState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ref.watch(workspaceViewSettingsProvider);
|
||||
ref.watch(workspaceNavigationProvider);
|
||||
final experience = ref.watch(deviceExperienceProvider);
|
||||
final desktop = experience == DeviceExperience.desktop;
|
||||
final projects = ref.watch(projectsProvider);
|
||||
final state = projects.value ?? const ProjectState();
|
||||
return EditorWindowChrome(
|
||||
headerHeight: desktop ? AppControlSize.panelHeader : 48,
|
||||
builder: (context, integrated) => Scaffold(
|
||||
body: SafeArea(
|
||||
top: !integrated,
|
||||
child: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 320),
|
||||
child: !_startupReady
|
||||
? const _StartupLoading(key: ValueKey('startup-loading'))
|
||||
: WorkspaceSessionScope(
|
||||
key: const ValueKey('workspace-content'),
|
||||
state: state,
|
||||
child: Stack(
|
||||
children: [
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final navigationHiddenBySpace =
|
||||
desktop &&
|
||||
!WorkspaceLayoutPolicy.desktopNavigationFits(
|
||||
constraints.maxWidth,
|
||||
);
|
||||
final navigationCollapsed =
|
||||
_sidebarCollapsed || navigationHiddenBySpace;
|
||||
Widget controls({
|
||||
bool navigationToggle = true,
|
||||
}) => HeaderControlRegion(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: AppSpacing.tiny,
|
||||
children: [
|
||||
if (navigationToggle)
|
||||
SizedBox.square(
|
||||
dimension: AppControlSize.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key(
|
||||
'project-sidebar-toggle',
|
||||
),
|
||||
tooltip: navigationCollapsed
|
||||
? context.l10n.expandSidebar
|
||||
: context.l10n.collapseSidebar,
|
||||
onPressed: () {
|
||||
if (navigationHiddenBySpace) {
|
||||
_desktopScaffoldKey.currentState
|
||||
?.openDrawer();
|
||||
} else {
|
||||
_sidebarCollapsed =
|
||||
!_sidebarCollapsed;
|
||||
_saveViewState();
|
||||
}
|
||||
},
|
||||
style: sidebarActionButtonStyle(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.view_sidebar_outlined,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (desktop &&
|
||||
navigationCollapsed &&
|
||||
navigationToggle)
|
||||
PopupMenuButton<WorkspaceMode>(
|
||||
key: const Key('desktop-workspace-mode'),
|
||||
initialValue: _mode,
|
||||
onSelected: _setMode,
|
||||
itemBuilder: (context) => [
|
||||
for (final mode in WorkspaceMode.values)
|
||||
PopupMenuItem(
|
||||
key: ValueKey(
|
||||
'desktop-mode-${mode.name}',
|
||||
),
|
||||
value: mode,
|
||||
child: Text(
|
||||
mode == WorkspaceMode.agent
|
||||
? context.l10n.workspaceAgent
|
||||
: context.l10n.workspaceCut,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_mode == WorkspaceMode.agent
|
||||
? context.l10n.workspaceAgent
|
||||
: context.l10n.workspaceCut,
|
||||
),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_down,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox.square(
|
||||
dimension: desktop
|
||||
? AppControlSize.headerButton
|
||||
: 48,
|
||||
child: IconButton(
|
||||
key: const Key('project-settings-button'),
|
||||
tooltip: context.l10n.settings,
|
||||
onPressed: () =>
|
||||
showSettingsDialog(context),
|
||||
style: sidebarActionButtonStyle(context),
|
||||
icon: const Icon(
|
||||
Icons.settings_outlined,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox.square(
|
||||
dimension: desktop
|
||||
? AppControlSize.headerButton
|
||||
: 48,
|
||||
child: const BackgroundTasksButton(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
Widget leading() => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (navigationCollapsed && integrated)
|
||||
SizedBox(
|
||||
width: EditorWindowChrome.leadingWidth,
|
||||
),
|
||||
if (navigationCollapsed) controls(),
|
||||
const SizedBox(width: AppSpacing.compact),
|
||||
],
|
||||
);
|
||||
void selectProject(RecentProject project) {
|
||||
if (project.availability.canOpen) {
|
||||
_openProject(ref, project);
|
||||
} else {
|
||||
_relocateProject(context, ref, project);
|
||||
}
|
||||
}
|
||||
|
||||
final agent = WorkspaceAgentSurface(
|
||||
key: _agentKey,
|
||||
state: state,
|
||||
onSelectProject: (project) =>
|
||||
project.availability.canOpen
|
||||
? _openProject(ref, project)
|
||||
: _relocateProject(context, ref, project),
|
||||
onCreateProject: () =>
|
||||
_selectProject(context, ref, create: true),
|
||||
);
|
||||
Widget navigation({
|
||||
DesktopWorkspaceGeometry? geometry,
|
||||
VoidCallback? expandEditor,
|
||||
bool drawer = false,
|
||||
}) => ProjectSidebar(
|
||||
experience: experience,
|
||||
key: drawer
|
||||
? _drawerNavigationKey
|
||||
: _navigationKey,
|
||||
agent: desktop && !drawer
|
||||
? agent
|
||||
: const SizedBox.shrink(),
|
||||
navigationOnly: !desktop || drawer,
|
||||
onNavigationComplete: desktop && !drawer
|
||||
? null
|
||||
: () => Navigator.of(context).maybePop(),
|
||||
editorHidden: geometry?.editorHidden ?? false,
|
||||
onExpandEditor: expandEditor,
|
||||
agentHeaderLeading: desktop
|
||||
? leading()
|
||||
: const SizedBox.shrink(),
|
||||
navigationCollapsed:
|
||||
desktop && !drawer && navigationCollapsed,
|
||||
mode: _mode,
|
||||
onModeChanged: _setMode,
|
||||
navigationWidth: geometry?.sidebarWidth ?? 320,
|
||||
state: state,
|
||||
selectedProjectId:
|
||||
_selectedProjectId ?? state.activeProject?.id,
|
||||
integratedTitlebar: integrated,
|
||||
onCreateProject: () =>
|
||||
_selectProject(context, ref, create: true),
|
||||
onSelectProject: selectProject,
|
||||
onRenameProject: (project) =>
|
||||
_renameProject(context, ref, project),
|
||||
headerControls: desktop && !drawer
|
||||
? controls()
|
||||
: HeaderControlRegion(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Builder(
|
||||
builder: (context) => IconButton(
|
||||
tooltip: MaterialLocalizations.of(
|
||||
context,
|
||||
).closeButtonTooltip,
|
||||
onPressed: () =>
|
||||
Scaffold.of(context)
|
||||
.closeDrawer(),
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
final editor = ProjectLoadingRegion(
|
||||
loading: _switchingProject,
|
||||
child:
|
||||
state.activeProject != null &&
|
||||
state.timeline != null
|
||||
? EditorWorkspace(
|
||||
key: _editorKey,
|
||||
experience: experience,
|
||||
projectId: state.activeProject!.id,
|
||||
timelineId: state.timeline!.id,
|
||||
projectName: state.activeProject!.name,
|
||||
showProjectName:
|
||||
desktop && _mode == WorkspaceMode.cut,
|
||||
integratedTitlebar: desktop && integrated,
|
||||
headerLeading:
|
||||
desktop && _mode == WorkspaceMode.cut
|
||||
? leading()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
)
|
||||
: EmptyEditor(
|
||||
state: state,
|
||||
showProjectName:
|
||||
desktop && _mode == WorkspaceMode.cut,
|
||||
headerLeading:
|
||||
desktop && _mode == WorkspaceMode.cut
|
||||
? leading()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
),
|
||||
);
|
||||
return switch (experience) {
|
||||
DeviceExperience.desktop => DesktopWorkspaceShell(
|
||||
controller: _desktopSplits,
|
||||
scaffoldKey: _desktopScaffoldKey,
|
||||
navigationDrawer: navigation(drawer: true),
|
||||
mode: _mode,
|
||||
sidebarCollapsed: navigationCollapsed,
|
||||
sidebarWidth: _sidebarWidthOverride,
|
||||
onSidebarCollapsedChanged: (value) {
|
||||
_sidebarCollapsed = value;
|
||||
_saveViewState();
|
||||
},
|
||||
onSidebarWidthChanged: (value) {
|
||||
_sidebarWidthOverride = value;
|
||||
_saveViewState();
|
||||
},
|
||||
sidebarBuilder: (geometry, expand) =>
|
||||
navigation(
|
||||
geometry: geometry,
|
||||
expandEditor: expand,
|
||||
),
|
||||
editor: editor,
|
||||
),
|
||||
DeviceExperience.tablet => TabletWorkspaceShell(
|
||||
mode: _mode,
|
||||
onModeChanged: _setMode,
|
||||
navigation: navigation(),
|
||||
headerActions: controls(
|
||||
navigationToggle: false,
|
||||
),
|
||||
title: state.activeProject?.name ?? 'Cutdex',
|
||||
integratedTitlebar: integrated,
|
||||
agent: agent,
|
||||
editor: editor,
|
||||
),
|
||||
DeviceExperience.phone => PhoneWorkspaceShell(
|
||||
mode: _mode,
|
||||
onModeChanged: _setMode,
|
||||
navigation: navigation(),
|
||||
headerActions: controls(
|
||||
navigationToggle: false,
|
||||
),
|
||||
title: state.activeProject?.name ?? 'Cutdex',
|
||||
integratedTitlebar: integrated,
|
||||
agent: agent,
|
||||
editor: editor,
|
||||
),
|
||||
};
|
||||
},
|
||||
),
|
||||
PositionedDirectional(
|
||||
top: AppSpacing.compact,
|
||||
end: AppSpacing.compact,
|
||||
child: _SonnerErrorToast(
|
||||
message: projects.hasError
|
||||
? const AppFailure(
|
||||
AppErrorCode.loadProjectsFailed,
|
||||
)
|
||||
: state.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StartupLoading extends StatefulWidget {
|
||||
const _StartupLoading({super.key});
|
||||
|
||||
@override
|
||||
State<_StartupLoading> createState() => _StartupLoadingState();
|
||||
}
|
||||
|
||||
class _StartupLoadingState extends State<_StartupLoading>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _pulse = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1800),
|
||||
)..repeat(reverse: true);
|
||||
|
||||
late final Animation<double> _opacity = Tween<double>(
|
||||
begin: 0.5,
|
||||
end: 1,
|
||||
).animate(CurvedAnimation(parent: _pulse, curve: Curves.easeInOut));
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pulse.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Center(
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: FadeTransition(
|
||||
opacity: _opacity,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'CUTDEX',
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.w600, letterSpacing: 3),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
Text(
|
||||
context.l10n.openingWorkspace,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _SonnerErrorToast extends StatefulWidget {
|
||||
const _SonnerErrorToast({required this.message});
|
||||
|
||||
final AppFailure? message;
|
||||
|
||||
@override
|
||||
State<_SonnerErrorToast> createState() => _SonnerErrorToastState();
|
||||
}
|
||||
|
||||
class _SonnerErrorToastState extends State<_SonnerErrorToast> {
|
||||
static const _displayDuration = Duration(seconds: 6);
|
||||
|
||||
Timer? _timer;
|
||||
AppFailure? _displayedMessage;
|
||||
bool _visible = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_show(widget.message);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _SonnerErrorToast oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.message != null &&
|
||||
(oldWidget.message == null || widget.message != oldWidget.message)) {
|
||||
_show(widget.message);
|
||||
}
|
||||
}
|
||||
|
||||
void _show(AppFailure? message) {
|
||||
if (message == null) return;
|
||||
_timer?.cancel();
|
||||
_displayedMessage = message;
|
||||
_visible = true;
|
||||
_timer = Timer(_displayDuration, _hide);
|
||||
}
|
||||
|
||||
void _hide() {
|
||||
if (mounted) setState(() => _visible = false);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final message = _displayedMessage;
|
||||
if (message == null) return const SizedBox.shrink();
|
||||
final theme = Theme.of(context);
|
||||
return IgnorePointer(
|
||||
ignoring: !_visible,
|
||||
child: AnimatedSlide(
|
||||
offset: _visible ? Offset.zero : const Offset(0.08, 0),
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOutCubic,
|
||||
child: AnimatedOpacity(
|
||||
opacity: _visible ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 160),
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 360),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHigh,
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: theme.colorScheme.shadow.withValues(alpha: .25),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
start: AppSpacing.compact,
|
||||
top: AppSpacing.small,
|
||||
bottom: AppSpacing.small,
|
||||
end: AppSpacing.tiny,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: AppIconSize.small,
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
Flexible(
|
||||
child: Text(
|
||||
context.l10n.failureMessage(message),
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: MaterialLocalizations.of(context)
|
||||
.closeButtonTooltip,
|
||||
onPressed: _hide,
|
||||
icon: const Icon(Icons.close, size: AppIconSize.small),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import '../../workspace/project_state.dart';
|
||||
|
||||
class TouchProjectsHeader extends StatelessWidget {
|
||||
const TouchProjectsHeader({super.key, required this.onCreate});
|
||||
final VoidCallback? onCreate;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Row(
|
||||
children: [
|
||||
Expanded(child: Text(context.l10n.projects)),
|
||||
SizedBox.square(
|
||||
dimension: 48,
|
||||
child: IconButton(
|
||||
key: const Key('create-project'),
|
||||
tooltip: context.l10n.newProject,
|
||||
onPressed: onCreate,
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Touch navigation keeps its actions visible and uses finger-sized targets.
|
||||
class TouchProjectTile extends StatelessWidget {
|
||||
const TouchProjectTile({
|
||||
super.key,
|
||||
required this.project,
|
||||
required this.selected,
|
||||
required this.expanded,
|
||||
required this.availabilityLabel,
|
||||
required this.onSelect,
|
||||
required this.onToggle,
|
||||
required this.onNewConversation,
|
||||
required this.onRename,
|
||||
required this.onRemove,
|
||||
});
|
||||
final RecentProject project;
|
||||
final bool selected;
|
||||
final bool expanded;
|
||||
final String availabilityLabel;
|
||||
final VoidCallback onSelect;
|
||||
final VoidCallback onToggle;
|
||||
final VoidCallback? onNewConversation;
|
||||
final VoidCallback? onRename;
|
||||
final VoidCallback? onRemove;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListTile(
|
||||
key: ValueKey('sidebar-project-${project.id}'),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
minTileHeight: 56,
|
||||
selected: selected,
|
||||
leading: IconButton(
|
||||
key: ValueKey('sidebar-project-toggle-${project.id}'),
|
||||
constraints: const BoxConstraints.tightFor(width: 48, height: 48),
|
||||
tooltip: expanded
|
||||
? context.l10n.collapseProject
|
||||
: context.l10n.expandProject,
|
||||
onPressed: onToggle,
|
||||
icon: Icon(expanded ? Icons.expand_more : Icons.chevron_right),
|
||||
),
|
||||
title: Text(project.name, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
subtitle: project.availability.canOpen ? null : Text(availabilityLabel),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
key: ValueKey('new-agent-conversation-${project.id}'),
|
||||
constraints: const BoxConstraints.tightFor(width: 48, height: 48),
|
||||
tooltip: context.l10n.agentNewConversation,
|
||||
onPressed: onNewConversation,
|
||||
icon: const Icon(Icons.edit_square),
|
||||
),
|
||||
AppPopover(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AppMenuItem(label: context.l10n.rename, onPressed: onRename),
|
||||
AppMenuItem(
|
||||
label: context.l10n.removeProjectFromSidebar,
|
||||
onPressed: onRemove,
|
||||
),
|
||||
],
|
||||
),
|
||||
builder: (context, toggle) => IconButton(
|
||||
key: ValueKey('sidebar-project-more-${project.id}'),
|
||||
constraints: const BoxConstraints.tightFor(width: 48, height: 48),
|
||||
onPressed: toggle,
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: onSelect,
|
||||
);
|
||||
}
|
||||
|
||||
class TouchConversationTile extends StatelessWidget {
|
||||
const TouchConversationTile({
|
||||
super.key,
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.selected,
|
||||
required this.onSelect,
|
||||
required this.actions,
|
||||
});
|
||||
final String id;
|
||||
final String title;
|
||||
final bool selected;
|
||||
final VoidCallback onSelect;
|
||||
final List<Widget> Function(BuildContext) actions;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListTile(
|
||||
key: ValueKey('sidebar-conversation-$id'),
|
||||
minTileHeight: 48,
|
||||
selected: selected,
|
||||
title: Text(title, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
onTap: onSelect,
|
||||
trailing: AppPopover(
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: actions(context)),
|
||||
builder: (context, toggle) => IconButton(
|
||||
key: ValueKey('sidebar-conversation-more-$id'),
|
||||
constraints: const BoxConstraints.tightFor(width: 48, height: 48),
|
||||
onPressed: toggle,
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
Future<String?> askName(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String label,
|
||||
String? description,
|
||||
String initialValue = '',
|
||||
String? submitLabel,
|
||||
}) => showAppDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => _NameDialog(
|
||||
title: title,
|
||||
label: label,
|
||||
description: description,
|
||||
initialValue: initialValue,
|
||||
submitLabel: submitLabel,
|
||||
),
|
||||
);
|
||||
|
||||
class _NameDialog extends StatefulWidget {
|
||||
const _NameDialog({
|
||||
required this.title,
|
||||
required this.label,
|
||||
this.description,
|
||||
required this.initialValue,
|
||||
this.submitLabel,
|
||||
});
|
||||
final String title;
|
||||
final String label;
|
||||
final String? description;
|
||||
final String initialValue;
|
||||
final String? submitLabel;
|
||||
@override
|
||||
State<_NameDialog> createState() => _NameDialogState();
|
||||
}
|
||||
|
||||
class _NameDialogState extends State<_NameDialog> {
|
||||
late final _controller = TextEditingController(text: widget.initialValue)
|
||||
..selection = TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: widget.initialValue.length,
|
||||
);
|
||||
final _form = GlobalKey<FormState>();
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
if (_form.currentState!.validate()) {
|
||||
Navigator.pop(context, _controller.text.trim());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AppDialog(
|
||||
title: widget.title,
|
||||
description: widget.description,
|
||||
width: 420,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(context.l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _submit,
|
||||
child: Text(widget.submitLabel ?? context.l10n.create),
|
||||
),
|
||||
],
|
||||
child: Builder(
|
||||
builder: (dialogContext) => Form(
|
||||
key: _form,
|
||||
child: TextFormField(
|
||||
controller: _controller,
|
||||
style: AppTheme.inputTextStyle(dialogContext),
|
||||
cursorHeight: AppTheme.inputCursorHeight(dialogContext),
|
||||
autofocus: true,
|
||||
maxLength: 80,
|
||||
buildCounter: (
|
||||
_, {
|
||||
required currentLength,
|
||||
required isFocused,
|
||||
maxLength,
|
||||
}) => null,
|
||||
decoration: InputDecoration(hintText: widget.label),
|
||||
validator: (value) => value == null || value.trim().isEmpty
|
||||
? context.l10n.enterName
|
||||
: RegExp(r'[/\\\x00-\x1F]').hasMatch(value) ||
|
||||
['.', '..'].contains(value.trim())
|
||||
? context.l10n.invalidName
|
||||
: null,
|
||||
onFieldSubmitted: (_) => _submit(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user