Browse Source

显示目录中文名和隐藏系统文件

master
hejl 2 months ago
parent
commit
712d2e586a
  1. 27
      win_text_editor/lib/framework/services/file_service.dart

27
win_text_editor/lib/framework/services/file_service.dart

@ -14,6 +14,17 @@ class FileService { @@ -14,6 +14,17 @@ class FileService {
'.uftfactorservice',
'.uftstructure',
];
static const Map<String, String> _uftFloders = {
'.settings': '项目设置',
'metadat': '元数据',
'tools': '工具资源',
'uftatom': 'UFT原子',
'uftbusiness': 'UFT业务逻辑',
'uftfactor': 'UFT因子',
'uftstructure': 'UFT业务逻辑',
};
static const _hiddenFiles = ['.classpath', '.project', '.respath', 'project.xml', 'module.xml'];
static Future<String?> getSpecialFileName(String filePath) async {
final extension = filePath.substring(filePath.lastIndexOf('.'));
if (!_specialExtensions.contains(extension)) {
@ -37,6 +48,9 @@ class FileService { @@ -37,6 +48,9 @@ class FileService {
// final stopwatch = Stopwatch()..start();
for (final entity in entities) {
final pathName = entity.path.split(Platform.pathSeparator).last;
if (_hiddenFiles.contains(pathName)) continue;
final isDirectory = await FileSystemEntity.isDirectory(entity.path);
final displayName =
isDirectory
@ -45,7 +59,7 @@ class FileService { @@ -45,7 +59,7 @@ class FileService {
nodes.add(
FileNode(
name: displayName ?? entity.path.split(Platform.pathSeparator).last,
name: displayName ?? pathName,
path: entity.path,
isDirectory: isDirectory,
depth: parentDepth + 1,
@ -61,6 +75,9 @@ class FileService { @@ -61,6 +75,9 @@ class FileService {
static Future<String?> getModuleDisplayName(String dirPath) async {
try {
final floderName = dirPath.split(Platform.pathSeparator).last;
if (_uftFloders.containsKey(floderName)) return _uftFloders[floderName];
final moduleFile = File('$dirPath${Platform.pathSeparator}module.xml');
if (await moduleFile.exists()) {
final content = await moduleFile.readAsString();
@ -83,11 +100,9 @@ class FileService { @@ -83,11 +100,9 @@ class FileService {
final entities = rootDirectory.listSync();
for (final entity in entities) {
final node = FileNode(
name: entity.path.split(Platform.pathSeparator).last,
path: entity.path,
isDirectory: entity is Directory,
);
final pathName = entity.path.split(Platform.pathSeparator).last;
if (_hiddenFiles.contains(pathName)) continue;
final node = FileNode(name: pathName, path: entity.path, isDirectory: entity is Directory);
if (entity is Directory) {
node.children.addAll(await buildFileTree(entity.path));

Loading…
Cancel
Save