2
This commit is contained in:
1 parent
b49e096355
commit
63e1fe3861
48 files changed
+5817
-556
No files matched your search
@@ -7,6 +7,7 @@ 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/permission_service.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';
|
||||
@@ -268,6 +269,8 @@ class _MainViewState extends State<MainView> {
|
||||
lastRunTaskId: isCurrentProject ? (runProvider.lastRunTaskId ?? runProvider.lastRunTask?.id) : null,
|
||||
onTaskSelected: (task) => _executeRunTask(context, task),
|
||||
onEditCustomTasks: () => _handleOpenEditRunTasks(context),
|
||||
onSyncModule: (moduleId) => runProvider.syncModuleTasks(moduleId),
|
||||
isSyncingModule: (moduleId) => runProvider.isModuleSyncing(moduleId),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -320,6 +323,18 @@ class _MainViewState extends State<MainView> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleOpenTerminal(BuildContext context) async {
|
||||
final wentToSettings = await PermissionService.instance.promptBatteryOptimizationIfNeeded(context);
|
||||
if (wentToSettings) return;
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (context) => const TerminalView(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final projectProvider = _getProjectProvider(context, listen: true);
|
||||
@@ -377,6 +392,7 @@ class _MainViewState extends State<MainView> {
|
||||
onCloseProject: () => _handleCloseProject(context),
|
||||
onRun: () => _handleRun(context),
|
||||
onRunTasks: () => _handleOpenRunTasksDialog(context),
|
||||
onTerminal: () => _handleOpenTerminal(context),
|
||||
onProjectDetect: () => _handleProjectDetect(context),
|
||||
onEditRunTasks: () => _handleOpenEditRunTasks(context),
|
||||
isDetecting: runProvider?.isDetecting ?? false,
|
||||
|
||||
@@ -235,6 +235,59 @@ class _ProjectManagementViewState extends State<ProjectManagementView> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onExportProject(Directory dir, String projectName) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
// 打开系统文件管理选择导出目标文件夹
|
||||
final selectedDir = await FilePicker.platform.getDirectoryPath(
|
||||
dialogTitle: l10n.selectExportDirectory,
|
||||
);
|
||||
|
||||
if (selectedDir == null || selectedDir.trim().isEmpty || !mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
final targetFileName = '$projectName.zip';
|
||||
final targetFilePath = p.join(selectedDir, targetFileName);
|
||||
final targetFile = File(targetFilePath);
|
||||
|
||||
// 若目标文件已存在,弹出覆盖确认
|
||||
if (targetFile.existsSync()) {
|
||||
final confirmOverwrite = await DialogUtils.showDestructiveConfirmDialog(
|
||||
context,
|
||||
title: l10n.exportProject,
|
||||
message: l10n.targetFileAlreadyExists(targetFileName),
|
||||
confirmText: l10n.overwrite,
|
||||
cancelText: l10n.cancel,
|
||||
);
|
||||
if (!confirmOverwrite || !mounted) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 执行流式压缩导出任务
|
||||
try {
|
||||
await DialogUtils.showSyncLoadingDialog(
|
||||
context,
|
||||
message: l10n.exportingProject,
|
||||
task: () async {
|
||||
await _projectService.exportProjectToZip(dir, targetFilePath);
|
||||
},
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
DialogUtils.showSuccessToast(context, l10n.projectExported);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
DialogUtils.showErrorToast(
|
||||
context,
|
||||
l10n.exportProjectFailed(e.toString()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onDeleteProject(Directory dir, String projectName) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final confirmed = await DialogUtils.showDestructiveConfirmDialog(
|
||||
@@ -360,6 +413,11 @@ class _ProjectManagementViewState extends State<ProjectManagementView> {
|
||||
tooltip: l10n.renameProject,
|
||||
onPressed: () => _onRenameProject(dir, projectName),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.drive_folder_upload_outlined),
|
||||
tooltip: l10n.exportProjectTooltip,
|
||||
onPressed: () => _onExportProject(dir, projectName),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
tooltip: l10n.deleteProject,
|
||||
|
||||
@@ -13,8 +13,11 @@ 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/services/internal_project_service.dart';
|
||||
import 'package:code_editor/widgets/virtual_keyboard_widget.dart';
|
||||
import 'package:code_editor/widgets/terminal_selection_overlay.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:xterm/xterm.dart' as xterm;
|
||||
import 'package:xterm/xterm.dart' show TerminalInputHandler, defaultInputHandler;
|
||||
@@ -105,10 +108,12 @@ class _TerminalViewState extends State<TerminalView> {
|
||||
final activeIndex = provider.activeIndex;
|
||||
|
||||
final titleText = activeSession?.name ?? l10n.sessionDefaultName;
|
||||
// 副标题严格取自当前会话绑定的工作目录根路径
|
||||
final sessionWorkspace = activeSession?.workspacePath;
|
||||
final String? subtitleText = (sessionWorkspace != null && sessionWorkspace.trim().isNotEmpty)
|
||||
? sessionWorkspace.trim()
|
||||
// 副标题取自当前会话绑定的工作目录:若是内部项目则展示项目名,外部项目展示完整绝对路径
|
||||
final sessionWorkspace = activeSession?.workspacePath?.trim();
|
||||
final String? subtitleText = (sessionWorkspace != null && sessionWorkspace.isNotEmpty)
|
||||
? (InternalProjectService.instance.isInternalProject(sessionWorkspace)
|
||||
? p.basename(sessionWorkspace)
|
||||
: sessionWorkspace)
|
||||
: null;
|
||||
|
||||
return Scaffold(
|
||||
@@ -201,6 +206,10 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
/// 小键盘修饰键的运行时状态:键盘组件与终端共用同一份
|
||||
late final TerminalModifierState _modifiers = TerminalModifierState();
|
||||
|
||||
/// 终端控制器与 View GlobalKey(用于选区、手柄与上下文菜单定位)
|
||||
late final xterm.TerminalController _terminalController = xterm.TerminalController();
|
||||
final GlobalKey<xterm.TerminalViewState> _terminalViewKey = GlobalKey<xterm.TerminalViewState>();
|
||||
|
||||
/// 终端原有的输入处理器与输出出口(用于串联,而不是替换)
|
||||
TerminalInputHandler? _delegateInputHandler;
|
||||
void Function(String)? _delegateOnOutput;
|
||||
@@ -235,6 +244,7 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
}
|
||||
terminal.onOutput = _delegateOnOutput;
|
||||
_modifiers.dispose();
|
||||
_terminalController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -264,14 +274,22 @@ class _TerminalSessionBodyState extends State<_TerminalSessionBody> {
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: xterm.TerminalView(
|
||||
session.terminal,
|
||||
child: TerminalSelectionOverlay(
|
||||
terminal: session.terminal,
|
||||
controller: _terminalController,
|
||||
terminalViewKey: _terminalViewKey,
|
||||
focusNode: session.focusNode,
|
||||
autofocus: true,
|
||||
theme: terminalThemeWithBackground(backgroundColor),
|
||||
textStyle: terminalStyle,
|
||||
cursorType: xterm.TerminalCursorType.block,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 8.0),
|
||||
child: xterm.TerminalView(
|
||||
session.terminal,
|
||||
key: _terminalViewKey,
|
||||
controller: _terminalController,
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user