tab close undo
This commit is contained in:
@@ -245,6 +245,10 @@ class TabRepository extends _$TabRepository {
|
|||||||
return _tabsService.removeTabs(ids: tabIds);
|
return _tabsService.removeTabs(ids: tabIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> undoClose() {
|
||||||
|
return _tabsService.undo();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void build() {
|
void build() {
|
||||||
final eventSerivce = ref.watch(eventServiceProvider);
|
final eventSerivce = ref.watch(eventServiceProvider);
|
||||||
|
|||||||
@@ -272,6 +272,13 @@ class BrowserScreen extends HookConsumerWidget {
|
|||||||
await ref
|
await ref
|
||||||
.read(tabRepositoryProvider.notifier)
|
.read(tabRepositoryProvider.notifier)
|
||||||
.closeTab(details.data.tabId);
|
.closeTab(details.data.tabId);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
builder: (context, _, _) {
|
builder: (context, _, _) {
|
||||||
return OverlayPortal(
|
return OverlayPortal(
|
||||||
@@ -372,6 +379,16 @@ class BrowserScreen extends HookConsumerWidget {
|
|||||||
await ref
|
await ref
|
||||||
.read(tabRepositoryProvider.notifier)
|
.read(tabRepositoryProvider.notifier)
|
||||||
.closeTab(tabState.id);
|
.closeTab(tabState.id);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref
|
||||||
|
.read(tabRepositoryProvider.notifier)
|
||||||
|
.undoClose,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
//Mark back as unhandled and navigator will pop
|
//Mark back as unhandled and navigator will pop
|
||||||
|
|||||||
+12
@@ -410,7 +410,19 @@ class BrowserBottomAppBar extends HookConsumerWidget {
|
|||||||
await ref
|
await ref
|
||||||
.read(tabRepositoryProvider.notifier)
|
.read(tabRepositoryProvider.notifier)
|
||||||
.closeTab(selectedTabId);
|
.closeTab(selectedTabId);
|
||||||
|
|
||||||
trippleDotMenuController.close();
|
trippleDotMenuController.close();
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref
|
||||||
|
.read(
|
||||||
|
tabRepositoryProvider.notifier,
|
||||||
|
)
|
||||||
|
.undoClose,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
),
|
),
|
||||||
|
|||||||
-2
@@ -108,8 +108,6 @@ class _BrowserViewState extends ConsumerState<BrowserView>
|
|||||||
_periodicScreenshotUpdate?.cancel();
|
_periodicScreenshotUpdate?.cancel();
|
||||||
_periodicScreenshotUpdate = null;
|
_periodicScreenshotUpdate = null;
|
||||||
_timerPaused = false;
|
_timerPaused = false;
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next.isLoading == false &&
|
if (next.isLoading == false &&
|
||||||
|
|||||||
+12
-31
@@ -31,6 +31,7 @@ import 'package:weblibre/core/routing/routes.dart';
|
|||||||
import 'package:weblibre/data/models/drag_data.dart';
|
import 'package:weblibre/data/models/drag_data.dart';
|
||||||
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
|
import 'package:weblibre/features/geckoview/domain/providers/selected_tab.dart';
|
||||||
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
|
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
|
||||||
|
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/browser/domain/providers.dart';
|
import 'package:weblibre/features/geckoview/features/browser/domain/providers.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/tab_suggestions.dart';
|
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/tab_suggestions.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/tree_view.dart';
|
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/tree_view.dart';
|
||||||
@@ -47,6 +48,7 @@ import 'package:weblibre/features/tor/presentation/controllers/start_tor_proxy.d
|
|||||||
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
|
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
|
||||||
import 'package:weblibre/presentation/hooks/listenable_callback.dart';
|
import 'package:weblibre/presentation/hooks/listenable_callback.dart';
|
||||||
import 'package:weblibre/presentation/widgets/speech_to_text_button.dart';
|
import 'package:weblibre/presentation/widgets/speech_to_text_button.dart';
|
||||||
|
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
||||||
|
|
||||||
class _TabDraggable extends HookConsumerWidget {
|
class _TabDraggable extends HookConsumerWidget {
|
||||||
final TabEntity entity;
|
final TabEntity entity;
|
||||||
@@ -216,38 +218,17 @@ class _TabSheetHeader extends HookConsumerWidget {
|
|||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final container = ref.read(selectedContainerProvider);
|
final container = ref.read(selectedContainerProvider);
|
||||||
final result = await showDialog<bool?>(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Close All Tabs'),
|
|
||||||
content: Text(
|
|
||||||
(container != null)
|
|
||||||
? 'Are you sure you want to close all container tabs?'
|
|
||||||
: 'Are you sure you want to close all unassigned tabs?',
|
|
||||||
),
|
|
||||||
actions: <Widget>[
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context, false);
|
|
||||||
},
|
|
||||||
child: const Text('Cancel'),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context, true);
|
|
||||||
},
|
|
||||||
child: const Text('Close'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == true) {
|
final count = await ref
|
||||||
await ref
|
.read(tabDataRepositoryProvider.notifier)
|
||||||
.read(tabDataRepositoryProvider.notifier)
|
.closeAllTabsByContainer(container);
|
||||||
.closeAllTabsByContainer(container);
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||||
|
count: count,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon: const Icon(MdiIcons.closeBoxMultiple),
|
icon: const Icon(MdiIcons.closeBoxMultiple),
|
||||||
|
|||||||
+8
@@ -23,6 +23,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:weblibre/core/routing/routes.dart';
|
import 'package:weblibre/core/routing/routes.dart';
|
||||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||||
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
|
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
|
||||||
|
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
||||||
|
|
||||||
class TabCreationMenu extends HookConsumerWidget {
|
class TabCreationMenu extends HookConsumerWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
@@ -56,6 +57,13 @@ class TabCreationMenu extends HookConsumerWidget {
|
|||||||
await ref
|
await ref
|
||||||
.read(tabRepositoryProvider.notifier)
|
.read(tabRepositoryProvider.notifier)
|
||||||
.closeTab(selectedTabId!);
|
.closeTab(selectedTabId!);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
leadingIcon: const Icon(Icons.close),
|
leadingIcon: const Icon(Icons.close),
|
||||||
child: const Text('Close Tab'),
|
child: const Text('Close Tab'),
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import 'package:weblibre/features/geckoview/features/tabs/domain/providers.dart'
|
|||||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/container.dart';
|
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/container.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
||||||
import 'package:weblibre/presentation/hooks/menu_controller.dart';
|
import 'package:weblibre/presentation/hooks/menu_controller.dart';
|
||||||
|
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
||||||
|
|
||||||
class TabContainer extends StatelessWidget {
|
class TabContainer extends StatelessWidget {
|
||||||
final bool isActive;
|
final bool isActive;
|
||||||
@@ -305,6 +306,13 @@ class SingleTabPreview extends HookConsumerWidget {
|
|||||||
onHorizontalDragEnd: (details) async {
|
onHorizontalDragEnd: (details) async {
|
||||||
if (draggedDistance.value >= deleteThreshold) {
|
if (draggedDistance.value >= deleteThreshold) {
|
||||||
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draggedDistance.value = 0.0;
|
draggedDistance.value = 0.0;
|
||||||
@@ -335,9 +343,17 @@ class SingleTabPreview extends HookConsumerWidget {
|
|||||||
.read(tabDataRepositoryProvider.notifier)
|
.read(tabDataRepositoryProvider.notifier)
|
||||||
.getContainerTabId(tabId);
|
.getContainerTabId(tabId);
|
||||||
|
|
||||||
await ref
|
final count = await ref
|
||||||
.read(tabDataRepositoryProvider.notifier)
|
.read(tabDataRepositoryProvider.notifier)
|
||||||
.closeAllTabsByHost(containerId, host);
|
.closeAllTabsByHost(containerId, host);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||||
|
count: count,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// onDoubleTap: () {
|
// onDoubleTap: () {
|
||||||
// ref.read(overlayDialogControllerProvider.notifier).show(
|
// ref.read(overlayDialogControllerProvider.notifier).show(
|
||||||
@@ -350,6 +366,13 @@ class SingleTabPreview extends HookConsumerWidget {
|
|||||||
// },
|
// },
|
||||||
onDelete: () async {
|
onDelete: () async {
|
||||||
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -510,41 +533,20 @@ class TabTreePreview extends HookConsumerWidget {
|
|||||||
// );
|
// );
|
||||||
// },
|
// },
|
||||||
onDelete: () async {
|
onDelete: () async {
|
||||||
final result = (entity.totalTabs > 1)
|
final tabs = await ref.read(
|
||||||
? await showDialog<bool?>(
|
tabDescendantsProvider(entity.rootId).future,
|
||||||
context: context,
|
);
|
||||||
builder: (BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Close Tab Tree'),
|
|
||||||
content: Text(
|
|
||||||
'Are you sure you want to close the entire tree containing ${entity.totalTabs} tabs?',
|
|
||||||
),
|
|
||||||
actions: <Widget>[
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context, false);
|
|
||||||
},
|
|
||||||
child: const Text('Cancel'),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context, true);
|
|
||||||
},
|
|
||||||
child: const Text('Close'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: true;
|
|
||||||
|
|
||||||
if (result == true) {
|
await ref
|
||||||
final tabs = await ref.read(
|
.read(tabRepositoryProvider.notifier)
|
||||||
tabDescendantsProvider(entity.rootId).future,
|
.closeTabs(tabs.keys.toList());
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ui_helper.showTabUndoClose(
|
||||||
|
context,
|
||||||
|
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||||
|
count: tabs.length,
|
||||||
);
|
);
|
||||||
await ref
|
|
||||||
.read(tabRepositoryProvider.notifier)
|
|
||||||
.closeTabs(tabs.keys.toList());
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class TabDataRepository extends _$TabDataRepository {
|
|||||||
.assignOrderKey(tabId, orderKey: orderKey);
|
.assignOrderKey(tabId, orderKey: orderKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeAllTabsByContainer(String? containerId) async {
|
Future<int> closeAllTabsByContainer(String? containerId) async {
|
||||||
final tabIds = await ref
|
final tabIds = await ref
|
||||||
.read(tabDatabaseProvider)
|
.read(tabDatabaseProvider)
|
||||||
.containerDao
|
.containerDao
|
||||||
@@ -81,9 +81,11 @@ class TabDataRepository extends _$TabDataRepository {
|
|||||||
if (tabIds.isNotEmpty) {
|
if (tabIds.isNotEmpty) {
|
||||||
await ref.read(tabRepositoryProvider.notifier).closeTabs(tabIds);
|
await ref.read(tabRepositoryProvider.notifier).closeTabs(tabIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return tabIds.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeAllTabsByHost(String? containerId, String host) async {
|
Future<int> closeAllTabsByHost(String? containerId, String host) async {
|
||||||
final tabs = await ref
|
final tabs = await ref
|
||||||
.read(tabDatabaseProvider)
|
.read(tabDatabaseProvider)
|
||||||
.containerDao
|
.containerDao
|
||||||
@@ -98,6 +100,8 @@ class TabDataRepository extends _$TabDataRepository {
|
|||||||
if (filtered.isNotEmpty) {
|
if (filtered.isNotEmpty) {
|
||||||
await ref.read(tabRepositoryProvider.notifier).closeTabs(filtered);
|
await ref.read(tabRepositoryProvider.notifier).closeTabs(filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return filtered.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getContainerTabId(String tabId) {
|
Future<String?> getContainerTabId(String tabId) {
|
||||||
|
|||||||
@@ -148,3 +148,20 @@ Future<void> launchUrlFeedback(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showTabUndoClose(
|
||||||
|
BuildContext context,
|
||||||
|
VoidCallback onUndo, {
|
||||||
|
int count = 1,
|
||||||
|
Duration duration = const Duration(seconds: 2),
|
||||||
|
}) {
|
||||||
|
final snackBar = SnackBar(
|
||||||
|
content: (count > 1)
|
||||||
|
? Text('$count Tabs closed')
|
||||||
|
: const Text('Tab closed'),
|
||||||
|
action: SnackBarAction(label: 'Undo', onPressed: onUndo),
|
||||||
|
duration: duration,
|
||||||
|
);
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
|
}
|
||||||
|
|||||||
+2
-1
@@ -51,6 +51,7 @@ import mozilla.components.feature.prompts.file.FileUploadsDirCleaner
|
|||||||
import mozilla.components.feature.readerview.ReaderViewMiddleware
|
import mozilla.components.feature.readerview.ReaderViewMiddleware
|
||||||
import mozilla.components.feature.session.HistoryDelegate
|
import mozilla.components.feature.session.HistoryDelegate
|
||||||
import mozilla.components.feature.session.middleware.LastAccessMiddleware
|
import mozilla.components.feature.session.middleware.LastAccessMiddleware
|
||||||
|
import mozilla.components.feature.session.middleware.undo.UndoMiddleware
|
||||||
import mozilla.components.feature.sitepermissions.OnDiskSitePermissionsStorage
|
import mozilla.components.feature.sitepermissions.OnDiskSitePermissionsStorage
|
||||||
import mozilla.components.feature.webnotifications.WebNotificationFeature
|
import mozilla.components.feature.webnotifications.WebNotificationFeature
|
||||||
import mozilla.components.support.base.worker.Frequency
|
import mozilla.components.support.base.worker.Frequency
|
||||||
@@ -163,7 +164,7 @@ class Core(private val context: Context,
|
|||||||
DownloadMiddleware(context, DownloadService::class.java, {false}),
|
DownloadMiddleware(context, DownloadService::class.java, {false}),
|
||||||
ThumbnailsMiddleware(thumbnailStorage),
|
ThumbnailsMiddleware(thumbnailStorage),
|
||||||
ReaderViewMiddleware(),
|
ReaderViewMiddleware(),
|
||||||
// UndoMiddleware(),
|
UndoMiddleware(),
|
||||||
LastAccessMiddleware(),
|
LastAccessMiddleware(),
|
||||||
// PromptMiddleware(),
|
// PromptMiddleware(),
|
||||||
SessionPrioritizationMiddleware(),
|
SessionPrioritizationMiddleware(),
|
||||||
|
|||||||
Reference in New Issue
Block a user