diff --git a/win_text_editor/lib/app/services/file_service.dart b/win_text_editor/lib/app/services/file_service.dart index dbce149..50266ce 100644 --- a/win_text_editor/lib/app/services/file_service.dart +++ b/win_text_editor/lib/app/services/file_service.dart @@ -9,18 +9,33 @@ class FileService { if (await directory.exists()) { final entities = directory.listSync(); + + // 遍历目录实体并创建FileNode for (final entity in entities) { nodes.add( FileNode( name: entity.path.split(Platform.pathSeparator).last, path: entity.path, isDirectory: entity is Directory, - depth: parentDepth + 1, // 关键修复:基于父节点深度+1 + depth: parentDepth + 1, children: [], ), ); } + + // 排序:文件夹在前按字母排序,文件在后按字母排序 + nodes.sort((a, b) { + if (a.isDirectory && !b.isDirectory) { + return -1; // a是文件夹,b是文件,a排在前面 + } else if (!a.isDirectory && b.isDirectory) { + return 1; // a是文件,b是文件夹,b排在前面 + } else { + // 都是文件夹或都是文件时,按名称字母排序 + return a.name.compareTo(b.name); + } + }); } + return nodes; } diff --git a/win_text_editor/lib/main.dart b/win_text_editor/lib/main.dart index b51b43c..2016b5a 100644 --- a/win_text_editor/lib/main.dart +++ b/win_text_editor/lib/main.dart @@ -8,9 +8,9 @@ void main() async { // 配置窗口 await windowManager.ensureInitialized(); WindowOptions windowOptions = const WindowOptions( - size: Size(1200, 800), + size: Size(1800, 1200), center: true, - title: 'Win Text Editor', + title: '文本转换', ); windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); @@ -26,7 +26,7 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: '文本编辑器', + title: '文本转换', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue,