Browse Source

优化了checkbox,函数调用完成部分

master
hejl 1 month ago
parent
commit
d6c20903c2
  1. 32
      win_text_editor/lib/modules/call_function/controllers/call_function_controller.dart
  2. 90
      win_text_editor/lib/modules/call_function/services/call_function_service.dart
  3. 6
      win_text_editor/lib/modules/call_function/widgets/call_function_left_side.dart
  4. 51
      win_text_editor/lib/modules/call_function/widgets/call_function_right_side.dart
  5. 3
      win_text_editor/lib/modules/content_search/widgets/search_settings.dart
  6. 13
      win_text_editor/lib/modules/memory_table/services/memory_table_service.dart
  7. 25
      win_text_editor/lib/modules/memory_table/widgets/memory_table_right_side.dart
  8. 11
      win_text_editor/lib/modules/uft_component/controllers/uft_component_controller.dart
  9. 76
      win_text_editor/lib/modules/uft_component/services/uft_component_service.dart
  10. 25
      win_text_editor/lib/modules/uft_component/widgets/uft_component_right_side.dart
  11. 13
      win_text_editor/lib/shared/components/my_checkbox.dart
  12. 71
      win_text_editor/lib/shared/data/std_fields_cache.dart
  13. 67
      win_text_editor/lib/shared/uft_std_fields/field_data_service.dart
  14. 8
      win_text_editor/lib/shared/uft_std_fields/fields_data_grid.dart

32
win_text_editor/lib/modules/call_function/controllers/call_function_controller.dart

