From 9186d87b7776535d17ccce815a2cdb5e13fd563f Mon Sep 17 00:00:00 2001 From: hejl Date: Wed, 25 Jun 2025 16:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=8C=E5=B0=8F=E4=BF=AE=E5=B0=8F=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/code_create_service.dart | 38 +++++++++++------ .../widgets/code_creater_view.dart | 8 ++++ .../code_creater/widgets/node_table.dart | 42 +++++++++++++++++++ .../services/uft_component_service.dart | 7 ++-- 4 files changed, 78 insertions(+), 17 deletions(-) diff --git a/win_text_editor/lib/modules/code_creater/services/code_create_service.dart b/win_text_editor/lib/modules/code_creater/services/code_create_service.dart index b800acc..849c18d 100644 --- a/win_text_editor/lib/modules/code_creater/services/code_create_service.dart +++ b/win_text_editor/lib/modules/code_creater/services/code_create_service.dart @@ -228,35 +228,47 @@ class CodeCreateService { iteratePartnerMap.values.expand((partners) => partners).toList(), ); + List fieldNames = component.fields.map((col) => col.name).toList(); + switch (action) { - case "获取组件": case "遍历组件": - List fieldNames = component.fields.map((col) => col.name).toList(); + iterateStack.add(component.name); //入栈 + iterateOutputFields.putIfAbsent(iterateStack.last, () => []).addAll(fieldNames); + iterateOutputFields[iterateStack.last]!.add(component.name); + iteratePartnerMap + .putIfAbsent(member.name, () => []) + .add(CodePartner(name: member.name, fields: fieldNames)); + + break; + + case "插入组件": + case "修改组件": + for (var field in component.fields) { + if (!outputFields.contains(field.name) && + !inputFields.contains(field.name) && + !iterateOutputFields.values.expand((list) => list).contains(field.name)) { + inputFields.add(field.name); + } + } + continue case_get; + case_get: + case "获取组件": //将出参加入作用域出参列表中 if (iterateStack.isNotEmpty) { //仍在遍历块内,加入最近遍历块中 iterateOutputFields.putIfAbsent(iterateStack.last, () => []).addAll(fieldNames); + iterateOutputFields[iterateStack.last]!.add(component.name); iteratePartnerMap .putIfAbsent(member.name, () => []) .add(CodePartner(name: member.name, fields: fieldNames)); } else { //加入全局出参中 outputFields.addAll(fieldNames); + outputFields.add(component.name); beforePartner.add(CodePartner(name: member.name, fields: fieldNames)); } - iterateStack.add(component.name); //入栈 - break; - - default: - for (var field in component.fields) { - if (!outputFields.contains(field.name) && - !inputFields.contains(field.name) && - !iterateOutputFields.values.expand((list) => list).contains(field.name)) { - inputFields.add(field.name); - } - } break; } diff --git a/win_text_editor/lib/modules/code_creater/widgets/code_creater_view.dart b/win_text_editor/lib/modules/code_creater/widgets/code_creater_view.dart index 36775e1..b680507 100644 --- a/win_text_editor/lib/modules/code_creater/widgets/code_creater_view.dart +++ b/win_text_editor/lib/modules/code_creater/widgets/code_creater_view.dart @@ -71,6 +71,7 @@ class _CodeCreaterViewState extends State { members: _controller.members, onMoveMember: _moveMember, onDeleteMember: _deleteMember, + onDeleteAll: _deleteAll, onMoveToTop: _moveToTop, onMoveToBottom: _moveToBottom, onActionTypeChanged: @@ -144,6 +145,13 @@ class _CodeCreaterViewState extends State { }); } + void _deleteAll() { + setState(() { + _controller.members.clear(); + _updateDisplay(); + }); + } + void _selectOperation(String? operation) { if (operation == null || operation.isEmpty) { return; diff --git a/win_text_editor/lib/modules/code_creater/widgets/node_table.dart b/win_text_editor/lib/modules/code_creater/widgets/node_table.dart index 7f813dc..2b72959 100644 --- a/win_text_editor/lib/modules/code_creater/widgets/node_table.dart +++ b/win_text_editor/lib/modules/code_creater/widgets/node_table.dart @@ -13,6 +13,7 @@ class NodeTable extends StatefulWidget { final List members; final Function(int, int) onMoveMember; final Function(int) onDeleteMember; + final Function() onDeleteAll; final Function(int) onMoveToTop; final Function(int) onMoveToBottom; final Function(int, String)? onActionTypeChanged; // 新增回调函数 @@ -22,6 +23,7 @@ class NodeTable extends StatefulWidget { required this.members, required this.onMoveMember, required this.onDeleteMember, + required this.onDeleteAll, required this.onMoveToTop, required this.onMoveToBottom, this.onActionTypeChanged, // 新增参数 @@ -108,6 +110,7 @@ class NodeTableState extends State { final canMoveUp = _selectedRowIndex != null && _selectedRowIndex! > 0; final canMoveDown = _selectedRowIndex != null && _selectedRowIndex! < widget.members.length - 1; final canDelete = _selectedRowIndex != null; + final canDeleteAll = widget.members.isNotEmpty; return Padding( padding: const EdgeInsets.all(2.0), @@ -158,6 +161,15 @@ class NodeTableState extends State { onPressed: canDelete ? () => widget.onDeleteMember(_selectedRowIndex!) : null, tooltip: '删除行', ), + IconButton( + icon: Icon( + Icons.delete_forever, + size: 14, + color: canDeleteAll ? Colors.red : Colors.grey, + ), + onPressed: canDeleteAll ? _showDeleteAllConfirmation : null, + tooltip: '全部删除', + ), ], ), ], @@ -165,6 +177,36 @@ class NodeTableState extends State { ); } + void _showDeleteAllConfirmation() { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('确认删除'), + content: const Text('确定要删除所有节点吗?此操作不可撤销。'), + actions: [ + TextButton(onPressed: () => Navigator.of(context).pop(false), child: const Text('取消')), + TextButton( + onPressed: () { + Navigator.of(context).pop(true); + _deleteAllMembers(); + }, + child: const Text('删除', style: TextStyle(color: Colors.red)), + ), + ], + ); + }, + ); + } + + // 添加删除所有成员的方法 + void _deleteAllMembers() { + setState(() { + _selectedRowIndex = null; + }); + widget.onDeleteAll(); + } + void _handleRowSelection() { if (_stateManager?.currentRow == null) return; setState(() { diff --git a/win_text_editor/lib/modules/uft_component/services/uft_component_service.dart b/win_text_editor/lib/modules/uft_component/services/uft_component_service.dart index c6987b7..b25e5ec 100644 --- a/win_text_editor/lib/modules/uft_component/services/uft_component_service.dart +++ b/win_text_editor/lib/modules/uft_component/services/uft_component_service.dart @@ -68,10 +68,6 @@ class UftComponentService { final name = node.getAttribute('name') ?? ''; final chineseName = node.getAttribute('chineseName') ?? ''; - if (filterName != null && filterName.isNotEmpty && filterName != name) { - continue; // 如果有过滤条件且不匹配,则跳过 - } - final fields = []; List? indexes = []; int index = 1; @@ -130,6 +126,9 @@ class UftComponentService { ); } + if (filterName != null && filterName.isNotEmpty) { + return _components.where((com) => com.name == filterName).toList(); + } return _components; } on xml.XmlParserException catch (e) { _logger.error("XML解析错误: ${e.message}");