Browse Source

开始搞代码生成了

master
hejl 3 weeks ago
parent
commit
92a27463c8
  1. 7
      win_text_editor/lib/framework/common/constants.dart
  2. 32
      win_text_editor/lib/modules/code_creater/controllers/code_creater_controller.dart
  3. 14
      win_text_editor/lib/modules/code_creater/widgets/code_creater_view.dart
  4. 14
      win_text_editor/lib/modules/code_creater/widgets/node_table.dart
  5. 5
      win_text_editor/lib/modules/outline/models/code_partner.dart
  6. 2
      win_text_editor/lib/modules/outline/models/outline_node.dart
  7. 24
      win_text_editor/lib/modules/outline/services/component_service.dart
  8. 64
      win_text_editor/lib/modules/outline/services/functions_service.dart
  9. 32
      win_text_editor/lib/modules/outline/services/outline_service.dart
  10. 31
      win_text_editor/lib/modules/outline/services/std_field_service.dart
  11. 13
      win_text_editor/lib/modules/outline/services/uft_object_service.dart
  12. 10
      win_text_editor/lib/modules/outline/widgets/outline_explorer.dart
  13. 11
      win_text_editor/lib/shared/components/code_generation_components.dart

7
win_text_editor/lib/framework/common/constants.dart

@ -0,0 +1,7 @@ @@ -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';
}

32
win_text_editor/lib/modules/code_creater/controllers/code_creater_controller.dart