@ -3,7 +3,6 @@ import 'package:win_text_editor/framework/controllers/logger.dart';
import 'package:win_text_editor/framework/services/macro_template_service.dart'; import 'package:win_text_editor/framework/services/macro_template_service.dart';
import 'package:win_text_editor/modules/call_function/models/call_function.dart'; import 'package:win_text_editor/modules/call_function/models/call_function.dart';
import 'package:win_text_editor/modules/call_function/services/call_function_service.dart'; import 'package:win_text_editor/modules/call_function/services/call_function_service.dart';
import 'package:win_text_editor/shared/models/std_filed.dart';
import 'package:win_text_editor/shared/uft_std_fields/field_data_source.dart'; import 'package:win_text_editor/shared/uft_std_fields/field_data_source.dart';
import 'package:win_text_editor/shared/base/base_content_controller.dart'; import 'package:win_text_editor/shared/base/base_content_controller.dart';
@ -23,28 +22,23 @@ class CallFunctionController extends BaseContentController {
CallFunctionController() : _service = CallFunctionService(Logger()) { CallFunctionController() : _service = CallFunctionService(Logger()) {
// //
final initialFields = [Field('1', '', '', '', false)];
inputSource = FieldsDataSource( inputSource = FieldsDataSource(
initialFields, [],
onSelectionChanged: (index, isSelected) { onSelectionChanged: (index, isSelected) {
updateFieldSelection(index, isSelected); updateInputSelection(index, isSelected);
}, },
); );
outputSource = FieldsDataSource( outputSource = FieldsDataSource(
initialFields, [],
onSelectionChanged: (index, isSelected) { onSelectionChanged: (index, isSelected) {
updateFieldSelection(index, isSelected); updateOutputSelection(index, isSelected);
}, },
); );
// CallFunction // CallFunction
_modle = CallFunction( _modle = CallFunction(functionName: '', inputParameters: [], outputParameters: []);
functionName: '',
inputParameters: initialFields,
outputParameters: initialFields,
);
} }
String? get errorMessage => _errorMessage; String? get errorMessage => _errorMessage;
@ -81,7 +75,7 @@ class CallFunctionController extends BaseContentController {
_modle = CallFunction( _modle = CallFunction(
functionName: tableName, functionName: tableName,
inputParameters: functionData.inputFields, inputParameters: functionData.inputFields,
outputParameters: functionData.inputFields, outputParameters: functionData.outputFields,
); );
// Clear any previous error // Clear any previous error
@ -97,7 +91,7 @@ class CallFunctionController extends BaseContentController {
} }
// //
void updateFieldSelection(int index, bool isSelected) { void updateInputSelection(int index, bool isSelected) {
final fields = (inputSource as FieldsDataSource).data; final fields = (inputSource as FieldsDataSource).data;
if (index >= 0 && index < fields.length) { if (index >= 0 && index < fields.length) {
fields[index].isSelected = isSelected; fields[index].isSelected = isSelected;
@ -109,6 +103,18 @@ class CallFunctionController extends BaseContentController {
} }
} }
void updateOutputSelection(int index, bool isSelected) {
final fields = (outputSource as FieldsDataSource).data;
if (index >= 0 && index < fields.length) {
fields[index].isSelected = isSelected;
outputSource.notifyListeners();
// CallFunction
_modle.outputParameters[index].isSelected = isSelected;
notifyListeners();
}
}
@override @override
void onOpenFolder(String folderPath) { void onOpenFolder(String folderPath) {
// //

90
win_text_editor/lib/modules/call_function/services/call_function_service.dart

@ -1,9 +1,10 @@
// memory_table_service.dart // memory_table_service.dart
import 'dart:io'; import 'dart:io';
import 'package:win_text_editor/modules/uft_component/models/uft_component.dart';
import 'package:win_text_editor/modules/uft_component/services/uft_component_service.dart';
import 'package:win_text_editor/shared/data/std_fields_cache.dart'; import 'package:win_text_editor/shared/data/std_fields_cache.dart';
import 'package:win_text_editor/shared/models/std_filed.dart'; import 'package:win_text_editor/shared/models/std_filed.dart';
import 'package:win_text_editor/shared/uft_std_fields/field_data_service.dart';
import 'package:xml/xml.dart' as xml; import 'package:xml/xml.dart' as xml;
import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/framework/controllers/logger.dart';
@ -31,13 +32,7 @@ class CallFunctionService {
} }
// 2. metadata stdfield.stfield // 2. metadata stdfield.stfield
if (await StdFieldsCache.getLength() == 0) { await StdFieldsCache.loadForFile(filePath);
_logger.info("加载标准字段缓存");
final metadataFile = await FieldDataService.findMetadataFile(filePath);
if (metadataFile != null) {
await FieldDataService.processStdFieldFile(metadataFile);
}
}
// 3. Read and parse structure file content // 3. Read and parse structure file content
final file = File(filePath); final file = File(filePath);
@ -54,49 +49,22 @@ class CallFunctionService {
final chineseName = rootNode.getAttribute('chineseName') ?? ''; final chineseName = rootNode.getAttribute('chineseName') ?? '';
final objectId = rootNode.getAttribute('objectId') ?? ''; final objectId = rootNode.getAttribute('objectId') ?? '';
List<UftComponent> componentList = [];
// 5. Process inputParameters (fields) // 5. Process inputParameters (fields)
final inputParameters = document.findAllElements('inputParameters'); final inputParameters = document.findAllElements('inputParameters');
final inputFields = <Field>[]; final inputFields = await parserFields(filePath, inputParameters, componentList);
int index = 1;
for (final parameter in inputParameters) {
final id = parameter.getAttribute('id') ?? '';
//
final stdField = StdFieldsCache.getData(id);
inputFields.add(
Field(
(index++).toString(), //
id, //
stdField?.chineseName ?? '', //
stdField?.dateType ?? '', //
),
);
}
// 6. Process outputParameters // 6. Process outputParameters
final outputParameters = document.findAllElements('outputParameters'); final outputParameters = document.findAllElements('outputParameters');
final outputFields = <Field>[]; final outputFields = await parserFields(filePath, outputParameters, componentList);
index = 1;
for (final parameter in outputParameters) {
final id = parameter.getAttribute('id') ?? '';
//
final stdField = StdFieldsCache.getData(id);
outputFields.add(
Field(
(index++).toString(), //
id, //
stdField?.chineseName ?? '', //
stdField?.dateType ?? '', //
),
);
}
return FunctionData( return FunctionData(
chineseName: chineseName, chineseName: chineseName,
objectId: objectId, objectId: objectId,
inputFields: inputFields.isNotEmpty ? inputFields : FieldDataService.getDefaultFields(), inputFields: inputFields,
outputFields: outputFields.isNotEmpty ? outputFields : FieldDataService.getDefaultFields(), outputFields: outputFields,
componentList: componentList,
); );
} on xml.XmlParserException catch (e) { } on xml.XmlParserException catch (e) {
_logger.error("XML解析错误: ${e.message}"); _logger.error("XML解析错误: ${e.message}");
@ -106,6 +74,42 @@ class CallFunctionService {
rethrow; rethrow;
} }
} }
Future<List<Field>> parserFields(
String filePath,
Iterable<xml.XmlElement> parameters,
List<UftComponent> componentList,
) async {
final fields = <Field>[];
int index = 0;
for (final parameter in parameters) {
index++;
final id = parameter.getAttribute('id') ?? '';
final paramType = parameter.getAttribute('paramType') ?? 'FIELD';
if (paramType == 'COMPONENT') {
final component = await UftComponentService.getUftComponent(filePath, id);
// _logger.debug("value.id:${component?.name}, chineseName:${component?.chineseName}");
if (component != null) componentList.add(component);
fields.add(
Field(
index.toString(),
id,
component?.chineseName ?? '', // 使
'COMPONENT',
),
);
} else {
final stdField = StdFieldsCache.getData(id);
fields.add(
Field(index.toString(), id, stdField?.chineseName ?? '', stdField?.dateType ?? ''),
);
}
}
return fields;
}
} }
class FunctionData { class FunctionData {
@ -113,11 +117,13 @@ class FunctionData {
final String objectId; final String objectId;
final List<Field> inputFields; final List<Field> inputFields;
final List<Field> outputFields; final List<Field> outputFields;
List<UftComponent>? componentList;
FunctionData({ FunctionData({
required this.chineseName, required this.chineseName,
required this.objectId, required this.objectId,
required this.inputFields, required this.inputFields,
required this.outputFields, required this.outputFields,
this.componentList,
}); });
} }

6
win_text_editor/lib/modules/call_function/widgets/call_function_left_side.dart

@ -55,7 +55,7 @@ class CallFunctionLeftSide extends StatelessWidget {
child: FieldsDataGrid( child: FieldsDataGrid(
fieldsSource: controller.inputSource as FieldsDataSource, fieldsSource: controller.inputSource as FieldsDataSource,
onSelectionChanged: (index, isSelected) { onSelectionChanged: (index, isSelected) {
controller.updateFieldSelection(index, isSelected); controller.updateInputSelection(index, isSelected);
}, },
), ),
), ),
@ -66,9 +66,9 @@ class CallFunctionLeftSide extends StatelessWidget {
Expanded( Expanded(
flex: 4, flex: 4,
child: FieldsDataGrid( child: FieldsDataGrid(
fieldsSource: controller.inputSource as FieldsDataSource, fieldsSource: controller.outputSource as FieldsDataSource,
onSelectionChanged: (index, isSelected) { onSelectionChanged: (index, isSelected) {
controller.updateFieldSelection(index, isSelected); controller.updateOutputSelection(index, isSelected);
}, },
), ),
), ),

51
win_text_editor/lib/modules/call_function/widgets/call_function_right_side.dart

@ -32,22 +32,10 @@ class _CallFunctionRightSideState extends State<CallFunctionRightSide> {
widget.codeController.text = widget.controller.genCodeString(_selectedOperations)!; widget.codeController.text = widget.controller.genCodeString(_selectedOperations)!;
} }
void _toggleOperation(String operation, bool? value) {
setState(() {
if (value == true) {
_selectedOperations.add(operation);
} else {
_selectedOperations.remove(operation);
}
_updateDisplay();
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
children: [ children: [
_buildCheckboxSection(),
Padding( Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0), padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Row( child: Row(
@ -74,45 +62,6 @@ class _CallFunctionRightSideState extends State<CallFunctionRightSide> {
); );
} }
Widget _buildCheckboxSection() {
final operations = ['获取记录', '获取记录数', '插入记录', '修改记录', '删除记录', '遍历记录'];
return SizedBox(
width: double.infinity,
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: 16,
runSpacing: 8,
children: operations.map((op) => _buildCheckbox(op)).toList(),
),
],
),
),
),
);
}
Widget _buildCheckbox(String label) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Transform.scale(
scale: 0.75, //
child: Checkbox(
value: _selectedOperations.contains(label),
onChanged: (bool? value) => _toggleOperation(label, value),
),
),
Text(label),
],
);
}
Widget _buildCodeEditor() { Widget _buildCodeEditor() {
return Card( return Card(
child: Padding( child: Padding(

3
win_text_editor/lib/modules/content_search/widgets/search_settings.dart

@ -232,7 +232,7 @@ class _SearchSettingsState extends State<SearchSettings> {
), ),
], ],
), ),
// const SizedBox(height: 8), const SizedBox(height: 8),
// JS函数说明 // JS函数说明
Visibility( Visibility(
visible: controller.customRule, visible: controller.customRule,
@ -286,6 +286,7 @@ class _SearchSettingsState extends State<SearchSettings> {
), ),
], ],
), ),
const SizedBox(height: 8),
Text( Text(
' 搜索计时:[${_formatDuration(_elapsedTime)}]', ' 搜索计时:[${_formatDuration(_elapsedTime)}]',
style: const TextStyle(fontSize: 12), style: const TextStyle(fontSize: 12),

13
win_text_editor/lib/modules/memory_table/services/memory_table_service.dart

@ -4,7 +4,6 @@ import 'dart:io';
import 'package:win_text_editor/modules/memory_table/models/memory_table.dart'; import 'package:win_text_editor/modules/memory_table/models/memory_table.dart';
import 'package:win_text_editor/shared/data/std_fields_cache.dart'; import 'package:win_text_editor/shared/data/std_fields_cache.dart';
import 'package:win_text_editor/shared/models/std_filed.dart'; import 'package:win_text_editor/shared/models/std_filed.dart';
import 'package:win_text_editor/shared/uft_std_fields/field_data_service.dart';
import 'package:xml/xml.dart' as xml; import 'package:xml/xml.dart' as xml;
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/framework/controllers/logger.dart';
@ -22,13 +21,7 @@ class MemoryTableService {
} }
// 2. metadata stdfield.stfield // 2. metadata stdfield.stfield
if (await StdFieldsCache.getLength() == 0) { await StdFieldsCache.loadForFile(filePath);
_logger.info("加载标准字段缓存");
final metadataFile = await FieldDataService.findMetadataFile(filePath);
if (metadataFile != null) {
await FieldDataService.processStdFieldFile(metadataFile);
}
}
// 3. Read and parse structure file content // 3. Read and parse structure file content
final file = File(filePath); final file = File(filePath);
@ -98,8 +91,8 @@ class MemoryTableService {
tableName: fileNameWithoutExt, tableName: fileNameWithoutExt,
chineseName: chineseName, chineseName: chineseName,
objectId: objectId, objectId: objectId,
fields: fields.isNotEmpty ? fields : FieldDataService.getDefaultFields(), fields: fields.isNotEmpty ? fields : [],
indexes: indexList.isNotEmpty ? indexList : FieldDataService.getDefaultIndexes(), indexes: indexList.isNotEmpty ? indexList : [],
); );
} on xml.XmlParserException catch (e) { } on xml.XmlParserException catch (e) {
_logger.error("XML解析错误: ${e.message}"); _logger.error("XML解析错误: ${e.message}");

25
win_text_editor/lib/modules/memory_table/widgets/memory_table_right_side.dart

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:win_text_editor/modules/memory_table/controllers/memory_table_controller.dart'; import 'package:win_text_editor/modules/memory_table/controllers/memory_table_controller.dart';
import 'package:win_text_editor/shared/components/my_checkbox.dart';
class MemoryTableRightSide extends StatefulWidget { class MemoryTableRightSide extends StatefulWidget {
final MemoryTableController controller; final MemoryTableController controller;
@ -81,12 +82,12 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
width: double.infinity, width: double.infinity,
child: Card( child: Card(
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.only(left: 8, top: 4, bottom: 12),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Wrap( Wrap(
spacing: 16, spacing: 8,
runSpacing: 8, runSpacing: 8,
children: operations.map((op) => _buildCheckbox(op)).toList(), children: operations.map((op) => _buildCheckbox(op)).toList(),
), ),
@ -97,21 +98,11 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
); );
} }
Widget _buildCheckbox(String label) { Widget _buildCheckbox(String label) => MyCheckbox(
return Row( title: label,
mainAxisSize: MainAxisSize.min, value: _selectedOperations.contains(label),
children: [ onChanged: (bool? value) => _toggleOperation(label, value),
Transform.scale( );
scale: 0.75,
child: Checkbox(
value: _selectedOperations.contains(label),
onChanged: (bool? value) => _toggleOperation(label, value),
),
),
Text(label),
],
);
}
Widget _buildCodeEditor() { Widget _buildCodeEditor() {
return Card( return Card(

11
win_text_editor/lib/modules/uft_component/controllers/uft_component_controller.dart

@ -15,19 +15,16 @@ class UftComponentController extends BaseContentController {
late DataGridSource fieldsSource; late DataGridSource fieldsSource;
late DataGridSource componentsSource; late DataGridSource componentsSource;
final UftComponentService _service;
final MacroTemplateService templateService = MacroTemplateService(); final MacroTemplateService templateService = MacroTemplateService();
// //
late UftComponent _currentUftComponent; late UftComponent _currentUftComponent;
UftComponentController() : _service = UftComponentService(Logger()) { UftComponentController() {
// //
final initialFields = [Field('1', '', '', '', false), Field('2', '', '', '', false)]; final List<Field> initialFields = [];
final initalComponents = [ final List<UftComponent> initalComponents = [];
UftComponent(id: 1, name: '', chineseName: '', fields: initialFields),
];
componentsSource = ComponentSource( componentsSource = ComponentSource(
initalComponents, initalComponents,
@ -67,7 +64,7 @@ class UftComponentController extends BaseContentController {
Future<void> onOpenFile(String filePath) async { Future<void> onOpenFile(String filePath) async {
Logger().info("Opening file: $filePath"); Logger().info("Opening file: $filePath");
try { try {
final components = await _service.parseComponentFile(filePath); final components = await UftComponentService.parseComponentFile(filePath);
// Update data sources // Update data sources
(componentsSource as ComponentSource).updateData(components); (componentsSource as ComponentSource).updateData(components);

76
win_text_editor/lib/modules/uft_component/services/uft_component_service.dart

@ -2,40 +2,50 @@
import 'dart:io'; import 'dart:io';
import 'package:collection/collection.dart';
import 'package:win_text_editor/modules/memory_table/models/memory_table.dart'; import 'package:win_text_editor/modules/memory_table/models/memory_table.dart';
import 'package:win_text_editor/modules/uft_component/models/uft_component.dart'; import 'package:win_text_editor/modules/uft_component/models/uft_component.dart';
import 'package:win_text_editor/shared/data/std_fields_cache.dart'; import 'package:win_text_editor/shared/data/std_fields_cache.dart';
import 'package:win_text_editor/shared/models/std_filed.dart'; import 'package:win_text_editor/shared/models/std_filed.dart';
import 'package:win_text_editor/framework/controllers/logger.dart'; import 'package:win_text_editor/framework/controllers/logger.dart';
import 'package:win_text_editor/shared/uft_std_fields/field_data_service.dart';
import 'package:xml/xml.dart' as xml; import 'package:xml/xml.dart' as xml;
class UftComponentService { class UftComponentService {
final Logger _logger; static final Logger _logger = Logger();
static List<UftComponent> _components = [];
UftComponentService(this._logger); static Future<UftComponent?> getUftComponent(String filePath, String componentName) async {
if (_components.isNotEmpty) {
return _components.firstWhereOrNull((c) => c.name == componentName);
}
return parseComponentFile(
filePath,
).then((l) => l.firstWhereOrNull((c) => c.name == componentName));
}
Future<List<UftComponent>> parseComponentFile(String filePath) async { static Future<List<UftComponent>> parseComponentFile(String filePath) async {
try { try {
if (_components.isNotEmpty) {
_components.firstWhereOrNull((c) => c.isSelected)?.isSelected = false;
return _components;
}
// 1. Check file extension // 1. Check file extension
if (!filePath.toLowerCase().endsWith('component.xml')) { File? file =
throw const FormatException("文件名必须是component.xml"); filePath.toLowerCase().endsWith('component.xml')
? File(filePath)
: await findMetadataFile(filePath);
if (file == null) {
throw const FormatException("没有找到标准组件文件:component.xml");
} }
// 2. metadata stdfield.stfield // 2. metadata stdfield.stfield
if (await StdFieldsCache.getLength() == 0) { await StdFieldsCache.loadForFile(filePath);
_logger.info("加载标准字段缓存");
final metadataFile = await FieldDataService.findMetadataFile(filePath);
if (metadataFile != null) {
await FieldDataService.processStdFieldFile(metadataFile);
}
}
// 3. Read and parse structure file content // 3. Read and parse structure file content
final file = File(filePath);
final content = await file.readAsString(); final content = await file.readAsString();
_logger.info('加载标准组件');
final document = xml.XmlDocument.parse(content); final document = xml.XmlDocument.parse(content);
final componentNodes = document.findAllElements('items'); final componentNodes = document.findAllElements('items');
@ -44,8 +54,8 @@ class UftComponentService {
} }
// 4. // 4.
final components = <UftComponent>[]; _components = <UftComponent>[];
int id = 1; int id = 0;
for (var node in componentNodes) { for (var node in componentNodes) {
if (node.findElements("items").isEmpty) continue; if (node.findElements("items").isEmpty) continue;
id++; id++;
@ -99,7 +109,7 @@ class UftComponentService {
); );
} }
components.add( _components.add(
UftComponent( UftComponent(
id: id, id: id,
name: name, name: name,
@ -110,7 +120,7 @@ class UftComponentService {
); );
} }
return components; return _components;
} on xml.XmlParserException catch (e) { } on xml.XmlParserException catch (e) {
_logger.error("XML解析错误: ${e.message}"); _logger.error("XML解析错误: ${e.message}");
rethrow; rethrow;
@ -119,4 +129,32 @@ class UftComponentService {
rethrow; rethrow;
} }
} }
static Future<File?> findMetadataFile(String filePath) async {
Directory currentDir = File(filePath).parent;
const targetDirName = 'metadata';
const targetFileName = 'component.xml';
// metadata
while (true) {
final metadataDir = Directory('${currentDir.path}/$targetDirName');
if (await metadataDir.exists()) {
final stdFieldFile = File('${metadataDir.path}/$targetFileName');
if (await stdFieldFile.exists()) {
return stdFieldFile;
} else {
Logger().error("没找到标准组件文件 $targetFileName");
return null;
}
}
//
if (currentDir.path == currentDir.parent.path) {
Logger().error("没有找到元数据目录 $targetDirName");
return null;
}
currentDir = currentDir.parent;
}
}
} }

25
win_text_editor/lib/modules/uft_component/widgets/uft_component_right_side.dart

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:win_text_editor/modules/uft_component/controllers/uft_component_controller.dart'; import 'package:win_text_editor/modules/uft_component/controllers/uft_component_controller.dart';
import 'package:win_text_editor/shared/components/my_checkbox.dart';
class UftComponentRightSide extends StatefulWidget { class UftComponentRightSide extends StatefulWidget {
final UftComponentController controller; final UftComponentController controller;
@ -81,12 +82,12 @@ class _UftComponentRightSideState extends State<UftComponentRightSide> {
width: double.infinity, width: double.infinity,
child: Card( child: Card(
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.only(left: 8, top: 4, bottom: 12),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Wrap( Wrap(
spacing: 16, spacing: 8,
runSpacing: 8, runSpacing: 8,
children: operations.map((op) => _buildCheckbox(op)).toList(), children: operations.map((op) => _buildCheckbox(op)).toList(),
), ),
@ -97,21 +98,11 @@ class _UftComponentRightSideState extends State<UftComponentRightSide> {
); );
} }
Widget _buildCheckbox(String label) { Widget _buildCheckbox(String label) => MyCheckbox(
return Row( title: label,
mainAxisSize: MainAxisSize.min, value: _selectedOperations.contains(label),
children: [ onChanged: (bool? value) => _toggleOperation(label, value),
Transform.scale( );
scale: 0.75,
child: Checkbox(
value: _selectedOperations.contains(label),
onChanged: (bool? value) => _toggleOperation(label, value),
),
),
Text(label),
],
);
}
Widget _buildCodeEditor() { Widget _buildCodeEditor() {
return Card( return Card(

13
win_text_editor/lib/shared/components/my_checkbox.dart

@ -1,21 +1,30 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@immutable
class MyCheckbox extends StatelessWidget { class MyCheckbox extends StatelessWidget {
final String title; final String title;
final bool value; final bool value;
final ValueChanged<bool?>? onChanged; final ValueChanged<bool?>? onChanged;
final bool enabled = true; final bool enabled = true;
final double? maxWidth;
const MyCheckbox({super.key, required this.title, required this.value, this.onChanged}); const MyCheckbox({
super.key,
required this.title,
required this.value,
this.onChanged,
this.maxWidth,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ConstrainedBox( return ConstrainedBox(
constraints: const BoxConstraints(minHeight: 32), constraints: BoxConstraints(maxHeight: 28, maxWidth: maxWidth ?? title.length * 12.0 + 38),
child: ListTile( child: ListTile(
dense: true, dense: true,
title: Text(title, style: const TextStyle(fontSize: 12)), title: Text(title, style: const TextStyle(fontSize: 12)),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
horizontalTitleGap: 4,
leading: Transform.scale( leading: Transform.scale(
scale: 0.75, scale: 0.75,
child: Checkbox( child: Checkbox(

71
win_text_editor/lib/shared/data/std_fields_cache.dart

@ -1,8 +1,13 @@
import 'dart:io';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:win_text_editor/framework/controllers/logger.dart';
import 'package:win_text_editor/shared/models/std_filed.dart'; import 'package:win_text_editor/shared/models/std_filed.dart';
import 'package:xml/xml.dart' as xml;
class StdFieldsCache { class StdFieldsCache {
static late final Box<StdField> _box; // static late final Box<StdField> _box; //
static bool _loaded = false;
// //
static Future<void> init() async { static Future<void> init() async {
@ -11,18 +16,82 @@ class StdFieldsCache {
_box = await Hive.openBox<StdField>('uft_stdFieldsCache'); // _box = await Hive.openBox<StdField>('uft_stdFieldsCache'); //
} }
static Future loadForFile(String currFilePath) async {
if (_loaded == false) {
Logger().info("加载标准字段缓存");
final metadataFile = await findMetadataFile(currFilePath);
if (metadataFile != null) {
await processStdFieldFile(metadataFile);
}
_loaded = true;
}
}
static Future<int> getLength() async { static Future<int> getLength() async {
return _box.length; return _box.length;
} }
// //
static StdField? getData(String key) => _box.get(key); static getData(String key) {
return _box.get(key);
}
static Future<void> setData(String key, StdField value) => _box.put(key, value); static Future<void> setData(String key, StdField value) => _box.put(key, value);
// //
static Future<void> clear() async { static Future<void> clear() async {
await _box.clear(); await _box.clear();
} }
static Future<File?> findMetadataFile(String filePath) async {
Directory currentDir = File(filePath).parent;
const targetDirName = 'metadata';
const targetFileName = 'stdfield.stdfield';
// metadata
while (true) {
final metadataDir = Directory('${currentDir.path}/$targetDirName');
if (await metadataDir.exists()) {
final stdFieldFile = File('${metadataDir.path}/$targetFileName');
if (await stdFieldFile.exists()) {
return stdFieldFile;
} else {
Logger().error("没找到标准字段文件 $targetFileName");
return null;
}
}
//
if (currentDir.path == currentDir.parent.path) {
Logger().error("没有找到元数据目录 $targetDirName");
return null;
}
currentDir = currentDir.parent;
}
}
//
static Future<void> processStdFieldFile(File stdFieldFile) async {
try {
final content = await stdFieldFile.readAsString();
final document = xml.XmlDocument.parse(content);
final items = document.findAllElements('items');
for (final item in items) {
final name = item.getAttribute('name') ?? '';
final chineseName = item.getAttribute('chineseName') ?? '';
final dataType = item.getAttribute('dataType') ?? '';
if (name.isNotEmpty) {
final stdField = StdField(name: name, chineseName: chineseName, dateType: dataType);
await StdFieldsCache.setData(name, stdField);
}
}
} catch (e) {
Logger().error("处理标准字段文件时出错: $e");
}
}
} }
// typeId在整个应用中唯一 // typeId在整个应用中唯一

67
win_text_editor/lib/shared/uft_std_fields/field_data_service.dart

@ -1,67 +0,0 @@
import 'dart:io';
import 'package:win_text_editor/framework/controllers/logger.dart';
import 'package:win_text_editor/modules/memory_table/models/memory_table.dart';
import 'package:win_text_editor/shared/data/std_fields_cache.dart';
import 'package:win_text_editor/shared/models/std_filed.dart';
import 'package:xml/xml.dart' as xml;
class FieldDataService {
static Future<File?> findMetadataFile(String filePath) async {
Directory currentDir = File(filePath).parent;
const targetDirName = 'metadata';
const targetFileName = 'stdfield.stdfield';
// metadata
while (true) {
final metadataDir = Directory('${currentDir.path}/$targetDirName');
if (await metadataDir.exists()) {
final stdFieldFile = File('${metadataDir.path}/$targetFileName');
if (await stdFieldFile.exists()) {
return stdFieldFile;
} else {
Logger().error("没找到标准字段文件 $targetFileName");
return null;
}
}
//
if (currentDir.path == currentDir.parent.path) {
Logger().error("没有找到元数据目录 $targetDirName");
return null;
}
currentDir = currentDir.parent;
}
}
//
static Future<void> processStdFieldFile(File stdFieldFile) async {
try {
final content = await stdFieldFile.readAsString();
final document = xml.XmlDocument.parse(content);
final items = document.findAllElements('items');
for (final item in items) {
final name = item.getAttribute('name') ?? '';
final chineseName = item.getAttribute('chineseName') ?? '';
final dataType = item.getAttribute('dataType') ?? '';
if (name.isNotEmpty) {
final stdField = StdField(name: name, chineseName: chineseName, dateType: dataType);
await StdFieldsCache.setData(name, stdField);
}
}
} catch (e) {
Logger().error("处理标准字段文件时出错: $e");
}
}
static List<Field> getDefaultFields() {
return [Field('1', '', '', ''), Field('2', '', '', ''), Field('3', '', '', '')];
}
static List<Index> getDefaultIndexes() {
return [Index('', false, '', ''), Index('', false, '', '')];
}
}

8
win_text_editor/lib/shared/uft_std_fields/fields_data_grid.dart

@ -11,14 +11,6 @@ class FieldsDataGrid extends StatelessWidget {
const FieldsDataGrid({super.key, required this.fieldsSource, this.onSelectionChanged}); const FieldsDataGrid({super.key, required this.fieldsSource, this.onSelectionChanged});
Container _buildGridHeader(String text) {
return Container(
alignment: Alignment.center,
color: Colors.grey[200],
child: Text(text, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
);
}
Widget _buildCheckboxHeader<T extends SelectableItem>( Widget _buildCheckboxHeader<T extends SelectableItem>(
BuildContext context, BuildContext context,
SelectableDataSource<T> dataSource, SelectableDataSource<T> dataSource,

Loading…
Cancel
Save