add confirm before closing multiple tabs

This commit is contained in:
csf
2022-10-13 21:19:05 +09:00
parent da18e69258
commit 67a5cf9771
27 changed files with 108 additions and 50 deletions

View File

@@ -232,11 +232,11 @@ class _GeneralState extends State<_General> {
controller: scrollController,
children: [
theme(),
abr(),
hwcodec(),
audio(context),
record(context),
_Card(title: 'Language', children: [language()]),
other()
],
).marginOnly(bottom: _kListViewBottomMargin));
}
@@ -267,8 +267,10 @@ class _GeneralState extends State<_General> {
]);
}
Widget abr() {
return _Card(title: 'Adaptive Bitrate', children: [
Widget other() {
return _Card(title: 'Other', children: [
_OptionCheckBox(context, 'Confirm before closing multiple tabs',
'enable-confirm-closing-tabs'),
_OptionCheckBox(context, 'Adaptive Bitrate', 'enable-abr'),
]);
}

View File

@@ -10,7 +10,7 @@ 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';
import '../../models/platform_model.dart';
/// File Transfer for multi tabs
class FileManagerTabPage extends StatefulWidget {
@@ -35,7 +35,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
label: params['id'],
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon,
onTabCloseButton: () => handleTabCloseButton(params['id']),
onTabCloseButton: () => () => tabController.closeBy(params['id']),
page: FileManagerPage(key: ValueKey(params['id']), id: params['id'])));
}
@@ -58,7 +58,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
label: id,
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon,
onTabCloseButton: () => handleTabCloseButton(id),
onTabCloseButton: () => tabController.closeBy(id),
page: FileManagerPage(key: ValueKey(id), id: id)));
} else if (call.method == "onDestroy") {
tabController.clear();
@@ -98,26 +98,19 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
return widget.params["windowId"];
}
void handleTabCloseButton(String peerId) {
final session = ffi('ft_$peerId');
if (session.ffiModel.pi.hostname.isNotEmpty) {
tabController.jumpBy(peerId);
clientClose(session.dialogManager);
} else {
tabController.closeBy(peerId);
}
}
Future<bool> handleWindowCloseButton() async {
final connLength = tabController.state.value.tabs.length;
if (connLength < 1) {
if (connLength <= 1) {
tabController.clear();
return true;
} else if (connLength == 1) {
final currentConn = tabController.state.value.tabs[0];
handleTabCloseButton(currentConn.key);
return false;
} else {
final res = await closeConfirmDialog();
final opt = "enable-confirm-closing-tabs";
final bool res;
if (!option2bool(opt, await bind.mainGetOption(key: opt))) {
res = true;
} else {
res = await closeConfirmDialog();
}
if (res) {
tabController.clear();
}

View File

@@ -12,7 +12,7 @@ import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import '../../mobile/widgets/dialog.dart';
import '../../models/platform_model.dart';
class ConnectionTabPage extends StatefulWidget {
final Map<String, dynamic> params;
@@ -42,7 +42,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
label: peerId,
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon,
onTabCloseButton: () => handleTabCloseButton(peerId),
onTabCloseButton: () => tabController.closeBy(peerId),
page: Obx(() => RemotePage(
key: ValueKey(peerId),
id: peerId,
@@ -78,7 +78,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
label: id,
selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon,
onTabCloseButton: () => handleTabCloseButton(id),
onTabCloseButton: () => tabController.closeBy(id),
page: Obx(() => RemotePage(
key: ValueKey(id),
id: id,
@@ -173,29 +173,21 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
return widget.params["windowId"];
}
void handleTabCloseButton(String peerId) {
final session = ffi(peerId);
if (session.ffiModel.pi.hostname.isNotEmpty) {
tabController.jumpBy(peerId);
clientClose(session.dialogManager);
} else {
tabController.closeBy(peerId);
}
}
Future<bool> handleWindowCloseButton() async {
final connLength = tabController.length;
if (connLength < 1) {
if (connLength <= 1) {
tabController.clear();
return true;
} else if (connLength == 1) {
final currentConn = tabController.state.value.tabs[0];
handleTabCloseButton(currentConn.key);
return false;
} else {
final res = await closeConfirmDialog();
final opt = "enable-confirm-closing-tabs";
final bool res;
if (!option2bool(opt, await bind.mainGetOption(key: opt))) {
res = true;
} else {
res = await closeConfirmDialog();
}
if (res) {
tabController.clear();
_update_remote_count();
}
return res;
}

View File

@@ -456,8 +456,15 @@ class WindowActionPanel extends StatelessWidget {
}
Future<bool> closeConfirmDialog() async {
var confirm = true;
final res = await gFFI.dialogManager.show<bool>((setState, close) {
submit() => close(true);
submit() {
final opt = "enable-confirm-closing-tabs";
String value = bool2option(opt, confirm);
bind.mainSetOption(key: opt, value: value);
close(true);
}
return CustomAlertDialog(
title: Row(children: [
const Icon(Icons.warning_amber_sharp,
@@ -465,7 +472,25 @@ Future<bool> closeConfirmDialog() async {
const SizedBox(width: 10),
Text(translate("Warning")),
]),
content: Text(translate("Disconnect all devices?")),
content: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(translate("Disconnect all devices?")),
CheckboxListTile(
contentPadding: const EdgeInsets.all(0),
dense: true,
controlAffinity: ListTileControlAffinity.leading,
title: Text(
translate("Confirm before closing multiple tabs"),
),
value: confirm,
onChanged: (v) {
if (v == null) return;
setState(() => confirm = v);
},
)
]), // confirm checkbox
actions: [
TextButton(onPressed: close, child: Text(translate("Cancel"))),
ElevatedButton(onPressed: submit, child: Text(translate("OK"))),