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
@@ -0,0 +1,241 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
import 'media_browser_body.dart';
|
||||
import 'media_browser_controller.dart';
|
||||
|
||||
class MediaBrowserToolbar extends StatefulWidget {
|
||||
const MediaBrowserToolbar({
|
||||
super.key,
|
||||
required this.canImport,
|
||||
required this.onImport,
|
||||
required this.filter,
|
||||
required this.onFilterChanged,
|
||||
required this.grid,
|
||||
required this.onToggleGrid,
|
||||
this.projects = const [],
|
||||
this.selectedProjectId,
|
||||
this.onProjectSelected,
|
||||
});
|
||||
|
||||
final bool canImport;
|
||||
final VoidCallback onImport;
|
||||
final MediaFilter filter;
|
||||
final ValueChanged<MediaFilter> onFilterChanged;
|
||||
final bool grid;
|
||||
final VoidCallback onToggleGrid;
|
||||
final List<RecentProject> projects;
|
||||
final String? selectedProjectId;
|
||||
final ValueChanged<RecentProject>? onProjectSelected;
|
||||
|
||||
@override
|
||||
State<MediaBrowserToolbar> createState() => _MediaBrowserToolbarState();
|
||||
}
|
||||
|
||||
class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
||||
Object? _filterConfiguration;
|
||||
Widget? _filterControls;
|
||||
|
||||
bool get canImport => widget.canImport;
|
||||
VoidCallback get onImport => widget.onImport;
|
||||
MediaFilter get filter => widget.filter;
|
||||
ValueChanged<MediaFilter> get onFilterChanged =>
|
||||
(value) => widget.onFilterChanged(value);
|
||||
bool get grid => widget.grid;
|
||||
VoidCallback get onToggleGrid =>
|
||||
() => widget.onToggleGrid();
|
||||
List<RecentProject> get projects => widget.projects;
|
||||
String? get selectedProjectId => widget.selectedProjectId;
|
||||
ValueChanged<RecentProject>? get onProjectSelected =>
|
||||
widget.onProjectSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final configuration = (
|
||||
filter,
|
||||
grid,
|
||||
Theme.of(context),
|
||||
Localizations.localeOf(context),
|
||||
MediaQuery.textScalerOf(context),
|
||||
Directionality.of(context),
|
||||
);
|
||||
if (_filterConfiguration != configuration) {
|
||||
_filterConfiguration = configuration;
|
||||
_filterControls = null;
|
||||
}
|
||||
final selected = projects
|
||||
.where((project) => project.id == selectedProjectId)
|
||||
.firstOrNull;
|
||||
Widget row(Key key, Widget child) => SizedBox(
|
||||
key: key,
|
||||
height: AppControlSize.panelToolbar,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSidebarMetrics.outerPadding,
|
||||
vertical: AppSpacing.gap,
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
return Column(
|
||||
key: const Key('media-panel-header'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
row(
|
||||
const Key('media-project-row'),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(
|
||||
text: context.l10n.importMedia,
|
||||
style: AppTheme.toolbarTextStyle(context),
|
||||
),
|
||||
textDirection: Directionality.of(context),
|
||||
textScaler: MediaQuery.textScalerOf(context),
|
||||
)..layout();
|
||||
final compact = constraints.maxWidth < painter.width + 140;
|
||||
painter.dispose();
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppDropdownMenu(
|
||||
enabled: onProjectSelected != null && projects.isNotEmpty,
|
||||
maxHeight: 320,
|
||||
items: [
|
||||
for (final project in projects)
|
||||
AppMenuItem(
|
||||
key: ValueKey('media-project-${project.id}'),
|
||||
label: project.name,
|
||||
selected: project.id == selectedProjectId,
|
||||
selectOption: true,
|
||||
onPressed: onProjectSelected == null
|
||||
? null
|
||||
: () => onProjectSelected!(project),
|
||||
),
|
||||
],
|
||||
builder: (context, toggle, focusNode) =>
|
||||
AppToolbarDropdownButton(
|
||||
buttonKey: const Key('media-project-button'),
|
||||
focusNode: focusNode,
|
||||
onPressed: toggle,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
selected?.name ??
|
||||
context.l10n.selectProject,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.tiny),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_down,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.tiny),
|
||||
if (compact)
|
||||
SizedBox.square(
|
||||
dimension: AppControlSize.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key('media-import-button'),
|
||||
tooltip: context.l10n.importMedia,
|
||||
onPressed: canImport ? onImport : 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: canImport ? onImport : null,
|
||||
icon: const Icon(Icons.add, size: AppIconSize.header),
|
||||
label: Text(context.l10n.importMedia),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
_filterControls ??= row(
|
||||
const Key('media-filter-row'),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: SizedBox(
|
||||
width: 88,
|
||||
height: AppControlSize.headerButton,
|
||||
child: Semantics(
|
||||
label: context.l10n.mediaCategory,
|
||||
child: AppDropdownMenu(
|
||||
items: [
|
||||
for (final option in MediaFilter.values)
|
||||
AppMenuItem(
|
||||
label: option.label(context),
|
||||
selected: option == filter,
|
||||
selectOption: true,
|
||||
onPressed: () => onFilterChanged(option),
|
||||
),
|
||||
],
|
||||
builder: (context, toggle, focus) =>
|
||||
AppToolbarDropdownButton(
|
||||
buttonKey: const Key('media-category-button'),
|
||||
focusNode: focus,
|
||||
onPressed: toggle,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
filter.label(context),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.tiny),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_down,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.tiny),
|
||||
SizedBox.square(
|
||||
dimension: AppControlSize.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key('media-layout-toggle'),
|
||||
onPressed: onToggleGrid,
|
||||
icon: Icon(
|
||||
grid ? Icons.view_list_outlined : Icons.grid_view_outlined,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
tooltip: grid
|
||||
? context.l10n.listLayout
|
||||
: context.l10n.gridLayout,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user