refactor(desktop): reorganize workspace panels and navigation
This commit is contained in:
1 parent
826745b407
commit
1f73765745
92 files changed
+5811
-2650
No files matched your search
@@ -1,17 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../integrations/platform/native_project_drop_region.dart';
|
||||
import '../../integrations/platform/platform_capabilities.dart';
|
||||
|
||||
import 'package:cutdex_ui/theme.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';
|
||||
|
||||
@@ -23,8 +25,10 @@ class MediaPanel extends ConsumerStatefulWidget {
|
||||
this.backgroundColor,
|
||||
this.grid,
|
||||
this.onGridChanged,
|
||||
this.onSelectProject,
|
||||
}) : assert((grid == null) == (onGridChanged == null));
|
||||
final String projectId;
|
||||
final String? projectId;
|
||||
final ValueChanged<RecentProject>? onSelectProject;
|
||||
final Color? backgroundColor;
|
||||
final bool? grid;
|
||||
final ValueChanged<bool>? onGridChanged;
|
||||
@@ -34,14 +38,70 @@ class MediaPanel extends ConsumerStatefulWidget {
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
return _body!;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant MediaPanel oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.projectId != widget.projectId) _hovering = false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ref.watch(projectsProvider);
|
||||
final browser = ref.watch(mediaBrowserProvider(widget.projectId));
|
||||
ref.watch(externalMediaImportProvider(widget.projectId));
|
||||
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(
|
||||
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));
|
||||
final nativeDrop = ref.watch(platformCapabilitiesProvider).nativeFileDrop;
|
||||
return ListenableBuilder(
|
||||
return ListenableSelector(
|
||||
listenable: browser,
|
||||
select: () =>
|
||||
(browser.filter, browser.grid, browser.busy, browser.canImport),
|
||||
builder: (context, _) {
|
||||
final grid = widget.grid ?? browser.grid;
|
||||
final visible =
|
||||
@@ -61,121 +121,26 @@ class _MediaPanelState extends ConsumerState<MediaPanel> {
|
||||
feedback: browser.feedback,
|
||||
child: Material(
|
||||
key: const Key('media-panel-surface'),
|
||||
color: widget.backgroundColor,
|
||||
color: widget.backgroundColor ?? Colors.transparent,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
key: const Key('media-panel-header'),
|
||||
height: AppControlSize.panelToolbar,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.gap),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final compact = constraints.maxWidth < 180;
|
||||
final controls = Row(
|
||||
mainAxisSize: compact
|
||||
? MainAxisSize.min
|
||||
: MainAxisSize.max,
|
||||
children: [
|
||||
if (compact)
|
||||
SizedBox.square(
|
||||
dimension: AppControlSize.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key('media-import-button'),
|
||||
tooltip: context.l10n.importMedia,
|
||||
onPressed: enabled
|
||||
? () => pickMediaFiles(browser)
|
||||
: null,
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
height: AppControlSize.headerButton,
|
||||
child: TextButton.icon(
|
||||
key: const Key('media-import-button'),
|
||||
style: AppTheme.toolbarButtonStyle(
|
||||
context,
|
||||
),
|
||||
onPressed: enabled
|
||||
? () => pickMediaFiles(browser)
|
||||
: null,
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
label: Text(context.l10n.importMedia),
|
||||
),
|
||||
),
|
||||
if (compact)
|
||||
const SizedBox(width: AppSpacing.tiny)
|
||||
else
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
width: 76,
|
||||
child: AppSelect<MediaFilter>(
|
||||
emptyLabel: context.l10n.noMatchingOptions,
|
||||
label: context.l10n.mediaCategory,
|
||||
outlined: false,
|
||||
controlHeight: AppControlSize.headerButton,
|
||||
textStyle: AppTheme.toolbarTextStyle(
|
||||
context,
|
||||
),
|
||||
value: browser.filter,
|
||||
onChanged: (value) =>
|
||||
browser.filter = value,
|
||||
options: [
|
||||
for (final filter in MediaFilter.values)
|
||||
AppSelectOption(
|
||||
filter,
|
||||
filter.label(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.tiny),
|
||||
SizedBox.square(
|
||||
dimension: AppControlSize.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key('media-layout-toggle'),
|
||||
onPressed: toggleGrid,
|
||||
icon: Icon(
|
||||
grid
|
||||
? Icons.view_list_outlined
|
||||
: Icons.grid_view_outlined,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
tooltip: grid
|
||||
? context.l10n.listLayout
|
||||
: context.l10n.gridLayout,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
return compact
|
||||
? SingleChildScrollView(
|
||||
key: const Key('media-header-scroll'),
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: controls,
|
||||
)
|
||||
: controls;
|
||||
},
|
||||
),
|
||||
),
|
||||
MediaBrowserToolbar(
|
||||
projects: workspace.$1,
|
||||
selectedProjectId: projectId,
|
||||
onProjectSelected: onSelectProject,
|
||||
canImport: enabled,
|
||||
onImport: () => pickMediaFiles(browser),
|
||||
filter: browser.filter,
|
||||
onFilterChanged: (value) => browser.filter = value,
|
||||
grid: grid,
|
||||
onToggleGrid: toggleGrid,
|
||||
),
|
||||
Expanded(
|
||||
key: const Key('media-panel-body'),
|
||||
child: MediaBrowserBody(
|
||||
projectId: widget.projectId,
|
||||
grid: grid,
|
||||
draggable: true,
|
||||
),
|
||||
child: _browserBody(projectId, grid),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user