feat(workspace): refresh desktop editing experience and prepare 0.1.2
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

This commit is contained in:
lingjhf committed 2026-10-09 01:56:01 +08:00
1 parent aa5255d1e4
commit 2e0033ce2d
260 files changed
+43963 -5591

No files matched your search

+65 -17
View File
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:collection';
import 'package:cutdex_ui/icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -8,9 +9,24 @@ import '../../errors/app_failure.dart';
import '../../l10n/l10n.dart';
class ErrorNotification {
const ErrorNotification({required this.content, this.details});
const ErrorNotification({required this.content, this.details})
: isError = true,
actionLabel = null,
onAction = null;
const ErrorNotification.message({
required this.content,
this.actionLabel,
this.onAction,
}) : assert((actionLabel == null) == (onAction == null)),
details = null,
isError = false;
final Widget content;
final String? details;
final bool isError;
final String? actionLabel;
final VoidCallback? onAction;
String get copyText {
String textOf(Widget widget) {
@@ -33,7 +49,7 @@ class ErrorNotification {
}
}
/// One error queue above navigation and dialogs, independent of local scaffolds.
/// One notification queue above navigation and dialogs, independent of scaffolds.
class ErrorNotificationHost extends StatefulWidget {
const ErrorNotificationHost({super.key, required this.child});
final Widget child;
@@ -61,6 +77,18 @@ class ErrorNotificationHostState extends State<ErrorNotificationHost> {
if (_current == null) _next();
}
void showMessage({
required Widget content,
String? actionLabel,
VoidCallback? onAction,
}) => show(
ErrorNotification.message(
content: content,
actionLabel: actionLabel,
onAction: onAction,
),
);
void showFailure(AppFailure failure, String message) => show(
ErrorNotification(
content: Text(message),
@@ -75,7 +103,7 @@ class ErrorNotificationHostState extends State<ErrorNotificationHost> {
void _startTimer() {
_timer?.cancel();
if (_current != null && !_hovered) {
_timer = Timer(const Duration(seconds: 8), dismiss);
_timer = Timer(Duration(seconds: _current!.isError ? 8 : 4), dismiss);
}
}
@@ -83,6 +111,7 @@ class ErrorNotificationHostState extends State<ErrorNotificationHost> {
setState(() {
_current = _pending.isEmpty ? null : _pending.removeFirst();
_copied = false;
_hovered = false;
});
_startTimer();
}
@@ -146,7 +175,11 @@ class ErrorNotificationHostState extends State<ErrorNotificationHost> {
_startTimer();
},
child: Material(
key: const Key('global-error-notification'),
key: Key(
current.isError
? 'global-error-notification'
: 'global-message-notification',
),
elevation: 8,
color: Theme.of(context).colorScheme.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
@@ -160,8 +193,10 @@ class ErrorNotificationHostState extends State<ErrorNotificationHost> {
child: Row(
children: [
Icon(
Icons.error_outline,
color: Theme.of(context).colorScheme.error,
current.isError ? AppIcons.error : AppIcons.success,
color: current.isError
? Theme.of(context).colorScheme.error
: Theme.of(context).colorScheme.primary,
size: 20,
),
const SizedBox(width: 8),
@@ -173,22 +208,35 @@ class ErrorNotificationHostState extends State<ErrorNotificationHost> {
),
),
),
IconButton(
key: const Key('copy-error-button'),
tooltip: MaterialLocalizations.of(context)
.copyButtonLabel,
onPressed: _copy,
icon: Icon(
_copied ? Icons.check : Icons.copy,
size: 18,
if (current.actionLabel case final label?)
TextButton(
onPressed: () {
dismiss();
current.onAction!();
},
child: Text(label),
),
if (current.isError)
IconButton(
key: const Key('copy-error-button'),
tooltip: MaterialLocalizations.of(context)
.copyButtonLabel,
onPressed: _copy,
icon: Icon(
_copied ? AppIcons.check : AppIcons.copy,
size: 18,
),
),
),
IconButton(
key: const Key('close-error-button'),
key: Key(
current.isError
? 'close-error-button'
: 'close-message-button',
),
tooltip: MaterialLocalizations.of(context)
.closeButtonTooltip,
onPressed: dismiss,
icon: const Icon(Icons.close, size: 18),
icon: const Icon(AppIcons.close, size: 18),
),
],
),
+54 -5
View File
@@ -7,8 +7,11 @@ class ListenableSelector<T> extends StatefulWidget {
required this.listenable,
required this.select,
required this.builder,
this.pauseWhenHidden = true,
});
/// Hidden presentation pauses observation, while its owner continues work.
final bool pauseWhenHidden;
final Listenable? listenable;
final T Function() select;
final Widget Function(BuildContext context, T value) builder;
@@ -19,36 +22,82 @@ class ListenableSelector<T> extends StatefulWidget {
class _ListenableSelectorState<T> extends State<ListenableSelector<T>> {
late T _value;
bool _listening = false;
bool _visible = true;
bool _active = true;
@override
void initState() {
super.initState();
_value = widget.select();
widget.listenable?.addListener(_changed);
_syncListener();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_visible = !widget.pauseWhenHidden || TickerMode.valuesOf(context).enabled;
if (!_active) return;
_syncListener();
_value = widget.select();
}
void _syncListener() {
final observe = _active && _visible && widget.listenable != null;
if (observe == _listening) return;
_listening = observe;
if (observe) {
widget.listenable!.addListener(_changed);
} else {
widget.listenable?.removeListener(_changed);
}
}
@override
void didUpdateWidget(covariant ListenableSelector<T> oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.listenable != widget.listenable) {
oldWidget.listenable?.removeListener(_changed);
widget.listenable?.addListener(_changed);
if (_listening) oldWidget.listenable?.removeListener(_changed);
_listening = false;
}
_visible = !widget.pauseWhenHidden || TickerMode.valuesOf(context).enabled;
if (!_active) return;
_syncListener();
_value = widget.select();
}
void _changed() {
if (!_active || !_listening) return;
final value = widget.select();
if (value == _value) return;
setState(() => _value = value);
}
@override
Widget build(BuildContext context) => widget.builder(context, _value);
Widget build(BuildContext context) {
if (!_active) {
// GlobalKey activation precedes installation of the new widget. Resume
// here, once select is bound to the current owner rather than the old one.
_active = true;
_value = widget.select();
_syncListener();
}
return widget.builder(context, _value);
}
@override
void deactivate() {
// Replacement widgets can notify before the old subtree is disposed.
// Its selector may read an owner's context/ref, which is already inactive.
_active = false;
_syncListener();
super.deactivate();
}
@override
void dispose() {
widget.listenable?.removeListener(_changed);
_active = false;
_syncListener();
super.dispose();
}
}
+18
View File
@@ -0,0 +1,18 @@
import 'package:flutter/foundation.dart';
/// Immutable list value for selecting membership/order separately from updates.
@immutable
class PresentationList<T> extends Iterable<T> {
PresentationList(Iterable<T> values) : _values = List<T>.unmodifiable(values);
final List<T> _values;
@override
Iterator<T> get iterator => _values.iterator;
@override
bool operator ==(Object other) =>
other is PresentationList<T> && listEquals(_values, other._values);
@override
int get hashCode => Object.hashAll(_values);
}
+1 -1
View File
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
class WorkspaceCard extends StatefulWidget {
const WorkspaceCard({super.key, required this.child});
static const radius = 12.0;
static const radius = 8.0;
static const borderWidth = 1.0;
final Widget child;
@@ -9,12 +9,14 @@ class WorkspaceResizeHandle extends StatefulWidget {
required this.initialValue,
required this.onResize,
this.direction = 1,
this.onStart,
this.onEnd,
});
final Axis axis;
final double initialValue;
final double direction;
final VoidCallback? onStart;
final ValueChanged<double> onResize;
final VoidCallback? onEnd;
@@ -37,6 +39,7 @@ class _WorkspaceResizeHandleState extends State<WorkspaceResizeHandle> {
void _start(DragStartDetails details) {
_startPosition = _coordinate(details.globalPosition);
_startValue = widget.initialValue;
widget.onStart?.call();
_releaseCursor();
final cursor = _cursor;
_cursorOverlay = OverlayEntry(