|
|
|
@ -1,18 +1,17 @@
@@ -1,18 +1,17 @@
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:win_text_editor/framework/models/tab_model.dart'; |
|
|
|
|
import 'package:win_text_editor/shared/base/base_view.dart'; |
|
|
|
|
import 'package:win_text_editor/modules/content_search/controllers/content_search_controller.dart'; |
|
|
|
|
import 'package:win_text_editor/shared/base/base_content_controller.dart'; |
|
|
|
|
import 'package:win_text_editor/framework/controllers/logger.dart'; |
|
|
|
|
|
|
|
|
|
class TabManager with ChangeNotifier { |
|
|
|
|
final List<AppTab> _tabs = []; |
|
|
|
|
final Map<String, ChangeNotifier> _tabControllers = {}; // 保存各Tab的Controller |
|
|
|
|
final Map<String, BaseContentController> _tabControllers = {}; // 保存各Tab的Controller |
|
|
|
|
String? _activeTabId; |
|
|
|
|
|
|
|
|
|
List<AppTab> get tabs => _tabs; |
|
|
|
|
String? get activeTabId => _activeTabId; |
|
|
|
|
|
|
|
|
|
BaseViewState? _activeViewState; |
|
|
|
|
|
|
|
|
|
AppTab? get activeTab { |
|
|
|
|
if (_activeTabId == null) return null; |
|
|
|
|
try { |
|
|
|
@ -29,11 +28,14 @@ class TabManager with ChangeNotifier {
@@ -29,11 +28,14 @@ class TabManager with ChangeNotifier {
|
|
|
|
|
String? type, |
|
|
|
|
IconData? icon, |
|
|
|
|
String content = '', |
|
|
|
|
ChangeNotifier? controller, |
|
|
|
|
}) async { |
|
|
|
|
//创建tab组件 |
|
|
|
|
final newTab = AppTab(id: id, title: title, type: type, icon: icon, content: content); |
|
|
|
|
|
|
|
|
|
_tabs.add(newTab); |
|
|
|
|
|
|
|
|
|
// 创建provider,管理状态 |
|
|
|
|
final controller = createContentController(newTab); |
|
|
|
|
if (controller != null) { |
|
|
|
|
_tabControllers[id] = controller; |
|
|
|
|
} |
|
|
|
@ -50,6 +52,21 @@ class TabManager with ChangeNotifier {
@@ -50,6 +52,21 @@ class TabManager with ChangeNotifier {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BaseContentController? createContentController(AppTab tab) { |
|
|
|
|
switch (tab.type) { |
|
|
|
|
case 'content_search': |
|
|
|
|
return ContentSearchController(); |
|
|
|
|
default: |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BaseContentController? get activeContentController { |
|
|
|
|
if (_activeTabId == null) return null; |
|
|
|
|
final controller = _tabControllers[_activeTabId]; |
|
|
|
|
return controller is BaseContentController ? controller : null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void closeTab(String tabId) { |
|
|
|
|
final controller = _tabControllers[tabId]; |
|
|
|
|
controller?.dispose(); // 先释放Controller |
|
|
|
@ -62,7 +79,7 @@ class TabManager with ChangeNotifier {
@@ -62,7 +79,7 @@ class TabManager with ChangeNotifier {
|
|
|
|
|
notifyListeners(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void registerController(String tabId, ChangeNotifier controller) { |
|
|
|
|
void registerController(String tabId, BaseContentController controller) { |
|
|
|
|
_tabControllers[tabId] = controller; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -77,24 +94,15 @@ class TabManager with ChangeNotifier {
@@ -77,24 +94,15 @@ class TabManager with ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
void setActiveTab(String tabId) { |
|
|
|
|
if (_activeTabId == tabId) return; // 如果已经是活动Tab则不通知 |
|
|
|
|
|
|
|
|
|
Logger().info('设置活动选项卡: $tabId'); |
|
|
|
|
_activeTabId = tabId; |
|
|
|
|
notifyListeners(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void handleFolderDoubleTap(String folderPath) { |
|
|
|
|
_activeViewState?.onOpenFolder(folderPath); |
|
|
|
|
activeContentController?.onOpenFolder(folderPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void handleFileDoubleTap(String filePath) { |
|
|
|
|
_activeViewState?.onOpenFile(filePath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void setActiveViewState(BaseViewState? state) { |
|
|
|
|
if (_activeViewState != state) { |
|
|
|
|
_activeViewState = state; |
|
|
|
|
// 不需要 notifyListeners(),因为这只是内部状态更新 |
|
|
|
|
} |
|
|
|
|
activeContentController?.onOpenFile(filePath); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|