|
|
|
@ -11,6 +11,7 @@ class TemplateParserController extends BaseContentController {
@@ -11,6 +11,7 @@ class TemplateParserController extends BaseContentController {
|
|
|
|
|
List<TemplateItem> _templateItems = []; |
|
|
|
|
String? _errorMessage; |
|
|
|
|
TemplateNode? _selectedNode; |
|
|
|
|
String? _currentParentPath; // 新增属性,用于记录当前选中节点的父节点路径 |
|
|
|
|
|
|
|
|
|
// Getters |
|
|
|
|
String get filePath => _filePath; |
|
|
|
@ -40,12 +41,38 @@ class TemplateParserController extends BaseContentController {
@@ -40,12 +41,38 @@ class TemplateParserController extends BaseContentController {
|
|
|
|
|
notifyListeners(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 新增方法,用于处理节点的选中状态 |
|
|
|
|
void toggleNodeCheck(TemplateNode node) { |
|
|
|
|
final parentPath = node.path.substring(0, node.path.lastIndexOf('/')); |
|
|
|
|
if (_currentParentPath != null && _currentParentPath != parentPath) { |
|
|
|
|
// 如果最新选择的节点与之前选中的节点不在同一个父节点下,清除之前的选中状态 |
|
|
|
|
clearAllChecked(); |
|
|
|
|
} |
|
|
|
|
node.isChecked = !node.isChecked; |
|
|
|
|
_currentParentPath = parentPath; |
|
|
|
|
notifyListeners(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 新增方法,用于清除所有节点的选中状态 |
|
|
|
|
void clearAllChecked() { |
|
|
|
|
void traverse(TemplateNode node) { |
|
|
|
|
node.isChecked = false; |
|
|
|
|
for (var child in node.children) { |
|
|
|
|
traverse(child); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (var node in _treeNodes) { |
|
|
|
|
traverse(node); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Future<void> _loadTemplateData() async { |
|
|
|
|
try { |
|
|
|
|
_errorMessage = null; |
|
|
|
|
_treeNodes = []; |
|
|
|
|
_templateItems = []; |
|
|
|
|
_selectedNode = null; |
|
|
|
|
_currentParentPath = null; // 加载数据时清空当前父节点路径 |
|
|
|
|
|
|
|
|
|
if (_filePath.isEmpty) return; |
|
|
|
|
|
|
|
|
|