feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s

This commit was merged in pull request #13.
This commit is contained in:
lingjhf committed 2026-10-08 18:17:12 +00:00
1 parent aa5255d1e4
commit abc1868550
260 files changed
+43964 -5591

No files matched your search

+438 -76
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
@@ -6,6 +7,7 @@ import '../../l10n/l10n.dart';
import '../../workspace/project_state.dart';
import 'media_browser_body.dart';
import 'media_browser_controller.dart';
import 'resource_navigation.dart';
class MediaBrowserToolbar extends StatefulWidget {
const MediaBrowserToolbar({
@@ -19,6 +21,16 @@ class MediaBrowserToolbar extends StatefulWidget {
this.projects = const [],
this.selectedProjectId,
this.onProjectSelected,
this.desktop = false,
this.query = '',
this.onQueryChanged,
this.sort = MediaSort.importOrder,
this.onSortChanged,
this.projectScoped = false,
this.resourceSection = ResourceSection.imported,
this.onResourceSectionChanged,
this.gridSize = MediaGridSize.medium,
this.onGridSizeChanged,
});
final bool canImport;
@@ -30,6 +42,16 @@ class MediaBrowserToolbar extends StatefulWidget {
final List<RecentProject> projects;
final String? selectedProjectId;
final ValueChanged<RecentProject>? onProjectSelected;
final bool desktop;
final bool projectScoped;
final ResourceSection resourceSection;
final ValueChanged<ResourceSection>? onResourceSectionChanged;
final String query;
final ValueChanged<String>? onQueryChanged;
final MediaSort sort;
final ValueChanged<MediaSort>? onSortChanged;
final MediaGridSize gridSize;
final ValueChanged<MediaGridSize>? onGridSizeChanged;
@override
State<MediaBrowserToolbar> createState() => _MediaBrowserToolbarState();
@@ -38,6 +60,25 @@ class MediaBrowserToolbar extends StatefulWidget {
class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
Object? _filterConfiguration;
Widget? _filterControls;
final _search = TextEditingController();
@override
void initState() {
super.initState();
_search.text = widget.query;
}
@override
void didUpdateWidget(covariant MediaBrowserToolbar oldWidget) {
super.didUpdateWidget(oldWidget);
if (_search.text != widget.query) _search.text = widget.query;
}
@override
void dispose() {
_search.dispose();
super.dispose();
}
bool get canImport => widget.canImport;
VoidCallback get onImport => widget.onImport;
@@ -57,6 +98,11 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
final configuration = (
filter,
grid,
widget.sort,
widget.gridSize,
widget.desktop,
widget.projectScoped,
canImport,
Theme.of(context),
Localizations.localeOf(context),
MediaQuery.textScalerOf(context),
@@ -69,13 +115,20 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
final selected = projects
.where((project) => project.id == selectedProjectId)
.firstOrNull;
if (widget.desktop || AppTheme.isDesktop(context)) {
return _desktopToolbar(context, selected);
}
Widget row(Key key, Widget child) => SizedBox(
key: key,
height: AppControlSize.panelToolbar,
height: AppTheme.isDesktop(context)
? AppDesktopMetrics.panelHeader
: AppControlSize.panelToolbar,
child: Padding(
padding: const EdgeInsets.symmetric(
padding: EdgeInsets.symmetric(
horizontal: AppSidebarMetrics.outerPadding,
vertical: AppSpacing.gap,
vertical: AppTheme.isDesktop(context)
? AppSpacing.tiny
: AppSpacing.gap,
),
child: child,
),
@@ -87,85 +140,84 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
row(
const Key('media-project-row'),
LayoutBuilder(
builder: (context, constraints) {
final painter = TextPainter(
text: TextSpan(
text: context.l10n.importMedia,
style: AppTheme.toolbarTextStyle(context),
builder: (context, constraints) => Row(
children: [
Expanded(
child: widget.projectScoped
? Text(
context.l10n.materials,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleSmall,
)
: 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(
AppIcons.expandMore,
size: AppIconSize.header,
),
],
),
),
),
),
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),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: (constraints.maxWidth * .45).clamp(
28,
double.infinity,
),
),
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(
child: SizedBox(
height: AppControlSize.headerButton,
child: Tooltip(
message: context.l10n.importMedia,
child: TextButton(
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),
child: Text(
context.l10n.importMedia,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
],
);
},
),
),
],
),
),
),
_filterControls ??= row(
@@ -206,7 +258,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
),
const SizedBox(width: AppSpacing.tiny),
const Icon(
Icons.keyboard_arrow_down,
AppIcons.expandMore,
size: AppIconSize.header,
),
],
@@ -224,7 +276,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
key: const Key('media-layout-toggle'),
onPressed: onToggleGrid,
icon: Icon(
grid ? Icons.view_list_outlined : Icons.grid_view_outlined,
grid ? AppIcons.listView : AppIcons.gridView,
size: AppIconSize.header,
),
tooltip: grid
@@ -238,4 +290,314 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
],
);
}
Widget _desktopToolbar(BuildContext context, RecentProject? selected) {
Widget category() => Semantics(
label: context.l10n.mediaCategory,
child: AppDropdownMenu(
items: [
for (final option in MediaFilter.values)
AppMenuItem(
key: ValueKey('media-filter-${option.name}'),
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 Icon(AppIcons.expandMore, size: 16),
],
),
),
),
);
String sortLabel(MediaSort value) => switch (value) {
MediaSort.importOrder => context.l10n.mediaSortImportOrder,
MediaSort.nameAscending => context.l10n.mediaSortNameAscending,
MediaSort.nameDescending => context.l10n.mediaSortNameDescending,
};
return Column(
key: const Key('media-panel-header'),
mainAxisSize: MainAxisSize.min,
children: [
if (widget.projectScoped)
ResourceSectionTabs(
selected: widget.resourceSection,
onSelected: widget.onResourceSectionChanged,
)
else
SizedBox(
key: const Key('media-project-row'),
height: 36,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: LayoutBuilder(
builder: (context, constraints) => 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 Icon(AppIcons.expandMore, size: 16),
],
),
),
),
),
const SizedBox(width: 4),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: (constraints.maxWidth * .45).clamp(
28,
double.infinity,
),
),
child: SizedBox(
height: 28,
child: Tooltip(
message: context.l10n.importMedia,
child: TextButton(
key: const Key('media-import-button'),
style: AppTheme.toolbarButtonStyle(context),
onPressed: canImport ? onImport : null,
child: Text(
context.l10n.importMedia,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
),
),
],
),
),
),
),
if (!widget.projectScoped ||
widget.resourceSection == ResourceSection.imported)
_filterControls ??= _desktopControls(context, category, sortLabel),
],
);
}
Widget _desktopControls(
BuildContext context,
Widget Function() category,
String Function(MediaSort) sortLabel,
) {
List<Widget> sortItems() => [
for (final value in MediaSort.values)
AppMenuItem(
key: ValueKey('media-sort-${value.name}'),
label: sortLabel(value),
selected: widget.sort == value,
selectOption: true,
onPressed: widget.onSortChanged == null
? null
: () => widget.onSortChanged!(value),
),
];
String sizeLabel(MediaGridSize value) => switch (value) {
MediaGridSize.small => context.l10n.mediaThumbnailSmall,
MediaGridSize.medium => context.l10n.mediaThumbnailMedium,
MediaGridSize.large => context.l10n.mediaThumbnailLarge,
};
List<Widget> sizeItems() => [
for (final value in MediaGridSize.values)
AppMenuItem(
key: ValueKey('media-size-${value.name}'),
label: sizeLabel(value),
selected: widget.gridSize == value,
selectOption: true,
onPressed: !grid || widget.onGridSizeChanged == null
? null
: () => widget.onGridSizeChanged!(value),
),
];
Widget menuButton({
required Key key,
required String tooltip,
required IconData icon,
required List<Widget> items,
}) => SizedBox.square(
dimension: 28,
child: AppDropdownMenu(
items: items,
builder: (context, toggle, focus) => IconButton(
key: key,
focusNode: focus,
tooltip: tooltip,
onPressed: toggle,
padding: EdgeInsets.zero,
icon: Icon(icon, size: 16),
),
),
);
return SizedBox(
key: const Key('media-filter-row'),
height: 40,
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 12, 4),
child: LayoutBuilder(
builder: (context, constraints) {
final wide = constraints.maxWidth >= 400;
return Row(
children: [
Expanded(
child: TextField(
key: const Key('media-search'),
controller: _search,
enabled: widget.onQueryChanged != null,
style: AppTheme.inputTextStyle(
context,
style: AppTheme.toolbarTextStyle(context),
),
cursorHeight: AppTheme.inputCursorHeight(
context,
style: AppTheme.toolbarTextStyle(context),
),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
hintText: context.l10n.searchOptions(
context.l10n.materials,
),
hintStyle: AppTheme.inputHintStyle(
context,
style: AppTheme.toolbarTextStyle(context),
),
isDense: true,
constraints: const BoxConstraints(minHeight: 32),
contentPadding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
prefixIcon: constraints.maxWidth < 160
? null
: const Icon(AppIcons.search, size: 16),
prefixIconConstraints: const BoxConstraints(
minWidth: 28,
minHeight: 28,
),
),
onChanged: (value) => widget.onQueryChanged?.call(value),
),
),
const SizedBox(width: 4),
if (wide) ...[
SizedBox(width: 88, height: 28, child: category()),
const SizedBox(width: 4),
menuButton(
key: const Key('media-sort-button'),
tooltip: context.l10n.sortMedia,
icon: AppIcons.sort,
items: sortItems(),
),
const SizedBox(width: 4),
menuButton(
key: const Key('media-size-button'),
tooltip: context.l10n.mediaThumbnailSize,
icon: AppIcons.gridView,
items: sizeItems(),
),
] else
menuButton(
key: const Key('media-category-button'),
tooltip: MaterialLocalizations.of(context).showMenuTooltip,
icon: AppIcons.more,
items: [
AppMenuLabel(context.l10n.mediaCategory),
for (final option in MediaFilter.values)
AppMenuItem(
key: ValueKey('media-filter-${option.name}'),
label: option.label(context),
selected: option == filter,
selectOption: true,
onPressed: () => onFilterChanged(option),
),
const AppMenuSeparator(),
AppMenuLabel(context.l10n.sortMedia),
...sortItems(),
const AppMenuSeparator(),
AppMenuLabel(context.l10n.mediaThumbnailSize),
...sizeItems(),
],
),
const SizedBox(width: 4),
SizedBox.square(
dimension: 28,
child: IconButton(
key: const Key('media-layout-toggle'),
onPressed: onToggleGrid,
padding: EdgeInsets.zero,
icon: Icon(
grid ? AppIcons.listView : AppIcons.gridView,
size: 16,
),
tooltip: grid
? context.l10n.listLayout
: context.l10n.gridLayout,
),
),
if (widget.projectScoped) ...[
const SizedBox(width: 4),
SizedBox.square(
dimension: 28,
child: IconButton(
key: const Key('media-import-button'),
onPressed: canImport ? () => onImport() : null,
tooltip: context.l10n.importMedia,
padding: EdgeInsets.zero,
icon: const Icon(AppIcons.add, size: 16),
),
),
],
],
);
},
),
),
);
}
}