Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
232 lines
8.0 KiB
Dart
232 lines
8.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/native_project_drop_region.dart';
|
|
import '../../integrations/platform/platform_capabilities.dart';
|
|
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
|
|
import '../../shared/widgets/drop_to_add_overlay.dart';
|
|
import '../../shared/widgets/listenable_selector.dart';
|
|
import '../../workspace/external_media_import.dart';
|
|
import '../../workspace/projects.dart';
|
|
import '../../workspace/project_state.dart';
|
|
import '../../l10n/l10n.dart';
|
|
import 'media_browser_body.dart';
|
|
import 'media_browser_toolbar.dart';
|
|
import 'media_browser_controller.dart';
|
|
import 'media_browser_feedback.dart';
|
|
import 'resource_navigation.dart';
|
|
|
|
/// Desktop presentation owns compact controls and native file dragging.
|
|
class MediaPanel extends ConsumerStatefulWidget {
|
|
const MediaPanel({
|
|
super.key,
|
|
required this.projectId,
|
|
this.backgroundColor,
|
|
this.grid,
|
|
this.onGridChanged,
|
|
this.onSelectProject,
|
|
this.projectScoped = false,
|
|
}) : assert((grid == null) == (onGridChanged == null));
|
|
final String? projectId;
|
|
final bool projectScoped;
|
|
final ValueChanged<RecentProject>? onSelectProject;
|
|
final Color? backgroundColor;
|
|
final bool? grid;
|
|
final ValueChanged<bool>? onGridChanged;
|
|
@override
|
|
ConsumerState<MediaPanel> createState() => _MediaPanelState();
|
|
}
|
|
|
|
class _MediaPanelState extends ConsumerState<MediaPanel> {
|
|
bool _hovering = false;
|
|
(String, bool)? _bodyConfiguration;
|
|
Widget? _body;
|
|
|
|
Widget _browserBody(String projectId, bool grid) {
|
|
final configuration = (projectId, grid);
|
|
if (_bodyConfiguration != configuration) {
|
|
_bodyConfiguration = configuration;
|
|
_body = MediaBrowserBody(
|
|
projectId: projectId,
|
|
grid: grid,
|
|
draggable: true,
|
|
compact: true,
|
|
desktop: true,
|
|
);
|
|
}
|
|
return _body!;
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant MediaPanel oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.projectId != widget.projectId) _hovering = false;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final workspace = ref.watch(
|
|
projectsProvider.select(
|
|
(value) => (
|
|
value.value?.recent ?? const <RecentProject>[],
|
|
value.value?.projectBusy ?? false,
|
|
value.value?.activeProject?.id,
|
|
),
|
|
),
|
|
);
|
|
final projectId = widget.projectId;
|
|
final onSelectProject = workspace.$2 ? null : widget.onSelectProject;
|
|
if (projectId == null) {
|
|
return Material(
|
|
key: const Key('media-panel-surface'),
|
|
color: widget.backgroundColor ?? Colors.transparent,
|
|
child: Column(
|
|
children: [
|
|
MediaBrowserToolbar(
|
|
desktop: true,
|
|
projectScoped: widget.projectScoped,
|
|
projects: workspace.$1,
|
|
onProjectSelected: onSelectProject,
|
|
canImport: false,
|
|
onImport: () {},
|
|
filter: MediaFilter.all,
|
|
onFilterChanged: (_) {},
|
|
grid: true,
|
|
onToggleGrid: () {},
|
|
),
|
|
Expanded(child: Center(child: Text(context.l10n.selectProject))),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
final browser = ref.watch(mediaBrowserProvider(projectId));
|
|
ref.watch(
|
|
externalMediaImportProvider(projectId).select((value) => value.isLoading),
|
|
);
|
|
final nativeDrop = ref.watch(platformCapabilitiesProvider).nativeFileDrop;
|
|
return ListenableSelector(
|
|
listenable: browser,
|
|
select: () => (
|
|
browser.filter,
|
|
browser.grid,
|
|
browser.busy,
|
|
browser.importing,
|
|
browser.canImport,
|
|
browser.query,
|
|
browser.sort,
|
|
browser.gridSize,
|
|
browser.resourceSection,
|
|
),
|
|
builder: (context, _) {
|
|
final grid = widget.grid ?? browser.grid;
|
|
final visible =
|
|
TickerMode.valuesOf(context).enabled &&
|
|
(ModalRoute.of(context)?.isCurrent ?? true);
|
|
final enabled = browser.canImport && visible;
|
|
final browsingImports =
|
|
!widget.projectScoped ||
|
|
browser.resourceSection == ResourceSection.imported;
|
|
void toggleGrid() {
|
|
final next = !grid;
|
|
if (widget.onGridChanged case final onChanged?) {
|
|
onChanged(next);
|
|
} else {
|
|
browser.grid = next;
|
|
}
|
|
}
|
|
|
|
final content = MediaImportFeedbackListener(
|
|
feedback: browser.feedback,
|
|
child: Material(
|
|
key: const Key('media-panel-surface'),
|
|
color: widget.backgroundColor ?? Colors.transparent,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Column(
|
|
children: [
|
|
MediaBrowserToolbar(
|
|
desktop: true,
|
|
projectScoped: widget.projectScoped,
|
|
resourceSection: browser.resourceSection,
|
|
onResourceSectionChanged: (value) =>
|
|
browser.resourceSection = value,
|
|
projects: workspace.$1,
|
|
selectedProjectId: projectId,
|
|
onProjectSelected: onSelectProject,
|
|
canImport: enabled,
|
|
onImport: () => pickMediaFiles(browser),
|
|
filter: browser.filter,
|
|
onFilterChanged: (value) => browser.filter = value,
|
|
grid: grid,
|
|
onToggleGrid: toggleGrid,
|
|
query: browser.query,
|
|
onQueryChanged: (value) => browser.query = value,
|
|
sort: browser.sort,
|
|
onSortChanged: (value) => browser.sort = value,
|
|
gridSize: browser.gridSize,
|
|
onGridSizeChanged: (value) => browser.gridSize = value,
|
|
),
|
|
Expanded(
|
|
key: const Key('media-panel-body'),
|
|
child: widget.projectScoped
|
|
? IndexedStack(
|
|
index: browsingImports ? 0 : 1,
|
|
children: [
|
|
TickerMode(
|
|
enabled: browsingImports,
|
|
child: _browserBody(projectId, grid),
|
|
),
|
|
ResourceLibraryEmpty(
|
|
key: ValueKey((
|
|
'resource-library-empty',
|
|
projectId,
|
|
browser.resourceSection,
|
|
)),
|
|
section: browser.resourceSection,
|
|
),
|
|
],
|
|
)
|
|
: _browserBody(projectId, grid),
|
|
),
|
|
],
|
|
),
|
|
if (browser.importing)
|
|
const DelayedLoadingIndicator(
|
|
child: Align(
|
|
alignment: Alignment.topCenter,
|
|
child: LinearProgressIndicator(),
|
|
),
|
|
),
|
|
if (_hovering && enabled && browsingImports)
|
|
const DropToAddOverlay(key: Key('media-drop-highlight')),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
if (!nativeDrop) return content;
|
|
return NativeProjectDropRegion(
|
|
enabled:
|
|
browsingImports &&
|
|
visible &&
|
|
browser.active &&
|
|
(enabled || browser.busy),
|
|
onEnter: (_) {
|
|
if (enabled) setState(() => _hovering = true);
|
|
},
|
|
onExit: () {
|
|
if (mounted && _hovering) setState(() => _hovering = false);
|
|
},
|
|
onDrop: (files) async {
|
|
setState(() => _hovering = false);
|
|
await importMediaFiles(browser, files);
|
|
},
|
|
child: content,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|