|
|
|
@ -4,9 +4,9 @@ import 'package:win_text_editor/modules/content_search/controllers/content_searc
@@ -4,9 +4,9 @@ import 'package:win_text_editor/modules/content_search/controllers/content_searc
|
|
|
|
|
import 'package:win_text_editor/shared/base/base_content_controller.dart'; |
|
|
|
|
import 'package:win_text_editor/framework/controllers/logger.dart'; |
|
|
|
|
|
|
|
|
|
class TabManager with ChangeNotifier { |
|
|
|
|
class TabItemsController with ChangeNotifier { |
|
|
|
|
final List<AppTab> _tabs = []; |
|
|
|
|
final Map<String, BaseContentController> _tabControllers = {}; // 保存各Tab的Controller |
|
|
|
|
final Map<String, BaseContentController> _contentControllers = {}; // 保存各Tab的Controller |
|
|
|
|
String? _activeTabId; |
|
|
|
|
|
|
|
|
|
List<AppTab> get tabs => _tabs; |
|
|
|
@ -37,7 +37,7 @@ class TabManager with ChangeNotifier {
@@ -37,7 +37,7 @@ class TabManager with ChangeNotifier {
|
|
|
|
|
// 创建provider,管理状态 |
|
|
|
|
final controller = createContentController(newTab); |
|
|
|
|
if (controller != null) { |
|
|
|
|
_tabControllers[id] = controller; |
|
|
|
|
_contentControllers[id] = controller; |
|
|
|
|
} |
|
|
|
|
_activeTabId = id; |
|
|
|
|
notifyListeners(); |
|
|
|
@ -63,14 +63,14 @@ class TabManager with ChangeNotifier {
@@ -63,14 +63,14 @@ class TabManager with ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
BaseContentController? get activeContentController { |
|
|
|
|
if (_activeTabId == null) return null; |
|
|
|
|
final controller = _tabControllers[_activeTabId]; |
|
|
|
|
final controller = _contentControllers[_activeTabId]; |
|
|
|
|
return controller is BaseContentController ? controller : null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void closeTab(String tabId) { |
|
|
|
|
final controller = _tabControllers[tabId]; |
|
|
|
|
final controller = _contentControllers[tabId]; |
|
|
|
|
controller?.dispose(); // 先释放Controller |
|
|
|
|
_tabControllers.remove(tabId); // 移除Controller引用 |
|
|
|
|
_contentControllers.remove(tabId); // 移除Controller引用 |
|
|
|
|
_tabs.removeWhere((tab) => tab.id == tabId); // 再移除Tab |
|
|
|
|
|
|
|
|
|
if (_activeTabId == tabId) { |
|
|
|
@ -80,16 +80,16 @@ class TabManager with ChangeNotifier {
@@ -80,16 +80,16 @@ class TabManager with ChangeNotifier {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void registerController(String tabId, BaseContentController controller) { |
|
|
|
|
_tabControllers[tabId] = controller; |
|
|
|
|
_contentControllers[tabId] = controller; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
T? getController<T extends ChangeNotifier>(String tabId) { |
|
|
|
|
return _tabControllers[tabId] as T?; |
|
|
|
|
return _contentControllers[tabId] as T?; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void disposeController(String tabId) { |
|
|
|
|
_tabControllers[tabId]?.dispose(); |
|
|
|
|
_tabControllers.remove(tabId); |
|
|
|
|
_contentControllers[tabId]?.dispose(); |
|
|
|
|
_contentControllers.remove(tabId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void setActiveTab(String tabId) { |