This commit is contained in:
LZX committed 2026-09-15 00:50:53 +08:00
1 parent cce34e7960
commit b49e096355
56 files changed
+8343 -296

No files matched your search

+18 -1
View File
@@ -70,7 +70,24 @@ class DistroProvider with ChangeNotifier {
}
}
/// 从应用内置资源导入 Alpine 系统实例
/// 从应用内置资源导入 Ubuntu 24.04 系统实例
Future<void> importBuiltinUbuntu({
required String systemName,
InstallProgressCallback? onProgress,
bool Function()? isCancelled,
}) async {
await _manager.importBuiltinUbuntu(
systemName: systemName,
onProgress: onProgress,
isCancelled: isCancelled,
);
// 导入成功后刷新列表并自动选为当前系统
await refreshSystems();
await selectSystem(systemName);
}
/// 从应用内置资源导入 Alpine 系统实例(保留备用)
Future<void> importBuiltinAlpine({
required String systemName,
InstallProgressCallback? onProgress,
+25
View File
@@ -152,6 +152,31 @@ class ProjectProvider extends ChangeNotifier {
}
}
// 打开指定路径的项目
Future<void> openSpecificDirectory(String directoryPath) async {
try {
if (directoryPath.trim().isEmpty) return;
final cleanPath = p.normalize(directoryPath.trim());
final currentRoot = _history.rootPath != null ? p.normalize(_history.rootPath!) : null;
final isSameRoot = currentRoot != null && cleanPath == currentRoot;
await ProjectHistoryService.instance.recordHistory(
rootPath: cleanPath,
lastOpenedFilePath: isSameRoot ? _history.lastOpenedFilePath : null,
openDirectoryPaths: isSameRoot ? _history.openDirectoryPaths : const [],
openFilePaths: isSameRoot ? _history.openFilePaths : const [],
);
_cutItem = null;
_copiedItem = null;
await _loadProjectFromHistory();
} catch (e) {
debugPrint('打开指定项目失败: $e');
}
}
//选择项目历史
Future<void> switchProject(ProjectHistory selectedHistory) async {
final selectedRoot = selectedHistory.rootPath;
+15 -2
View File
@@ -40,6 +40,7 @@ class RunProvider extends ChangeNotifier {
/// 内部方法:尝试从现有任务列表中匹配 lastRunTaskId
void _resolveLastRunTask() {
_lastRunTask = null;
if (_lastRunTaskId == null) return;
for (final task in allTasks) {
if (task.id == _lastRunTaskId) {
@@ -67,8 +68,17 @@ class RunProvider extends ChangeNotifier {
/// 当打开或切换工程时初始化任务(读取持久化任务 + 首次自动探测系统任务)
Future<void> onProjectOpened(String projectRoot, {String? activeFilePath}) async {
_currentProjectRoot = projectRoot;
// 切换工程时首先立即清空上一工程的内存任务状态,防止跨项目污染
_detectedTasks = [];
_customTasks = [];
_lastRunTaskId = null;
_lastRunTask = null;
notifyListeners();
// 1. 加载持久化的自定义任务与最近运行任务ID
final config = await _storageService.loadConfig(projectRoot);
if (_currentProjectRoot != projectRoot) return;
_customTasks = config.tasks;
_lastRunTaskId = config.lastRunTaskId;
_resolveLastRunTask();
@@ -101,6 +111,7 @@ class RunProvider extends ChangeNotifier {
_isDetecting = true;
// 清空内存中的旧探测结果
_detectedTasks = [];
_resolveLastRunTask();
notifyListeners();
try {
@@ -108,8 +119,10 @@ class RunProvider extends ChangeNotifier {
projectRoot: projectRoot,
currentFilePath: currentFilePath,
);
_detectedTasks = detected;
_resolveLastRunTask();
if (_currentProjectRoot == projectRoot) {
_detectedTasks = detected;
_resolveLastRunTask();
}
} catch (e) {
debugPrint('[RunProvider] 项目探测失败: $e');
} finally {
+24
View File
@@ -1,5 +1,6 @@
import 'dart:convert';
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:flutter/foundation.dart';
@@ -30,6 +31,9 @@ class SettingsProvider extends ChangeNotifier {
//项目配置
static const String _keyShowHiddenFiles = 'show_hidden_files'; //显示隐藏文件
//下载配置
static const String _keyDownloadMirrorId = 'download_mirror_id'; //下载源镜像ID
//语言
static const String _keyAppLocale = 'app_locale';
@@ -50,9 +54,12 @@ class SettingsProvider extends ChangeNotifier {
String _terminalKeyboardConfigJson = VirtualKeyboardConfig.defaultTerminalJsonPretty();
VirtualKeyboardConfig _terminalKeyboardConfig = VirtualKeyboardConfig.defaultTerminalConfiguration();
bool _showHiddenFiles = true;
String _downloadMirrorId = 'tsinghua'; // 默认清华源
Locale? _locale;
bool get showHiddenFiles => _showHiddenFiles;
String get downloadMirrorId => _downloadMirrorId;
DistroMirror get downloadMirror => DistroRepository.getMirrorById(_downloadMirrorId);
ThemeMode get appThemeMode => _appThemeMode;
Color get appThemeColor => _appThemeColor;
@@ -260,6 +267,12 @@ class SettingsProvider extends ChangeNotifier {
_showHiddenFiles = savedShowHiddenFiles;
}
//设置下载源镜像配置
final savedMirrorId = prefs.getString(_keyDownloadMirrorId);
if (savedMirrorId != null && savedMirrorId.isNotEmpty) {
_downloadMirrorId = savedMirrorId;
}
//设置语言
final savedLocale = prefs.getString(_keyAppLocale);
if(savedLocale != null && savedLocale.isNotEmpty) {
@@ -412,4 +425,15 @@ class SettingsProvider extends ChangeNotifier {
await prefs.setBool(_keyShowHiddenFiles, show);
} catch (_) {}
}
/// 设置系统安装包下载镜像源
Future<void> setDownloadMirrorId(String mirrorId) async {
if (_downloadMirrorId == mirrorId) return;
_downloadMirrorId = mirrorId;
notifyListeners();
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyDownloadMirrorId, mirrorId);
} catch (_) {}
}
}
+1
View File
@@ -26,6 +26,7 @@ class TabProvider extends ChangeNotifier {
String? get currentFilePath => _activeFilePath;
bool get isModified => activeTab?.isModified ?? _isModified;
bool get hasUnsavedChanges => _isModified || _openTabs.any((t) => t.isModified);
void bindProjectProvider(ProjectProvider projectProvider) {
if (_projectProvider == projectProvider) return;
+18 -5
View File
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:code_editor/models/terminal_session.dart';
import 'package:flutter/material.dart';
@@ -26,9 +27,15 @@ class TerminalProvider extends ChangeNotifier {
void ensureInitialized({
String defaultName = '会话',
String defaultDistroId = 'alpine',
String? workspacePath,
}) {
if (_sessions.isEmpty) {
createSession(name: defaultName, distroId: defaultDistroId, activate: true);
createSession(
name: defaultName,
distroId: defaultDistroId,
workspacePath: workspacePath,
activate: true,
);
}
}
@@ -66,17 +73,23 @@ class TerminalProvider extends ChangeNotifier {
return session;
}
/// 查找或复用绑定了指定工程路径的终端会话
/// 查找或复用绑定了指定工程路径与系统实例的终端会话
/// 如果存在,直接激活并返回;如果不存在,则新建并激活一个会话
TerminalSession getOrCreateSessionForProject({
required String projectRoot,
String distroId = 'alpine',
String distroId = 'ubuntu',
String? sessionName,
}) {
final index = _sessions.indexWhere((s) => s.workspacePath == projectRoot);
final index = _sessions.indexWhere(
(s) => s.workspacePath == projectRoot && s.distroId == distroId,
);
if (index != -1) {
final session = _sessions[index];
selectSession(index);
return _sessions[index];
if (!session.isProcessRunning) {
unawaited(session.startProcess());
}
return session;
}
return createSession(