diff --git a/flutter/lib/desktop/pages/connection_tab_page.dart b/flutter/lib/desktop/pages/connection_tab_page.dart index 8f5350792..bf12f443c 100644 --- a/flutter/lib/desktop/pages/connection_tab_page.dart +++ b/flutter/lib/desktop/pages/connection_tab_page.dart @@ -10,6 +10,8 @@ import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart'; import 'package:flutter_hbb/utils/multi_window_manager.dart'; import 'package:get/get.dart'; +import '../../mobile/widgets/dialog.dart'; + class ConnectionTabPage extends StatefulWidget { final Map params; @@ -37,6 +39,11 @@ class _ConnectionTabPageState extends State { label: peerId, selectedIcon: selectedIcon, unselectedIcon: unselectedIcon, + onTabCloseButton: () { + debugPrint("onTabCloseButton"); + tabController.jumpBy(peerId); + clientClose(ffi(peerId).dialogManager); + }, page: Obx(() => RemotePage( key: ValueKey(peerId), id: peerId, @@ -69,6 +76,11 @@ class _ConnectionTabPageState extends State { label: id, selectedIcon: selectedIcon, unselectedIcon: unselectedIcon, + onTabCloseButton: () { + debugPrint("onTabCloseButton"); + tabController.jumpBy(id); + clientClose(ffi(id).dialogManager); + }, page: Obx(() => RemotePage( key: ValueKey(id), id: id, @@ -95,7 +107,7 @@ class _ConnectionTabPageState extends State { body: Obx(() => DesktopTab( controller: tabController, showTabBar: fullscreen.isFalse, - onClose: () { + onWindowCloseButton: () { tabController.clear(); }, tail: AddButton().paddingOnly(left: 10), diff --git a/flutter/lib/desktop/pages/file_manager_tab_page.dart b/flutter/lib/desktop/pages/file_manager_tab_page.dart index d6f01e55f..d33c0084c 100644 --- a/flutter/lib/desktop/pages/file_manager_tab_page.dart +++ b/flutter/lib/desktop/pages/file_manager_tab_page.dart @@ -71,10 +71,10 @@ class _FileManagerTabPageState extends State { backgroundColor: MyTheme.color(context).bg, body: DesktopTab( controller: tabController, - onClose: () { + onWindowCloseButton: () { tabController.clear(); }, - tail: AddButton().paddingOnly(left: 10), + tail: const AddButton().paddingOnly(left: 10), )), ), ); diff --git a/flutter/lib/desktop/pages/port_forward_tab_page.dart b/flutter/lib/desktop/pages/port_forward_tab_page.dart index e0384b614..5dd69e8eb 100644 --- a/flutter/lib/desktop/pages/port_forward_tab_page.dart +++ b/flutter/lib/desktop/pages/port_forward_tab_page.dart @@ -78,7 +78,7 @@ class _PortForwardTabPageState extends State { backgroundColor: MyTheme.color(context).bg, body: DesktopTab( controller: tabController, - onClose: () { + onWindowCloseButton: () { tabController.clear(); }, tail: AddButton().paddingOnly(left: 10), @@ -88,7 +88,6 @@ class _PortForwardTabPageState extends State { } void onRemoveId(String id) { - ffi("pf_$id").close(); if (tabController.state.value.tabs.isEmpty) { WindowController.fromWindowId(windowId()).hide(); } diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart index 5daa1aeb6..f2fc5f8ca 100644 --- a/flutter/lib/desktop/widgets/tabbar_widget.dart +++ b/flutter/lib/desktop/widgets/tabbar_widget.dart @@ -24,7 +24,8 @@ class TabInfo { final String label; final IconData? selectedIcon; final IconData? unselectedIcon; - final bool closable; + final bool closable; // + final VoidCallback? onTabCloseButton; final Widget page; TabInfo( @@ -33,6 +34,7 @@ class TabInfo { this.selectedIcon, this.unselectedIcon, this.closable = true, + this.onTabCloseButton, required this.page}); } @@ -137,16 +139,23 @@ class DesktopTabController { } } + void jumpBy(String key) { + if (!isDesktop) return; + final index = state.value.tabs.indexWhere((tab) => tab.key == key); + jumpTo(index); + } + void closeBy(String? key) { if (!isDesktop) return; + debugPrint("closeBy: $key"); assert(onRemove != null); if (key == null) { if (state.value.selected < state.value.tabs.length) { remove(state.value.selected); } } else { - state.value.tabs.indexWhere((tab) => tab.key == key); - remove(state.value.selected); + final index = state.value.tabs.indexWhere((tab) => tab.key == key); + remove(index); } } @@ -175,7 +184,7 @@ class DesktopTab extends StatelessWidget { final bool showClose; final Widget Function(Widget pageView)? pageViewBuilder; final Widget? tail; - final VoidCallback? onClose; + final VoidCallback? onWindowCloseButton; final TabBuilder? tabBuilder; final LabelGetter? labelGetter; @@ -196,7 +205,7 @@ class DesktopTab extends StatelessWidget { this.showClose = true, this.pageViewBuilder, this.tail, - this.onClose, + this.onWindowCloseButton, this.tabBuilder, this.labelGetter, }) : super(key: key) { @@ -333,7 +342,7 @@ class DesktopTab extends StatelessWidget { showMinimize: showMinimize, showMaximize: showMaximize, showClose: showClose, - onClose: onClose, + onClose: onWindowCloseButton, ) ], ); @@ -511,7 +520,13 @@ class _ListView extends StatelessWidget { unselectedIcon: tab.unselectedIcon, closable: tab.closable, selected: state.value.selected, - onClose: () => controller.remove(index), + onClose: () { + if (tab.onTabCloseButton != null) { + tab.onTabCloseButton!(); + } else { + controller.remove(index); + } + }, onSelected: () => controller.jumpTo(index), tabBuilder: tabBuilder == null ? null