2
This commit is contained in:
1 parent
5ac164b407
commit
f93f6095af
94 files changed
+7877
-4018
No files matched your search
@@ -1,10 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../models/lsp_language_config.dart';
|
||||
import '../providers/settings_provider.dart';
|
||||
import '../services/internal_engine_service.dart';
|
||||
import '../services/lsp/lsp_manager.dart';
|
||||
import '../services/lsp_config_service.dart';
|
||||
import '../utils/dialog_utils.dart';
|
||||
import '../widgets/lsp_language_edit_dialog.dart';
|
||||
import 'main_view.dart';
|
||||
|
||||
/// 代码补全与语言服务管理视图
|
||||
class CodeCompletionManagementView extends StatefulWidget {
|
||||
@@ -21,6 +25,9 @@ class _CodeCompletionManagementViewState
|
||||
final _engineService = InternalEngineService.instance;
|
||||
|
||||
final Map<String, bool> _installedStatus = {};
|
||||
final Set<String> _expandedConfigIds = {};
|
||||
/// 记录正在进行后台安装/卸载任务的语言配置 ID 及其动作类型('install' 或 'uninstall')
|
||||
final Map<String, String> _busyConfigActions = {};
|
||||
bool _isLoadingStatus = false;
|
||||
bool _engineReady = false;
|
||||
|
||||
@@ -61,12 +68,22 @@ class _CodeCompletionManagementViewState
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_engineReady = true;
|
||||
_installedStatus.addAll(newStatus);
|
||||
_installedStatus
|
||||
..clear()
|
||||
..addAll(newStatus);
|
||||
_isLoadingStatus = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleToggleEnabled(LspLanguageConfig config) async {
|
||||
final updated = config.copyWith(enabled: !config.enabled);
|
||||
if (!updated.enabled) {
|
||||
await LspManager.instance.stopSession(config.id);
|
||||
}
|
||||
await _lspService.updateConfig(updated);
|
||||
}
|
||||
|
||||
Future<void> _handleEdit(LspLanguageConfig config) async {
|
||||
final updated = await LspLanguageEditDialog.show(
|
||||
context,
|
||||
@@ -86,21 +103,57 @@ class _CodeCompletionManagementViewState
|
||||
final newConfig = await LspLanguageEditDialog.show(context);
|
||||
if (newConfig != null && mounted) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
await _lspService.updateConfig(newConfig);
|
||||
if (mounted && l10n != null) {
|
||||
DialogUtils.showSuccessToast(context, l10n.languageConfigSaved);
|
||||
if (l10n == null) return;
|
||||
|
||||
final hasPkg = newConfig.package.trim().isNotEmpty;
|
||||
if (hasPkg) {
|
||||
final success = await DialogUtils.showSyncLoadingDialog<bool>(
|
||||
context,
|
||||
message: l10n.installingComponent(newConfig.package),
|
||||
task: () => InternalEngineService.instance.installPackage(newConfig.package),
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (success) {
|
||||
await _lspService.updateConfig(newConfig);
|
||||
if (mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.installComponentSuccess(newConfig.name));
|
||||
_checkCommandsStatus();
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n.installComponentFailed('apt exit with non-zero code'),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 无系统依赖包名直接保存配置
|
||||
await _lspService.updateConfig(newConfig);
|
||||
if (mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.languageConfigSaved);
|
||||
_checkCommandsStatus();
|
||||
}
|
||||
}
|
||||
_checkCommandsStatus();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleDelete(LspLanguageConfig config) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final isInstalled = _installedStatus[config.id] ?? false;
|
||||
final hasPackage = config.package.trim().isNotEmpty;
|
||||
|
||||
final contentText = (isInstalled && hasPackage)
|
||||
? l10n.deleteLanguageWithPackageConfirmMessage(config.name)
|
||||
: l10n.deleteLanguageConfirmMessage(config.name);
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(l10n.deleteLanguageConfirmTitle),
|
||||
content: Text(l10n.deleteLanguageConfirmMessage(config.name)),
|
||||
content: Text(contentText),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
@@ -118,60 +171,49 @@ class _CodeCompletionManagementViewState
|
||||
);
|
||||
|
||||
if (confirmed == true && mounted) {
|
||||
// 1. 删除前先优雅停用后台语言服务并清理活跃会话
|
||||
await LspManager.instance.stopSession(config.id);
|
||||
if (!mounted) return;
|
||||
|
||||
if (isInstalled && hasPackage) {
|
||||
// 同步弹出卸载 dialog,与安装组件保持一致的同步交互体验
|
||||
final success = await DialogUtils.showSyncLoadingDialog<bool>(
|
||||
context,
|
||||
message: l10n.uninstallingComponent(config.name),
|
||||
task: () => InternalEngineService.instance.uninstallPackage(
|
||||
config.package,
|
||||
serverCommand: config.serverCommand,
|
||||
),
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (success == true) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n.uninstallComponentSuccess(config.name),
|
||||
);
|
||||
} else {
|
||||
// 卸载失败:给出明确提示并中止,避免误删本地配置导致状态脱节
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n.uninstallComponentFailed('apt purge non-zero or binary retained'),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 卸载成功(或纯配置项无包):删除本地配置并清除防打扰白名单
|
||||
await _lspService.deleteConfig(config.id);
|
||||
setState(() {
|
||||
_installedStatus.remove(config.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
MainView.clearPromptedLanguage(config.id);
|
||||
|
||||
Future<void> _handleReset() async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(l10n.resetDefaultLanguages),
|
||||
content: Text(l10n.resetDefaultLanguagesConfirm),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: Text(l10n.confirm),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && mounted) {
|
||||
await _lspService.resetToDefaults();
|
||||
_checkCommandsStatus();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleInstallComponent(LspLanguageConfig config) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final success = await DialogUtils.showSyncLoadingDialog<bool>(
|
||||
context,
|
||||
message: l10n.installingComponent(config.apkPackage),
|
||||
task: () => _engineService.installPackage(config.apkPackage),
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (success) {
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n.installComponentSuccess(config.name),
|
||||
);
|
||||
_checkCommandsStatus();
|
||||
} else {
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n.installComponentFailed('apk add exit with non-zero'),
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_installedStatus.remove(config.id);
|
||||
_expandedConfigIds.remove(config.id);
|
||||
});
|
||||
_checkCommandsStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,11 +226,6 @@ class _CodeCompletionManagementViewState
|
||||
appBar: AppBar(
|
||||
title: Text(l10n.codeCompletionManagement),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.restore),
|
||||
tooltip: l10n.resetDefaultLanguages,
|
||||
onPressed: _handleReset,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
tooltip: l10n.addLanguageConfig,
|
||||
@@ -206,6 +243,8 @@ class _CodeCompletionManagementViewState
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
children: [
|
||||
_buildCompletionSwitchesCard(context, theme, l10n),
|
||||
const SizedBox(height: 12),
|
||||
_buildEngineStatusCard(context, theme, l10n),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
@@ -230,7 +269,10 @@ class _CodeCompletionManagementViewState
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
...configs.map((cfg) => _buildLanguageItem(context, theme, l10n, cfg)),
|
||||
if (configs.isEmpty)
|
||||
_buildEmptyPlaceholder(context, theme, l10n)
|
||||
else
|
||||
...configs.map((cfg) => _buildLanguageItem(context, theme, l10n, cfg)),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -239,6 +281,85 @@ class _CodeCompletionManagementViewState
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCompletionSwitchesCard(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final settings = context.watch<SettingsProvider?>();
|
||||
if (settings == null) return const SizedBox.shrink();
|
||||
|
||||
final colorScheme = theme.colorScheme;
|
||||
return Card(
|
||||
elevation: 0,
|
||||
color: colorScheme.surfaceContainerHighest.withValues(alpha: 0.35),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: colorScheme.outlineVariant.withValues(alpha: 0.6)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
l10n.completionSourceSection,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
secondary: const Icon(Icons.hub_outlined),
|
||||
title: Text(l10n.lspCompletionTitle),
|
||||
value: settings.enableLspCompletion,
|
||||
onChanged: (val) => settings.setEnableLspCompletion(val),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyPlaceholder(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final colorScheme = theme.colorScheme;
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 24),
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surfaceContainerLowest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: colorScheme.outlineVariant.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.code_off_rounded,
|
||||
size: 48,
|
||||
color: colorScheme.outline,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.emptyLspLanguagesTitle,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEngineStatusCard(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
@@ -247,20 +368,18 @@ class _CodeCompletionManagementViewState
|
||||
final isInstalled = _engineReady;
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
final (bgColor, borderColor, icon, statusText, subText) = isInstalled
|
||||
final (bgColor, borderColor, icon, statusText) = isInstalled
|
||||
? (
|
||||
colorScheme.surfaceContainerHighest.withValues(alpha: 0.5),
|
||||
colorScheme.outlineVariant,
|
||||
Icon(Icons.check_circle_outline, color: colorScheme.primary, size: 28),
|
||||
l10n.internalEngineStatusReady,
|
||||
'Alpine Linux (musl libc)',
|
||||
)
|
||||
: (
|
||||
colorScheme.errorContainer.withValues(alpha: 0.3),
|
||||
colorScheme.error.withValues(alpha: 0.5),
|
||||
Icon(Icons.warning_amber_outlined, color: colorScheme.error, size: 28),
|
||||
l10n.internalEngineStatusNotReady,
|
||||
l10n.internalEngineExtracting,
|
||||
);
|
||||
|
||||
return Card(
|
||||
@@ -277,25 +396,12 @@ class _CodeCompletionManagementViewState
|
||||
icon,
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.internalEngineTitle,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'$statusText • $subText',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: isInstalled
|
||||
? colorScheme.onSurfaceVariant
|
||||
: colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: Text(
|
||||
statusText,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isInstalled ? null : colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!isInstalled)
|
||||
@@ -320,163 +426,192 @@ class _CodeCompletionManagementViewState
|
||||
AppLocalizations l10n,
|
||||
LspLanguageConfig config,
|
||||
) {
|
||||
final isInstalled = _installedStatus[config.id] ?? false;
|
||||
final isExpanded = _expandedConfigIds.contains(config.id);
|
||||
final busyAction = _busyConfigActions[config.id];
|
||||
final isBusy = busyAction != null;
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
// 状态描边:正在处理为品牌强调色(Primary);启用状态为绿色;未启用时保持普通灰色描边
|
||||
final BorderSide borderSide;
|
||||
if (isBusy) {
|
||||
borderSide = BorderSide(color: colorScheme.primary, width: 1.5);
|
||||
} else if (config.enabled) {
|
||||
borderSide = const BorderSide(color: Colors.green, width: 1.5);
|
||||
} else {
|
||||
borderSide = BorderSide(color: colorScheme.outlineVariant.withValues(alpha: 0.5));
|
||||
}
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
margin: const EdgeInsets.symmetric(vertical: 6),
|
||||
color: colorScheme.surfaceContainerLow,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: colorScheme.outlineVariant.withValues(alpha: 0.5)),
|
||||
side: borderSide,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 16,
|
||||
backgroundColor: colorScheme.primaryContainer,
|
||||
child: Text(
|
||||
config.name.isNotEmpty ? config.name.substring(0, 1).toUpperCase() : '?',
|
||||
style: TextStyle(
|
||||
color: colorScheme.onPrimaryContainer,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 头部:点击折叠/展开,仅显示头像、主标题和折叠指示图标
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (isExpanded) {
|
||||
_expandedConfigIds.remove(config.id);
|
||||
} else {
|
||||
_expandedConfigIds.add(config.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14.0, vertical: 12.0),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 16,
|
||||
backgroundColor: config.enabled
|
||||
? colorScheme.primaryContainer
|
||||
: colorScheme.surfaceContainerHighest,
|
||||
child: Text(
|
||||
config.name.isNotEmpty ? config.name.substring(0, 1).toUpperCase() : '?',
|
||||
style: TextStyle(
|
||||
color: config.enabled
|
||||
? colorScheme.onPrimaryContainer
|
||||
: colorScheme.onSurfaceVariant,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
config.name,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: config.enabled ? null : colorScheme.onSurfaceVariant,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (isBusy) ...[
|
||||
const SizedBox(width: 8),
|
||||
SizedBox(
|
||||
width: 12,
|
||||
height: 12,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
busyAction == 'uninstall'
|
||||
? l10n.uninstallingStatus
|
||||
: l10n.installingStatus,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildStatusBadge(theme, l10n, isInstalled),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'${config.serverCommand} (${config.apkPackage}) • id: ${config.languageId}',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
isExpanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 展开区域:显示文件扩展名标签与功能菜单选项
|
||||
if (isExpanded) ...[
|
||||
const Divider(height: 1),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 10, 14, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 文件后缀标签
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 4,
|
||||
children: config.fileExtensions.map(
|
||||
(ext) => Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
ext,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
fontFamily: 'JetBrains Mono',
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
).toList(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// 功能菜单:启用/停用、安装组件(若未安装)、编辑、删除
|
||||
// 正在进行后台任务时,所有操作均被禁用以防止并发冲突
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
// 启用 / 停用
|
||||
if (!isBusy)
|
||||
OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
||||
),
|
||||
onPressed: () => _handleToggleEnabled(config),
|
||||
icon: Icon(
|
||||
config.enabled ? Icons.pause_circle_outline : Icons.play_circle_outline,
|
||||
size: 16,
|
||||
),
|
||||
label: Text(config.enabled ? l10n.disable : l10n.enable),
|
||||
),
|
||||
|
||||
// 编辑配置(后台任务进行中禁用)
|
||||
OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
||||
),
|
||||
onPressed: isBusy ? null : () => _handleEdit(config),
|
||||
icon: const Icon(Icons.edit_outlined, size: 16),
|
||||
label: Text(l10n.edit),
|
||||
),
|
||||
|
||||
// 删除配置(后台任务进行中禁用)
|
||||
OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: isBusy ? colorScheme.outline : colorScheme.error,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
||||
),
|
||||
onPressed: isBusy ? null : () => _handleDelete(config),
|
||||
icon: const Icon(Icons.delete_outline, size: 16),
|
||||
label: Text(l10n.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined, size: 20),
|
||||
tooltip: l10n.editLanguageConfig,
|
||||
onPressed: () => _handleEdit(config),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline, size: 20),
|
||||
tooltip: l10n.delete,
|
||||
onPressed: () => _handleDelete(config),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
...config.fileExtensions.map(
|
||||
(ext) => Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
ext,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
fontFamily: 'JetBrains Mono',
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!isInstalled)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 4),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
onTap: () => _handleInstallComponent(config),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primary.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.download, size: 14, color: colorScheme.primary),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
l10n.installComponent,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusBadge(
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
bool isInstalled,
|
||||
) {
|
||||
final (bgColor, fgColor, text) = isInstalled
|
||||
? (
|
||||
Colors.green.withValues(alpha: 0.15),
|
||||
Colors.green.shade700,
|
||||
l10n.installedStatus,
|
||||
)
|
||||
: (
|
||||
Colors.grey.withValues(alpha: 0.2),
|
||||
Colors.grey.shade700,
|
||||
l10n.notInstalledStatus,
|
||||
);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: fgColor,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user