refactor dialogs into separate files
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/database/definitions.drift.dart';
|
||||
|
||||
/// Dialog to select between extracted or full content for sharing.
|
||||
/// Shows options for extracted (reader-optimized) vs full (complete) content.
|
||||
Future<void> showContentSelectionDialog(
|
||||
BuildContext context, {
|
||||
required Widget title,
|
||||
required TabData tabData,
|
||||
required Future<void> Function(String content, String? fileName)
|
||||
shareMarkdownAction,
|
||||
}) async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
title: title,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text('Extracted Content'),
|
||||
subtitle: const Text(
|
||||
'Reader-optimized content without navigation and ads',
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.of(context).pop();
|
||||
await shareMarkdownAction(
|
||||
tabData.extractedContentMarkdown!,
|
||||
tabData.title ?? tabData.url?.authority,
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Full Content'),
|
||||
subtitle: const Text(
|
||||
'Complete page including all elements and structure',
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.of(context).pop();
|
||||
await shareMarkdownAction(
|
||||
tabData.fullContentMarkdown!,
|
||||
tabData.title ?? tabData.url?.authority,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
+6
-33
@@ -8,6 +8,7 @@ import 'package:nullability/nullability.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/providers/tab_session.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/dialogs/content_selection_dialog.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/dialogs/qr_code.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
||||
@@ -144,39 +145,11 @@ class ShareMarkdownActionMenuItemButton extends HookConsumerWidget {
|
||||
BuildContext context,
|
||||
TabData tabData,
|
||||
) async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
title: title,
|
||||
children: [
|
||||
ListTile(
|
||||
title: const Text('Extracted Content'),
|
||||
subtitle: const Text(
|
||||
'Reader-optimized content without navigation and ads',
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.of(context).pop();
|
||||
await shareMarkdownAction(
|
||||
tabData.extractedContentMarkdown!,
|
||||
tabData.title ?? tabData.url?.authority,
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Full Content'),
|
||||
subtitle: const Text(
|
||||
'Complete page including all elements and structure',
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.of(context).pop();
|
||||
await shareMarkdownAction(
|
||||
tabData.fullContentMarkdown!,
|
||||
tabData.title ?? tabData.url?.authority,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
await showContentSelectionDialog(
|
||||
context,
|
||||
title: title,
|
||||
tabData: tabData,
|
||||
shareMarkdownAction: shareMarkdownAction,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
|
||||
Future<bool?> showClearContainerDataDialog(
|
||||
BuildContext context,
|
||||
int tabCount,
|
||||
) {
|
||||
return showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(
|
||||
MdiIcons.databaseRemove,
|
||||
),
|
||||
title: const Text(
|
||||
'Clear Container Data?',
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'This will clear all data for this container:',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text('• Cookies'),
|
||||
const Text('• Site data'),
|
||||
const Text('• Cache'),
|
||||
const Text('• Permissions'),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'$tabCount tab(s) will be closed and reopened fresh.',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.tertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Clear Data'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<bool?> showCloseAllPrivateTabsDialog(BuildContext context) {
|
||||
return showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Close All Private Tabs'),
|
||||
content: const Text(
|
||||
'Are you sure you want to close all displayed private tabs?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<bool?> showCloseAllTabsDialog(BuildContext context) {
|
||||
return showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Close All Tabs'),
|
||||
content: const Text(
|
||||
'Are you sure you want to close all displayed tabs?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
|
||||
Future<bool?> showEnableAiTabSuggestionsDialog(BuildContext context) {
|
||||
return showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(MdiIcons.download),
|
||||
title: const Text(
|
||||
'Enable AI Tab Suggestions',
|
||||
),
|
||||
content: const Text(
|
||||
'Enabling this feature may require downloading AI models. '
|
||||
'The download size and progress cannot be determined in advance.\n\n'
|
||||
'Do you want to continue?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Enable'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+10
-133
@@ -11,6 +11,10 @@ import 'package:weblibre/features/geckoview/domain/providers.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_data.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/tab_view_controllers.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/dialogs/clear_container_data_dialog.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/dialogs/close_all_private_tabs_dialog.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/dialogs/close_all_tabs_dialog.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_view/dialogs/enable_ai_tab_suggestions_dialog.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/providers/selected_container.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab_search.dart';
|
||||
@@ -172,36 +176,7 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
: 'Enable AI tab suggestions',
|
||||
onPressed: () async {
|
||||
if (!tabSuggestionsEnabled) {
|
||||
final result = await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(MdiIcons.download),
|
||||
title: const Text(
|
||||
'Enable AI Tab Suggestions',
|
||||
),
|
||||
content: const Text(
|
||||
'Enabling this feature may require downloading AI models. '
|
||||
'The download size and progress cannot be determined in advance.\n\n'
|
||||
'Do you want to continue?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Enable'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
final result = await showEnableAiTabSuggestionsDialog(context);
|
||||
|
||||
if (result == true) {
|
||||
ref
|
||||
@@ -300,32 +275,7 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
leadingIcon: const Icon(MdiIcons.closeCircle),
|
||||
child: const Text('Close All Tabs'),
|
||||
onPressed: () async {
|
||||
final result = await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Close All Tabs'),
|
||||
content: const Text(
|
||||
'Are you sure you want to close all displayed tabs?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
final result = await showCloseAllTabsDialog(context);
|
||||
|
||||
if (result == true) {
|
||||
final container = ref.read(
|
||||
@@ -352,32 +302,7 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
leadingIcon: const Icon(MdiIcons.incognitoCircleOff),
|
||||
child: const Text('Close Private Tabs'),
|
||||
onPressed: () async {
|
||||
final result = await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Close All Private Tabs'),
|
||||
content: const Text(
|
||||
'Are you sure you want to close all displayed private tabs?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
final result = await showCloseAllPrivateTabsDialog(context);
|
||||
|
||||
if (result == true) {
|
||||
final container = ref.read(
|
||||
@@ -439,57 +364,9 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
final result = await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(
|
||||
MdiIcons.databaseRemove,
|
||||
),
|
||||
title: const Text(
|
||||
'Clear Container Data?',
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'This will clear all data for this container:',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text('• Cookies'),
|
||||
const Text('• Site data'),
|
||||
const Text('• Cache'),
|
||||
const Text('• Permissions'),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'${tabs.length} tab(s) will be closed and reopened fresh.',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.tertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Clear Data'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
final result = await showClearContainerDataDialog(
|
||||
context,
|
||||
tabs.length,
|
||||
);
|
||||
|
||||
if (result == true) {
|
||||
|
||||
Reference in New Issue
Block a user