confirm connection tab close

This commit is contained in:
csf 2022-09-08 19:26:55 +08:00
parent 1c170366e7
commit b93e59df21
4 changed files with 38 additions and 12 deletions

View File

@ -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<String, dynamic> params;
@ -37,6 +39,11 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
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<ConnectionTabPage> {
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<ConnectionTabPage> {
body: Obx(() => DesktopTab(
controller: tabController,
showTabBar: fullscreen.isFalse,
onClose: () {
onWindowCloseButton: () {
tabController.clear();
},
tail: AddButton().paddingOnly(left: 10),

View File

@ -71,10 +71,10 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
backgroundColor: MyTheme.color(context).bg,
body: DesktopTab(
controller: tabController,
onClose: () {
onWindowCloseButton: () {
tabController.clear();
},
tail: AddButton().paddingOnly(left: 10),
tail: const AddButton().paddingOnly(left: 10),
)),
),
);

View File

@ -78,7 +78,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
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<PortForwardTabPage> {
}
void onRemoveId(String id) {
ffi("pf_$id").close();
if (tabController.state.value.tabs.isEmpty) {
WindowController.fromWindowId(windowId()).hide();
}

View File

@ -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