2
This commit is contained in:
1 parent
9fbb414ee6
commit
4554f22c87
233 files changed
+147430
-605
No files matched your search
+183
-2
@@ -1,18 +1,31 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/run_task.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/utils/dialog_utils.dart';
|
||||
import 'package:code_editor/views/settings_view.dart';
|
||||
import 'package:code_editor/views/terminal_view.dart';
|
||||
import 'package:code_editor/widgets/code_editor_app_bar.dart';
|
||||
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/run_tasks_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MainView extends StatelessWidget {
|
||||
class MainView extends StatefulWidget {
|
||||
const MainView({super.key});
|
||||
|
||||
@override
|
||||
State<MainView> createState() => _MainViewState();
|
||||
}
|
||||
|
||||
class _MainViewState extends State<MainView> {
|
||||
String? _lastProjectRoot;
|
||||
|
||||
static ProjectProvider _getProjectProvider(BuildContext context, {bool listen = false}) {
|
||||
return listen ? context.watch<ProjectProvider>() : context.read<ProjectProvider>();
|
||||
}
|
||||
@@ -21,6 +34,22 @@ class MainView extends StatelessWidget {
|
||||
return listen ? context.watch<TabProvider>() : context.read<TabProvider>();
|
||||
}
|
||||
|
||||
static RunProvider? _getRunProvider(BuildContext context, {bool listen = false}) {
|
||||
try {
|
||||
return listen ? Provider.of<RunProvider>(context, listen: listen) : Provider.of<RunProvider>(context, listen: false);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static TerminalProvider? _getTerminalProvider(BuildContext context, {bool listen = false}) {
|
||||
try {
|
||||
return listen ? Provider.of<TerminalProvider>(context, listen: listen) : Provider.of<TerminalProvider>(context, listen: false);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void _handleSave(BuildContext context) async {
|
||||
final tabProvider = _getTabProvider(context);
|
||||
if (tabProvider.currentFilePath == null || tabProvider.currentFilePath!.isEmpty) {
|
||||
@@ -52,6 +81,143 @@ class MainView extends StatelessWidget {
|
||||
final canProceed = await tabProvider.checkUnsavedChanges(context);
|
||||
if (canProceed && context.mounted) {
|
||||
await projectProvider.closeProject();
|
||||
if (context.mounted) {
|
||||
_getRunProvider(context)?.onProjectClosed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 执行某个具体的运行任务(复用/创建当前工程工作目录的终端并执行指令)
|
||||
void _executeRunTask(BuildContext context, RunTask task) {
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final rootPath = projectProvider.rootPath;
|
||||
if (rootPath == null || rootPath.isEmpty) {
|
||||
DialogUtils.showErrorToast(context, l10n.noOpenDirectory);
|
||||
return;
|
||||
}
|
||||
|
||||
final terminalProvider = _getTerminalProvider(context);
|
||||
final runProvider = _getRunProvider(context);
|
||||
|
||||
// 1. 查找或创建绑定了该工程工作路径的终端会话(保持系统默认会话名称)
|
||||
final session = terminalProvider?.getOrCreateSessionForProject(
|
||||
projectRoot: rootPath,
|
||||
distroId: 'alpine',
|
||||
);
|
||||
|
||||
// 2. 记录最近执行的任务
|
||||
runProvider?.setLastRunTask(task);
|
||||
|
||||
// 3. 跳转至终端视图
|
||||
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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// 点击运行按钮 (Play):有历史任务或单文件即直接执行,否则弹出任务列表
|
||||
void _handleRun(BuildContext context) {
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final rootPath = projectProvider.rootPath;
|
||||
if (rootPath == null || rootPath.isEmpty) {
|
||||
DialogUtils.showErrorToast(context, l10n.pleaseOpenProjectFirst);
|
||||
return;
|
||||
}
|
||||
|
||||
final runProvider = _getRunProvider(context);
|
||||
if (runProvider == null) return;
|
||||
|
||||
// 优先: 最近运行的任务(若已持久化并存在)
|
||||
if (runProvider.lastRunTask != null) {
|
||||
_executeRunTask(context, runProvider.lastRunTask!);
|
||||
return;
|
||||
}
|
||||
|
||||
// 若没有上一次运行的任务,直接打开运行任务列表
|
||||
_handleOpenRunTasksDialog(context);
|
||||
}
|
||||
|
||||
/// 打开运行任务选择弹窗
|
||||
void _handleOpenRunTasksDialog(BuildContext context) {
|
||||
final runProvider = _getRunProvider(context);
|
||||
if (runProvider == null) return;
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final rootPath = projectProvider.rootPath;
|
||||
if (rootPath == null || rootPath.isEmpty) {
|
||||
DialogUtils.showErrorToast(context, l10n.pleaseOpenProjectFirst);
|
||||
return;
|
||||
}
|
||||
|
||||
RunTasksDialog.show(
|
||||
context: context,
|
||||
customTasks: runProvider.customTasks,
|
||||
detectedTasks: runProvider.detectedTasks,
|
||||
lastRunTaskId: runProvider.lastRunTaskId ?? runProvider.lastRunTask?.id,
|
||||
onTaskSelected: (task) => _executeRunTask(context, task),
|
||||
onEditCustomTasks: () => _handleOpenEditRunTasks(context),
|
||||
);
|
||||
}
|
||||
|
||||
/// 打开运行任务编辑独立 View
|
||||
void _handleOpenEditRunTasks(BuildContext context) {
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final rootPath = projectProvider.rootPath;
|
||||
if (rootPath == null || rootPath.isEmpty) {
|
||||
DialogUtils.showErrorToast(context, l10n.pleaseOpenProjectFirst);
|
||||
return;
|
||||
}
|
||||
|
||||
final runProvider = _getRunProvider(context);
|
||||
if (runProvider == null) return;
|
||||
|
||||
RunTaskEditView.navigate(
|
||||
context: context,
|
||||
currentTasks: runProvider.customTasks,
|
||||
onSave: (updatedTasks) async {
|
||||
await runProvider.updateCustomTasks(updatedTasks);
|
||||
if (context.mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.runTasksUpdated);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 手动触发项目探测
|
||||
void _handleProjectDetect(BuildContext context) async {
|
||||
final projectProvider = _getProjectProvider(context);
|
||||
final rootPath = projectProvider.rootPath;
|
||||
if (rootPath == null || rootPath.isEmpty) return;
|
||||
|
||||
final tabProvider = _getTabProvider(context);
|
||||
final runProvider = _getRunProvider(context);
|
||||
if (runProvider == null) return;
|
||||
|
||||
await runProvider.detectTasks(
|
||||
projectRoot: rootPath,
|
||||
currentFilePath: tabProvider.currentFilePath,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
DialogUtils.showSuccessToast(
|
||||
context,
|
||||
l10n.detectCompletedMessage(runProvider.detectedTasks.length),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +225,7 @@ class MainView extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final projectProvider = _getProjectProvider(context, listen: true);
|
||||
final tabProvider = _getTabProvider(context, listen: true);
|
||||
final runProvider = _getRunProvider(context, listen: true);
|
||||
|
||||
if (projectProvider.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@@ -68,6 +235,16 @@ class MainView extends StatelessWidget {
|
||||
final rootPath = projectProvider.rootPath;
|
||||
final isModified = tabProvider.isModified;
|
||||
|
||||
// 当检测到切换了项目根目录时,自动触发初始化并进行一次探测
|
||||
if (rootPath != null && rootPath != _lastProjectRoot) {
|
||||
_lastProjectRoot = rootPath;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
runProvider?.onProjectOpened(rootPath, activeFilePath: currentFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return PopScope(
|
||||
canPop: !isModified,
|
||||
onPopInvokedWithResult: (didPop, result) async {
|
||||
@@ -86,7 +263,11 @@ class MainView extends StatelessWidget {
|
||||
onSaveAll: () => _handleSaveAll(context),
|
||||
onCloseAllTabs: () => _handleCloseAllTabs(context),
|
||||
onCloseProject: () => _handleCloseProject(context),
|
||||
onRun: () {},
|
||||
onRun: () => _handleRun(context),
|
||||
onRunTasks: () => _handleOpenRunTasksDialog(context),
|
||||
onProjectDetect: () => _handleProjectDetect(context),
|
||||
onEditRunTasks: () => _handleOpenEditRunTasks(context),
|
||||
isDetecting: runProvider?.isDetecting ?? false,
|
||||
onSettings: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/run_task.dart';
|
||||
import '../utils/dialog_utils.dart';
|
||||
|
||||
/// 运行任务单项创建/编辑 View(独立页面,点击返回键返回任务配置界面)
|
||||
class RunTaskDetailView extends StatefulWidget {
|
||||
final RunTask? initialTask;
|
||||
final ValueChanged<RunTask> onSave;
|
||||
|
||||
const RunTaskDetailView({
|
||||
super.key,
|
||||
this.initialTask,
|
||||
required this.onSave,
|
||||
});
|
||||
|
||||
static Future<void> navigate({
|
||||
required BuildContext context,
|
||||
RunTask? initialTask,
|
||||
required ValueChanged<RunTask> onSave,
|
||||
}) {
|
||||
return Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (ctx) => RunTaskDetailView(
|
||||
initialTask: initialTask,
|
||||
onSave: onSave,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<RunTaskDetailView> createState() => _RunTaskDetailViewState();
|
||||
}
|
||||
|
||||
class _RunTaskDetailViewState extends State<RunTaskDetailView> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late TextEditingController _nameController;
|
||||
late TextEditingController _commandController;
|
||||
late TextEditingController _descController;
|
||||
bool _clearBeforeRun = false;
|
||||
|
||||
late String _initialName;
|
||||
late String _initialCommand;
|
||||
late String _initialDesc;
|
||||
late bool _initialClearBeforeRun;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final task = widget.initialTask;
|
||||
_initialName = task?.name ?? '';
|
||||
_initialCommand = task?.command ?? '';
|
||||
_initialDesc = task?.description ?? '';
|
||||
_initialClearBeforeRun = task?.clearBeforeRun ?? false;
|
||||
|
||||
_nameController = TextEditingController(text: _initialName);
|
||||
_commandController = TextEditingController(text: _initialCommand);
|
||||
_descController = TextEditingController(text: _initialDesc);
|
||||
_clearBeforeRun = _initialClearBeforeRun;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_commandController.dispose();
|
||||
_descController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _isDirty {
|
||||
return _nameController.text != _initialName ||
|
||||
_commandController.text != _initialCommand ||
|
||||
_descController.text != _initialDesc ||
|
||||
_clearBeforeRun != _initialClearBeforeRun;
|
||||
}
|
||||
|
||||
Future<bool> _confirmDiscardChanges() async {
|
||||
if (!_isDirty) return true;
|
||||
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final shouldDiscard = await DialogUtils.showConfirmDialog(
|
||||
context,
|
||||
title: l10n.unsavedTaskChangesTitle,
|
||||
message: l10n.unsavedTaskChangesMessage,
|
||||
confirmText: l10n.dontSave,
|
||||
cancelText: l10n.cancel,
|
||||
icon: Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
size: 28,
|
||||
),
|
||||
);
|
||||
return shouldDiscard;
|
||||
}
|
||||
|
||||
void _save() {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
final task = RunTask(
|
||||
id: widget.initialTask?.id ?? 'custom_${DateTime.now().microsecondsSinceEpoch}',
|
||||
name: _nameController.text.trim(),
|
||||
command: _commandController.text.trim(),
|
||||
source: TaskSource.custom,
|
||||
description: _descController.text.trim().isEmpty ? null : _descController.text.trim(),
|
||||
clearBeforeRun: _clearBeforeRun,
|
||||
);
|
||||
|
||||
widget.onSave(task);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final isEditing = widget.initialTask != null;
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) async {
|
||||
if (didPop) return;
|
||||
final canDiscard = await _confirmDiscardChanges();
|
||||
if (canDiscard && context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(isEditing ? l10n.editTask : l10n.addTask),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
tooltip: l10n.back,
|
||||
onPressed: () async {
|
||||
final canDiscard = await _confirmDiscardChanges();
|
||||
if (canDiscard && context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.check),
|
||||
tooltip: l10n.done,
|
||||
onPressed: _save,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.taskNameRequired,
|
||||
hintText: l10n.taskNameHint,
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
validator: (v) => (v == null || v.trim().isEmpty) ? l10n.taskNameEmptyError : null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _descController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.taskDescOptional,
|
||||
hintText: l10n.taskDescHint,
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _commandController,
|
||||
maxLines: 4,
|
||||
style: const TextStyle(fontFamily: 'monospace', fontSize: 13),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.shellCommandRequired,
|
||||
hintText: l10n.shellCommandHint,
|
||||
border: const OutlineInputBorder(),
|
||||
alignLabelWithHint: true,
|
||||
isDense: true,
|
||||
),
|
||||
validator: (v) => (v == null || v.trim().isEmpty) ? l10n.shellCommandEmptyError : null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(l10n.clearBeforeRun),
|
||||
subtitle: Text(l10n.clearBeforeRunSubtitle, style: const TextStyle(fontSize: 12)),
|
||||
value: _clearBeforeRun,
|
||||
onChanged: (val) => setState(() => _clearBeforeRun = val),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/run_task.dart';
|
||||
import 'run_task_detail_view.dart';
|
||||
|
||||
/// 运行任务列表配置 View(支持拖动排序、单项与多选删除确认、自动静默保存至 JSON)
|
||||
class RunTaskEditView extends StatefulWidget {
|
||||
final List<RunTask> tasks;
|
||||
final ValueChanged<List<RunTask>> onSave;
|
||||
|
||||
const RunTaskEditView({
|
||||
super.key,
|
||||
required this.tasks,
|
||||
required this.onSave,
|
||||
});
|
||||
|
||||
static Future<void> navigate({
|
||||
required BuildContext context,
|
||||
required List<RunTask> currentTasks,
|
||||
required ValueChanged<List<RunTask>> onSave,
|
||||
}) {
|
||||
return Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (ctx) => RunTaskEditView(
|
||||
tasks: currentTasks,
|
||||
onSave: onSave,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<RunTaskEditView> createState() => _RunTaskEditViewState();
|
||||
}
|
||||
|
||||
class _RunTaskEditViewState extends State<RunTaskEditView> {
|
||||
late List<RunTask> _taskList;
|
||||
bool _isSelectionMode = false;
|
||||
final Set<String> _selectedTaskIds = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_taskList = List.from(widget.tasks);
|
||||
}
|
||||
|
||||
/// 任何变动立即写回(直接写回 JSON,无需点击额外保存按钮)
|
||||
void _persistChanges() {
|
||||
widget.onSave(List.unmodifiable(_taskList));
|
||||
}
|
||||
|
||||
void _openCreateView() {
|
||||
RunTaskDetailView.navigate(
|
||||
context: context,
|
||||
onSave: (newTask) {
|
||||
setState(() {
|
||||
_taskList.add(newTask);
|
||||
});
|
||||
_persistChanges();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _openEditView(RunTask task) {
|
||||
RunTaskDetailView.navigate(
|
||||
context: context,
|
||||
initialTask: task,
|
||||
onSave: (updatedTask) {
|
||||
final index = _taskList.indexWhere((t) => t.id == updatedTask.id);
|
||||
if (index != -1) {
|
||||
setState(() {
|
||||
_taskList[index] = updatedTask;
|
||||
});
|
||||
_persistChanges();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 单项删除确认弹窗
|
||||
Future<void> _confirmDeleteSingle(RunTask task) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(l10n.confirmDelete),
|
||||
content: Text(l10n.deleteTaskConfirmMessage(task.name)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: Theme.of(context).colorScheme.error),
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: Text(l10n.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && mounted) {
|
||||
setState(() {
|
||||
_taskList.removeWhere((t) => t.id == task.id);
|
||||
_selectedTaskIds.remove(task.id);
|
||||
});
|
||||
_persistChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/// 多选批量删除确认弹窗
|
||||
Future<void> _confirmDeleteBatch() async {
|
||||
if (_selectedTaskIds.isEmpty) return;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text(l10n.confirmDelete),
|
||||
content: Text(l10n.deleteSelectedTasksConfirmMessage(_selectedTaskIds.length)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: Theme.of(context).colorScheme.error),
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: Text(l10n.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && mounted) {
|
||||
setState(() {
|
||||
_taskList.removeWhere((t) => _selectedTaskIds.contains(t.id));
|
||||
_selectedTaskIds.clear();
|
||||
_isSelectionMode = false;
|
||||
});
|
||||
_persistChanges();
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleSelection(String id) {
|
||||
setState(() {
|
||||
if (_selectedTaskIds.contains(id)) {
|
||||
_selectedTaskIds.remove(id);
|
||||
if (_selectedTaskIds.isEmpty) {
|
||||
_isSelectionMode = false;
|
||||
}
|
||||
} else {
|
||||
_selectedTaskIds.add(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_isSelectionMode
|
||||
? l10n.selectedCount(_selectedTaskIds.length)
|
||||
: l10n.runTasksConfig),
|
||||
leading: _isSelectionMode
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isSelectionMode = false;
|
||||
_selectedTaskIds.clear();
|
||||
});
|
||||
},
|
||||
)
|
||||
: null,
|
||||
actions: [
|
||||
if (_isSelectionMode)
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete_outline, color: theme.colorScheme.error),
|
||||
tooltip: l10n.deleteSelected,
|
||||
onPressed: _confirmDeleteBatch,
|
||||
)
|
||||
else if (_taskList.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.checklist),
|
||||
tooltip: l10n.selectTasksToDelete,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isSelectionMode = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: _taskList.isEmpty ? _buildEmptyView(theme, l10n) : _buildReorderableList(theme, l10n),
|
||||
),
|
||||
floatingActionButton: !_isSelectionMode
|
||||
? FloatingActionButton(
|
||||
onPressed: _openCreateView,
|
||||
tooltip: l10n.addTask,
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyView(ThemeData theme, AppLocalizations l10n) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.playlist_remove, size: 56, color: theme.colorScheme.outline),
|
||||
const SizedBox(height: 12),
|
||||
Text(l10n.noCustomTasksInProject,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(color: theme.colorScheme.outline)),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.icon(
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(l10n.createNow),
|
||||
onPressed: _openCreateView,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReorderableList(ThemeData theme, AppLocalizations l10n) {
|
||||
return ReorderableListView.builder(
|
||||
buildDefaultDragHandles: false,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: _taskList.length,
|
||||
onReorderItem: (oldIndex, newIndex) {
|
||||
setState(() {
|
||||
final task = _taskList.removeAt(oldIndex);
|
||||
_taskList.insert(newIndex, task);
|
||||
});
|
||||
_persistChanges();
|
||||
},
|
||||
itemBuilder: (ctx, index) {
|
||||
final task = _taskList[index];
|
||||
final isSelected = _selectedTaskIds.contains(task.id);
|
||||
|
||||
return Card(
|
||||
key: ValueKey(task.id),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
elevation: 0,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primaryContainer.withValues(alpha: 0.3)
|
||||
: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.3),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
side: BorderSide(
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.outlineVariant.withValues(alpha: 0.4),
|
||||
),
|
||||
),
|
||||
child: ListTile(
|
||||
dense: true,
|
||||
contentPadding: const EdgeInsets.only(left: 12, right: 4, top: 2, bottom: 2),
|
||||
leading: _isSelectionMode
|
||||
? Checkbox(
|
||||
value: isSelected,
|
||||
onChanged: (_) => _toggleSelection(task.id),
|
||||
)
|
||||
: const CircleAvatar(
|
||||
radius: 16,
|
||||
child: Icon(Icons.terminal, size: 18),
|
||||
),
|
||||
// 只显示:名称 + 用途(描述)
|
||||
title: Text(
|
||||
task.name,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 14),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: (task.description != null && task.description!.trim().isNotEmpty)
|
||||
? Text(
|
||||
task.description!.trim(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 12, color: theme.colorScheme.outline),
|
||||
)
|
||||
: null,
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (!_isSelectionMode) ...[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined, size: 20),
|
||||
tooltip: l10n.editTask,
|
||||
onPressed: () => _openEditView(task),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete_outline, size: 20, color: theme.colorScheme.error),
|
||||
tooltip: l10n.delete,
|
||||
onPressed: () => _confirmDeleteSingle(task),
|
||||
),
|
||||
// 最右侧拖动把手,支持长按/拖动排序
|
||||
ReorderableDragStartListener(
|
||||
index: index,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
child: Icon(
|
||||
Icons.drag_handle,
|
||||
color: theme.colorScheme.outline,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
if (_isSelectionMode) {
|
||||
_toggleSelection(task.id);
|
||||
} else {
|
||||
_openEditView(task);
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (!_isSelectionMode) {
|
||||
setState(() {
|
||||
_isSelectionMode = true;
|
||||
_selectedTaskIds.add(task.id);
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
+187
-16
@@ -5,6 +5,7 @@ import 'package:code_editor/models/virtual_keyboard_config.dart';
|
||||
import 'package:code_editor/providers/settings_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../widgets/color_palette_dialog.dart';
|
||||
import 'virtual_keyboard_config_view.dart';
|
||||
|
||||
/// 设置页面
|
||||
@@ -38,6 +39,7 @@ class SettingsView extends StatelessWidget {
|
||||
// ==============================
|
||||
_buildSectionHeader(context, l10n.appearanceSection),
|
||||
_buildThemeModeTile(context, provider, l10n),
|
||||
_buildThemeColorTile(context, provider, l10n),
|
||||
_buildUiFontTile(context, provider),
|
||||
|
||||
const Divider(height: 32, indent: 16, endIndent: 16),
|
||||
@@ -59,13 +61,24 @@ class SettingsView extends StatelessWidget {
|
||||
// ==============================
|
||||
// 3. 终端分组 (Terminal)
|
||||
// ==============================
|
||||
_buildSectionHeader(context, '终端'),
|
||||
_buildSectionHeader(context, l10n.terminal),
|
||||
_buildTerminalBackgroundTile(context, provider, l10n),
|
||||
_buildTerminalVirtualKeyboardTile(context, provider, l10n),
|
||||
_buildTerminalVirtualKeyboardConfigTile(context, provider, l10n),
|
||||
_buildTerminalFontTile(context, provider),
|
||||
|
||||
const Divider(height: 32, indent: 16, endIndent: 16),
|
||||
|
||||
// ==============================
|
||||
// 4. 语言分组 (Language)
|
||||
// 4. 项目分组 (Project)
|
||||
// ==============================
|
||||
_buildSectionHeader(context, l10n.projectSection),
|
||||
_buildShowHiddenFilesTile(context, provider, l10n),
|
||||
|
||||
const Divider(height: 32, indent: 16, endIndent: 16),
|
||||
|
||||
// ==============================
|
||||
// 5. 语言分组 (Language)
|
||||
// ==============================
|
||||
_buildSectionHeader(context, l10n.languageSection),
|
||||
_buildLanguageTile(context, provider, l10n),
|
||||
@@ -178,19 +191,20 @@ class SettingsView extends StatelessWidget {
|
||||
/// 外观:UI 界面字体条目
|
||||
Widget _buildUiFontTile(BuildContext context, SettingsProvider provider) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final currentFont = provider.uiFont;
|
||||
return ListTile(
|
||||
leading: Icon(Icons.font_download_outlined, color: theme.colorScheme.primary),
|
||||
title: const Text('界面字体'),
|
||||
subtitle: Text(currentFont.name),
|
||||
title: Text(l10n.uiFont),
|
||||
subtitle: Text(l10n.fontName(currentFont.id)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showFontSelector(
|
||||
context,
|
||||
title: '选择界面字体',
|
||||
title: l10n.selectUiFont,
|
||||
fonts: AppFonts.uiFonts,
|
||||
currentId: provider.uiFontId,
|
||||
previewSample: '代码编辑器界面字体预览 Code Editor 123',
|
||||
previewSample: l10n.uiFontPreview,
|
||||
onSelected: (id) => provider.setUiFontId(id),
|
||||
);
|
||||
},
|
||||
@@ -200,19 +214,25 @@ class SettingsView extends StatelessWidget {
|
||||
/// 编辑区:代码字体条目
|
||||
Widget _buildEditorFontTile(BuildContext context, SettingsProvider provider) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final currentFont = provider.editorFont;
|
||||
final fontName = l10n.fontName(currentFont.id);
|
||||
final subtitle = currentFont.id == 'jetbrains_mono'
|
||||
? '$fontName (${l10n.recommended})'
|
||||
: fontName;
|
||||
return ListTile(
|
||||
leading: Icon(Icons.text_fields, color: theme.colorScheme.primary),
|
||||
title: const Text('代码字体'),
|
||||
subtitle: Text(currentFont.name),
|
||||
title: Text(l10n.codeFont),
|
||||
subtitle: Text(subtitle),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showFontSelector(
|
||||
context,
|
||||
title: '选择代码字体',
|
||||
title: l10n.selectCodeFont,
|
||||
fonts: AppFonts.editorFonts,
|
||||
currentId: provider.editorFontId,
|
||||
previewSample: 'void main() { int a = 123; } // 代码预览',
|
||||
previewSample: l10n.codeFontPreview,
|
||||
showRecommendation: true,
|
||||
onSelected: (id) => provider.setEditorFontId(id),
|
||||
);
|
||||
},
|
||||
@@ -222,25 +242,108 @@ class SettingsView extends StatelessWidget {
|
||||
/// 终端:终端字体条目
|
||||
Widget _buildTerminalFontTile(BuildContext context, SettingsProvider provider) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final currentFont = provider.terminalFont;
|
||||
final fontName = l10n.fontName(currentFont.id);
|
||||
final subtitle = currentFont.id == 'jetbrains_mono'
|
||||
? '$fontName (${l10n.recommended})'
|
||||
: fontName;
|
||||
return ListTile(
|
||||
leading: Icon(Icons.terminal, color: theme.colorScheme.primary),
|
||||
title: const Text('终端字体'),
|
||||
subtitle: Text(currentFont.name),
|
||||
leading: Icon(Icons.font_download_outlined, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.terminalFont),
|
||||
subtitle: Text(subtitle),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showFontSelector(
|
||||
context,
|
||||
title: '选择终端字体',
|
||||
title: l10n.selectTerminalFont,
|
||||
fonts: AppFonts.terminalFonts,
|
||||
currentId: provider.terminalFontId,
|
||||
previewSample: '\$ git status -s # 终端字体预览',
|
||||
previewSample: l10n.terminalFontPreview,
|
||||
showRecommendation: true,
|
||||
onSelected: (id) => provider.setTerminalFontId(id),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 外观:主题颜色条目(点击弹出调色板)
|
||||
Widget _buildThemeColorTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
final current = provider.appThemeColor;
|
||||
|
||||
return ListTile(
|
||||
leading: Icon(Icons.palette_outlined, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.themeColor),
|
||||
subtitle: Text(colorToHex(current)),
|
||||
trailing: _buildColorTrailing(context, current),
|
||||
onTap: () async {
|
||||
final picked = await ColorPaletteDialog.show(
|
||||
context,
|
||||
title: l10n.selectThemeColor,
|
||||
current: current,
|
||||
palette: ColorPaletteDialog.uiPalette,
|
||||
);
|
||||
if (picked != null) {
|
||||
await provider.setAppThemeColor(picked);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 终端:终端背景颜色条目(点击弹出调色板)
|
||||
Widget _buildTerminalBackgroundTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
final current = provider.terminalBackgroundColor;
|
||||
|
||||
return ListTile(
|
||||
leading: Icon(Icons.palette_outlined, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.terminalBackgroundColor),
|
||||
subtitle: Text(colorToHex(current)),
|
||||
trailing: _buildColorTrailing(context, current),
|
||||
onTap: () async {
|
||||
final picked = await ColorPaletteDialog.show(
|
||||
context,
|
||||
title: l10n.selectTerminalBackgroundColor,
|
||||
current: current,
|
||||
palette: ColorPaletteDialog.terminalPalette,
|
||||
);
|
||||
if (picked != null) {
|
||||
await provider.setTerminalBackgroundColor(picked);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 颜色预览圆点 + 右箭头(与"代码高亮主题"条目的尾部样式一致)
|
||||
Widget _buildColorTrailing(BuildContext context, Color color) {
|
||||
final theme = Theme.of(context);
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant, width: 1.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Icon(Icons.chevron_right),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 字体选择底部弹窗
|
||||
void _showFontSelector(
|
||||
BuildContext context, {
|
||||
@@ -249,7 +352,9 @@ class SettingsView extends StatelessWidget {
|
||||
required String currentId,
|
||||
required ValueChanged<String> onSelected,
|
||||
required String previewSample,
|
||||
bool showRecommendation = false,
|
||||
}) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -280,13 +385,17 @@ class SettingsView extends StatelessWidget {
|
||||
itemBuilder: (context, index) {
|
||||
final item = fonts[index];
|
||||
final isSelected = item.id == currentId;
|
||||
final isRecommended = showRecommendation && item.id == 'jetbrains_mono';
|
||||
final fontTitle = isRecommended
|
||||
? '${l10n.fontName(item.id)} (${l10n.recommended})'
|
||||
: l10n.fontName(item.id);
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
item.isMonospace ? Icons.code : Icons.font_download_outlined,
|
||||
color: isSelected ? theme.colorScheme.primary : null,
|
||||
),
|
||||
title: Text(
|
||||
item.name,
|
||||
fontTitle,
|
||||
style: TextStyle(
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
color: isSelected ? theme.colorScheme.primary : null,
|
||||
@@ -681,6 +790,50 @@ class SettingsView extends StatelessWidget {
|
||||
|
||||
|
||||
|
||||
/// 终端:终端小键盘开关条目(与编辑区开关相互独立)
|
||||
Widget _buildTerminalVirtualKeyboardTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return SwitchListTile(
|
||||
secondary: Icon(Icons.keyboard_command_key, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.terminalVirtualKeyboard),
|
||||
subtitle: Text(l10n.terminalVirtualKeyboardSubtitle),
|
||||
value: provider.enableTerminalVirtualKeyboard,
|
||||
onChanged: (val) => provider.setKeyboardEnabled(KeyboardScope.terminal, val),
|
||||
);
|
||||
}
|
||||
|
||||
/// 终端:终端键盘配置编辑条目
|
||||
Widget _buildTerminalVirtualKeyboardConfigTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
final enabled = provider.enableTerminalVirtualKeyboard;
|
||||
|
||||
return ListTile(
|
||||
enabled: enabled,
|
||||
leading: Icon(Icons.tune, color: enabled ? theme.colorScheme.primary : theme.disabledColor),
|
||||
title: Text(l10n.editTerminalVirtualKeyboardConfig),
|
||||
subtitle: Text(l10n.editTerminalVirtualKeyboardConfigSubtitle),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const VirtualKeyboardConfigView(
|
||||
scope: KeyboardScope.terminal,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 语言:应用语言选择条目
|
||||
Widget _buildLanguageTile(
|
||||
BuildContext context,
|
||||
@@ -769,4 +922,22 @@ class SettingsView extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 项目配置:显示隐藏文件开关
|
||||
Widget _buildShowHiddenFilesTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
return SwitchListTile(
|
||||
secondary: Icon(Icons.visibility_outlined, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.showHiddenFiles),
|
||||
subtitle: Text(l10n.showHiddenFilesSubtitle),
|
||||
value: provider.showHiddenFiles,
|
||||
onChanged: (val) {
|
||||
provider.setShowHiddenFiles(val);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,22 @@
|
||||
import 'package:code_editor/l10n/app_localizations.dart';
|
||||
import 'package:code_editor/models/app_font.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';
|
||||
import 'package:code_editor/providers/project_provider.dart';
|
||||
import 'package:code_editor/providers/settings_provider.dart';
|
||||
import 'package:code_editor/providers/terminal_provider.dart';
|
||||
import 'package:code_editor/utils/terminal_theme_helper.dart';
|
||||
import 'package:code_editor/widgets/distro_extract_dialog.dart';
|
||||
import 'package:code_editor/widgets/distro_selector_dialog.dart';
|
||||
import 'package:code_editor/widgets/terminal_drawer.dart';
|
||||
import 'package:code_editor/widgets/terminal_keyboard_sink.dart';
|
||||
import 'package:code_editor/widgets/terminal_modifier_state.dart';
|
||||
import 'package:code_editor/widgets/virtual_keyboard_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:xterm/xterm.dart' as xterm;
|
||||
import 'package:xterm/xterm.dart' show TerminalInputHandler, defaultInputHandler;
|
||||
|
||||
/// 终端视图(支持多系统实例切换、全屏会话保持、右侧抽屉多会话管理与交互)
|
||||
class TerminalView extends StatefulWidget {
|
||||
@@ -84,15 +91,17 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final provider = context.watch<TerminalProvider>();
|
||||
final distroProvider = context.watch<DistroProvider?>();
|
||||
final projectProvider = context.watch<ProjectProvider?>();
|
||||
|
||||
final activeSession = provider.activeSession;
|
||||
final sessions = provider.sessions;
|
||||
final activeIndex = provider.activeIndex;
|
||||
|
||||
final titleText = activeSession?.name ?? l10n.sessionDefaultName;
|
||||
final currentSystem = activeSession?.distroId ?? distroProvider?.selectedSystem;
|
||||
final subtitleText = currentSystem != null ? l10n.terminalWithSystem(currentSystem) : l10n.terminal;
|
||||
final projectRoot = activeSession?.workspacePath ?? projectProvider?.rootPath;
|
||||
final String? subtitleText = (projectRoot != null && projectRoot.trim().isNotEmpty)
|
||||
? projectRoot.trim()
|
||||
: null;
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
@@ -116,14 +125,15 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
subtitleText,
|
||||
style: TextStyle(
|
||||
fontSize: 11.0,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
if (subtitleText != null)
|
||||
Text(
|
||||
subtitleText,
|
||||
style: TextStyle(
|
||||
fontSize: 11.0,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
@@ -180,6 +190,46 @@ class _TerminalSessionBody extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
/// 小键盘修饰键的运行时状态:键盘组件与终端共用同一份
|
||||
late final TerminalModifierState _modifiers = TerminalModifierState();
|
||||
|
||||
/// 终端原有的输入处理器与输出出口(用于串联,而不是替换)
|
||||
TerminalInputHandler? _delegateInputHandler;
|
||||
void Function(String)? _delegateOnOutput;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final terminal = widget.session.terminal;
|
||||
|
||||
// ① 按键事件(硬件键盘、小键盘 key 格)都会经过 inputHandler:
|
||||
// 把运行时修饰键叠加进事件,再交给 xterm 默认链路。
|
||||
_delegateInputHandler = terminal.inputHandler;
|
||||
terminal.inputHandler = ModifierAwareInputHandler(
|
||||
state: _modifiers,
|
||||
delegate: _delegateInputHandler ?? defaultInputHandler,
|
||||
);
|
||||
|
||||
// ② 软键盘 / IME 打进来的字符不产生 KeyEvent,只能在这里改写。
|
||||
_delegateOnOutput = terminal.onOutput;
|
||||
terminal.onOutput = (data) {
|
||||
final transformed = applyModifierToTypedText(data, _modifiers.mods);
|
||||
_delegateOnOutput?.call(transformed ?? data);
|
||||
if (transformed != null) _modifiers.consume();
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
final terminal = widget.session.terminal;
|
||||
if (terminal.inputHandler is ModifierAwareInputHandler) {
|
||||
terminal.inputHandler = _delegateInputHandler;
|
||||
}
|
||||
terminal.onOutput = _delegateOnOutput;
|
||||
_modifiers.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final session = widget.session;
|
||||
@@ -192,18 +242,42 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
fontFamilyFallback: terminalFont.fallback,
|
||||
);
|
||||
|
||||
// 终端小键盘:开关与配置均独立于编辑区
|
||||
final keyboardEnabled = settings?.keyboardEnabledFor(KeyboardScope.terminal) ?? false;
|
||||
final keyboardConfig = settings?.keyboardConfigFor(KeyboardScope.terminal);
|
||||
|
||||
// 终端背景颜色(设置项):容器与 xterm 主题保持一致
|
||||
final backgroundColor = settings?.terminalBackgroundColor ?? const Color(0xFF1E1E1E);
|
||||
|
||||
return Container(
|
||||
color: const Color(0xFF181818),
|
||||
color: backgroundColor,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: xterm.TerminalView(
|
||||
session.terminal,
|
||||
focusNode: session.focusNode,
|
||||
autofocus: true,
|
||||
theme: xterm.TerminalThemes.defaultTheme,
|
||||
textStyle: terminalStyle,
|
||||
cursorType: xterm.TerminalCursorType.block,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: xterm.TerminalView(
|
||||
session.terminal,
|
||||
focusNode: session.focusNode,
|
||||
autofocus: true,
|
||||
theme: terminalThemeWithBackground(backgroundColor),
|
||||
textStyle: terminalStyle,
|
||||
cursorType: xterm.TerminalCursorType.block,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 8.0),
|
||||
),
|
||||
),
|
||||
if (keyboardEnabled && keyboardConfig != null && keyboardConfig.hasKeys)
|
||||
VirtualKeyboardWidget(
|
||||
controller: null,
|
||||
focusNode: session.focusNode,
|
||||
sink: TerminalKeyboardSink(
|
||||
terminal: session.terminal,
|
||||
focusNode: session.focusNode,
|
||||
),
|
||||
modifierState: _modifiers,
|
||||
config: keyboardConfig,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ class _VirtualKeyboardConfigViewState extends State<VirtualKeyboardConfigView> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
final settingsProvider = context.read<SettingsProvider>();
|
||||
_config = settingsProvider.virtualKeyboardConfig;
|
||||
_config = settingsProvider.keyboardConfigFor(widget.scope);
|
||||
if (_currentPageIndex >= _config.pages.length) {
|
||||
_currentPageIndex = 0;
|
||||
}
|
||||
@@ -77,12 +77,12 @@ class _VirtualKeyboardConfigViewState extends State<VirtualKeyboardConfigView> {
|
||||
});
|
||||
}
|
||||
|
||||
/// 保存并同步到 SettingsProvider
|
||||
/// 保存并同步到 SettingsProvider(按作用域写入对应的那份配置)
|
||||
Future<void> _syncAndSaveConfig() async {
|
||||
final settingsProvider = context.read<SettingsProvider>();
|
||||
const encoder = JsonEncoder.withIndent(' ');
|
||||
final jsonStr = encoder.convert(_config.toJson());
|
||||
await settingsProvider.setVirtualKeyboardConfig(jsonStr);
|
||||
await settingsProvider.setKeyboardConfig(widget.scope, jsonStr);
|
||||
}
|
||||
|
||||
/// 恢复默认配置
|
||||
@@ -109,10 +109,10 @@ class _VirtualKeyboardConfigViewState extends State<VirtualKeyboardConfigView> {
|
||||
if (confirmed == true) {
|
||||
if (!mounted) return;
|
||||
final settingsProvider = context.read<SettingsProvider>();
|
||||
await settingsProvider.resetVirtualKeyboardConfig();
|
||||
await settingsProvider.resetKeyboardConfig(widget.scope);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_config = settingsProvider.virtualKeyboardConfig;
|
||||
_config = settingsProvider.keyboardConfigFor(widget.scope);
|
||||
_currentPageIndex = 0;
|
||||
_expandedRowsByPage.clear();
|
||||
_scrollOffsetByPage.clear();
|
||||
@@ -132,13 +132,10 @@ class _VirtualKeyboardConfigViewState extends State<VirtualKeyboardConfigView> {
|
||||
}
|
||||
|
||||
setState(() {
|
||||
// 新建页面默认为空,不自动新增按键行,由用户手动添加
|
||||
final newPage = KeyboardPageItem(
|
||||
count: 7,
|
||||
keys: [
|
||||
[
|
||||
const KeyboardKeyItem(label: 'New', value: 'New'),
|
||||
],
|
||||
],
|
||||
keys: const [],
|
||||
);
|
||||
final newPages = List<KeyboardPageItem>.from(_config.pages)..add(newPage);
|
||||
_config = _config.copyWith(pages: newPages);
|
||||
@@ -471,10 +468,14 @@ class _VirtualKeyboardConfigViewState extends State<VirtualKeyboardConfigView> {
|
||||
children: [
|
||||
Text(
|
||||
l10n.virtualKeyboardConfigTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
Text(
|
||||
subtitleText,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: theme.colorScheme.onSurface.withValues(alpha: 0.65),
|
||||
@@ -531,17 +532,23 @@ class _VirtualKeyboardConfigViewState extends State<VirtualKeyboardConfigView> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.keyboard_alt_outlined, size: 20, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
l10n.keyboardPageKeysSectionTitle,
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
// 左侧标题需可收缩,右侧“添加新行”按钮才不会把标题挤出右边界
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.keyboard_alt_outlined, size: 20, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Text(
|
||||
l10n.keyboardPageKeysSectionTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.add, size: 18),
|
||||
|
||||
Reference in new issue
Block a user