1
This commit is contained in:
1 parent
5efc778165
commit
59125d185c
64 files changed
+7912
-1393
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/services/permission_service.dart';
|
||||
import 'package:code_editor/views/terminal_view.dart';
|
||||
import 'package:code_editor/widgets/terminal_entry_guard.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@@ -327,7 +328,14 @@ class _MoreMenuButtonState extends State<_MoreMenuButton> with SingleTickerProvi
|
||||
title: l10n.terminal,
|
||||
iconColor: onSurfaceColor,
|
||||
onTap: () {
|
||||
_closeMenu(onClosed: widget.onTerminal);
|
||||
_closeMenu(onClosed: () async {
|
||||
// 探测进行中:先提示(探测与终端共用同一个容器,可能互相阻塞)
|
||||
if (widget.isDetecting) {
|
||||
final proceed = await confirmEnterTerminalWhileProbing(context);
|
||||
if (!proceed) return;
|
||||
}
|
||||
widget.onTerminal?.call();
|
||||
});
|
||||
},
|
||||
),
|
||||
Divider(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/providers/distro_provider.dart';
|
||||
import 'package:code_editor/providers/project_provider.dart';
|
||||
import 'package:code_editor/providers/run_provider.dart';
|
||||
import 'package:code_editor/providers/tab_provider.dart';
|
||||
@@ -8,6 +9,7 @@ import 'package:code_editor/utils/dialog_utils.dart';
|
||||
import 'package:code_editor/views/project_management_view.dart';
|
||||
import 'package:code_editor/widgets/project_history_widget.dart';
|
||||
import 'package:code_editor/widgets/file_tree_widget.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -92,6 +94,38 @@ class CodeEditorDrawer extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleImportFiles(BuildContext context, String rootPath) async {
|
||||
final hasPermission = await PermissionService.instance
|
||||
.ensureStoragePermission(context: context);
|
||||
if (!hasPermission || !context.mounted) return;
|
||||
|
||||
final l10n = AppLocalizations.of(context);
|
||||
try {
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
allowMultiple: true,
|
||||
);
|
||||
if (result == null || result.files.isEmpty || !context.mounted) return;
|
||||
|
||||
final count = await _getProjectProvider(context).importFiles(
|
||||
rootPath,
|
||||
result.files,
|
||||
);
|
||||
if (context.mounted && count > 0) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n?.importFilesSuccess(count) ?? '成功导入 $count 个文件',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n?.importFilesFailed(e.toString()) ?? '导入文件失败: $e',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
@@ -132,7 +166,11 @@ class CodeEditorDrawer extends StatelessWidget {
|
||||
final runProvider = context.read<RunProvider?>();
|
||||
final root = _getProjectProvider(context).rootPath;
|
||||
if (root != null && root.isNotEmpty) {
|
||||
runProvider?.onProjectOpened(root);
|
||||
// 传入当前真实选中的系统,无系统时不进行任何任务探测
|
||||
runProvider?.onProjectOpened(
|
||||
root,
|
||||
systemName: context.read<DistroProvider?>()?.selectedSystem,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -223,33 +261,59 @@ class CodeEditorDrawer extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
if (hasProject) ...[
|
||||
const SizedBox(width: 8),
|
||||
const SizedBox(width: 6),
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 18,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 28,
|
||||
minHeight: 28,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(3),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
iconSize: 18,
|
||||
icon: const Icon(Icons.note_add_outlined),
|
||||
tooltip: l10n.newFile,
|
||||
onPressed: () => _handleNewFile(context, rootPath),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const SizedBox(width: 2),
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 18,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 28,
|
||||
minHeight: 28,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(3),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
iconSize: 18,
|
||||
icon: const Icon(Icons.create_new_folder_outlined),
|
||||
tooltip: l10n.newFolder,
|
||||
onPressed: () =>
|
||||
_handleNewFolder(context, rootPath),
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
style: IconButton.styleFrom(
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
minimumSize: Size.zero,
|
||||
padding: const EdgeInsets.all(3),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
iconSize: 18,
|
||||
icon: const Icon(Icons.file_upload_outlined),
|
||||
tooltip: l10n.importFromExternal,
|
||||
onPressed: () =>
|
||||
_handleImportFiles(context, rootPath),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
@@ -66,8 +66,63 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
Offset? _currentLocalFocal;
|
||||
double _initialScrollV = 0.0;
|
||||
double _initialScrollH = 0.0;
|
||||
double _focalLineContinuous = 0.0;
|
||||
double _focalCharContinuous = 0.0;
|
||||
|
||||
void _handlePointerDown(PointerDownEvent event, double currentFontSize) {
|
||||
final Map<String, double> _lineHeightCache = {};
|
||||
final Map<String, double> _charWidthCache = {};
|
||||
|
||||
double getLineHeight(double fontSize, String? fontFamily, List<String>? fallback) {
|
||||
final key = '$fontSize-$fontFamily-${fallback?.join(',')}';
|
||||
if (_lineHeightCache.containsKey(key)) {
|
||||
return _lineHeightCache[key]!;
|
||||
}
|
||||
final painter = TextPainter(
|
||||
textDirection: TextDirection.ltr,
|
||||
strutStyle: StrutStyle(
|
||||
fontSize: fontSize,
|
||||
fontFamily: fontFamily,
|
||||
fontFamilyFallback: fallback,
|
||||
height: 1.4,
|
||||
forceStrutHeight: true,
|
||||
),
|
||||
text: TextSpan(
|
||||
text: '0',
|
||||
style: TextStyle(
|
||||
fontSize: fontSize,
|
||||
fontFamily: fontFamily,
|
||||
fontFamilyFallback: fallback,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
)..layout();
|
||||
final h = painter.preferredLineHeight;
|
||||
_lineHeightCache[key] = h;
|
||||
return h;
|
||||
}
|
||||
|
||||
double getCharWidth(double fontSize, String? fontFamily, List<String>? fallback) {
|
||||
final key = '$fontSize-$fontFamily-${fallback?.join(',')}';
|
||||
if (_charWidthCache.containsKey(key)) {
|
||||
return _charWidthCache[key]!;
|
||||
}
|
||||
final painter = TextPainter(
|
||||
textDirection: TextDirection.ltr,
|
||||
text: TextSpan(
|
||||
text: '0',
|
||||
style: TextStyle(
|
||||
fontSize: fontSize,
|
||||
fontFamily: fontFamily,
|
||||
fontFamilyFallback: fallback,
|
||||
),
|
||||
),
|
||||
)..layout();
|
||||
final w = painter.width;
|
||||
_charWidthCache[key] = w;
|
||||
return w;
|
||||
}
|
||||
|
||||
void _handlePointerDown(PointerDownEvent event, double currentFontSize, AppFontItem activeEditorFont) {
|
||||
_pointerPositions[event.pointer] = event.position;
|
||||
if (_pointerPositions.length >= 2 && !_isPinching) {
|
||||
final keys = _pointerPositions.keys.toList();
|
||||
@@ -104,6 +159,12 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
? _scrollController!.horizontalScroller.offset
|
||||
: 0.0;
|
||||
|
||||
final startH = getLineHeight(_initialPinchFontSize!, activeEditorFont.fontFamily, activeEditorFont.fallback);
|
||||
final startW = getCharWidth(_initialPinchFontSize!, activeEditorFont.fontFamily, activeEditorFont.fallback);
|
||||
|
||||
_focalLineContinuous = (_initialScrollV + localFocal.dy) / max(1.0, startH);
|
||||
_focalCharContinuous = (_initialScrollH + localFocal.dx) / max(1.0, startW);
|
||||
|
||||
final currentController = _controller;
|
||||
if (currentController != null &&
|
||||
!currentController.selection.isCollapsed &&
|
||||
@@ -148,25 +209,33 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
: currentGlobalFocal;
|
||||
_currentLocalFocal = currentLocalFocal;
|
||||
|
||||
// 连续高精度浮点字号(避免 0.1 离散跳变造成的阶梯式顿挫)
|
||||
final continuousFontSize = ((_initialPinchFontSize! * clampedScale) * 100).round() / 100.0;
|
||||
final continuousFontSize = ((_initialPinchFontSize! * clampedScale) * 10).round() / 10.0;
|
||||
final newFontSize = continuousFontSize.clamp(10.0, 30.0);
|
||||
final fontRatio = newFontSize / _initialPinchFontSize!;
|
||||
|
||||
// 焦心连续锚定公式:保持手指焦心下的代码行与手指相对位置绝对静止
|
||||
final targetScrollV = (_initialScrollV + _initialLocalFocal!.dy) * fontRatio - currentLocalFocal.dy;
|
||||
final targetScrollH = (_initialScrollH + _initialLocalFocal!.dx) * fontRatio - currentLocalFocal.dx;
|
||||
AppFontItem activeEditorFont = AppFonts.editorJetBrainsMono;
|
||||
try {
|
||||
activeEditorFont = _getSettingsProvider(context).editorFont;
|
||||
} catch (_) {}
|
||||
|
||||
final newH = getLineHeight(newFontSize, activeEditorFont.fontFamily, activeEditorFont.fallback);
|
||||
final newW = getCharWidth(newFontSize, activeEditorFont.fontFamily, activeEditorFont.fallback);
|
||||
|
||||
final targetScrollV = _focalLineContinuous * newH - currentLocalFocal.dy;
|
||||
final targetScrollH = _focalCharContinuous * newW - currentLocalFocal.dx;
|
||||
|
||||
if (_scrollController?.verticalScroller.hasClients == true) {
|
||||
final pos = _scrollController!.verticalScroller.position;
|
||||
final maxV = max(0.0, pos.maxScrollExtent);
|
||||
final clampedV = targetScrollV.clamp(0.0, maxV);
|
||||
final totalLines = _controller?.lineCount ?? 1;
|
||||
final viewportHeight = renderBox?.size.height ?? 500.0;
|
||||
final computedMaxV = max(0.0, totalLines * newH + viewportHeight * 0.5 - viewportHeight);
|
||||
final maxV = max(computedMaxV, pos.maxScrollExtent);
|
||||
final clampedV = targetScrollV.clamp(0.0, maxV).toDouble();
|
||||
_scrollController!.verticalScroller.jumpTo(clampedV);
|
||||
}
|
||||
if (_scrollController?.horizontalScroller.hasClients == true) {
|
||||
final pos = _scrollController!.horizontalScroller.position;
|
||||
final maxH = max(0.0, pos.maxScrollExtent);
|
||||
final clampedH = targetScrollH.clamp(0.0, maxH);
|
||||
final clampedH = targetScrollH.clamp(0.0, max(maxH, targetScrollH)).toDouble();
|
||||
_scrollController!.horizontalScroller.jumpTo(clampedH);
|
||||
}
|
||||
|
||||
@@ -217,32 +286,38 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
final initialFontSize = _initialPinchFontSize;
|
||||
final initialLocalFocal = _initialLocalFocal;
|
||||
final currentLocalFocal = _currentLocalFocal ?? initialLocalFocal;
|
||||
final initialScrollV = _initialScrollV;
|
||||
final initialScrollH = _initialScrollH;
|
||||
|
||||
if (finalSize != null && initialFontSize != null && initialLocalFocal != null && currentLocalFocal != null) {
|
||||
// 手势释放后定格为整数(如 16.0),持久化到用户设置
|
||||
final double targetFontSize = finalSize.clamp(10.0, 30.0).roundToDouble();
|
||||
final double fontRatio = targetFontSize / initialFontSize;
|
||||
|
||||
final targetScrollV = (initialScrollV + initialLocalFocal.dy) * fontRatio - currentLocalFocal.dy;
|
||||
final targetScrollH = (initialScrollH + initialLocalFocal.dx) * fontRatio - currentLocalFocal.dx;
|
||||
|
||||
AppFontItem activeEditorFont = AppFonts.editorJetBrainsMono;
|
||||
try {
|
||||
final settings = _getSettingsProvider(context);
|
||||
activeEditorFont = settings.editorFont;
|
||||
settings.setFontSize(targetFontSize);
|
||||
} catch (_) {}
|
||||
|
||||
final finalH = getLineHeight(targetFontSize, activeEditorFont.fontFamily, activeEditorFont.fallback);
|
||||
final finalW = getCharWidth(targetFontSize, activeEditorFont.fontFamily, activeEditorFont.fallback);
|
||||
|
||||
final targetScrollV = _focalLineContinuous * finalH - currentLocalFocal.dy;
|
||||
final targetScrollH = _focalCharContinuous * finalW - currentLocalFocal.dx;
|
||||
|
||||
if (_scrollController?.verticalScroller.hasClients == true) {
|
||||
final pos = _scrollController!.verticalScroller.position;
|
||||
final maxV = max(0.0, pos.maxScrollExtent);
|
||||
final clampedV = targetScrollV.clamp(0.0, maxV);
|
||||
final totalLines = _controller?.lineCount ?? 1;
|
||||
final renderBox = _editorContainerKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
final viewportHeight = renderBox?.size.height ?? 500.0;
|
||||
final computedMaxV = max(0.0, totalLines * finalH + viewportHeight * 0.5 - viewportHeight);
|
||||
final maxV = max(computedMaxV, pos.maxScrollExtent);
|
||||
final clampedV = targetScrollV.clamp(0.0, maxV).toDouble();
|
||||
_scrollController!.verticalScroller.jumpTo(clampedV);
|
||||
}
|
||||
if (_scrollController?.horizontalScroller.hasClients == true) {
|
||||
final pos = _scrollController!.horizontalScroller.position;
|
||||
final maxH = max(0.0, pos.maxScrollExtent);
|
||||
final clampedH = targetScrollH.clamp(0.0, maxH);
|
||||
final clampedH = targetScrollH.clamp(0.0, max(maxH, targetScrollH)).toDouble();
|
||||
_scrollController!.horizontalScroller.jumpTo(clampedH);
|
||||
}
|
||||
}
|
||||
@@ -258,6 +333,8 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
_currentLocalFocal = null;
|
||||
_initialScrollV = 0.0;
|
||||
_initialScrollH = 0.0;
|
||||
_focalLineContinuous = 0.0;
|
||||
_focalCharContinuous = 0.0;
|
||||
});
|
||||
|
||||
if (savedSelection != null && !savedSelection.isCollapsed) {
|
||||
@@ -601,7 +678,7 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
child: Listener(
|
||||
key: _editorContainerKey,
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (event) => _handlePointerDown(event, activeFontSize),
|
||||
onPointerDown: (event) => _handlePointerDown(event, activeFontSize, activeEditorFont),
|
||||
onPointerMove: _handlePointerMove,
|
||||
onPointerUp: _handlePointerUp,
|
||||
onPointerCancel: _handlePointerCancel,
|
||||
@@ -652,6 +729,7 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
fontSize: (displayFontSize - 1).clamp(9.0, 30.0),
|
||||
fontFamily: activeEditorFont.fontFamily,
|
||||
fontFamilyFallback: activeEditorFont.fallback,
|
||||
height: 1.4,
|
||||
),
|
||||
focusedTextStyle: TextStyle(
|
||||
color: activeTheme.focusedGutterTextColor,
|
||||
@@ -659,6 +737,7 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: activeEditorFont.fontFamily,
|
||||
fontFamilyFallback: activeEditorFont.fallback,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
DefaultCodeChunkIndicator(
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../models/notice_item.dart';
|
||||
import '../providers/notice_center.dart';
|
||||
import '../utils/notice_text_resolver.dart';
|
||||
|
||||
/// 通用「通知堆叠宿主」控件。
|
||||
///
|
||||
/// 把 [NoticeCenter] 里的可见通知渲染成一列卡片:
|
||||
/// * 每条卡片**带动画插入**(尺寸 + 淡入 + 从右侧滑入);
|
||||
/// * 支持同时插入多条(受 [NoticeCenter.visibleLimit] 限制,超出进入队列并显示折叠提示);
|
||||
/// * 任一卡片关闭时播放退场动画,动画结束后队列首条**自动弹出补位**,
|
||||
/// 并且下方卡片因外层 [SizeTransition] 而平滑上移。
|
||||
///
|
||||
/// 控件本身不关心业务:文案由 [resolveNoticeDisplay] 依据 l10n 解析,禁止硬编码。
|
||||
class NoticeHost extends StatelessWidget {
|
||||
final NoticeCenter center;
|
||||
|
||||
/// 停靠位置(默认编辑区右上角)
|
||||
final AlignmentGeometry alignment;
|
||||
|
||||
final EdgeInsets margin;
|
||||
|
||||
/// 单张卡片最大宽度(窄屏自适应)
|
||||
final double maxWidth;
|
||||
|
||||
final Duration insertDuration;
|
||||
final Duration removeDuration;
|
||||
|
||||
/// 破坏性通知([NoticeItem.confirmBeforeDismiss])关闭前的二次确认;
|
||||
/// 返回 false 表示用户放弃关闭(卡片保留,附带动作不执行)。
|
||||
final Future<bool> Function(BuildContext context)? confirmDismissBuilder;
|
||||
|
||||
const NoticeHost({
|
||||
super.key,
|
||||
required this.center,
|
||||
this.alignment = Alignment.topRight,
|
||||
this.margin = const EdgeInsets.only(top: 12, right: 12),
|
||||
this.maxWidth = 300,
|
||||
this.insertDuration = const Duration(milliseconds: 220),
|
||||
this.removeDuration = const Duration(milliseconds: 180),
|
||||
this.confirmDismissBuilder,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: center,
|
||||
builder: (context, _) {
|
||||
final visible = center.visible;
|
||||
final queuedCount = center.queued.length;
|
||||
if (visible.isEmpty && queuedCount == 0) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final l10n = AppLocalizations.of(context);
|
||||
return Align(
|
||||
alignment: alignment,
|
||||
child: Padding(
|
||||
padding: margin,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
for (final item in visible)
|
||||
_NoticeEntry(
|
||||
key: ValueKey<String>(item.id),
|
||||
item: item,
|
||||
removing: center.removingIds.contains(item.id),
|
||||
maxWidth: maxWidth,
|
||||
insertDuration: insertDuration,
|
||||
removeDuration: removeDuration,
|
||||
onDismiss: () async {
|
||||
// 破坏性操作:先二次确认;用户放弃则卡片保留、附加动作不执行
|
||||
if (item.confirmBeforeDismiss && confirmDismissBuilder != null) {
|
||||
final confirmed = await confirmDismissBuilder!(context);
|
||||
if (!confirmed) return;
|
||||
}
|
||||
// 用户点 × :先执行附加动作(如取消正在进行的探测),再移除卡片
|
||||
item.onUserDismiss?.call();
|
||||
center.dismiss(item.id);
|
||||
},
|
||||
onRemoved: () => center.finalizeDismiss(item.id),
|
||||
),
|
||||
if (queuedCount > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: _QueueBadge(
|
||||
label: l10n?.noticeQueueMore(queuedCount) ?? '+$queuedCount',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 单条通知:负责自身的插入/退场动画
|
||||
class _NoticeEntry extends StatefulWidget {
|
||||
final NoticeItem item;
|
||||
final bool removing;
|
||||
final double maxWidth;
|
||||
final Duration insertDuration;
|
||||
final Duration removeDuration;
|
||||
final VoidCallback onDismiss;
|
||||
final VoidCallback onRemoved;
|
||||
|
||||
const _NoticeEntry({
|
||||
super.key,
|
||||
required this.item,
|
||||
required this.removing,
|
||||
required this.maxWidth,
|
||||
required this.insertDuration,
|
||||
required this.removeDuration,
|
||||
required this.onDismiss,
|
||||
required this.onRemoved,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_NoticeEntry> createState() => _NoticeEntryState();
|
||||
}
|
||||
|
||||
class _NoticeEntryState extends State<_NoticeEntry> with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: widget.insertDuration,
|
||||
reverseDuration: widget.removeDuration,
|
||||
);
|
||||
|
||||
bool _removalNotified = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.forward();
|
||||
if (widget.removing) {
|
||||
_playRemoval();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(_NoticeEntry oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.removing && !oldWidget.removing) {
|
||||
_playRemoval();
|
||||
}
|
||||
}
|
||||
|
||||
void _playRemoval() {
|
||||
if (_removalNotified) return;
|
||||
_controller.reverse().whenComplete(() {
|
||||
if (!mounted || _removalNotified) return;
|
||||
_removalNotified = true;
|
||||
widget.onRemoved();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final curved = CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: Curves.easeOutCubic,
|
||||
reverseCurve: Curves.easeInCubic,
|
||||
);
|
||||
|
||||
return SizeTransition(
|
||||
sizeFactor: curved,
|
||||
alignment: Alignment.topRight,
|
||||
child: FadeTransition(
|
||||
opacity: curved,
|
||||
child: SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0.18, 0),
|
||||
end: Offset.zero,
|
||||
).animate(curved),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _NoticeCard(
|
||||
item: widget.item,
|
||||
maxWidth: widget.maxWidth,
|
||||
onDismiss: widget.onDismiss,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 单张通知卡片外观(与编辑器内"缩放字号胶囊"同一视觉语言)
|
||||
class _NoticeCard extends StatelessWidget {
|
||||
final NoticeItem item;
|
||||
final double maxWidth;
|
||||
final VoidCallback onDismiss;
|
||||
|
||||
const _NoticeCard({
|
||||
required this.item,
|
||||
required this.maxWidth,
|
||||
required this.onDismiss,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final display = l10n != null
|
||||
? resolveNoticeDisplay(l10n, item.text)
|
||||
: NoticeDisplay(title: item.text.runtimeType.toString());
|
||||
|
||||
final isSuccess = item.kind == NoticeKind.success;
|
||||
final isFailure = item.kind == NoticeKind.failure;
|
||||
|
||||
final (Color accent, Widget leading) = switch (item.kind) {
|
||||
NoticeKind.progress => (
|
||||
theme.colorScheme.primary,
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
value: item.progress,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
NoticeKind.success => (
|
||||
Colors.white,
|
||||
const Icon(Icons.check_circle_outline, size: 18, color: Colors.white),
|
||||
),
|
||||
NoticeKind.failure => (
|
||||
theme.colorScheme.error,
|
||||
Icon(Icons.error_outline, size: 18, color: theme.colorScheme.error),
|
||||
),
|
||||
NoticeKind.info => (
|
||||
theme.colorScheme.primary,
|
||||
Icon(Icons.info_outline, size: 18, color: theme.colorScheme.primary),
|
||||
),
|
||||
};
|
||||
|
||||
final cardBgColor = isSuccess
|
||||
? (theme.brightness == Brightness.dark
|
||||
? const Color(0xFF1E5E2F)
|
||||
: const Color(0xFF2E7D32))
|
||||
: theme.colorScheme.surfaceContainerHighest;
|
||||
|
||||
final cardBorder = isFailure
|
||||
? const BorderSide(color: Color(0xFFE53935), width: 1.5)
|
||||
: isSuccess
|
||||
? BorderSide(color: Colors.green.shade400.withValues(alpha: 0.6), width: 1)
|
||||
: BorderSide(color: theme.colorScheme.outlineVariant.withValues(alpha: 0.45), width: 1);
|
||||
|
||||
final titleColor = isSuccess ? Colors.white : theme.colorScheme.onSurface;
|
||||
final subtitleColor = isSuccess ? Colors.white70 : theme.colorScheme.onSurfaceVariant;
|
||||
final closeIconColor = isSuccess ? Colors.white70 : theme.colorScheme.onSurfaceVariant;
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: maxWidth),
|
||||
child: Material(
|
||||
elevation: 6,
|
||||
shadowColor: Colors.black38,
|
||||
color: cardBgColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
side: cardBorder,
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 4, 8),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
leading,
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
display.title,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: titleColor,
|
||||
),
|
||||
),
|
||||
if (display.subtitle != null && display.subtitle!.isNotEmpty) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
display.subtitle!,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: subtitleColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onDismiss,
|
||||
tooltip: l10n?.probeBannerClose,
|
||||
icon: const Icon(Icons.close, size: 16),
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: const EdgeInsets.all(4),
|
||||
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
|
||||
color: closeIconColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 队列折叠提示(还能看到"还有 N 项进行中")
|
||||
class _QueueBadge extends StatelessWidget {
|
||||
final String label;
|
||||
|
||||
const _QueueBadge({required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.9),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 11, color: theme.colorScheme.onSurfaceVariant),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
|
||||
/// 取消"正在进行的探测"前的二次确认。
|
||||
///
|
||||
/// 背景:探测会在容器里长时间运行(构建工具自省 + 依赖安装),一个误触就会把整轮
|
||||
/// 探测 kill 掉(已完成的模块结果保留,未完成的模块会被跳过)。因此 × 这类破坏性关闭
|
||||
/// 需要用户明确确认。
|
||||
///
|
||||
/// 返回 true = 确认取消(真的中止探测);false = 放弃取消(探测继续)。
|
||||
/// 点弹窗外部/返回键按"放弃取消"处理(保守:不打断正在跑的探测)。
|
||||
Future<bool> confirmCancelProbe(BuildContext context) async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
if (l10n == null) return false;
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.warning_amber_rounded, color: Colors.orange, size: 24),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.probeCancelConfirmTitle,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: Text(l10n.probeCancelConfirmMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: Text(l10n.probeKeepDetecting),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
icon: const Icon(Icons.stop_circle_outlined, size: 18),
|
||||
label: Text(l10n.cancelProbe),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return confirmed ?? false;
|
||||
}
|
||||
+135
-106
@@ -1,7 +1,9 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../models/project_task_table.dart';
|
||||
import '../models/run_task.dart';
|
||||
import '../models/run_task_type.dart';
|
||||
import '../providers/run_provider.dart';
|
||||
|
||||
/// 运行任务选择弹窗(带顶部搜索栏、区分系统探测与自定义任务、支持模块深度重新同步、点击直接调度执行)
|
||||
@@ -54,9 +56,17 @@ class RunTasksDialog extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
/// 内存中持久化各类型任务段的折叠状态(生命周期内常驻,不写磁盘)
|
||||
static final Set<RunTaskType> _collapsedTypes = <RunTaskType>{};
|
||||
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
String _searchQuery = '';
|
||||
|
||||
bool _isCollapsed(RunTaskType type) {
|
||||
if (_searchQuery.isNotEmpty) return false;
|
||||
return _collapsedTypes.contains(type);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -96,22 +106,28 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
runProvider = Provider.of<RunProvider>(context);
|
||||
} catch (_) {}
|
||||
|
||||
final effectiveCustomTasks = runProvider?.customTasks ?? widget.customTasks;
|
||||
final effectiveDetectedTasks = runProvider?.detectedTasks ?? widget.detectedTasks;
|
||||
final effectiveLastRunTaskId = runProvider?.lastRunTaskId ?? widget.lastRunTaskId;
|
||||
|
||||
final filteredCustom = effectiveCustomTasks.where((t) => _matchesQuery(t, l10n)).toList();
|
||||
final filteredDetected = effectiveDetectedTasks.where((t) => _matchesQuery(t, l10n)).toList();
|
||||
final hasAny = filteredCustom.isNotEmpty || filteredDetected.isNotEmpty;
|
||||
// 类型 → 任务数组:优先取 Provider 的当前工程内存表;
|
||||
// 无 Provider(独立使用弹窗/单测)时按同构结构由入参临时组装。
|
||||
final ProjectTaskTable table;
|
||||
if (runProvider != null) {
|
||||
table = runProvider.taskTable;
|
||||
} else {
|
||||
table = ProjectTaskTable()..setUserTasks(widget.customTasks);
|
||||
for (final task in widget.detectedTasks) {
|
||||
final type = RunTaskType.ofTask(task);
|
||||
table.replaceType(type, [...table.tasksOf(type), task]);
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否存在 Gradle 模块任务
|
||||
final hasGradleTasks = filteredDetected.any(
|
||||
(t) => t.moduleId == 'gradle' || t.id.startsWith('gradle_') || t.id.startsWith('detected_gradle_'),
|
||||
);
|
||||
|
||||
final isGradleSyncing = (widget.isSyncingModule != null)
|
||||
? widget.isSyncingModule!('gradle')
|
||||
: (runProvider?.isModuleSyncing('gradle') ?? false);
|
||||
// 按类型过滤(搜索命中),保留非空类型的顺序
|
||||
final sections = <({RunTaskType type, List<RunTask> tasks})>[];
|
||||
for (final type in RunTaskType.values) {
|
||||
final tasks = table.tasksOf(type).where((t) => _matchesQuery(t, l10n)).toList();
|
||||
if (tasks.isNotEmpty) sections.add((type: type, tasks: tasks));
|
||||
}
|
||||
final hasAny = sections.isNotEmpty;
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
@@ -179,27 +195,31 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
)
|
||||
: ListView(
|
||||
children: [
|
||||
if (filteredDetected.isNotEmpty) ...[
|
||||
// 任务类型 → 具体任务:每个类型为独立折叠 Tile(折叠状态内存常驻)
|
||||
for (final section in sections) ...[
|
||||
_buildSectionHeader(
|
||||
context,
|
||||
l10n.systemDetectedTasks,
|
||||
Icons.radar_outlined,
|
||||
trailing: hasGradleTasks
|
||||
? _buildGradleSyncAction(context, l10n, isGradleSyncing, () {
|
||||
if (widget.onSyncModule != null) {
|
||||
widget.onSyncModule!('gradle');
|
||||
} else {
|
||||
runProvider?.syncModuleTasks('gradle');
|
||||
}
|
||||
})
|
||||
: null,
|
||||
section.type,
|
||||
_typeLabel(l10n, section.type, runProvider),
|
||||
_typeIcon(section.type),
|
||||
section.tasks.length,
|
||||
_isCollapsed(section.type),
|
||||
() {
|
||||
setState(() {
|
||||
if (_collapsedTypes.contains(section.type)) {
|
||||
_collapsedTypes.remove(section.type);
|
||||
} else {
|
||||
_collapsedTypes.add(section.type);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
...filteredDetected.map((task) => _buildTaskItem(context, task, l10n, effectiveLastRunTaskId)),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
if (filteredCustom.isNotEmpty) ...[
|
||||
_buildSectionHeader(context, l10n.userCustomTasks, Icons.person_outline),
|
||||
...filteredCustom.map((task) => _buildTaskItem(context, task, l10n, effectiveLastRunTaskId)),
|
||||
if (!_isCollapsed(section.type)) ...[
|
||||
...section.tasks.map(
|
||||
(task) => _buildTaskItem(context, task, l10n, effectiveLastRunTaskId),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 6),
|
||||
],
|
||||
],
|
||||
),
|
||||
@@ -211,88 +231,91 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGradleSyncAction(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
bool isSyncing,
|
||||
VoidCallback onSync,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
if (isSyncing) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
l10n.syncingTasks,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
/// 任务类型展示名:模块类型用专有名词(取自模块 displayName),单文件/用户任务走 l10n
|
||||
String _typeLabel(AppLocalizations l10n, RunTaskType type, RunProvider? runProvider) {
|
||||
final moduleId = type.moduleId;
|
||||
if (moduleId == null) {
|
||||
return switch (type) {
|
||||
RunTaskType.singleFile => l10n.taskTypeSingleFile,
|
||||
RunTaskType.user => l10n.userCustomTasks,
|
||||
RunTaskType.other => l10n.taskTypeOther,
|
||||
_ => type.name,
|
||||
};
|
||||
}
|
||||
return runProvider?.moduleDisplayName(moduleId) ?? _moduleLabel(type);
|
||||
}
|
||||
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: onSync,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.refresh, size: 14, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
l10n.resyncModuleTasks,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
/// 模块类型专有名词(Gradle / CMake / …)
|
||||
String _moduleLabel(RunTaskType type) {
|
||||
final moduleId = type.moduleId;
|
||||
if (moduleId == null) return type.name;
|
||||
return moduleId[0].toUpperCase() + moduleId.substring(1);
|
||||
}
|
||||
|
||||
IconData _typeIcon(RunTaskType type) {
|
||||
return switch (type) {
|
||||
RunTaskType.user => Icons.person_outline,
|
||||
RunTaskType.singleFile => Icons.description_outlined,
|
||||
RunTaskType.other => Icons.category_outlined,
|
||||
_ => Icons.radar_outlined,
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(
|
||||
BuildContext context,
|
||||
RunTaskType type,
|
||||
String title,
|
||||
IconData icon, {
|
||||
Widget? trailing,
|
||||
}) {
|
||||
IconData icon,
|
||||
int count,
|
||||
bool isCollapsed,
|
||||
VoidCallback onToggle,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: onToggle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primaryContainer.withValues(alpha: 0.5),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'$count',
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (trailing != null) trailing,
|
||||
],
|
||||
Icon(
|
||||
isCollapsed ? Icons.expand_more : Icons.expand_less,
|
||||
size: 18,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -322,11 +345,14 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
child: ListTile(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
dense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 2),
|
||||
title: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.getLocalizedName(l10n),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isLastRun ? Colors.green.shade700 : null,
|
||||
@@ -335,7 +361,8 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
),
|
||||
if (task.group != null && task.group!.isNotEmpty && task.group != 'single_file')
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 6),
|
||||
margin: const EdgeInsets.only(left: 8),
|
||||
constraints: const BoxConstraints(maxWidth: 130),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1.5),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.secondaryContainer.withValues(alpha: 0.6),
|
||||
@@ -343,6 +370,8 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
),
|
||||
child: Text(
|
||||
task.group!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -378,12 +407,12 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
)
|
||||
: null,
|
||||
trailing: CircleAvatar(
|
||||
radius: 16,
|
||||
radius: 15,
|
||||
backgroundColor: isLastRun
|
||||
? Colors.green.withValues(alpha: 0.25)
|
||||
: theme.colorScheme.primaryContainer,
|
||||
foregroundColor: isLastRun ? Colors.green : theme.colorScheme.onPrimaryContainer,
|
||||
child: const Icon(Icons.play_arrow, size: 20),
|
||||
child: const Icon(Icons.play_arrow, size: 18),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
|
||||
/// 「进入终端」前的探测占用确认。
|
||||
///
|
||||
/// 背景:任务探测会占用当前容器执行构建工具自省与依赖自动安装;此时进入终端并在里面
|
||||
/// 做安装软件包、构建等操作,可能与探测互相阻塞(包管理器锁、构建缓存写冲突)或产生异常。
|
||||
/// 因此主页面「更多 → 终端」入口在探测进行中时先弹提示,由用户决定是否仍进入。
|
||||
///
|
||||
/// 返回 true = 继续进入终端;false = 取消(不进入)。
|
||||
/// 点弹窗外部/返回键同样按"取消"处理(保守策略:不进入)。
|
||||
Future<bool> confirmEnterTerminalWhileProbing(BuildContext context) async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
if (l10n == null) return true;
|
||||
|
||||
final result = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.hourglass_top_rounded, color: Colors.orange, size: 24),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.probeBusyEnterTerminalTitle,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: Text(l10n.probeBusyEnterTerminalMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
icon: const Icon(Icons.terminal, size: 18),
|
||||
label: Text(l10n.probeEnterTerminalAnyway),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return result ?? false;
|
||||
}
|
||||
Reference in new issue
Block a user