diff --git a/win_text_editor/lib/framework/common/constants.dart b/win_text_editor/lib/framework/common/constants.dart new file mode 100644 index 0000000..758e452 --- /dev/null +++ b/win_text_editor/lib/framework/common/constants.dart @@ -0,0 +1,7 @@ +class Constants { + static const String uftTable = 'uftTable'; + static const String component = 'component'; + static const String business = 'business'; + static const String atomService = 'atomService'; + static const String atomFunction = 'atomFunction'; +} diff --git a/win_text_editor/lib/modules/code_creater/controllers/code_creater_controller.dart b/win_text_editor/lib/modules/code_creater/controllers/code_creater_controller.dart index 2a367f1..2f4108d 100644 --- a/win_text_editor/lib/modules/code_creater/controllers/code_creater_controller.dart +++ b/win_text_editor/lib/modules/code_creater/controllers/code_creater_controller.dart @@ -1,10 +1,29 @@ +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:win_text_editor/shared/base/base_content_controller.dart'; class CodeCreaterController extends BaseContentController { + final Map> unMatchMap = { + Constants.atomFunction: ['逻辑服务', '逻辑函数'], + Constants.atomService: ['原子服务', '原子函数'], + Constants.business: ['原子服务', '原子函数'], + Constants.uftTable: [], + Constants.component: [], + }; List _members = []; List get members => _members; + String _selectedOperation = '原子函数'; + + String get selectedOperation => _selectedOperation; + + set selectedOperation(String value) { + final filtered = + _members.where((node) => !(unMatchMap[node.value]?.contains(value) ?? false)).toList(); + _members = filtered; // 更新成员列表,移除不匹配的节点 + _selectedOperation = value; + notifyListeners(); // 通知监听者 + } void updateMembers(List newMembers) { _members = newMembers; @@ -12,17 +31,18 @@ class CodeCreaterController extends BaseContentController { } @override - void onOpenFile(String filePath, {dynamic appendArg}) { - // TODO: implement onOpenFile - } + void onOpenFile(String filePath, {dynamic appendArg}) {} @override - void onOpenFolder(String folderPath) { - // TODO: implement onOpenFolder - } + void onOpenFolder(String folderPath) {} @override void onDropOutlineNode(OutlineNode node) { + if (unMatchMap[node.value]?.contains(selectedOperation) ?? false) { + Logger().error('当前节点不支持操作: $selectedOperation'); + return; + } + members.add(node); notifyListeners(); } 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 0b2c64e..0a31d04 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 @@ -21,7 +21,6 @@ class _CodeCreaterViewState extends State { bool _isControllerFromTabManager = false; final TextEditingController _codeController = TextEditingController(); final List operations = ['逻辑服务', '逻辑函数', '原子服务', '原子函数']; - String? _selectedOperation = '原子函数'; get tabManager => Provider.of(context, listen: false); @@ -87,7 +86,7 @@ class _CodeCreaterViewState extends State { onNodeDropped: (node) => _controller.onDropOutlineNode(node), child: OperationRadioSection( operations: operations, - selectedOperation: _selectedOperation, + selectedOperation: _controller.selectedOperation, onOperationSelected: _selectOperation, ), ), @@ -136,17 +135,16 @@ class _CodeCreaterViewState extends State { } void _selectOperation(String? operation) { + if (operation == null || operation.isEmpty) { + return; + } setState(() { - _selectedOperation = operation; + _controller.selectedOperation = operation; _updateDisplay(); }); } void _updateDisplay() { - if (_selectedOperation != null) { - _codeController.text = _controller.genCodeString([_selectedOperation!]) ?? ''; - } else { - _codeController.text = ''; - } + _codeController.text = _controller.genCodeString([_controller.selectedOperation!]) ?? ''; } } 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 0defa67..f409695 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 @@ -2,6 +2,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:pluto_grid/pluto_grid.dart'; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:win_text_editor/shared/components/my_pluto_column.dart'; import 'package:win_text_editor/shared/components/my_pluto_configuration.dart'; @@ -222,13 +223,14 @@ class NodeTableState extends State { List _getOptions(String type) { switch (type) { - case 'Atom': - case 'Business': + case Constants.atomFunction: + case Constants.atomService: + case Constants.business: return ['普通调用', '事务调用']; - case 'UFTTable': - return ['遍历记录', '获取记录', '插入记录', '修改记录', '删除记录']; - case 'Component': - return ['遍历组件', '获取组件', '插入组件', '修改组件', '尾部插入组件']; + case Constants.uftTable: + return ['获取记录', '遍历记录', '插入记录', '修改记录', '删除记录']; + case Constants.component: + return ['获取组件', '遍历组件', '插入组件', '修改组件', '尾部插入组件']; default: return ['']; // 确保返回非空列表 } diff --git a/win_text_editor/lib/modules/outline/models/code_partner.dart b/win_text_editor/lib/modules/outline/models/code_partner.dart index 5ef8fa6..a161523 100644 --- a/win_text_editor/lib/modules/outline/models/code_partner.dart +++ b/win_text_editor/lib/modules/outline/models/code_partner.dart @@ -1,4 +1,5 @@ import 'package:path/path.dart' as path; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:win_text_editor/modules/outline/services/component_service.dart'; import 'package:win_text_editor/modules/outline/services/uft_object_service.dart'; @@ -13,14 +14,14 @@ class CodePartner { String? name; List fields = []; switch (node.value) { - case "UFTTable": + case Constants.uftTable: final List? values = UftObjectService.uftObjectMap[node.title]; if (values != null && values.isNotEmpty) { name = path.basenameWithoutExtension(values[0]); fields.addAll(values.sublist(1)); } break; - case "Component": + case Constants.component: name = node.name; final List? values = ComponentService.componentFieldMap[node.name]; if (values != null && values.isNotEmpty) { diff --git a/win_text_editor/lib/modules/outline/models/outline_node.dart b/win_text_editor/lib/modules/outline/models/outline_node.dart index 2af38bb..11ac077 100644 --- a/win_text_editor/lib/modules/outline/models/outline_node.dart +++ b/win_text_editor/lib/modules/outline/models/outline_node.dart @@ -40,7 +40,7 @@ class OutlineNode implements TreeNode { List? children, this.title = "", }) : _children = children ?? [] { - id = DateTime.now().microsecondsSinceEpoch.toRadixString(36) + value.hashCode.toRadixString(36); + id = DateTime.now().microsecondsSinceEpoch.toRadixString(36) + title.hashCode.toRadixString(36); } OutlineNode copyWith({bool? isExpanded, List? children}) { diff --git a/win_text_editor/lib/modules/outline/services/component_service.dart b/win_text_editor/lib/modules/outline/services/component_service.dart index 8ef8f8f..aa206ca 100644 --- a/win_text_editor/lib/modules/outline/services/component_service.dart +++ b/win_text_editor/lib/modules/outline/services/component_service.dart @@ -1,5 +1,7 @@ import 'dart:io'; +import 'package:flutter/widgets.dart'; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:xml/xml.dart'; @@ -44,7 +46,7 @@ class ComponentService { } //组合匹配 - static Future> matchComponent(String fieldName) async { + static Map matchComponent(String fieldName) { Map matchComponents = {}; componentFieldMap.forEach((key, value) { @@ -54,13 +56,19 @@ class ComponentService { return matchComponents; } - static Future loadComponent(String? fieldName, OutlineNode parentNode) async { + static void loadComponent(String? fieldName, OutlineNode parentNode) { if (fieldName == null || fieldName.isEmpty) return; - final matches = await matchComponent(fieldName); + final matches = matchComponent(fieldName); matches.forEach( (key, value) => parentNode.children.add( - OutlineNode(name: key, title: value, value: 'Component', isDirectory: false, depth: 4), + OutlineNode( + name: key, + title: value, + value: Constants.component, + isDirectory: false, + depth: 4, + ), ), ); } @@ -70,7 +78,13 @@ class ComponentService { componentFieldMap.forEach((key, value) { if (key.contains(searchQuery) || value[0].contains(searchQuery)) { componentNodes.add( - OutlineNode(name: key, title: value[0], value: 'Component', isDirectory: false, depth: 4), + OutlineNode( + name: key, + title: value[0], + value: Constants.component, + isDirectory: false, + depth: 4, + ), ); } }); diff --git a/win_text_editor/lib/modules/outline/services/functions_service.dart b/win_text_editor/lib/modules/outline/services/functions_service.dart index 0d21d9e..77bf6c0 100644 --- a/win_text_editor/lib/modules/outline/services/functions_service.dart +++ b/win_text_editor/lib/modules/outline/services/functions_service.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:win_text_editor/modules/outline/services/component_service.dart'; @@ -10,12 +11,14 @@ class FunctionsService { static Map> uftbusinessMap = {}; //原子层索引 - static Map> uftatomMap = {}; + static Map> uftatomserviceMap = {}; + static Map> uftatomFunctionMap = {}; static Future initFunctionsMap(String rootPath) async { await _initUftMap('uftbusiness', rootPath, uftbusinessMap, ['.uftfunction']); - await _initUftMap('uftatom', rootPath, uftatomMap, ['.uftatomfunction', '.uftatomservice']); + await _initUftMap('uftatom', rootPath, uftatomserviceMap, ['.uftatomservice']); + await _initUftMap('uftatom', rootPath, uftatomFunctionMap, ['.uftatomfunction']); } static Future _initUftMap( @@ -78,17 +81,35 @@ class FunctionsService { } } - //加载原子逻辑层 - static Future loadAtom(String? fieldName, OutlineNode parentNode) async { + //加载原子服务层 + static void loadAtomService(String? fieldName, OutlineNode parentNode) { if (fieldName == null || fieldName.isEmpty) return; - uftatomMap.forEach((key, value) { + uftatomserviceMap.forEach((key, value) { if (value.contains(fieldName)) { parentNode.children.add( OutlineNode( name: value[0], // 文件名 title: key, - value: 'Atom', + value: Constants.atomService, + isDirectory: false, // 这些是叶子节点 + depth: 4, + ), + ); + } + }); + } + + static Future loadAtomFunction(String? fieldName, OutlineNode parentNode) async { + if (fieldName == null || fieldName.isEmpty) return; + + uftatomFunctionMap.forEach((key, value) { + if (value.contains(fieldName)) { + parentNode.children.add( + OutlineNode( + name: value[0], // 文件名 + title: key, + value: Constants.atomFunction, isDirectory: false, // 这些是叶子节点 depth: 4, ), @@ -98,7 +119,7 @@ class FunctionsService { } //加载业务逻辑层 - static Future loadBusiness(String? fieldName, OutlineNode parentNode) async { + static void loadBusiness(String? fieldName, OutlineNode parentNode) { if (fieldName == null || fieldName.isEmpty) return; uftbusinessMap.forEach((key, value) { @@ -107,7 +128,7 @@ class FunctionsService { OutlineNode( name: value[0], // 文件名 title: key, - value: 'Atom', + value: Constants.business, isDirectory: false, // 这些是叶子节点 depth: 4, ), @@ -124,7 +145,26 @@ class FunctionsService { OutlineNode( name: value[0], // 文件名 title: key, - value: 'Atom', + value: Constants.business, + isDirectory: false, // 这些是叶子节点 + depth: 4, + ), + ); + } + }); + + return nodes; + } + + static List searchAtomServices(String searchQuery) { + final List nodes = []; + uftatomserviceMap.forEach((key, value) { + if (key.contains(searchQuery)) { + nodes.add( + OutlineNode( + name: value[0], // 文件名 + title: key, + value: Constants.atomService, isDirectory: false, // 这些是叶子节点 depth: 4, ), @@ -135,15 +175,15 @@ class FunctionsService { return nodes; } - static List searchAtoms(String searchQuery) { + static List searchAtomFunctions(String searchQuery) { final List nodes = []; - uftatomMap.forEach((key, value) { + uftatomFunctionMap.forEach((key, value) { if (key.contains(searchQuery)) { nodes.add( OutlineNode( name: value[0], // 文件名 title: key, - value: 'Atom', + value: Constants.atomFunction, isDirectory: false, // 这些是叶子节点 depth: 4, ), 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 282c335..92ebce6 100644 --- a/win_text_editor/lib/modules/outline/services/outline_service.dart +++ b/win_text_editor/lib/modules/outline/services/outline_service.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:jieba_flutter/analysis/jieba_segmenter.dart'; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:win_text_editor/modules/outline/services/component_service.dart'; import 'package:win_text_editor/modules/outline/services/functions_service.dart'; @@ -253,7 +254,7 @@ class OutlineService { final List uftObjectNodes = UftObjectService.searchUftObjects(searchQuery); if (uftObjectNodes.isNotEmpty) { final uftObjectActionNode = OutlineNode( - name: 'UFTTable', + name: Constants.uftTable, title: 'UFT对象(${uftObjectNodes.length})', value: 'virtualNode', isDirectory: true, @@ -267,7 +268,7 @@ class OutlineService { final List componentNodes = ComponentService.searchComponents(searchQuery); if (componentNodes.isNotEmpty) { final componentActionNode = OutlineNode( - name: 'Component', + name: Constants.component, title: '标准组件(${componentNodes.length})', value: 'virtualNode', isDirectory: true, @@ -281,8 +282,8 @@ class OutlineService { final List businessNodes = FunctionsService.searchBusiness(searchQuery); if (businessNodes.isNotEmpty) { final businessActionNode = OutlineNode( - name: 'Business', - title: "业务层(${businessNodes.length})", + name: Constants.business, + title: "业务函数(${businessNodes.length})", value: 'virtualNode', isDirectory: true, depth: 3, @@ -292,16 +293,29 @@ class OutlineService { } //搜索函数 - final List atomNodes = FunctionsService.searchAtoms(searchQuery); - if (atomNodes.isNotEmpty) { + final List atomServiceNodes = FunctionsService.searchAtomServices(searchQuery); + if (atomServiceNodes.isNotEmpty) { final atomActionNode = OutlineNode( - name: 'Atom', - title: '原子层(${atomNodes.length})', + name: Constants.atomService, + title: '原子服务(${atomServiceNodes.length})', value: 'virtualNode', isDirectory: true, depth: 3, ); - atomActionNode.children.addAll(atomNodes); + atomActionNode.children.addAll(atomServiceNodes); + virtualNode.children.add(atomActionNode); + } + + final List atomFunctionNodes = FunctionsService.searchAtomFunctions(searchQuery); + if (atomFunctionNodes.isNotEmpty) { + final atomActionNode = OutlineNode( + name: Constants.atomFunction, + title: '原子函数(${atomFunctionNodes.length})', + value: 'virtualNode', + isDirectory: true, + depth: 3, + ); + atomActionNode.children.addAll(atomFunctionNodes); virtualNode.children.add(atomActionNode); } diff --git a/win_text_editor/lib/modules/outline/services/std_field_service.dart b/win_text_editor/lib/modules/outline/services/std_field_service.dart index 59550ed..a9c69ce 100644 --- a/win_text_editor/lib/modules/outline/services/std_field_service.dart +++ b/win_text_editor/lib/modules/outline/services/std_field_service.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:win_text_editor/modules/outline/services/component_service.dart'; @@ -10,10 +11,11 @@ import 'package:xml/xml.dart'; class StdFieldService { // ignore: constant_identifier_names static const Map FIELD_ACTIONS = { - "UFTTable": "UFT对象", - "Component": "标准组件", - "Business": "业务层", - "Atom": "原子层", + Constants.uftTable: "UFT对象", + Constants.component: "标准组件", + Constants.business: "业务函数", + Constants.atomService: "原子服务", + Constants.atomFunction: "原子函数", }; //字段索引 static Map stdfieldMap = {}; @@ -42,19 +44,22 @@ class StdFieldService { } // 加载字段操作 - static Future _loadFieldActions(OutlineNode dirNode) async { + static void _loadFieldActions(OutlineNode dirNode) { switch (dirNode.name) { - case 'UFTTable': - await UftObjectService.loadUftObject(dirNode.value, dirNode); + case Constants.uftTable: + UftObjectService.loadUftObject(dirNode.value, dirNode); break; - case 'Component': - await ComponentService.loadComponent(dirNode.value, dirNode); + case Constants.component: + ComponentService.loadComponent(dirNode.value, dirNode); break; - case 'Business': - await FunctionsService.loadBusiness(dirNode.value, dirNode); + case Constants.business: + FunctionsService.loadBusiness(dirNode.value, dirNode); break; - case 'Atom': - await FunctionsService.loadAtom(dirNode.value, dirNode); + case Constants.atomService: + FunctionsService.loadAtomService(dirNode.value, dirNode); + break; + case Constants.atomFunction: + FunctionsService.loadAtomFunction(dirNode.value, dirNode); break; default: Logger().error("操作节点类型不支持: ${dirNode.value}"); diff --git a/win_text_editor/lib/modules/outline/services/uft_object_service.dart b/win_text_editor/lib/modules/outline/services/uft_object_service.dart index c4cc334..48686cc 100644 --- a/win_text_editor/lib/modules/outline/services/uft_object_service.dart +++ b/win_text_editor/lib/modules/outline/services/uft_object_service.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:path/path.dart' as path; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; import 'package:xml/xml.dart'; @@ -60,7 +61,7 @@ class UftObjectService { } // 私有方法:加载UFT对象 - static Future loadUftObject(String? fieldName, OutlineNode parentNode) async { + static void loadUftObject(String? fieldName, OutlineNode parentNode) { if (fieldName == null || fieldName.isEmpty) return; uftObjectMap.forEach((key, value) { @@ -69,7 +70,7 @@ class UftObjectService { OutlineNode( name: value[0], title: key, - value: 'UFTTable', + value: Constants.uftTable, isDirectory: false, // 这些是叶子节点 depth: 4, ), @@ -85,7 +86,13 @@ class UftObjectService { if (key.contains(searchQuery) || path.basenameWithoutExtension(value[0]).contains(searchQuery)) { searchNodes.add( - OutlineNode(name: value[0], title: key, value: 'UFTTable', isDirectory: false, depth: 4), + OutlineNode( + name: value[0], + title: key, + value: Constants.uftTable, + isDirectory: false, + depth: 4, + ), ); } }); diff --git a/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart b/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart index aab2ba2..68ffedc 100644 --- a/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart +++ b/win_text_editor/lib/modules/outline/widgets/outline_explorer.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/framework/controllers/file_provider.dart'; import 'package:win_text_editor/framework/services/file_path_manager.dart'; import 'package:win_text_editor/modules/outline/controllers/outline_provider.dart'; @@ -172,14 +173,15 @@ class _OutlineExplorerState extends State { return; } switch (outlineNode.value) { - case "UFTTable": - case "Business": - case "Atom": + case Constants.uftTable: + case Constants.business: + case Constants.atomFunction: + case Constants.atomService: if (widget.onFileDoubleTap != null) { widget.onFileDoubleTap!(outlineNode.name, null); } break; - case "Component": + case Constants.component: if (widget.onFileDoubleTap != null && fileProvider.rootPath != null) { widget.onFileDoubleTap!( '${fileProvider.rootPath}\\metadata\\component.xml', diff --git a/win_text_editor/lib/shared/components/code_generation_components.dart b/win_text_editor/lib/shared/components/code_generation_components.dart index 7b25991..6f1c2ff 100644 --- a/win_text_editor/lib/shared/components/code_generation_components.dart +++ b/win_text_editor/lib/shared/components/code_generation_components.dart @@ -1,6 +1,7 @@ // shared/components/code_generation_components.dart import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:win_text_editor/framework/common/constants.dart'; import 'package:win_text_editor/modules/outline/models/outline_node.dart'; class CodeGenerationRadioItem extends StatelessWidget { @@ -118,11 +119,13 @@ class CodeGenerationSection extends StatelessWidget { if (outlineNode.depth < 3) { return false; } + switch (outlineNode.value) { - case "UFTTable": - case "Business": - case "Atom": - case "Component": + case Constants.uftTable: + case Constants.business: + case Constants.atomFunction: + case Constants.atomService: + case Constants.component: return true; // 允许拖入这些类型的节点 default: return false; // 其他类型的节点不允许拖入