Files
cutdex/lib/features/media/media_browser_page.dart
T
lingjhf 1f73765745
Gitea CI / Windows x64 and Android (pull_request) Successful in 16m21s
Gitea CI / Gitea CI passed (pull_request) Successful in 3s
refactor(desktop): reorganize workspace panels and navigation
2026-10-06 12:11:59 +08:00

170 lines
6.5 KiB
Dart

import 'package:cutdex/shared/widgets/error_notification_host.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../l10n/l10n.dart';
import '../../workspace/external_media_import.dart';
import '../../workspace/media_availability.dart';
import '../../workspace/projects.dart';
import '../../workspace/timeline_provider.dart';
import 'media_browser_body.dart';
import 'media_browser_controller.dart';
import 'media_browser_feedback.dart';
class MediaBrowserPage extends StatelessWidget {
const MediaBrowserPage({super.key, required this.projectId});
final String projectId;
@override
Widget build(BuildContext context) => TouchMediaBrowser(
key: const Key('media-browser-page'),
projectId: projectId,
);
}
class MediaBrowserDrawer extends StatelessWidget {
const MediaBrowserDrawer({super.key, required this.projectId});
final String projectId;
@override
Widget build(BuildContext context) => TouchMediaBrowser(
key: const Key('media-browser-drawer'),
projectId: projectId,
);
}
/// Touch controls share browser commands and item components with desktop.
class TouchMediaBrowser extends ConsumerWidget {
const TouchMediaBrowser({super.key, required this.projectId});
final String projectId;
@override
Widget build(BuildContext context, WidgetRef ref) {
final browser = ref.watch(mediaBrowserProvider(projectId));
ref.watch(externalMediaImportProvider(projectId));
final workspace = ref.watch(projectsProvider).value;
final timelineId = workspace?.activeProject?.id == projectId
? workspace?.timeline?.id
: null;
final timeline = timelineId == null
? null
: ref.watch(editorTimelineProvider(projectId, timelineId)).value;
return ListenableBuilder(
listenable: browser,
builder: (context, _) {
final selected = workspace?.assets
.where((asset) => asset.id == browser.selectedAssetId)
.firstOrNull;
final availability = selected == null
? null
: ref.watch(mediaAvailabilityProvider(projectId, selected)).value;
final canInsert =
browser.canEdit &&
selected != null &&
timeline?.activeSequenceId != null &&
availability == MediaAvailability.available;
return MediaImportFeedbackListener(
feedback: browser.feedback,
child: Material(
key: const Key('media-panel-surface'),
child: Column(
children: [
SizedBox(
key: const Key('media-panel-header'),
height: 56,
child: Row(
children: [
SizedBox.square(
dimension: 48,
child: IconButton(
key: const Key('media-import-button'),
tooltip: context.l10n.importMedia,
onPressed: browser.canImport
? () => pickMediaFiles(browser)
: null,
icon: const Icon(Icons.add),
),
),
Expanded(
child: DropdownButton<MediaFilter>(
key: const Key('media-category-picker'),
isExpanded: true,
underline: const SizedBox.shrink(),
value: browser.filter,
items: [
for (final filter in MediaFilter.values)
DropdownMenuItem(
value: filter,
child: Text(filter.label(context)),
),
],
onChanged: (filter) {
if (filter != null) browser.filter = filter;
},
),
),
SizedBox.square(
dimension: 48,
child: IconButton(
key: const Key('media-layout-toggle'),
tooltip: browser.grid
? context.l10n.listLayout
: context.l10n.gridLayout,
icon: Icon(
browser.grid
? Icons.view_list_outlined
: Icons.grid_view_outlined,
),
onPressed: () => browser.grid = !browser.grid,
),
),
],
),
),
if (browser.busy) const LinearProgressIndicator(),
Expanded(
key: const Key('media-panel-body'),
child: MediaBrowserBody(
projectId: projectId,
grid: browser.grid,
),
),
Padding(
padding: const EdgeInsets.all(8),
child: SizedBox(
width: double.infinity,
child: FilledButton.icon(
key: const Key('media-add-selected'),
style: FilledButton.styleFrom(
minimumSize: const Size(0, 48),
),
onPressed: !canInsert
? null
: () async {
final inserted = await browser.insertAsset(
selected,
);
if (!inserted && context.mounted) {
ErrorNotificationHost.of(context).show(
ErrorNotification(
content: Text(context.l10n.operationFailed),
),
);
}
},
icon: const Icon(Icons.add),
label: Text(
context.l10n.addToTimeline,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
),
],
),
),
);
},
);
}
}