From ed24565135698244f12821d6d9f8e477e8e2ba71 Mon Sep 17 00:00:00 2001 From: hejl Date: Tue, 17 Jun 2025 17:56:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E9=83=A8=E6=90=9E=E5=AE=8C=EF=BC=8C?= =?UTF-8?q?=E6=89=93=E5=8C=85=E5=8F=91=E5=B8=83v0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outline/services/outline_service.dart | 87 ++++++++++++++----- 1 file changed, 66 insertions(+), 21 deletions(-) diff --git a/win_text_editor/lib/modules/outline/services/outline_service.dart b/win_text_editor/lib/modules/outline/services/outline_service.dart index 681577e..a427bef 100644 --- a/win_text_editor/lib/modules/outline/services/outline_service.dart +++ b/win_text_editor/lib/modules/outline/services/outline_service.dart @@ -180,10 +180,28 @@ class OutlineService { ) async { if (fieldName == null || fieldName.isEmpty) return; + final matches = await _matchComponent(rootPath, fieldName); + matches.forEach( + (key, value) => parentNode.children.add( + OutlineNode( + name: key, + title: value, + value: 'Component', + frequency: 0, + isDirectory: false, + depth: 4, + ), + ), + ); + } + + //组合匹配 + static Future> _matchComponent(String rootPath, String fieldName) async { + Map matchComponents = {}; final componentFile = File('$rootPath/metadata/component.xml'); if (!await componentFile.exists()) { Logger().error('component.xml文件不存在'); - return; + return matchComponents; } try { @@ -202,27 +220,15 @@ class OutlineService { final parentChineseName = parentElement.getAttribute('chineseName'); if (parentName != null && parentChineseName != null) { - // 创建并添加子节点 - parentNode.children.add( - OutlineNode( - name: parentName, - title: parentChineseName, - value: 'Component', - frequency: 0, - isDirectory: false, - depth: 4, - ), - ); + matchComponents[parentName] = parentChineseName; } } } } - - Logger().info('为 $fieldName 找到 ${parentNode.children.length} 个匹配项'); } catch (e) { Logger().error('加载Component失败: $e'); - rethrow; } + return matchComponents; } //加载原子逻辑层 @@ -236,6 +242,9 @@ class OutlineService { } try { + //获取对应组合 + final matchComponents = await _matchComponent(rootPath, fieldName); + // 遍历所有.uftstructure文件 final uftatomFiles = await uftatomDir @@ -258,27 +267,46 @@ class OutlineService { final List matchingProperties = document .findAllElements('inputParameters') - .where((element) => element.getAttribute('id') == fieldName) + .where( + (element) => + element.getAttribute('id') == fieldName || + element.getAttribute("paramType") == "COMPONENT" && + matchComponents.containsKey(element.getAttribute('id')), + ) .toList(); + //匹配出参 if (matchingProperties.isEmpty) { matchingProperties.addAll( document .findAllElements('outputParameters') - .where((element) => element.getAttribute('id') == fieldName), + .where( + (element) => + element.getAttribute('id') == fieldName || + element.getAttribute("paramType") == "COMPONENT" && + matchComponents.containsKey(element.getAttribute('id')), + ), ); matchType = "O"; } + //匹配内部变量 if (matchingProperties.isEmpty) { matchingProperties.addAll( document .findAllElements('internalParams') - .where((element) => element.getAttribute('id') == fieldName), + .where( + (element) => + element.getAttribute('id') == fieldName || + element.getAttribute("paramType") == "COMPONENT" && + matchComponents.containsKey(element.getAttribute('id')), + ), ); matchType = "X"; } + //匹配组合 + if (matchingProperties.isNotEmpty) { // 获取structure:Structure节点的chineseName final businessNode = document.findAllElements('business:Function').firstOrNull; @@ -326,6 +354,8 @@ class OutlineService { } try { + final matchComponents = await _matchComponent(rootPath, fieldName); + // 遍历所有.uftstructure文件 final uftbusinessFiles = await uftbusinessDir @@ -344,14 +374,24 @@ class OutlineService { final List matchingProperties = document .findAllElements('inputParameters') - .where((element) => element.getAttribute('id') == fieldName) + .where( + (element) => + element.getAttribute('id') == fieldName || + element.getAttribute("paramType") == "COMPONENT" && + matchComponents.containsKey(element.getAttribute('id')), + ) .toList(); if (matchingProperties.isEmpty) { matchingProperties.addAll( document .findAllElements('outputParameters') - .where((element) => element.getAttribute('id') == fieldName), + .where( + (element) => + element.getAttribute('id') == fieldName || + element.getAttribute("paramType") == "COMPONENT" && + matchComponents.containsKey(element.getAttribute('id')), + ), ); matchType = "O"; } @@ -360,7 +400,12 @@ class OutlineService { matchingProperties.addAll( document .findAllElements('internalParams') - .where((element) => element.getAttribute('id') == fieldName), + .where( + (element) => + element.getAttribute('id') == fieldName || + element.getAttribute("paramType") == "COMPONENT" && + matchComponents.containsKey(element.getAttribute('id')), + ), ); matchType = "X"; }