2
This commit is contained in:
1 parent
cce34e7960
commit
b49e096355
56 files changed
+8343
-296
No files matched your search
@@ -0,0 +1,433 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/distro_manifest.dart';
|
||||
import 'package:code_editor/providers/settings_provider.dart';
|
||||
import 'package:code_editor/services/distro_download_manager.dart';
|
||||
import 'package:code_editor/utils/dialog_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
/// 独立的系统管理与发行版包选择视图页面
|
||||
///
|
||||
/// 功能:
|
||||
/// 1. AppBar 包含返回键与标题“系统管理”(遵循 l10n 国际化)。
|
||||
/// 2. 列举当前架构支持的系统安装包(左侧图标、两行名称与版本,无高亮选框,无“内置”字样)。
|
||||
/// 3. 安装包项分为两种状态:
|
||||
/// - 已就绪 (zip 存在):
|
||||
/// * 不显示“已安装”文本,不显示“安装”按键;
|
||||
/// * Ubuntu 和 Alpine 为内置包,受保护右侧不显示删除按键;
|
||||
/// * 在线下载的系统包右侧显示红色删除按钮(二次确认后居中同步转圈删除离线包);
|
||||
/// * 用户直接点击该项卡片,即代表选中该安装包,返回上一页进行解压创建系统。
|
||||
/// - 未下载 / 下载中:
|
||||
/// * 未下载显示“下载”按键;
|
||||
/// * 下载中显示百分比进度条与取消按键(取消后清空临时文件)。
|
||||
class DistroManagementView extends StatefulWidget {
|
||||
const DistroManagementView({super.key});
|
||||
|
||||
@override
|
||||
State<DistroManagementView> createState() => _DistroManagementViewState();
|
||||
}
|
||||
|
||||
class _DistroManagementViewState extends State<DistroManagementView> {
|
||||
final DistroDownloadManager _downloadManager = DistroDownloadManager();
|
||||
final Set<String> _downloadedPackageIds = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_downloadManager.addListener(_onDownloadProgressChanged);
|
||||
_checkDownloadedPackages();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_downloadManager.removeListener(_onDownloadProgressChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onDownloadProgressChanged() {
|
||||
if (mounted) {
|
||||
for (final entry in _downloadManager.allProgress.entries) {
|
||||
if (entry.value.state == DistroDownloadState.completed) {
|
||||
_downloadedPackageIds.add(entry.key);
|
||||
}
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkDownloadedPackages() async {
|
||||
final distros = DistroRepository.currentArchDistros;
|
||||
final Set<String> downloaded = {};
|
||||
for (final d in distros) {
|
||||
if (!d.isBuiltin && d.currentPackageSource != null) {
|
||||
if (await _downloadManager.isPackageDownloaded(d.id, d.currentPackageSource)) {
|
||||
downloaded.add(d.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final entry in _downloadManager.allProgress.entries) {
|
||||
if (entry.value.state == DistroDownloadState.completed) {
|
||||
downloaded.add(entry.key);
|
||||
}
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_downloadedPackageIds.clear();
|
||||
_downloadedPackageIds.addAll(downloaded);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
// 当前架构支持的发行版清单
|
||||
final distros = DistroRepository.currentArchDistros;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
l10n.distroManagementTitle,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
),
|
||||
body: ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
||||
itemCount: distros.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, index) {
|
||||
final item = distros[index];
|
||||
final downloadProgress = _downloadManager.getProgress(item.id);
|
||||
final isDownloaded = _downloadedPackageIds.contains(item.id) ||
|
||||
downloadProgress?.state == DistroDownloadState.completed;
|
||||
final isReady = item.isBuiltin || isDownloaded;
|
||||
final isDownloading = downloadProgress?.state == DistroDownloadState.downloading;
|
||||
|
||||
return _buildDistroCard(
|
||||
context: context,
|
||||
theme: theme,
|
||||
l10n: l10n,
|
||||
item: item,
|
||||
isReady: isReady,
|
||||
isDownloading: isDownloading,
|
||||
downloadProgress: downloadProgress,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDistroCard({
|
||||
required BuildContext context,
|
||||
required ThemeData theme,
|
||||
required AppLocalizations l10n,
|
||||
required DistroManifestItem item,
|
||||
required bool isReady,
|
||||
required bool isDownloading,
|
||||
required DistroDownloadProgress? downloadProgress,
|
||||
}) {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
side: BorderSide(
|
||||
color: theme.colorScheme.outlineVariant.withValues(alpha: 0.4),
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
color: theme.colorScheme.surface,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
onTap: isReady
|
||||
? () {
|
||||
// 点击已就绪的安装包 item:代表选择该 zip,返回上一页解压创建系统
|
||||
Navigator.of(context).pop(item);
|
||||
}
|
||||
: null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
// 1. 系统左侧品牌图标
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
decoration: BoxDecoration(
|
||||
color: item.brandColor.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
border: Border.all(
|
||||
color: item.brandColor.withValues(alpha: 0.3),
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
child: item.assetIconPath != null
|
||||
? Image.asset(
|
||||
item.assetIconPath!,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder: (_, _, _) => Icon(
|
||||
item.iconData,
|
||||
color: item.brandColor,
|
||||
size: 26,
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
item.iconData,
|
||||
color: item.brandColor,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
|
||||
// 2. 中间两行文本 (系统名与推荐标签 + 版本)
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
item.name,
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (item.isRecommended) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6.0, vertical: 2.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.amber.shade700.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(6.0),
|
||||
border: Border.all(
|
||||
color: Colors.amber.shade800.withValues(alpha: 0.4),
|
||||
width: 0.8,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
l10n.recommendedTag,
|
||||
style: TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.amber.shade800,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
item.version,
|
||||
style: TextStyle(
|
||||
fontSize: 12.0,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 3. 右侧状态与操作按钮
|
||||
const SizedBox(width: 10),
|
||||
_buildTrailingAction(
|
||||
context: context,
|
||||
theme: theme,
|
||||
l10n: l10n,
|
||||
item: item,
|
||||
isReady: isReady,
|
||||
isDownloading: isDownloading,
|
||||
downloadProgress: downloadProgress,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// 若处于下载中,展示下载进度条与百分比
|
||||
if (isDownloading && downloadProgress != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4.0),
|
||||
child: LinearProgressIndicator(
|
||||
value: downloadProgress.totalBytes > 0
|
||||
? downloadProgress.progress
|
||||
: null,
|
||||
minHeight: 5,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'${(downloadProgress.progress * 100).toStringAsFixed(0)}%',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTrailingAction({
|
||||
required BuildContext context,
|
||||
required ThemeData theme,
|
||||
required AppLocalizations l10n,
|
||||
required DistroManifestItem item,
|
||||
required bool isReady,
|
||||
required bool isDownloading,
|
||||
required DistroDownloadProgress? downloadProgress,
|
||||
}) {
|
||||
if (isReady) {
|
||||
// 对于已就绪 (已安装) 的 item (zip 文件):
|
||||
// 不显示“已安装”文本,不显示“安装”按键。
|
||||
// 对于内置 ubuntu 和 alpine,受保护无按键 (SizedBox.shrink);
|
||||
// 其他在线下载完成的包,右侧直接显示红色删除按钮
|
||||
if (item.isBuiltin) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.delete_outline, color: Colors.redAccent, size: 22),
|
||||
tooltip: l10n.deletePackageTooltip,
|
||||
onPressed: () => _handleDeleteDownloadedPackage(item),
|
||||
);
|
||||
}
|
||||
|
||||
if (isDownloading) {
|
||||
// 下载中状态:显示取消下载按钮
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.cancel_outlined, color: Colors.grey, size: 22),
|
||||
tooltip: l10n.cancelDownloadAction,
|
||||
onPressed: () => _handleCancelDownload(item),
|
||||
);
|
||||
}
|
||||
|
||||
// 未就绪/未下载状态:显示下载按钮
|
||||
return FilledButton.tonalIcon(
|
||||
icon: const Icon(Icons.download_outlined, size: 18),
|
||||
label: Text(l10n.downloadAction),
|
||||
style: FilledButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||
textStyle: const TextStyle(fontSize: 13.0),
|
||||
),
|
||||
onPressed: () => _handleStartDownload(item),
|
||||
);
|
||||
}
|
||||
|
||||
/// 启动在线下载
|
||||
Future<void> _handleStartDownload(DistroManifestItem item) async {
|
||||
final url = item.currentPackageSource;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final settings = context.read<SettingsProvider>();
|
||||
final mirror = settings.downloadMirror;
|
||||
if (url == null || url.isEmpty) return;
|
||||
|
||||
// 前置资源检测:若已下载完备,立即更新状态并拒绝重复下载
|
||||
if (await _downloadManager.isPackageDownloaded(item.id, url)) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_downloadedPackageIds.add(item.id);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final targetFile = await _downloadManager.startDownload(
|
||||
distroId: item.id,
|
||||
downloadUrl: url,
|
||||
mirror: mirror,
|
||||
manifestItem: item,
|
||||
);
|
||||
|
||||
if (targetFile != null && mounted) {
|
||||
setState(() {
|
||||
_downloadedPackageIds.add(item.id);
|
||||
});
|
||||
} else if (mounted) {
|
||||
final progress = _downloadManager.getProgress(item.id);
|
||||
if (progress?.state == DistroDownloadState.failed) {
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n.downloadFailed(progress?.errorMessage ?? ''),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 取消下载确认弹窗
|
||||
Future<void> _handleCancelDownload(DistroManifestItem item) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await DialogUtils.showConfirmDialog(
|
||||
context,
|
||||
title: l10n.cancelDownloadConfirmTitle,
|
||||
message: l10n.cancelDownloadConfirmMessage,
|
||||
);
|
||||
|
||||
if (confirmed && mounted) {
|
||||
await _downloadManager.cancelDownload(item.id);
|
||||
}
|
||||
}
|
||||
|
||||
/// 删除已下载的系统安装包(弹确认 Dialog -> 居中转圈同步 Dialog -> 完成)
|
||||
Future<void> _handleDeleteDownloadedPackage(DistroManifestItem item) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await DialogUtils.showDestructiveConfirmDialog(
|
||||
context,
|
||||
title: l10n.deletePackageConfirmTitle,
|
||||
message: l10n.deletePackageConfirmMessage(item.name),
|
||||
confirmText: l10n.permanentDelete,
|
||||
);
|
||||
|
||||
if (!confirmed || !mounted) return;
|
||||
|
||||
// 弹出居中转圈的同步等待弹窗,直至删除完毕
|
||||
await DialogUtils.showSyncLoadingDialog<void>(
|
||||
context,
|
||||
message: l10n.deletingPackageProgress,
|
||||
task: () async {
|
||||
try {
|
||||
await _downloadManager.deletePackage(item.id, item.currentPackageSource);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_downloadedPackageIds.remove(item.id);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, e.toString());
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
DialogUtils.showToast(context, l10n.deletePackageSuccess(item.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
+144
-32
@@ -1,9 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/run_task.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';
|
||||
import 'package:code_editor/providers/terminal_provider.dart';
|
||||
import 'package:code_editor/services/distro_manager.dart';
|
||||
import 'package:code_editor/services/toolchain_service.dart';
|
||||
import 'package:code_editor/utils/dialog_utils.dart';
|
||||
import 'package:code_editor/views/settings_view.dart';
|
||||
import 'package:code_editor/views/terminal_view.dart';
|
||||
@@ -12,8 +16,10 @@ import 'package:code_editor/widgets/code_editor_drawer.dart';
|
||||
import 'package:code_editor/widgets/code_editor_tab_bar.dart';
|
||||
import 'package:code_editor/widgets/code_editor_widget.dart';
|
||||
import 'package:code_editor/views/run_task_edit_view.dart';
|
||||
import 'package:code_editor/widgets/distro_selector_dialog.dart';
|
||||
import 'package:code_editor/widgets/run_tasks_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MainView extends StatefulWidget {
|
||||
@@ -87,9 +93,63 @@ class _MainViewState extends State<MainView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 执行某个具体的运行任务(复用/创建当前工程工作目录的终端并执行指令)
|
||||
void _executeRunTask(BuildContext context, RunTask task) {
|
||||
static DistroProvider? _getDistroProvider(BuildContext context, {bool listen = false}) {
|
||||
try {
|
||||
return listen ? Provider.of<DistroProvider>(context, listen: listen) : Provider.of<DistroProvider>(context, listen: false);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 提示用户缺失 Linux 执行环境并引导前往系统管理进行配置
|
||||
void _showMissingDistroDialog(BuildContext context, String? targetDistro) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (ctx) => 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.missingDistroTitle,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: Text(
|
||||
targetDistro == null
|
||||
? l10n.noDistroAvailableContent
|
||||
: l10n.distroNotInstalledContent(targetDistro),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
DistroSelectorDialog.show(context);
|
||||
},
|
||||
icon: const Icon(Icons.dns_outlined, size: 18),
|
||||
label: Text(l10n.systemManagement),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 执行某个具体的运行任务(前置校验环境、识别工具链并推入终端 PTY 执行)
|
||||
Future<void> _executeRunTask(BuildContext context, RunTask task) async {
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
final terminalProvider = _getTerminalProvider(context);
|
||||
final runProvider = _getRunProvider(context);
|
||||
final distroProvider = _getDistroProvider(context);
|
||||
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final rootPath = projectProvider.rootPath;
|
||||
if (rootPath == null || rootPath.isEmpty) {
|
||||
@@ -97,34 +157,66 @@ class _MainViewState extends State<MainView> {
|
||||
return;
|
||||
}
|
||||
|
||||
final terminalProvider = _getTerminalProvider(context);
|
||||
final runProvider = _getRunProvider(context);
|
||||
final distroManager = DistroManager();
|
||||
var targetDistro = distroProvider?.selectedSystem;
|
||||
|
||||
// 1. 查找或创建绑定了该工程工作路径的终端会话(保持系统默认会话名称)
|
||||
final session = terminalProvider?.getOrCreateSessionForProject(
|
||||
projectRoot: rootPath,
|
||||
distroId: 'alpine',
|
||||
// 1. 运行前环境可用性前置拦截校验与状态自动校准
|
||||
// 如果尚未选定系统,或者已选系统校验未通过,主动重新扫描物理系统列表进行校准
|
||||
if (targetDistro == null || !(await distroManager.isSystemInstalled(targetDistro))) {
|
||||
if (distroProvider != null) {
|
||||
await distroProvider.refreshSystems();
|
||||
targetDistro = distroProvider.selectedSystem;
|
||||
}
|
||||
// 如果 Provider 仍未选定,兜底从物理已安装列表中选取并同步
|
||||
if (targetDistro == null || !(await distroManager.isSystemInstalled(targetDistro))) {
|
||||
final physicalSystems = await distroManager.listInstalledSystems();
|
||||
if (physicalSystems.isNotEmpty) {
|
||||
targetDistro = physicalSystems.first;
|
||||
await distroProvider?.selectSystem(targetDistro);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final hasDistro = targetDistro != null && await distroManager.isSystemInstalled(targetDistro);
|
||||
if (!hasDistro) {
|
||||
if (!context.mounted) return;
|
||||
_showMissingDistroDialog(context, targetDistro);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 识别目标系统发行版家族并自适应合成工具链前置检测/安装命令
|
||||
final family = await distroManager.detectDistroFamily(targetDistro);
|
||||
final rootDir = await distroManager.getSystemRootDir(targetDistro);
|
||||
final effectiveCommand = ToolchainService.resolveCommand(
|
||||
task.command,
|
||||
family,
|
||||
rootDir: rootDir,
|
||||
);
|
||||
|
||||
// 2. 记录最近执行的任务
|
||||
// 3. 查找或创建绑定了该工程工作路径与目标系统的终端会话
|
||||
final session = terminalProvider?.getOrCreateSessionForProject(
|
||||
projectRoot: rootPath,
|
||||
distroId: targetDistro,
|
||||
);
|
||||
|
||||
// 4. 记录最近执行的任务
|
||||
runProvider?.setLastRunTask(task);
|
||||
|
||||
// 3. 跳转至终端视图
|
||||
// 5. 跳转至终端视图
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (context) => const TerminalView(),
|
||||
),
|
||||
);
|
||||
|
||||
// 4. 等待界面跳转后向终端发送指令
|
||||
Future.delayed(const Duration(milliseconds: 300), () {
|
||||
if (session != null) {
|
||||
if (task.clearBeforeRun) {
|
||||
session.write('clear\r\n');
|
||||
}
|
||||
session.write('${task.command}\r\n');
|
||||
// 6. 执行任务命令(推入底层 PTY 的 stdin 并等待进程就绪)
|
||||
if (session != null) {
|
||||
if (task.clearBeforeRun) {
|
||||
session.clear();
|
||||
}
|
||||
});
|
||||
unawaited(session.executeCommand(effectiveCommand));
|
||||
}
|
||||
}
|
||||
|
||||
/// 点击运行按钮 (Play):有历史任务或单文件即直接执行,否则弹出任务列表
|
||||
@@ -140,13 +232,13 @@ class _MainViewState extends State<MainView> {
|
||||
final runProvider = _getRunProvider(context);
|
||||
if (runProvider == null) return;
|
||||
|
||||
// 优先: 最近运行的任务(若已持久化并存在)
|
||||
if (runProvider.lastRunTask != null) {
|
||||
// 优先: 最近运行的任务(若已持久化并存在且确实属于当前打开的工程)
|
||||
if (runProvider.currentProjectRoot == rootPath && runProvider.lastRunTask != null) {
|
||||
_executeRunTask(context, runProvider.lastRunTask!);
|
||||
return;
|
||||
}
|
||||
|
||||
// 若没有上一次运行的任务,直接打开运行任务列表
|
||||
// 若当前项目尚未初始化完成或没有上一次运行的任务,直接打开运行任务列表
|
||||
_handleOpenRunTasksDialog(context);
|
||||
}
|
||||
|
||||
@@ -162,11 +254,18 @@ class _MainViewState extends State<MainView> {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果 runProvider 尚未绑定当前项目,立即触发同步
|
||||
if (runProvider.currentProjectRoot != rootPath) {
|
||||
final tabProvider = _getTabProvider(context);
|
||||
runProvider.onProjectOpened(rootPath, activeFilePath: tabProvider.currentFilePath);
|
||||
}
|
||||
|
||||
final isCurrentProject = runProvider.currentProjectRoot == rootPath;
|
||||
RunTasksDialog.show(
|
||||
context: context,
|
||||
customTasks: runProvider.customTasks,
|
||||
detectedTasks: runProvider.detectedTasks,
|
||||
lastRunTaskId: runProvider.lastRunTaskId ?? runProvider.lastRunTask?.id,
|
||||
customTasks: isCurrentProject ? runProvider.customTasks : const [],
|
||||
detectedTasks: isCurrentProject ? runProvider.detectedTasks : const [],
|
||||
lastRunTaskId: isCurrentProject ? (runProvider.lastRunTaskId ?? runProvider.lastRunTask?.id) : null,
|
||||
onTaskSelected: (task) => _executeRunTask(context, task),
|
||||
onEditCustomTasks: () => _handleOpenEditRunTasks(context),
|
||||
);
|
||||
@@ -236,22 +335,35 @@ class _MainViewState extends State<MainView> {
|
||||
final isModified = tabProvider.isModified;
|
||||
|
||||
// 当检测到切换了项目根目录时,自动触发初始化并进行一次探测
|
||||
if (rootPath != null && rootPath != _lastProjectRoot) {
|
||||
if (rootPath != _lastProjectRoot) {
|
||||
_lastProjectRoot = rootPath;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
runProvider?.onProjectOpened(rootPath, activeFilePath: currentFile);
|
||||
}
|
||||
});
|
||||
if (rootPath != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
runProvider?.onProjectOpened(rootPath, activeFilePath: currentFile);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
runProvider?.onProjectClosed();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return PopScope(
|
||||
canPop: !isModified,
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) async {
|
||||
if (didPop) return;
|
||||
final canProceed = await _getTabProvider(context).checkUnsavedChanges(context);
|
||||
if (canProceed && context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
final nav = Navigator.of(context);
|
||||
if (nav.canPop()) {
|
||||
nav.pop();
|
||||
} else {
|
||||
await SystemNavigator.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
import 'dart:io';
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/providers/project_provider.dart';
|
||||
import 'package:code_editor/providers/tab_provider.dart';
|
||||
import 'package:code_editor/services/internal_project_service.dart';
|
||||
import 'package:code_editor/utils/dialog_utils.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';
|
||||
|
||||
/// 内部存储项目管理页面 (files/projects)
|
||||
class ProjectManagementView extends StatefulWidget {
|
||||
const ProjectManagementView({super.key});
|
||||
|
||||
@override
|
||||
State<ProjectManagementView> createState() => _ProjectManagementViewState();
|
||||
}
|
||||
|
||||
class _ProjectManagementViewState extends State<ProjectManagementView> {
|
||||
final InternalProjectService _projectService = InternalProjectService.instance;
|
||||
List<Directory> _projects = [];
|
||||
bool _isLoading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadProjects();
|
||||
}
|
||||
|
||||
static ProjectProvider _getProjectProvider(BuildContext context, {bool listen = false}) {
|
||||
return listen ? context.watch<ProjectProvider>() : context.read<ProjectProvider>();
|
||||
}
|
||||
|
||||
static TabProvider _getTabProvider(BuildContext context, {bool listen = false}) {
|
||||
return listen ? context.watch<TabProvider>() : context.read<TabProvider>();
|
||||
}
|
||||
|
||||
Future<void> _loadProjects() async {
|
||||
final list = await _projectService.listProjects();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_projects = list;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool _isValidProjectArchive(String path) {
|
||||
final lower = path.toLowerCase();
|
||||
return lower.endsWith('.zip') ||
|
||||
lower.endsWith('.tar.gz') ||
|
||||
lower.endsWith('.tgz') ||
|
||||
lower.endsWith('.tar.xz') ||
|
||||
lower.endsWith('.txz') ||
|
||||
lower.endsWith('.tar.bz2') ||
|
||||
lower.endsWith('.tbz') ||
|
||||
lower.endsWith('.tbz2') ||
|
||||
lower.endsWith('.tar');
|
||||
}
|
||||
|
||||
Future<void> _onImportProject() async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
// 1. 打开手机系统文件管理选择一个压缩文件(限制为常用压缩格式)
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: const ['zip', 'tar', 'gz', 'tgz', 'xz', 'txz', 'bz2', 'tbz'],
|
||||
);
|
||||
|
||||
if (result == null || result.files.isEmpty || !mounted) return;
|
||||
final filePath = result.files.single.path;
|
||||
if (filePath == null || filePath.trim().isEmpty || !mounted) return;
|
||||
|
||||
// 校验文件格式是否属于受支持的压缩包格式
|
||||
if (!_isValidProjectArchive(filePath)) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, l10n.unsupportedProjectArchiveFormat);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 提取压缩包默认项目名称(去除 .tar.gz, .tgz, .zip 等扩展名)
|
||||
String defaultName = p.basename(filePath);
|
||||
if (defaultName.endsWith('.tar.gz')) {
|
||||
defaultName = defaultName.substring(0, defaultName.length - 7);
|
||||
} else if (defaultName.endsWith('.tar.xz')) {
|
||||
defaultName = defaultName.substring(0, defaultName.length - 7);
|
||||
} else if (defaultName.endsWith('.tgz')) {
|
||||
defaultName = defaultName.substring(0, defaultName.length - 4);
|
||||
} else {
|
||||
defaultName = p.basenameWithoutExtension(filePath);
|
||||
}
|
||||
defaultName = defaultName.trim();
|
||||
|
||||
// 3. 弹出一个 dialog,让用户确定项目名称
|
||||
final confirmedName = await DialogUtils.showInputDialog(
|
||||
context,
|
||||
title: l10n.confirmProjectNameTitle,
|
||||
hintText: l10n.projectNameHint,
|
||||
initialValue: defaultName,
|
||||
validator: (val) {
|
||||
if (val == null || val.trim().isEmpty) {
|
||||
return l10n.nameCannotBeEmpty;
|
||||
}
|
||||
if (val.contains(RegExp(r'[\\/:*?"<>|]'))) {
|
||||
return l10n.nameInvalidChars;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
if (confirmedName == null || confirmedName.trim().isEmpty || !mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
final trimmedName = confirmedName.trim();
|
||||
if (await _projectService.projectExists(trimmedName)) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, l10n.projectAlreadyExists);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 注意:确定项目名称之后才去进行解压复制操作
|
||||
if (!mounted) return;
|
||||
try {
|
||||
await DialogUtils.showSyncLoadingDialog(
|
||||
context,
|
||||
message: l10n.importingProject,
|
||||
task: () async {
|
||||
await _projectService.importProjectFromArchive(filePath, trimmedName);
|
||||
},
|
||||
);
|
||||
if (mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.projectImported);
|
||||
await _loadProjects();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n.importProjectFailed(e.toString()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onCreateProject() async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final name = await DialogUtils.showInputDialog(
|
||||
context,
|
||||
title: l10n.newProjectTitle,
|
||||
hintText: l10n.projectNameHint,
|
||||
validator: (val) {
|
||||
if (val == null || val.trim().isEmpty) {
|
||||
return l10n.nameCannotBeEmpty;
|
||||
}
|
||||
if (val.contains(RegExp(r'[\\/:*?"<>|]'))) {
|
||||
return l10n.nameInvalidChars;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
if (name == null || name.trim().isEmpty || !mounted) return;
|
||||
|
||||
final trimmedName = name.trim();
|
||||
if (await _projectService.projectExists(trimmedName)) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, l10n.projectAlreadyExists);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await _projectService.createProject(trimmedName);
|
||||
if (mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.projectCreated);
|
||||
await _loadProjects();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRenameProject(Directory dir, String currentName) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final newName = await DialogUtils.showInputDialog(
|
||||
context,
|
||||
title: l10n.renameProject,
|
||||
hintText: l10n.projectNameHint,
|
||||
initialValue: currentName,
|
||||
validator: (val) {
|
||||
if (val == null || val.trim().isEmpty) {
|
||||
return l10n.nameCannotBeEmpty;
|
||||
}
|
||||
if (val.contains(RegExp(r'[\\/:*?"<>|]'))) {
|
||||
return l10n.nameInvalidChars;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
if (newName == null || newName.trim().isEmpty || newName.trim() == currentName || !mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
final trimmedName = newName.trim();
|
||||
if (await _projectService.projectExists(trimmedName)) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, l10n.projectAlreadyExists);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
try {
|
||||
final newDir = await _projectService.renameProject(dir, trimmedName);
|
||||
if (projectProvider.rootPath != null &&
|
||||
p.normalize(projectProvider.rootPath!) == p.normalize(dir.path)) {
|
||||
await projectProvider.openSpecificDirectory(newDir.path);
|
||||
}
|
||||
if (mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.projectRenamed);
|
||||
await _loadProjects();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onDeleteProject(Directory dir, String projectName) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await DialogUtils.showDestructiveConfirmDialog(
|
||||
context,
|
||||
title: l10n.deleteProject,
|
||||
message: l10n.deleteProjectConfirmMessage(projectName),
|
||||
confirmText: l10n.delete,
|
||||
cancelText: l10n.cancel,
|
||||
);
|
||||
|
||||
if (!confirmed || !mounted) return;
|
||||
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
try {
|
||||
await _projectService.deleteProject(dir);
|
||||
if (projectProvider.rootPath != null &&
|
||||
p.normalize(projectProvider.rootPath!) == p.normalize(dir.path)) {
|
||||
await projectProvider.closeProject();
|
||||
}
|
||||
if (mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.projectDeleted);
|
||||
await _loadProjects();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(context, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onOpenProject(Directory dir) async {
|
||||
final tabProvider = _getTabProvider(context);
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
|
||||
final canProceed = await tabProvider.checkUnsavedChanges(context);
|
||||
if (!canProceed || !mounted) return;
|
||||
|
||||
await projectProvider.openSpecificDirectory(dir.path);
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
l10n.projectsTitle,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
tooltip: l10n.back,
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.file_upload_outlined),
|
||||
tooltip: l10n.importFromExternal,
|
||||
onPressed: _onImportProject,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
tooltip: l10n.newProject,
|
||||
onPressed: _onCreateProject,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _projects.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.folder_open_outlined,
|
||||
size: 64,
|
||||
color: theme.colorScheme.outline,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
l10n.noProjects,
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.outline,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
|
||||
itemCount: _projects.length,
|
||||
itemBuilder: (context, index) {
|
||||
final dir = _projects[index];
|
||||
final projectName = p.basename(dir.path);
|
||||
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 2.0),
|
||||
leading: Icon(
|
||||
Icons.folder,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
title: Text(
|
||||
projectName,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
tooltip: l10n.renameProject,
|
||||
onPressed: () => _onRenameProject(dir, projectName),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
tooltip: l10n.deleteProject,
|
||||
onPressed: () => _onDeleteProject(dir, projectName),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () => _onOpenProject(dir),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -175,11 +175,13 @@ class _RunTaskDetailViewState extends State<RunTaskDetailView> {
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _commandController,
|
||||
maxLines: 4,
|
||||
minLines: 3,
|
||||
maxLines: 8,
|
||||
style: const TextStyle(fontFamily: 'monospace', fontSize: 13),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.shellCommandRequired,
|
||||
hintText: l10n.shellCommandHint,
|
||||
helperText: l10n.shellCommandHelperText,
|
||||
border: const OutlineInputBorder(),
|
||||
alignLabelWithHint: true,
|
||||
isDense: true,
|
||||
|
||||
@@ -272,14 +272,14 @@ class _RunTaskEditViewState extends State<RunTaskEditView> {
|
||||
),
|
||||
// 只显示:名称 + 用途(描述)
|
||||
title: Text(
|
||||
task.name,
|
||||
task.getLocalizedName(l10n),
|
||||
style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 14),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: (task.description != null && task.description!.trim().isNotEmpty)
|
||||
subtitle: task.getLocalizedDescription(l10n).trim().isNotEmpty
|
||||
? Text(
|
||||
task.description!.trim(),
|
||||
task.getLocalizedDescription(l10n).trim(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 12, color: theme.colorScheme.outline),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/app_font.dart';
|
||||
import 'package:code_editor/models/distro_manifest.dart';
|
||||
import 'package:code_editor/models/editor_theme.dart';
|
||||
import 'package:code_editor/models/virtual_keyboard_config.dart';
|
||||
import 'package:code_editor/providers/settings_provider.dart';
|
||||
@@ -78,7 +79,15 @@ class SettingsView extends StatelessWidget {
|
||||
const Divider(height: 32, indent: 16, endIndent: 16),
|
||||
|
||||
// ==============================
|
||||
// 5. 语言分组 (Language)
|
||||
// 5. 下载分组 (Download)
|
||||
// ==============================
|
||||
_buildSectionHeader(context, l10n.downloadSection),
|
||||
_buildDownloadSourceTile(context, provider, l10n),
|
||||
|
||||
const Divider(height: 32, indent: 16, endIndent: 16),
|
||||
|
||||
// ==============================
|
||||
// 6. 语言分组 (Language)
|
||||
// ==============================
|
||||
_buildSectionHeader(context, l10n.languageSection),
|
||||
_buildLanguageTile(context, provider, l10n),
|
||||
@@ -940,4 +949,98 @@ class SettingsView extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 下载:下载源设置条目
|
||||
Widget _buildDownloadSourceTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
final currentMirrorId = provider.downloadMirrorId;
|
||||
return ListTile(
|
||||
leading: Icon(Icons.cloud_download_outlined, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.downloadSource),
|
||||
subtitle: Text(l10n.mirrorName(currentMirrorId)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showDownloadSourceSelector(context, provider, l10n);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示下载源底部选择器(与字体选择器一致的弹窗体验)
|
||||
void _showDownloadSourceSelector(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
builder: (sheetContext) {
|
||||
final theme = Theme.of(context);
|
||||
final mirrors = DistroRepository.availableMirrors;
|
||||
return SafeArea(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(sheetContext).size.height * 0.65,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
l10n.selectDownloadSource,
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: mirrors.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = mirrors[index];
|
||||
final isSelected = item.id == provider.downloadMirrorId;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.dns_outlined,
|
||||
color: isSelected ? theme.colorScheme.primary : null,
|
||||
),
|
||||
title: Text(
|
||||
l10n.mirrorName(item.id),
|
||||
style: TextStyle(
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
color: isSelected ? theme.colorScheme.primary : null,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
item.baseUrl,
|
||||
style: TextStyle(
|
||||
fontSize: 12.0,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
trailing: isSelected
|
||||
? Icon(Icons.check, color: theme.colorScheme.primary)
|
||||
: null,
|
||||
onTap: () {
|
||||
provider.setDownloadMirrorId(item.id);
|
||||
Navigator.of(sheetContext).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/app_font.dart';
|
||||
import 'package:code_editor/models/distro_manifest.dart';
|
||||
import 'package:code_editor/models/terminal_session.dart';
|
||||
import 'package:code_editor/models/virtual_keyboard_config.dart';
|
||||
import 'package:code_editor/providers/distro_provider.dart';
|
||||
@@ -39,8 +40,13 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final defaultSessionName = l10n.sessionDefaultName;
|
||||
|
||||
final projectRoot = context.read<ProjectProvider?>()?.rootPath;
|
||||
|
||||
if (distroProvider == null) {
|
||||
context.read<TerminalProvider>().ensureInitialized(defaultName: defaultSessionName);
|
||||
context.read<TerminalProvider>().ensureInitialized(
|
||||
defaultName: defaultSessionName,
|
||||
workspacePath: projectRoot,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,13 +54,13 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
if (!mounted) return;
|
||||
|
||||
if (!distroProvider.hasAnySystem) {
|
||||
// 自动从软件内置资源导入 alpine,名称即为 alpine
|
||||
// 自动从软件内置资源导入 Ubuntu 24.04(推荐主力开发环境),名称为 ubuntu
|
||||
final success = await DistroExtractDialog.show(
|
||||
context: context,
|
||||
systemName: 'alpine',
|
||||
systemName: DistroRepository.defaultSystemName,
|
||||
task: (onProgress, isCancelled) {
|
||||
return distroProvider.importBuiltinAlpine(
|
||||
systemName: 'alpine',
|
||||
return distroProvider.importBuiltinUbuntu(
|
||||
systemName: DistroRepository.defaultSystemName,
|
||||
onProgress: onProgress,
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
@@ -66,7 +72,8 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
if (termProvider.isEmpty) {
|
||||
termProvider.createSession(
|
||||
name: defaultSessionName,
|
||||
distroId: 'alpine',
|
||||
distroId: DistroRepository.defaultSystemName,
|
||||
workspacePath: projectRoot,
|
||||
activate: true,
|
||||
);
|
||||
}
|
||||
@@ -75,10 +82,11 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
// 已有系统,确保初始化首个会话
|
||||
final termProvider = context.read<TerminalProvider>();
|
||||
if (termProvider.isEmpty) {
|
||||
final system = distroProvider.selectedSystem ?? 'alpine';
|
||||
final system = distroProvider.selectedSystem ?? DistroRepository.defaultSystemName;
|
||||
termProvider.createSession(
|
||||
name: defaultSessionName,
|
||||
distroId: system,
|
||||
workspacePath: projectRoot,
|
||||
activate: true,
|
||||
);
|
||||
}
|
||||
@@ -91,16 +99,16 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final provider = context.watch<TerminalProvider>();
|
||||
final projectProvider = context.watch<ProjectProvider?>();
|
||||
|
||||
final activeSession = provider.activeSession;
|
||||
final sessions = provider.sessions;
|
||||
final activeIndex = provider.activeIndex;
|
||||
|
||||
final titleText = activeSession?.name ?? l10n.sessionDefaultName;
|
||||
final projectRoot = activeSession?.workspacePath ?? projectProvider?.rootPath;
|
||||
final String? subtitleText = (projectRoot != null && projectRoot.trim().isNotEmpty)
|
||||
? projectRoot.trim()
|
||||
// 副标题严格取自当前会话绑定的工作目录根路径
|
||||
final sessionWorkspace = activeSession?.workspacePath;
|
||||
final String? subtitleText = (sessionWorkspace != null && sessionWorkspace.trim().isNotEmpty)
|
||||
? sessionWorkspace.trim()
|
||||
: null;
|
||||
|
||||
return Scaffold(
|
||||
|
||||
Reference in new issue
Block a user