2
This commit is contained in:
1 parent
b49e096355
commit
63e1fe3861
48 files changed
+5817
-556
No files matched your search
@@ -1,14 +1,18 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../models/run_task.dart';
|
||||
import '../providers/run_provider.dart';
|
||||
|
||||
/// 运行任务选择弹窗(带顶部搜索栏、区分系统探测与自定义任务,点击直接调度执行)
|
||||
/// 运行任务选择弹窗(带顶部搜索栏、区分系统探测与自定义任务、支持模块深度重新同步、点击直接调度执行)
|
||||
class RunTasksDialog extends StatefulWidget {
|
||||
final List<RunTask> customTasks;
|
||||
final List<RunTask> detectedTasks;
|
||||
final String? lastRunTaskId;
|
||||
final ValueChanged<RunTask> onTaskSelected;
|
||||
final VoidCallback onEditCustomTasks;
|
||||
final void Function(String moduleId)? onSyncModule;
|
||||
final bool Function(String moduleId)? isSyncingModule;
|
||||
|
||||
const RunTasksDialog({
|
||||
super.key,
|
||||
@@ -17,6 +21,8 @@ class RunTasksDialog extends StatefulWidget {
|
||||
this.lastRunTaskId,
|
||||
required this.onTaskSelected,
|
||||
required this.onEditCustomTasks,
|
||||
this.onSyncModule,
|
||||
this.isSyncingModule,
|
||||
});
|
||||
|
||||
static Future<void> show({
|
||||
@@ -26,6 +32,8 @@ class RunTasksDialog extends StatefulWidget {
|
||||
String? lastRunTaskId,
|
||||
required ValueChanged<RunTask> onTaskSelected,
|
||||
required VoidCallback onEditCustomTasks,
|
||||
void Function(String moduleId)? onSyncModule,
|
||||
bool Function(String moduleId)? isSyncingModule,
|
||||
}) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
@@ -35,6 +43,8 @@ class RunTasksDialog extends StatefulWidget {
|
||||
lastRunTaskId: lastRunTaskId,
|
||||
onTaskSelected: onTaskSelected,
|
||||
onEditCustomTasks: onEditCustomTasks,
|
||||
onSyncModule: onSyncModule,
|
||||
isSyncingModule: isSyncingModule,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -67,9 +77,11 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
if (_searchQuery.isEmpty) return true;
|
||||
final name = task.getLocalizedName(l10n);
|
||||
final desc = task.getLocalizedDescription(l10n);
|
||||
final group = task.group ?? '';
|
||||
return name.toLowerCase().contains(_searchQuery) ||
|
||||
task.command.toLowerCase().contains(_searchQuery) ||
|
||||
desc.toLowerCase().contains(_searchQuery) ||
|
||||
group.toLowerCase().contains(_searchQuery) ||
|
||||
(task.description?.toLowerCase().contains(_searchQuery) ?? false);
|
||||
}
|
||||
|
||||
@@ -77,10 +89,30 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final filteredCustom = widget.customTasks.where((t) => _matchesQuery(t, l10n)).toList();
|
||||
final filteredDetected = widget.detectedTasks.where((t) => _matchesQuery(t, l10n)).toList();
|
||||
|
||||
// 优先响应父级 Provider 数据变化,保证静默后台自省完成后对话框无感自动刷新
|
||||
RunProvider? runProvider;
|
||||
try {
|
||||
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;
|
||||
|
||||
// 检测是否存在 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);
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: ConstrainedBox(
|
||||
@@ -148,13 +180,26 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
: ListView(
|
||||
children: [
|
||||
if (filteredDetected.isNotEmpty) ...[
|
||||
_buildSectionHeader(context, l10n.systemDetectedTasks, Icons.radar_outlined),
|
||||
...filteredDetected.map((task) => _buildTaskItem(context, task, l10n)),
|
||||
_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,
|
||||
),
|
||||
...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)),
|
||||
...filteredCustom.map((task) => _buildTaskItem(context, task, l10n, effectiveLastRunTaskId)),
|
||||
],
|
||||
],
|
||||
),
|
||||
@@ -166,7 +211,70 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(BuildContext context, String title, IconData icon) {
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(
|
||||
BuildContext context,
|
||||
String title,
|
||||
IconData icon, {
|
||||
Widget? trailing,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 4),
|
||||
@@ -174,21 +282,24 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
children: [
|
||||
Icon(icon, size: 16, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
title,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (trailing != null) trailing,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskItem(BuildContext context, RunTask task, AppLocalizations l10n) {
|
||||
Widget _buildTaskItem(BuildContext context, RunTask task, AppLocalizations l10n, String? lastRunTaskId) {
|
||||
final theme = Theme.of(context);
|
||||
final isLastRun = widget.lastRunTaskId != null && widget.lastRunTaskId == task.id;
|
||||
final isLastRun = lastRunTaskId != null && lastRunTaskId == task.id;
|
||||
|
||||
final cardColor = isLastRun
|
||||
? Colors.green.withValues(alpha: 0.15)
|
||||
@@ -222,6 +333,23 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (task.group != null && task.group!.isNotEmpty && task.group != 'single_file')
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 6),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1.5),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.secondaryContainer.withValues(alpha: 0.6),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
task.group!,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: theme.colorScheme.onSecondaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isLastRun)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 6),
|
||||
|
||||
Reference in new issue
Block a user