|
|
|
// modules/tab_content_registry.dart
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:win_text_editor/framework/models/tab_model.dart';
|
|
|
|
import 'package:win_text_editor/modules/data_compare/controllers/data_compare_controller.dart';
|
|
|
|
import 'package:win_text_editor/modules/data_compare/widgets/data_compare_view.dart';
|
|
|
|
import 'package:win_text_editor/modules/data_format/controllers/data_format_controller.dart';
|
|
|
|
import 'package:win_text_editor/modules/data_format/widgets/data_format_view.dart';
|
|
|
|
import 'package:win_text_editor/modules/demo/controllers/demo_controller.dart';
|
|
|
|
import 'package:win_text_editor/modules/demo/widgets/demo_view.dart';
|
|
|
|
import 'package:win_text_editor/modules/uft_file/controllers/uft_file_controller.dart';
|
|
|
|
import 'package:win_text_editor/modules/uft_file/widgets/uft_file_view.dart';
|
|
|
|
import 'package:win_text_editor/shared/base/base_content_controller.dart';
|
|
|
|
import 'package:win_text_editor/modules/content_search/controllers/content_search_controller.dart';
|
|
|
|
import 'package:win_text_editor/modules/template_parser/controllers/template_parser_controller.dart';
|
|
|
|
import 'package:win_text_editor/modules/content_search/widgets/content_search_view.dart';
|
|
|
|
import 'package:win_text_editor/modules/template_parser/widgets/template_parser_view.dart';
|
|
|
|
|
|
|
|
class RouterKey {
|
|
|
|
static const String contentSearch = 'content_search';
|
|
|
|
static const String templateParser = 'template_parser';
|
|
|
|
static const String dataFormat = 'data_format';
|
|
|
|
static const String textEditor = 'text_editor';
|
|
|
|
static const String dataCompare = 'data_compare';
|
|
|
|
static const String uftFile = 'uft_file';
|
|
|
|
static const String demo = 'demo';
|
|
|
|
}
|
|
|
|
|
|
|
|
class ModuleRouter {
|
|
|
|
//映射控制器
|
|
|
|
static final Map<String, ContentControllerCreator> _controllerCreators = {
|
|
|
|
RouterKey.contentSearch: (tab) => ContentSearchController(),
|
|
|
|
RouterKey.templateParser: (tab) => TemplateParserController(),
|
|
|
|
RouterKey.dataFormat: (tab) => DataFormatController(),
|
|
|
|
RouterKey.dataCompare: (tab) => DataCompareController(),
|
|
|
|
RouterKey.uftFile: (tab) => UftFileController(),
|
|
|
|
RouterKey.demo: (tab) => DemoController(),
|
|
|
|
};
|
|
|
|
|
|
|
|
// 映射UI组件
|
|
|
|
static final Map<String, ContentWidgetBuilder> _widgetBuilders = {
|
|
|
|
RouterKey.contentSearch: (tab, controller) => ContentSearchView(tabId: tab.id),
|
|
|
|
RouterKey.templateParser: (tab, controller) => TemplateParserView(tabId: tab.id),
|
|
|
|
RouterKey.dataFormat: (tab, controller) => DataFormatView(tabId: tab.id),
|
|
|
|
RouterKey.dataCompare: (tab, controller) => DataCompareView(tabId: tab.id),
|
|
|
|
RouterKey.uftFile: (tab, controller) => UftFileView(tabId: tab.id),
|
|
|
|
RouterKey.demo: (tab, controller) => DemoView(tabId: tab.id),
|
|
|
|
};
|
|
|
|
|
|
|
|
static BaseContentController? createControllerForTab(AppTab tab) {
|
|
|
|
final creator = _controllerCreators[tab.type];
|
|
|
|
return creator != null ? creator(tab) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Widget buildWidgetForTab(AppTab tab, ChangeNotifier? controller) {
|
|
|
|
final builder = _widgetBuilders[tab.type] ?? _widgetBuilders['default'];
|
|
|
|
return builder!(tab, controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void registerControllerCreator(String type, ContentControllerCreator creator) {
|
|
|
|
_controllerCreators[type] = creator;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void registerWidgetBuilder(String type, ContentWidgetBuilder builder) {
|
|
|
|
_widgetBuilders[type] = builder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef ContentControllerCreator = BaseContentController Function(AppTab tab);
|
|
|
|
typedef ContentWidgetBuilder = Widget Function(AppTab tab, ChangeNotifier? controller);
|