make tab restoration optional
This commit is contained in:
+58
-8
@@ -18,15 +18,43 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
|
||||
Future<bool?> showClearContainerDataDialog(BuildContext context, int tabCount) {
|
||||
return showDialog<bool?>(
|
||||
class ClearContainerDataResult {
|
||||
final bool confirmed;
|
||||
final bool reopenTabs;
|
||||
|
||||
const ClearContainerDataResult({
|
||||
required this.confirmed,
|
||||
required this.reopenTabs,
|
||||
});
|
||||
}
|
||||
|
||||
Future<ClearContainerDataResult?> showClearContainerDataDialog(
|
||||
BuildContext context,
|
||||
int tabCount,
|
||||
) {
|
||||
return showDialog<ClearContainerDataResult?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return _ClearContainerDataDialog(tabCount: tabCount);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _ClearContainerDataDialog extends HookWidget {
|
||||
final int tabCount;
|
||||
|
||||
const _ClearContainerDataDialog({required this.tabCount});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final reopenTabs = useState(false);
|
||||
|
||||
return AlertDialog(
|
||||
icon: const Icon(MdiIcons.databaseRemove),
|
||||
title: const Text('Clear Container Data?'),
|
||||
title: const Text('Clear Container Data'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -39,29 +67,51 @@ Future<bool?> showClearContainerDataDialog(BuildContext context, int tabCount) {
|
||||
const Text('• Permissions'),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'$tabCount tab(s) will be closed and reopened fresh.',
|
||||
'$tabCount tab(s) will be closed.',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
),
|
||||
),
|
||||
CheckboxListTile(
|
||||
value: reopenTabs.value,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
reopenTabs.value = value;
|
||||
}
|
||||
},
|
||||
title: const Text('Recreate tabs after clearing'),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.trailing,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
Navigator.pop(
|
||||
context,
|
||||
const ClearContainerDataResult(
|
||||
confirmed: false,
|
||||
reopenTabs: false,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
Navigator.pop(
|
||||
context,
|
||||
ClearContainerDataResult(
|
||||
confirmed: true,
|
||||
reopenTabs: reopenTabs.value,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Clear Data'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -378,7 +378,9 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
tabs.length,
|
||||
);
|
||||
|
||||
if (result == true) {
|
||||
if (result?.confirmed == true) {
|
||||
final shouldReopenTabs = result!.reopenTabs;
|
||||
|
||||
try {
|
||||
final closedTabIds = await ref
|
||||
.read(
|
||||
@@ -398,6 +400,7 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
.contextualIdentity!,
|
||||
);
|
||||
|
||||
if (shouldReopenTabs) {
|
||||
await ref
|
||||
.read(
|
||||
tabRepositoryProvider.notifier,
|
||||
@@ -436,14 +439,17 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
selectedContainer,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(
|
||||
const SnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Container data cleared successfully',
|
||||
shouldReopenTabs
|
||||
? 'Container data cleared successfully'
|
||||
: 'Container data cleared. ${tabs.length} tab(s) closed.',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user