@ -1,10 +1,29 @@ @@ -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<String, List<String>> unMatchMap = {
Constants.atomFunction: ['逻辑服务', '逻辑函数'],
Constants.atomService: ['原子服务', '原子函数'],
Constants.business: ['原子服务', '原子函数'],
Constants.uftTable: [],
Constants.component: [],
};
List<OutlineNode> _members = [];
List<OutlineNode> 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<OutlineNode> newMembers) {
_members = newMembers;
@ -12,17 +31,18 @@ class CodeCreaterController extends BaseContentController { @@ -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();
}

14
win_text_editor/lib/modules/code_creater/widgets/code_creater_view.dart

@ -21,7 +21,6 @@ class _CodeCreaterViewState extends State<CodeCreaterView> { @@ -21,7 +21,6 @@ class _CodeCreaterViewState extends State<CodeCreaterView> {
bool _isControllerFromTabManager = false;
final TextEditingController _codeController = TextEditingController();
final List<String> operations = ['逻辑服务', '逻辑函数', '原子服务', '原子函数'];
String? _selectedOperation = '原子函数';
get tabManager => Provider.of<TabItemsController>(context, listen: false);
@ -87,7 +86,7 @@ class _CodeCreaterViewState extends State<CodeCreaterView> { @@ -87,7 +86,7 @@ class _CodeCreaterViewState extends State<CodeCreaterView> {
onNodeDropped: (node) => _controller.onDropOutlineNode(node),
child: OperationRadioSection(
operations: operations,
selectedOperation: _selectedOperation,
selectedOperation: _controller.selectedOperation,
onOperationSelected: _selectOperation,
),
),
@ -136,17 +135,16 @@ class _CodeCreaterViewState extends State<CodeCreaterView> { @@ -136,17 +135,16 @@ class _CodeCreaterViewState extends State<CodeCreaterView> {
}
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!]) ?? '';
}
}

14
win_text_editor/lib/modules/code_creater/widgets/node_table.dart

@ -2,6 +2,7 @@ import 'dart:ui'; @@ -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<NodeTable> { @@ -222,13 +223,14 @@ class NodeTableState extends State<NodeTable> {
List<String> _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 ['']; //
}

5
win_text_editor/lib/modules/outline/models/code_partner.dart

@ -1,4 +1,5 @@ @@ -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 { @@ -13,14 +14,14 @@ class CodePartner {
String? name;
List<String> fields = [];
switch (node.value) {
case "UFTTable":
case Constants.uftTable:
final List<String>? 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<String>? values = ComponentService.componentFieldMap[node.name];
if (values != null && values.isNotEmpty) {

2
win_text_editor/lib/modules/outline/models/outline_node.dart

@ -40,7 +40,7 @@ class OutlineNode implements TreeNode { @@ -40,7 +40,7 @@ class OutlineNode implements TreeNode {
List<OutlineNode>? 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<OutlineNode>? children}) {

24
win_text_editor/lib/modules/outline/services/component_service.dart

@ -1,5 +1,7 @@ @@ -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 { @@ -44,7 +46,7 @@ class ComponentService {
}
//
static Future<Map<String, String>> matchComponent(String fieldName) async {
static Map<String, String> matchComponent(String fieldName) {
Map<String, String> matchComponents = {};
componentFieldMap.forEach((key, value) {
@ -54,13 +56,19 @@ class ComponentService { @@ -54,13 +56,19 @@ class ComponentService {
return matchComponents;
}
static Future<void> 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 { @@ -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,
),
);
}
});

64
win_text_editor/lib/modules/outline/services/functions_service.dart

@ -1,5 +1,6 @@ @@ -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 { @@ -10,12 +11,14 @@ class FunctionsService {
static Map<String, List<String>> uftbusinessMap = {};
//
static Map<String, List<String>> uftatomMap = {};
static Map<String, List<String>> uftatomserviceMap = {};
static Map<String, List<String>> uftatomFunctionMap = {};
static Future<void> 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<void> _initUftMap(
@ -78,17 +81,35 @@ class FunctionsService { @@ -78,17 +81,35 @@ class FunctionsService {
}
}
//
static Future<void> 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<void> 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 { @@ -98,7 +119,7 @@ class FunctionsService {
}
//
static Future<void> 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 { @@ -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 { @@ -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<OutlineNode> searchAtomServices(String searchQuery) {
final List<OutlineNode> 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 { @@ -135,15 +175,15 @@ class FunctionsService {
return nodes;
}
static List<OutlineNode> searchAtoms(String searchQuery) {
static List<OutlineNode> searchAtomFunctions(String searchQuery) {
final List<OutlineNode> 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,
),

32
win_text_editor/lib/modules/outline/services/outline_service.dart

@ -2,6 +2,7 @@ @@ -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 { @@ -253,7 +254,7 @@ class OutlineService {
final List<OutlineNode> 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 { @@ -267,7 +268,7 @@ class OutlineService {
final List<OutlineNode> 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 { @@ -281,8 +282,8 @@ class OutlineService {
final List<OutlineNode> 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 { @@ -292,16 +293,29 @@ class OutlineService {
}
//
final List<OutlineNode> atomNodes = FunctionsService.searchAtoms(searchQuery);
if (atomNodes.isNotEmpty) {
final List<OutlineNode> 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<OutlineNode> 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);
}

31
win_text_editor/lib/modules/outline/services/std_field_service.dart

@ -1,5 +1,6 @@ @@ -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'; @@ -10,10 +11,11 @@ import 'package:xml/xml.dart';
class StdFieldService {
// ignore: constant_identifier_names
static const Map<String, String> FIELD_ACTIONS = {
"UFTTable": "UFT对象",
"Component": "标准组件",
"Business": "业务层",
"Atom": "原子层",
Constants.uftTable: "UFT对象",
Constants.component: "标准组件",
Constants.business: "业务函数",
Constants.atomService: "原子服务",
Constants.atomFunction: "原子函数",
};
//
static Map<String, String> stdfieldMap = {};
@ -42,19 +44,22 @@ class StdFieldService { @@ -42,19 +44,22 @@ class StdFieldService {
}
//
static Future<void> _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}");

13
win_text_editor/lib/modules/outline/services/uft_object_service.dart

@ -1,6 +1,7 @@ @@ -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 { @@ -60,7 +61,7 @@ class UftObjectService {
}
// UFT对象
static Future<void> 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 { @@ -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 { @@ -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,
),
);
}
});

10
win_text_editor/lib/modules/outline/widgets/outline_explorer.dart

@ -2,6 +2,7 @@ import 'dart:async'; @@ -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<OutlineExplorer> { @@ -172,14 +173,15 @@ class _OutlineExplorerState extends State<OutlineExplorer> {
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',

11
win_text_editor/lib/shared/components/code_generation_components.dart

@ -1,6 +1,7 @@ @@ -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 { @@ -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; //

Loading…
Cancel
Save