2
This commit is contained in:
1 parent
9fbb414ee6
commit
4554f22c87
233 files changed
+147430
-605
No files matched your search
@@ -25,6 +25,9 @@ class ProjectProvider extends ChangeNotifier {
|
||||
//是否正在加载项目
|
||||
bool _isLoading = false;
|
||||
|
||||
//是否显示隐藏文件
|
||||
bool _showHiddenFiles = true;
|
||||
|
||||
// 跨 Provider 协同回调
|
||||
void Function(String oldPath, String newPath)? onEntityRenamed;
|
||||
void Function(String deletedPath)? onEntityDeleted;
|
||||
@@ -37,10 +40,18 @@ class ProjectProvider extends ChangeNotifier {
|
||||
List<String> get openDirectoryPaths => _history.openDirectoryPaths;
|
||||
List<FileItem> get items => _items;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get showHiddenFiles => _showHiddenFiles;
|
||||
FileItem? get cutItem => _cutItem;
|
||||
FileItem? get copiedItem => _copiedItem;
|
||||
bool get canPaste => _cutItem != null || _copiedItem != null;
|
||||
|
||||
void updateShowHiddenFiles(bool show) {
|
||||
if (_showHiddenFiles != show) {
|
||||
_showHiddenFiles = show;
|
||||
refreshTree();
|
||||
}
|
||||
}
|
||||
|
||||
bool isItemCut(String path) {
|
||||
if (_cutItem == null) return false;
|
||||
return _cutItem!.path == path || _cutItem!.path.trim() == path.trim();
|
||||
@@ -88,6 +99,7 @@ class ProjectProvider extends ChangeNotifier {
|
||||
? await FileService.instance.buildTree(
|
||||
cleanPath,
|
||||
openDirectoryPaths: validOpenPaths,
|
||||
showHiddenFiles: _showHiddenFiles,
|
||||
)
|
||||
: [];
|
||||
|
||||
@@ -187,6 +199,7 @@ class ProjectProvider extends ChangeNotifier {
|
||||
item.path,
|
||||
depth: item.depth + 1,
|
||||
openDirectoryPaths: updatedOpenPaths,
|
||||
showHiddenFiles: _showHiddenFiles,
|
||||
);
|
||||
item.children.clear();
|
||||
item.children.addAll(children);
|
||||
@@ -218,6 +231,7 @@ class ProjectProvider extends ChangeNotifier {
|
||||
final items = await FileService.instance.buildTree(
|
||||
currentRoot,
|
||||
openDirectoryPaths: _history.openDirectoryPaths,
|
||||
showHiddenFiles: _showHiddenFiles,
|
||||
);
|
||||
|
||||
String? currentFile = _history.lastOpenedFilePath;
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/run_task.dart';
|
||||
import '../services/project_task_detector.dart';
|
||||
import '../services/run_task_storage_service.dart';
|
||||
|
||||
/// 运行任务状态管理 Provider
|
||||
class RunProvider extends ChangeNotifier {
|
||||
final RunTaskStorageService _storageService;
|
||||
|
||||
RunProvider({RunTaskStorageService? storageService})
|
||||
: _storageService = storageService ?? RunTaskStorageService();
|
||||
|
||||
/// 内存中保存的系统动态探测任务列表(不落盘)
|
||||
List<RunTask> _detectedTasks = [];
|
||||
|
||||
/// 用户持久化配置的自定义任务列表(存放在 .code_editor/run_tasks.json)
|
||||
List<RunTask> _customTasks = [];
|
||||
|
||||
/// 最近一次运行的任务ID(持久化保存)
|
||||
String? _lastRunTaskId;
|
||||
|
||||
/// 最近一次运行的任务(如果有)
|
||||
RunTask? _lastRunTask;
|
||||
|
||||
/// 是否正在探测中(探测期间互斥,防止并发与按钮连点)
|
||||
bool _isDetecting = false;
|
||||
|
||||
/// 当前绑定的工程根路径
|
||||
String? _currentProjectRoot;
|
||||
|
||||
List<RunTask> get detectedTasks => List.unmodifiable(_detectedTasks);
|
||||
List<RunTask> get customTasks => List.unmodifiable(_customTasks);
|
||||
RunTask? get lastRunTask => _lastRunTask;
|
||||
String? get lastRunTaskId => _lastRunTaskId;
|
||||
bool get isDetecting => _isDetecting;
|
||||
String? get currentProjectRoot => _currentProjectRoot;
|
||||
|
||||
/// 获取当前合并后的所有可用任务列表(自定义任务置顶,随后为探测任务)
|
||||
List<RunTask> get allTasks => [..._customTasks, ..._detectedTasks];
|
||||
|
||||
/// 内部方法:尝试从现有任务列表中匹配 lastRunTaskId
|
||||
void _resolveLastRunTask() {
|
||||
if (_lastRunTaskId == null) return;
|
||||
for (final task in allTasks) {
|
||||
if (task.id == _lastRunTaskId) {
|
||||
_lastRunTask = task;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 记录最近一次执行的任务并持久化
|
||||
Future<void> setLastRunTask(RunTask task) async {
|
||||
_lastRunTask = task;
|
||||
_lastRunTaskId = task.id;
|
||||
notifyListeners();
|
||||
|
||||
if (_currentProjectRoot != null) {
|
||||
await _storageService.saveConfig(
|
||||
projectRoot: _currentProjectRoot!,
|
||||
tasks: _customTasks,
|
||||
lastRunTaskId: _lastRunTaskId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 当打开或切换工程时初始化任务(读取持久化任务 + 首次自动探测系统任务)
|
||||
Future<void> onProjectOpened(String projectRoot, {String? activeFilePath}) async {
|
||||
_currentProjectRoot = projectRoot;
|
||||
// 1. 加载持久化的自定义任务与最近运行任务ID
|
||||
final config = await _storageService.loadConfig(projectRoot);
|
||||
_customTasks = config.tasks;
|
||||
_lastRunTaskId = config.lastRunTaskId;
|
||||
_resolveLastRunTask();
|
||||
notifyListeners();
|
||||
|
||||
// 2. 自动触发一次系统探测
|
||||
await detectTasks(projectRoot: projectRoot, currentFilePath: activeFilePath);
|
||||
}
|
||||
|
||||
/// 关闭工程时清理状态
|
||||
void onProjectClosed() {
|
||||
_currentProjectRoot = null;
|
||||
_detectedTasks = [];
|
||||
_customTasks = [];
|
||||
_lastRunTaskId = null;
|
||||
_lastRunTask = null;
|
||||
_isDetecting = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 手动或自动触发项目探测
|
||||
/// [projectRoot] 目标工程路径
|
||||
/// [currentFilePath] 当前激活的编辑器文件路径
|
||||
Future<void> detectTasks({
|
||||
required String projectRoot,
|
||||
String? currentFilePath,
|
||||
}) async {
|
||||
if (_isDetecting) return;
|
||||
|
||||
_isDetecting = true;
|
||||
// 清空内存中的旧探测结果
|
||||
_detectedTasks = [];
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final detected = await ProjectTaskDetector.detect(
|
||||
projectRoot: projectRoot,
|
||||
currentFilePath: currentFilePath,
|
||||
);
|
||||
_detectedTasks = detected;
|
||||
_resolveLastRunTask();
|
||||
} catch (e) {
|
||||
debugPrint('[RunProvider] 项目探测失败: $e');
|
||||
} finally {
|
||||
_isDetecting = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 保存并更新用户自定义任务
|
||||
Future<void> updateCustomTasks(List<RunTask> updatedTasks) async {
|
||||
if (_currentProjectRoot == null) return;
|
||||
|
||||
_customTasks = List.from(updatedTasks);
|
||||
_resolveLastRunTask();
|
||||
notifyListeners();
|
||||
|
||||
await _storageService.saveConfig(
|
||||
projectRoot: _currentProjectRoot!,
|
||||
tasks: _customTasks,
|
||||
lastRunTaskId: _lastRunTaskId,
|
||||
);
|
||||
}
|
||||
|
||||
/// 添加单个自定义任务
|
||||
Future<void> addCustomTask(RunTask task) async {
|
||||
final list = List<RunTask>.from(_customTasks);
|
||||
list.add(task);
|
||||
await updateCustomTasks(list);
|
||||
}
|
||||
|
||||
/// 删除单个自定义任务
|
||||
Future<void> removeCustomTask(String taskId) async {
|
||||
final list = _customTasks.where((t) => t.id != taskId).toList();
|
||||
await updateCustomTasks(list);
|
||||
}
|
||||
|
||||
/// 修改单个自定义任务
|
||||
Future<void> editCustomTask(RunTask task) async {
|
||||
final index = _customTasks.indexWhere((t) => t.id == task.id);
|
||||
if (index != -1) {
|
||||
final list = List<RunTask>.from(_customTasks);
|
||||
list[index] = task;
|
||||
await updateCustomTasks(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
class SettingsProvider extends ChangeNotifier {
|
||||
//外观
|
||||
static const String _keyAppThemeMode = 'app_theme_mode'; //应用主题
|
||||
static const String _keyAppThemeColor = 'app_theme_color'; //主题颜色
|
||||
static const String _keyUiFont = 'app_ui_font'; //界面字体
|
||||
|
||||
//编辑区
|
||||
@@ -22,24 +23,39 @@ class SettingsProvider extends ChangeNotifier {
|
||||
|
||||
//终端
|
||||
static const String _keyTerminalFont = 'terminal_font_family'; //终端字体
|
||||
static const String _keyTerminalBackgroundColor = 'terminal_background_color'; //终端背景颜色
|
||||
static const String _keyEnableTerminalVirtualKeyboard = 'enable_terminal_virtual_keyboard'; //终端小键盘启用
|
||||
static const String _keyTerminalKeyboardConfig = 'terminal_virtual_keyboard_config'; //终端小键盘配置JSON
|
||||
|
||||
//项目配置
|
||||
static const String _keyShowHiddenFiles = 'show_hidden_files'; //显示隐藏文件
|
||||
|
||||
//语言
|
||||
static const String _keyAppLocale = 'app_locale';
|
||||
|
||||
ThemeMode _appThemeMode = ThemeMode.system;
|
||||
Color _appThemeColor = Colors.blue;
|
||||
String _uiFontId = 'system_default';
|
||||
EditorTheme _editorTheme = EditorTheme.atomOneDark;
|
||||
String _editorFontId = 'jetbrains_mono';
|
||||
String _terminalFontId = 'jetbrains_mono';
|
||||
Color _terminalBackgroundColor = const Color(0xFF1E1E1E);
|
||||
double _fontSize = 14.0;
|
||||
int _indentSize = 4;
|
||||
bool _wordWrap = false;
|
||||
bool _enableVirtualKeyboard = defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS;
|
||||
String _virtualKeyboardConfigJson = VirtualKeyboardConfig.defaultJsonPretty();
|
||||
VirtualKeyboardConfig _virtualKeyboardConfig = VirtualKeyboardConfig.defaultConfiguration();
|
||||
bool _enableTerminalVirtualKeyboard = defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS;
|
||||
String _terminalKeyboardConfigJson = VirtualKeyboardConfig.defaultTerminalJsonPretty();
|
||||
VirtualKeyboardConfig _terminalKeyboardConfig = VirtualKeyboardConfig.defaultTerminalConfiguration();
|
||||
bool _showHiddenFiles = true;
|
||||
Locale? _locale;
|
||||
|
||||
bool get showHiddenFiles => _showHiddenFiles;
|
||||
|
||||
ThemeMode get appThemeMode => _appThemeMode;
|
||||
Color get appThemeColor => _appThemeColor;
|
||||
String get uiFontId => _uiFontId;
|
||||
AppFontItem get uiFont => AppFonts.getUiFont(_uiFontId);
|
||||
|
||||
@@ -49,6 +65,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
|
||||
String get terminalFontId => _terminalFontId;
|
||||
AppFontItem get terminalFont => AppFonts.getTerminalFont(_terminalFontId);
|
||||
Color get terminalBackgroundColor => _terminalBackgroundColor;
|
||||
|
||||
double get fontSize => _fontSize;
|
||||
int get indentSize => _indentSize;
|
||||
@@ -56,8 +73,89 @@ class SettingsProvider extends ChangeNotifier {
|
||||
bool get enableVirtualKeyboard => _enableVirtualKeyboard;
|
||||
String get virtualKeyboardConfigJson => _virtualKeyboardConfigJson;
|
||||
VirtualKeyboardConfig get virtualKeyboardConfig => _virtualKeyboardConfig;
|
||||
bool get enableTerminalVirtualKeyboard => _enableTerminalVirtualKeyboard;
|
||||
String get terminalKeyboardConfigJson => _terminalKeyboardConfigJson;
|
||||
VirtualKeyboardConfig get terminalKeyboardConfig => _terminalKeyboardConfig;
|
||||
Locale? get locale => _locale;
|
||||
|
||||
// ==========================================
|
||||
// 小键盘配置:按作用域(编辑区 / 终端)读写两份互不干扰的配置
|
||||
// ==========================================
|
||||
|
||||
/// 读取指定作用域的键盘配置
|
||||
VirtualKeyboardConfig keyboardConfigFor(KeyboardScope scope) =>
|
||||
scope == KeyboardScope.terminal ? _terminalKeyboardConfig : _virtualKeyboardConfig;
|
||||
|
||||
/// 读取指定作用域的键盘配置 JSON
|
||||
String keyboardConfigJsonFor(KeyboardScope scope) =>
|
||||
scope == KeyboardScope.terminal ? _terminalKeyboardConfigJson : _virtualKeyboardConfigJson;
|
||||
|
||||
/// 指定作用域的小键盘是否启用(两个开关相互独立)
|
||||
bool keyboardEnabledFor(KeyboardScope scope) =>
|
||||
scope == KeyboardScope.terminal ? _enableTerminalVirtualKeyboard : _enableVirtualKeyboard;
|
||||
|
||||
static String _enablePrefKey(KeyboardScope scope) =>
|
||||
scope == KeyboardScope.terminal ? _keyEnableTerminalVirtualKeyboard : _keyEnableVirtualKeyboard;
|
||||
|
||||
static String _configPrefKey(KeyboardScope scope) =>
|
||||
scope == KeyboardScope.terminal ? _keyTerminalKeyboardConfig : _keyVirtualKeyboardConfig;
|
||||
|
||||
/// 设置指定作用域小键盘的启用状态
|
||||
Future<void> setKeyboardEnabled(KeyboardScope scope, bool enable) async {
|
||||
if (keyboardEnabledFor(scope) == enable) return;
|
||||
if (scope == KeyboardScope.terminal) {
|
||||
_enableTerminalVirtualKeyboard = enable;
|
||||
} else {
|
||||
_enableVirtualKeyboard = enable;
|
||||
}
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_enablePrefKey(scope), enable);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 保存指定作用域的键盘配置 JSON,校验失败返回 false
|
||||
Future<bool> setKeyboardConfig(KeyboardScope scope, String jsonStr) async {
|
||||
final err = VirtualKeyboardConfig.validateJson(jsonStr, scope);
|
||||
if (err != null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final decoded = jsonDecode(jsonStr) as Map<String, dynamic>;
|
||||
final config = VirtualKeyboardConfig.fromJson(decoded);
|
||||
if (scope == KeyboardScope.terminal) {
|
||||
_terminalKeyboardConfig = config;
|
||||
_terminalKeyboardConfigJson = jsonStr;
|
||||
} else {
|
||||
_virtualKeyboardConfig = config;
|
||||
_virtualKeyboardConfigJson = jsonStr;
|
||||
}
|
||||
notifyListeners();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_configPrefKey(scope), jsonStr);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 将指定作用域的键盘配置恢复为该作用域的默认预设
|
||||
Future<void> resetKeyboardConfig(KeyboardScope scope) async {
|
||||
if (scope == KeyboardScope.terminal) {
|
||||
_terminalKeyboardConfig = VirtualKeyboardConfig.defaultTerminalConfiguration();
|
||||
_terminalKeyboardConfigJson = VirtualKeyboardConfig.defaultTerminalJsonPretty();
|
||||
} else {
|
||||
_virtualKeyboardConfig = VirtualKeyboardConfig.defaultConfiguration();
|
||||
_virtualKeyboardConfigJson = VirtualKeyboardConfig.defaultJsonPretty();
|
||||
}
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_configPrefKey(scope));
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
await _loadSettings();
|
||||
}
|
||||
@@ -75,6 +173,11 @@ class SettingsProvider extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
final savedThemeColor = prefs.getInt(_keyAppThemeColor);
|
||||
if (savedThemeColor != null) {
|
||||
_appThemeColor = Color(savedThemeColor);
|
||||
}
|
||||
|
||||
//设置编辑区
|
||||
final themeId = prefs.getString(_keyEditorTheme);
|
||||
_editorTheme = EditorTheme.fromId(themeId);
|
||||
@@ -102,7 +205,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
|
||||
final savedKeyboardConfig = prefs.getString(_keyVirtualKeyboardConfig);
|
||||
if (savedKeyboardConfig != null && savedKeyboardConfig.trim().isNotEmpty) {
|
||||
final err = VirtualKeyboardConfig.validateJson(savedKeyboardConfig);
|
||||
final err = VirtualKeyboardConfig.validateJson(savedKeyboardConfig, KeyboardScope.editor);
|
||||
if (err == null) {
|
||||
try {
|
||||
final decoded = jsonDecode(savedKeyboardConfig) as Map<String, dynamic>;
|
||||
@@ -112,6 +215,24 @@ class SettingsProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
//终端小键盘(独立开关 + 独立配置)
|
||||
final savedEnableTerminalKeyboard = prefs.getBool(_keyEnableTerminalVirtualKeyboard);
|
||||
if (savedEnableTerminalKeyboard != null) {
|
||||
_enableTerminalVirtualKeyboard = savedEnableTerminalKeyboard;
|
||||
}
|
||||
|
||||
final savedTerminalKeyboardConfig = prefs.getString(_keyTerminalKeyboardConfig);
|
||||
if (savedTerminalKeyboardConfig != null && savedTerminalKeyboardConfig.trim().isNotEmpty) {
|
||||
final err = VirtualKeyboardConfig.validateJson(savedTerminalKeyboardConfig, KeyboardScope.terminal);
|
||||
if (err == null) {
|
||||
try {
|
||||
final decoded = jsonDecode(savedTerminalKeyboardConfig) as Map<String, dynamic>;
|
||||
_terminalKeyboardConfig = VirtualKeyboardConfig.fromJson(decoded);
|
||||
_terminalKeyboardConfigJson = savedTerminalKeyboardConfig;
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
//设置字体
|
||||
final savedUiFont = prefs.getString(_keyUiFont);
|
||||
if (savedUiFont != null && savedUiFont.isNotEmpty) {
|
||||
@@ -128,6 +249,17 @@ class SettingsProvider extends ChangeNotifier {
|
||||
_terminalFontId = savedTerminalFont;
|
||||
}
|
||||
|
||||
final savedTerminalBackground = prefs.getInt(_keyTerminalBackgroundColor);
|
||||
if (savedTerminalBackground != null) {
|
||||
_terminalBackgroundColor = Color(savedTerminalBackground);
|
||||
}
|
||||
|
||||
//设置项目配置
|
||||
final savedShowHiddenFiles = prefs.getBool(_keyShowHiddenFiles);
|
||||
if (savedShowHiddenFiles != null) {
|
||||
_showHiddenFiles = savedShowHiddenFiles;
|
||||
}
|
||||
|
||||
//设置语言
|
||||
final savedLocale = prefs.getString(_keyAppLocale);
|
||||
if(savedLocale != null && savedLocale.isNotEmpty) {
|
||||
@@ -150,6 +282,17 @@ class SettingsProvider extends ChangeNotifier {
|
||||
}catch (_) {}
|
||||
}
|
||||
|
||||
/// 设置主题颜色(Material 3 的 seed color)
|
||||
Future<void> setAppThemeColor(Color color) async {
|
||||
if (_appThemeColor.toARGB32() == color.toARGB32()) return;
|
||||
_appThemeColor = color;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_keyAppThemeColor, color.toARGB32());
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> setEditorTheme(EditorTheme theme) async {
|
||||
if(_editorTheme.id == theme.id) return;
|
||||
_editorTheme = theme;
|
||||
@@ -192,43 +335,17 @@ class SettingsProvider extends ChangeNotifier {
|
||||
}catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> setEnableVirtualKeyboard(bool enable) async {
|
||||
if (_enableVirtualKeyboard == enable) return;
|
||||
_enableVirtualKeyboard = enable;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_keyEnableVirtualKeyboard, enable);
|
||||
} catch (_) {}
|
||||
}
|
||||
/// 编辑区小键盘开关(等价于 `setKeyboardEnabled(KeyboardScope.editor, ...)`)
|
||||
Future<void> setEnableVirtualKeyboard(bool enable) =>
|
||||
setKeyboardEnabled(KeyboardScope.editor, enable);
|
||||
|
||||
Future<bool> setVirtualKeyboardConfig(String jsonStr) async {
|
||||
final err = VirtualKeyboardConfig.validateJson(jsonStr);
|
||||
if (err != null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final decoded = jsonDecode(jsonStr) as Map<String, dynamic>;
|
||||
_virtualKeyboardConfig = VirtualKeyboardConfig.fromJson(decoded);
|
||||
_virtualKeyboardConfigJson = jsonStr;
|
||||
notifyListeners();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_keyVirtualKeyboardConfig, jsonStr);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// 编辑区小键盘配置(等价于 `setKeyboardConfig(KeyboardScope.editor, ...)`)
|
||||
Future<bool> setVirtualKeyboardConfig(String jsonStr) =>
|
||||
setKeyboardConfig(KeyboardScope.editor, jsonStr);
|
||||
|
||||
Future<void> resetVirtualKeyboardConfig() async {
|
||||
_virtualKeyboardConfig = VirtualKeyboardConfig.defaultConfiguration();
|
||||
_virtualKeyboardConfigJson = VirtualKeyboardConfig.defaultJsonPretty();
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_keyVirtualKeyboardConfig);
|
||||
} catch (_) {}
|
||||
}
|
||||
/// 编辑区小键盘恢复默认
|
||||
Future<void> resetVirtualKeyboardConfig() =>
|
||||
resetKeyboardConfig(KeyboardScope.editor);
|
||||
|
||||
Future<void> setLocale(Locale? newLocale) async {
|
||||
if(_locale == newLocale) return;
|
||||
@@ -273,4 +390,26 @@ class SettingsProvider extends ChangeNotifier {
|
||||
await prefs.setString(_keyTerminalFont, fontId);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 设置终端背景颜色
|
||||
Future<void> setTerminalBackgroundColor(Color color) async {
|
||||
if (_terminalBackgroundColor.toARGB32() == color.toARGB32()) return;
|
||||
_terminalBackgroundColor = color;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_keyTerminalBackgroundColor, color.toARGB32());
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 设置是否显示隐藏文件
|
||||
Future<void> setShowHiddenFiles(bool show) async {
|
||||
if (_showHiddenFiles == show) return;
|
||||
_showHiddenFiles = show;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_keyShowHiddenFiles, show);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,12 @@ class TerminalProvider extends ChangeNotifier {
|
||||
|
||||
/// 创建新会话
|
||||
/// [distroId]: 发行版标识符(如 'alpine', 'host')
|
||||
/// [workspacePath]: 绑定的工程根目录路径(挂载至容器内部的 /workspace)
|
||||
/// [activate]: 是否自动跳转切换到该会话。抽屉右上角加号点击时为 false(直接添加但不跳转)。
|
||||
TerminalSession createSession({
|
||||
String? name,
|
||||
String distroId = 'alpine',
|
||||
String? workspacePath,
|
||||
bool activate = false,
|
||||
bool autoStartProcess = true,
|
||||
}) {
|
||||
@@ -47,7 +49,11 @@ class TerminalProvider extends ChangeNotifier {
|
||||
id: 'session_${DateTime.now().microsecondsSinceEpoch}_$nextIndex',
|
||||
name: sessionName,
|
||||
distroId: distroId,
|
||||
workspacePath: workspacePath,
|
||||
autoStartProcess: autoStartProcess,
|
||||
onProcessTerminated: () {
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
|
||||
_sessions.add(session);
|
||||
@@ -60,6 +66,28 @@ class TerminalProvider extends ChangeNotifier {
|
||||
return session;
|
||||
}
|
||||
|
||||
/// 查找或复用绑定了指定工程路径的终端会话
|
||||
/// 如果存在,直接激活并返回;如果不存在,则新建并激活一个会话
|
||||
TerminalSession getOrCreateSessionForProject({
|
||||
required String projectRoot,
|
||||
String distroId = 'alpine',
|
||||
String? sessionName,
|
||||
}) {
|
||||
final index = _sessions.indexWhere((s) => s.workspacePath == projectRoot);
|
||||
if (index != -1) {
|
||||
selectSession(index);
|
||||
return _sessions[index];
|
||||
}
|
||||
|
||||
return createSession(
|
||||
name: sessionName,
|
||||
distroId: distroId,
|
||||
workspacePath: projectRoot,
|
||||
activate: true,
|
||||
autoStartProcess: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// 切换当前激活的会话
|
||||
void selectSession(int index) {
|
||||
if (index >= 0 && index < _sessions.length) {
|
||||
|
||||
Reference in new issue
Block a user