This commit is contained in:
LZX committed 2026-09-17 19:45:53 +08:00
1 parent 6fd164fa6f
commit 27cdb00af2
7 files changed
+420 -20

No files matched your search

+4 -1
View File
@@ -1009,5 +1009,8 @@
}
},
"chrootDisabledNoRoot": "Unavailable without Root permission",
"chrootFailedFallbackToProot": "Chroot mount or permission failed, automatically fell back to PRoot"
"chrootFailedFallbackToProot": "Chroot mount or permission failed, automatically fell back to PRoot",
"drawerTabExplorer": "Explorer",
"drawerTabSearch": "Search",
"drawerTabGit": "Source Control"
}
+18
View File
@@ -3025,6 +3025,24 @@ abstract class AppLocalizations {
/// In zh, this message translates to:
/// **'Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式'**
String get chrootFailedFallbackToProot;
/// No description provided for @drawerTabExplorer.
///
/// In zh, this message translates to:
/// **'文件'**
String get drawerTabExplorer;
/// No description provided for @drawerTabSearch.
///
/// In zh, this message translates to:
/// **'搜索'**
String get drawerTabSearch;
/// No description provided for @drawerTabGit.
///
/// In zh, this message translates to:
/// **'源代码管理'**
String get drawerTabGit;
}
class _AppLocalizationsDelegate
+9
View File
@@ -1827,4 +1827,13 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get chrootFailedFallbackToProot =>
'Chroot mount or permission failed, automatically fell back to PRoot';
@override
String get drawerTabExplorer => 'Explorer';
@override
String get drawerTabSearch => 'Search';
@override
String get drawerTabGit => 'Source Control';
}
+9
View File
@@ -1767,4 +1767,13 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get chrootFailedFallbackToProot => 'Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式';
@override
String get drawerTabExplorer => '文件';
@override
String get drawerTabSearch => '搜索';
@override
String get drawerTabGit => '源代码管理';
}
+4 -1
View File
@@ -1009,5 +1009,8 @@
}
},
"chrootDisabledNoRoot": "未授予 Root 权限不可用",
"chrootFailedFallbackToProot": "Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式"
"chrootFailedFallbackToProot": "Chroot 挂载或权限失败,已自动降级为 PRoot 运行模式",
"drawerTabExplorer": "文件",
"drawerTabSearch": "搜索",
"drawerTabGit": "源代码管理"
}
+238 -18
View File
@@ -19,9 +19,16 @@ enum _OpenProjectSource {
fromExternal,
}
class CodeEditorDrawer extends StatelessWidget {
class CodeEditorDrawer extends StatefulWidget {
const CodeEditorDrawer({super.key});
@override
State<CodeEditorDrawer> createState() => _CodeEditorDrawerState();
}
class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
int _selectedIndex = 0;
static ProjectProvider _getProjectProvider(
BuildContext context, {
bool listen = false,
@@ -126,16 +133,119 @@ class CodeEditorDrawer extends StatelessWidget {
}
}
@override
Widget build(BuildContext context) {
Widget _buildActivityBarItem({
required BuildContext context,
required int index,
required IconData icon,
required String label,
}) {
final theme = Theme.of(context);
final l10n = AppLocalizations.of(context)!;
final projectProvider = _getProjectProvider(context, listen: true);
final rootPath = projectProvider.rootPath;
final hasProject = rootPath != null && rootPath.trim().isNotEmpty;
final isSelected = _selectedIndex == index;
final colorScheme = theme.colorScheme;
return Drawer(
return Tooltip(
message: label,
preferBelow: false,
child: InkWell(
onTap: () {
if (_selectedIndex != index) {
setState(() {
_selectedIndex = index;
});
}
},
child: SizedBox(
width: 48,
height: 48,
child: Stack(
alignment: Alignment.center,
children: [
if (isSelected)
Positioned(
left: 0,
top: 10,
bottom: 10,
width: 3,
child: Container(
decoration: BoxDecoration(
color: colorScheme.primary,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(2),
bottomRight: Radius.circular(2),
),
),
),
),
Icon(
icon,
size: 22,
color: isSelected
? colorScheme.primary
: colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
),
],
),
),
),
);
}
Widget _buildActivityBar(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
) {
return Container(
width: 48,
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerLow,
border: Border(
right: BorderSide(
color: theme.colorScheme.outlineVariant.withValues(alpha: 0.4),
width: 1,
),
),
),
child: SafeArea(
bottom: true,
right: false,
child: Column(
children: [
const SizedBox(height: 8),
_buildActivityBarItem(
context: context,
index: 0,
icon: Icons.folder_copy_outlined,
label: l10n.drawerTabExplorer,
),
const SizedBox(height: 4),
_buildActivityBarItem(
context: context,
index: 1,
icon: Icons.search,
label: l10n.drawerTabSearch,
),
const SizedBox(height: 4),
_buildActivityBarItem(
context: context,
index: 2,
icon: Icons.alt_route_rounded,
label: l10n.drawerTabGit,
),
],
),
),
);
}
Widget _buildExplorerPage(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
String? rootPath,
bool hasProject,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
@@ -144,21 +254,26 @@ class CodeEditorDrawer extends StatelessWidget {
),
child: SafeArea(
bottom: false,
left: false,
child: Padding(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
Expanded(
child: Text(
l10n.fileDirectory,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
const Spacer(),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.refresh),
tooltip: l10n.refreshDirectory,
onPressed: () {
@@ -166,7 +281,6 @@ class CodeEditorDrawer extends StatelessWidget {
final runProvider = context.read<RunProvider?>();
final root = _getProjectProvider(context).rootPath;
if (root != null && root.isNotEmpty) {
// 传入当前真实选中的系统,无系统时不进行任何任务探测
runProvider?.onProjectOpened(
root,
systemName: context.read<DistroProvider?>()?.selectedSystem,
@@ -224,6 +338,7 @@ class CodeEditorDrawer extends StatelessWidget {
},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.history),
tooltip: l10n.viewProjectHistory,
onPressed: () {
@@ -249,7 +364,7 @@ class CodeEditorDrawer extends StatelessWidget {
child: Text(
hasProject
? (InternalProjectService.instance
.isInternalProject(rootPath)
.isInternalProject(rootPath!)
? p.basename(rootPath)
: rootPath)
: '',
@@ -261,7 +376,7 @@ class CodeEditorDrawer extends StatelessWidget {
),
),
if (hasProject) ...[
const SizedBox(width: 6),
const SizedBox(width: 4),
IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
@@ -276,7 +391,7 @@ class CodeEditorDrawer extends StatelessWidget {
iconSize: 18,
icon: const Icon(Icons.note_add_outlined),
tooltip: l10n.newFile,
onPressed: () => _handleNewFile(context, rootPath),
onPressed: () => _handleNewFile(context, rootPath!),
),
const SizedBox(width: 2),
IconButton(
@@ -294,7 +409,7 @@ class CodeEditorDrawer extends StatelessWidget {
icon: const Icon(Icons.create_new_folder_outlined),
tooltip: l10n.newFolder,
onPressed: () =>
_handleNewFolder(context, rootPath),
_handleNewFolder(context, rootPath!),
),
const SizedBox(width: 2),
IconButton(
@@ -312,7 +427,7 @@ class CodeEditorDrawer extends StatelessWidget {
icon: const Icon(Icons.file_upload_outlined),
tooltip: l10n.importFromExternal,
onPressed: () =>
_handleImportFiles(context, rootPath),
_handleImportFiles(context, rootPath!),
),
],
],
@@ -322,7 +437,112 @@ class CodeEditorDrawer extends StatelessWidget {
),
),
),
const Expanded(child: SafeArea(top: false, child: FileTreeWidget())),
const Expanded(child: SafeArea(top: false, left: false, child: FileTreeWidget())),
],
);
}
Widget _buildSearchPlaceholder(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: SafeArea(
bottom: false,
left: false,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
child: Row(
children: [
Expanded(
child: Text(
l10n.drawerTabSearch,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
),
),
const Expanded(child: SizedBox.shrink()),
],
);
}
Widget _buildGitPlaceholder(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: SafeArea(
bottom: false,
left: false,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
child: Row(
children: [
Expanded(
child: Text(
l10n.drawerTabGit,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
),
),
const Expanded(child: SizedBox.shrink()),
],
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l10n = AppLocalizations.of(context)!;
final projectProvider = _getProjectProvider(context, listen: true);
final rootPath = projectProvider.rootPath;
final hasProject = rootPath != null && rootPath.trim().isNotEmpty;
return Drawer(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildActivityBar(context, l10n, theme),
Expanded(
child: IndexedStack(
index: _selectedIndex,
children: [
_buildExplorerPage(context, l10n, theme, rootPath, hasProject),
_buildSearchPlaceholder(context, l10n, theme),
_buildGitPlaceholder(context, l10n, theme),
],
),
),
],
),
);
+138
View File
@@ -0,0 +1,138 @@
import 'dart:io';
import 'package:code_editor/l10n/app_localizations.dart';
import 'package:code_editor/models/project_history.dart';
import 'package:code_editor/providers/project_provider.dart';
import 'package:code_editor/providers/run_provider.dart';
import 'package:code_editor/providers/settings_provider.dart';
import 'package:code_editor/providers/tab_provider.dart';
import 'package:code_editor/services/internal_project_service.dart';
import 'package:code_editor/widgets/code_editor_drawer.dart';
import 'package:code_editor/widgets/file_tree_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late Directory tempBaseDir;
late Directory testProjectDir;
late ProjectProvider projectProvider;
late TabProvider tabProvider;
late SettingsProvider settingsProvider;
late RunProvider runProvider;
setUp(() async {
SharedPreferences.setMockInitialValues({});
tempBaseDir = Directory.systemTemp.createTempSync('drawer_tab_test_');
testProjectDir = Directory(p.join(tempBaseDir.path, 'my_project'))..createSync();
InternalProjectService.instance.customProjectsDir =
Directory(p.join(tempBaseDir.path, 'files', 'projects'));
projectProvider = ProjectProvider();
tabProvider = TabProvider()..bindProjectProvider(projectProvider);
settingsProvider = SettingsProvider();
runProvider = RunProvider();
await projectProvider.switchProject(
ProjectHistory(
rootPath: testProjectDir.path,
lastOpenedFilePath: null,
),
);
});
tearDown(() {
InternalProjectService.instance.customProjectsDir = null;
if (tempBaseDir.existsSync()) {
tempBaseDir.deleteSync(recursive: true);
}
});
Widget buildTestWidget({Locale locale = const Locale('zh')}) {
return MultiProvider(
providers: [
ChangeNotifierProvider<ProjectProvider>.value(value: projectProvider),
ChangeNotifierProvider<TabProvider>.value(value: tabProvider),
ChangeNotifierProvider<SettingsProvider>.value(value: settingsProvider),
ChangeNotifierProvider<RunProvider>.value(value: runProvider),
],
child: MaterialApp(
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('zh'),
Locale('en'),
],
locale: locale,
home: const Scaffold(
drawer: CodeEditorDrawer(),
body: Center(child: Text('Editor Body')),
),
),
);
}
testWidgets('Activity Bar renders 3 vertical tab buttons and switches pages correctly', (tester) async {
await tester.pumpWidget(buildTestWidget(locale: const Locale('zh')));
final scaffoldState = tester.state<ScaffoldState>(find.byType(Scaffold));
scaffoldState.openDrawer();
await tester.pumpAndSettle();
// 1. Initial state: Explorer is active
expect(find.byIcon(Icons.folder_copy_outlined), findsOneWidget);
expect(find.byIcon(Icons.search), findsOneWidget);
expect(find.byIcon(Icons.alt_route_rounded), findsOneWidget);
// Initial page shows file tree and directory title ("项目")
expect(find.byType(FileTreeWidget), findsOneWidget);
expect(find.text('项目'), findsOneWidget);
// Tooltips
expect(find.byTooltip('文件'), findsOneWidget);
expect(find.byTooltip('搜索'), findsOneWidget);
expect(find.byTooltip('源代码管理'), findsOneWidget);
// 2. Tap Search tab
await tester.tap(find.byTooltip('搜索'));
await tester.pumpAndSettle();
// IndexedStack index is 1 -> Search page header is visible
final searchHeader = find.text('搜索');
expect(searchHeader, findsWidgets); // tooltip & header title
// 3. Tap Git tab
await tester.tap(find.byTooltip('源代码管理'));
await tester.pumpAndSettle();
// Git header is visible
final gitHeader = find.text('源代码管理');
expect(gitHeader, findsWidgets); // tooltip & header title
// 4. Tap back to Explorer
await tester.tap(find.byTooltip('文件'));
await tester.pumpAndSettle();
expect(find.byType(FileTreeWidget), findsOneWidget);
expect(find.text('项目'), findsOneWidget);
});
testWidgets('Activity Bar tooltips follow English locale', (tester) async {
await tester.pumpWidget(buildTestWidget(locale: const Locale('en')));
final scaffoldState = tester.state<ScaffoldState>(find.byType(Scaffold));
scaffoldState.openDrawer();
await tester.pumpAndSettle();
expect(find.byTooltip('Explorer'), findsOneWidget);
expect(find.byTooltip('Search'), findsOneWidget);
expect(find.byTooltip('Source Control'), findsOneWidget);
});
}