2
This commit is contained in:
1 parent
cce34e7960
commit
b49e096355
56 files changed
+8343
-296
No files matched your search
@@ -1,14 +1,22 @@
|
||||
import 'package:code_editor/l10n/app_localizations.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/services/internal_project_service.dart';
|
||||
import 'package:code_editor/services/permission_service.dart';
|
||||
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:flutter/material.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
enum _OpenProjectSource {
|
||||
fromApp,
|
||||
fromExternal,
|
||||
}
|
||||
|
||||
class CodeEditorDrawer extends StatelessWidget {
|
||||
const CodeEditorDrawer({super.key});
|
||||
|
||||
@@ -119,22 +127,62 @@ class CodeEditorDrawer extends StatelessWidget {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: l10n.refreshDirectory,
|
||||
onPressed: () =>
|
||||
_getProjectProvider(context).refreshTree(),
|
||||
onPressed: () {
|
||||
_getProjectProvider(context).refreshTree();
|
||||
final runProvider = context.read<RunProvider?>();
|
||||
final root = _getProjectProvider(context).rootPath;
|
||||
if (root != null && root.isNotEmpty) {
|
||||
runProvider?.onProjectOpened(root);
|
||||
}
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
PopupMenuButton<_OpenProjectSource>(
|
||||
icon: const Icon(Icons.folder_open),
|
||||
tooltip: l10n.openFileDirectory,
|
||||
onPressed: () async {
|
||||
final hasPermission = await PermissionService
|
||||
.instance
|
||||
.ensureStoragePermission(context: context);
|
||||
if (!hasPermission || !context.mounted) return;
|
||||
final canProceed = await _getTabProvider(
|
||||
context,
|
||||
).checkUnsavedChanges(context);
|
||||
if (!canProceed || !context.mounted) return;
|
||||
_getProjectProvider(context).openDirectory();
|
||||
itemBuilder: (popupContext) => [
|
||||
PopupMenuItem<_OpenProjectSource>(
|
||||
value: _OpenProjectSource.fromApp,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.inventory_2_outlined, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.openFromApp),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem<_OpenProjectSource>(
|
||||
value: _OpenProjectSource.fromExternal,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.folder_open_outlined, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.openFromExternal),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
onSelected: (source) async {
|
||||
switch (source) {
|
||||
case _OpenProjectSource.fromApp:
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ProjectManagementView(),
|
||||
),
|
||||
);
|
||||
break;
|
||||
case _OpenProjectSource.fromExternal:
|
||||
final hasPermission = await PermissionService
|
||||
.instance
|
||||
.ensureStoragePermission(context: context);
|
||||
if (!hasPermission || !context.mounted) return;
|
||||
final canProceed = await _getTabProvider(
|
||||
context,
|
||||
).checkUnsavedChanges(context);
|
||||
if (!canProceed || !context.mounted) return;
|
||||
_getProjectProvider(context).openDirectory();
|
||||
break;
|
||||
}
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
@@ -161,7 +209,12 @@ class CodeEditorDrawer extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
rootPath ?? '',
|
||||
hasProject
|
||||
? (InternalProjectService.instance
|
||||
.isInternalProject(rootPath)
|
||||
? p.basename(rootPath)
|
||||
: rootPath)
|
||||
: '',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
|
||||
@@ -2,7 +2,10 @@ import 'dart:io';
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/providers/distro_provider.dart';
|
||||
import 'package:code_editor/providers/terminal_provider.dart';
|
||||
import 'package:code_editor/models/distro_manifest.dart';
|
||||
import 'package:code_editor/services/distro_download_manager.dart';
|
||||
import 'package:code_editor/utils/dialog_utils.dart';
|
||||
import 'package:code_editor/views/distro_management_view.dart';
|
||||
import 'package:code_editor/widgets/distro_extract_dialog.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -55,14 +58,14 @@ class DistroSelectorDialog extends StatelessWidget {
|
||||
onSelected: (action) => _handleImportAction(context, action),
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'builtin',
|
||||
value: 'management_view',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.layers_outlined, size: 18),
|
||||
const Icon(Icons.apps_rounded, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Text(
|
||||
l10n.importBuiltinAlpine,
|
||||
l10n.importFromApp,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -197,47 +200,46 @@ class DistroSelectorDialog extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// 处理导入菜单操作
|
||||
bool _isValidDistroArchive(String path) {
|
||||
final lower = path.toLowerCase();
|
||||
return lower.endsWith('.tar.gz') ||
|
||||
lower.endsWith('.tgz') ||
|
||||
lower.endsWith('.tar.xz') ||
|
||||
lower.endsWith('.txz') ||
|
||||
lower.endsWith('.tar');
|
||||
}
|
||||
|
||||
Future<void> _handleImportAction(BuildContext context, String action) async {
|
||||
final distroProvider = context.read<DistroProvider>();
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
if (action == 'builtin') {
|
||||
// 1. 从内置 Alpine 导入
|
||||
final defaultName = _generateUniqueSystemName('alpine', distroProvider.installedSystems);
|
||||
final systemName = await DialogUtils.showInputDialog(
|
||||
context,
|
||||
title: l10n.importBuiltinAlpineTitle,
|
||||
hintText: l10n.systemNameHintWithDefault(defaultName),
|
||||
initialValue: defaultName,
|
||||
if (action == 'management_view') {
|
||||
// 1. 跳转到应用内系统管理页面
|
||||
final selectedItem = await Navigator.of(context).push<DistroManifestItem>(
|
||||
MaterialPageRoute(builder: (_) => const DistroManagementView()),
|
||||
);
|
||||
|
||||
if (systemName == null || systemName.trim().isEmpty || !context.mounted) return;
|
||||
final cleanName = systemName.trim();
|
||||
|
||||
// 模态同步解压
|
||||
final success = await DistroExtractDialog.show(
|
||||
context: context,
|
||||
systemName: cleanName,
|
||||
task: (onProgress, isCancelled) {
|
||||
return distroProvider.importBuiltinAlpine(
|
||||
systemName: cleanName,
|
||||
onProgress: onProgress,
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (success && context.mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.systemImportSuccess(cleanName));
|
||||
if (selectedItem != null && context.mounted) {
|
||||
// 用户直接点击已经安装的 item 本身,代表用户选择了那个 zip,返回后解压创建系统
|
||||
await _handleCreateSystemFromManifest(context, selectedItem);
|
||||
}
|
||||
} else if (action == 'external') {
|
||||
// 2. 从外部选择 .tar.gz 压缩包导入
|
||||
// 2. 从外部选择 .tar.gz / .tar.xz 压缩包导入
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.any,
|
||||
type: FileType.custom,
|
||||
allowedExtensions: const ['tar', 'gz', 'tgz', 'xz', 'txz'],
|
||||
);
|
||||
|
||||
if (result == null || result.files.single.path == null || !context.mounted) return;
|
||||
final filePath = result.files.single.path!;
|
||||
|
||||
if (!_isValidDistroArchive(filePath)) {
|
||||
if (context.mounted) {
|
||||
DialogUtils.showErrorToast(context, l10n.unsupportedDistroArchiveFormat);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final file = File(filePath);
|
||||
|
||||
// 提取默认名称(去掉 .tar.gz, .tgz 等后缀)
|
||||
@@ -284,6 +286,58 @@ class DistroSelectorDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 从选中的发行版安装包解压创建新的系统实例
|
||||
Future<void> _handleCreateSystemFromManifest(BuildContext context, DistroManifestItem item) async {
|
||||
final distroProvider = context.read<DistroProvider>();
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
final defaultName = _generateUniqueSystemName(item.id, distroProvider.installedSystems);
|
||||
final systemName = await DialogUtils.showInputDialog(
|
||||
context,
|
||||
title: l10n.importSystemInstanceTitle(item.name),
|
||||
hintText: l10n.systemNameHintWithDefault(defaultName),
|
||||
initialValue: defaultName,
|
||||
);
|
||||
|
||||
if (systemName == null || systemName.trim().isEmpty || !context.mounted) return;
|
||||
final cleanName = systemName.trim();
|
||||
|
||||
// 模态同步解压
|
||||
final success = await DistroExtractDialog.show(
|
||||
context: context,
|
||||
systemName: cleanName,
|
||||
task: (onProgress, isCancelled) async {
|
||||
if (item.id == 'ubuntu') {
|
||||
return distroProvider.importBuiltinUbuntu(
|
||||
systemName: cleanName,
|
||||
onProgress: onProgress,
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
} else if (item.id == 'alpine') {
|
||||
return distroProvider.importBuiltinAlpine(
|
||||
systemName: cleanName,
|
||||
onProgress: onProgress,
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
} else {
|
||||
final file = await DistroDownloadManager().getPackageFile(item.id, item.currentPackageSource!);
|
||||
return distroProvider.importFromCustomTarGz(
|
||||
systemName: cleanName,
|
||||
tarGzFile: file,
|
||||
onProgress: onProgress,
|
||||
isCancelled: isCancelled,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (success && context.mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.systemImportSuccess(cleanName));
|
||||
await distroProvider.refreshSystems();
|
||||
await distroProvider.selectSystem(cleanName);
|
||||
}
|
||||
}
|
||||
|
||||
/// 高危操作:二次确认删除系统
|
||||
Future<void> _handleDeleteSystem(BuildContext context, String systemName) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
@@ -63,10 +63,13 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool _matchesQuery(RunTask task) {
|
||||
bool _matchesQuery(RunTask task, AppLocalizations l10n) {
|
||||
if (_searchQuery.isEmpty) return true;
|
||||
return task.name.toLowerCase().contains(_searchQuery) ||
|
||||
final name = task.getLocalizedName(l10n);
|
||||
final desc = task.getLocalizedDescription(l10n);
|
||||
return name.toLowerCase().contains(_searchQuery) ||
|
||||
task.command.toLowerCase().contains(_searchQuery) ||
|
||||
desc.toLowerCase().contains(_searchQuery) ||
|
||||
(task.description?.toLowerCase().contains(_searchQuery) ?? false);
|
||||
}
|
||||
|
||||
@@ -74,8 +77,8 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final filteredCustom = widget.customTasks.where(_matchesQuery).toList();
|
||||
final filteredDetected = widget.detectedTasks.where(_matchesQuery).toList();
|
||||
final filteredCustom = widget.customTasks.where((t) => _matchesQuery(t, l10n)).toList();
|
||||
final filteredDetected = widget.detectedTasks.where((t) => _matchesQuery(t, l10n)).toList();
|
||||
final hasAny = filteredCustom.isNotEmpty || filteredDetected.isNotEmpty;
|
||||
|
||||
return Dialog(
|
||||
@@ -146,12 +149,12 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
children: [
|
||||
if (filteredDetected.isNotEmpty) ...[
|
||||
_buildSectionHeader(context, l10n.systemDetectedTasks, Icons.radar_outlined),
|
||||
...filteredDetected.map((task) => _buildTaskItem(context, task)),
|
||||
...filteredDetected.map((task) => _buildTaskItem(context, task, l10n)),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
if (filteredCustom.isNotEmpty) ...[
|
||||
_buildSectionHeader(context, l10n.userCustomTasks, Icons.person_outline),
|
||||
...filteredCustom.map((task) => _buildTaskItem(context, task)),
|
||||
...filteredCustom.map((task) => _buildTaskItem(context, task, l10n)),
|
||||
],
|
||||
],
|
||||
),
|
||||
@@ -183,7 +186,7 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTaskItem(BuildContext context, RunTask task) {
|
||||
Widget _buildTaskItem(BuildContext context, RunTask task, AppLocalizations l10n) {
|
||||
final theme = Theme.of(context);
|
||||
final isLastRun = widget.lastRunTaskId != null && widget.lastRunTaskId == task.id;
|
||||
|
||||
@@ -195,6 +198,8 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
? Colors.green.withValues(alpha: 0.8)
|
||||
: theme.colorScheme.outlineVariant.withValues(alpha: 0.5);
|
||||
|
||||
final localizedDesc = task.getLocalizedDescription(l10n).trim();
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
elevation: 0,
|
||||
@@ -210,7 +215,7 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.name,
|
||||
task.getLocalizedName(l10n),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isLastRun ? Colors.green.shade700 : null,
|
||||
@@ -233,9 +238,9 @@ class _RunTasksDialogState extends State<RunTasksDialog> {
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: (task.description != null && task.description!.trim().isNotEmpty)
|
||||
subtitle: localizedDesc.isNotEmpty
|
||||
? Text(
|
||||
task.description!.trim(),
|
||||
localizedDesc,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
|
||||
Reference in new issue
Block a user