tab close undo
This commit is contained in:
@@ -245,6 +245,10 @@ class TabRepository extends _$TabRepository {
|
||||
return _tabsService.removeTabs(ids: tabIds);
|
||||
}
|
||||
|
||||
Future<void> undoClose() {
|
||||
return _tabsService.undo();
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {
|
||||
final eventSerivce = ref.watch(eventServiceProvider);
|
||||
|
||||
@@ -272,6 +272,13 @@ class BrowserScreen extends HookConsumerWidget {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.closeTab(details.data.tabId);
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, _, _) {
|
||||
return OverlayPortal(
|
||||
@@ -372,6 +379,16 @@ class BrowserScreen extends HookConsumerWidget {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.closeTab(tabState.id);
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.undoClose,
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
//Mark back as unhandled and navigator will pop
|
||||
|
||||
+12
@@ -410,7 +410,19 @@ class BrowserBottomAppBar extends HookConsumerWidget {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.closeTab(selectedTabId);
|
||||
|
||||
trippleDotMenuController.close();
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref
|
||||
.read(
|
||||
tabRepositoryProvider.notifier,
|
||||
)
|
||||
.undoClose,
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
|
||||
-2
@@ -108,8 +108,6 @@ class _BrowserViewState extends ConsumerState<BrowserView>
|
||||
_periodicScreenshotUpdate?.cancel();
|
||||
_periodicScreenshotUpdate = null;
|
||||
_timerPaused = false;
|
||||
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
}
|
||||
|
||||
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/features/geckoview/domain/providers/selected_tab.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/presentation/controllers/tab_suggestions.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/presentation/hooks/listenable_callback.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 {
|
||||
final TabEntity entity;
|
||||
@@ -216,38 +218,17 @@ class _TabSheetHeader extends HookConsumerWidget {
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
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) {
|
||||
await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.closeAllTabsByContainer(container);
|
||||
final count = await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.closeAllTabsByContainer(container);
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||
count: count,
|
||||
);
|
||||
}
|
||||
},
|
||||
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/features/geckoview/domain/repositories/tab.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 {
|
||||
final Widget child;
|
||||
@@ -56,6 +57,13 @@ class TabCreationMenu extends HookConsumerWidget {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.closeTab(selectedTabId!);
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||
);
|
||||
}
|
||||
},
|
||||
leadingIcon: const Icon(Icons.close),
|
||||
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/tab.dart';
|
||||
import 'package:weblibre/presentation/hooks/menu_controller.dart';
|
||||
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
||||
|
||||
class TabContainer extends StatelessWidget {
|
||||
final bool isActive;
|
||||
@@ -305,6 +306,13 @@ class SingleTabPreview extends HookConsumerWidget {
|
||||
onHorizontalDragEnd: (details) async {
|
||||
if (draggedDistance.value >= deleteThreshold) {
|
||||
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
draggedDistance.value = 0.0;
|
||||
@@ -335,9 +343,17 @@ class SingleTabPreview extends HookConsumerWidget {
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.getContainerTabId(tabId);
|
||||
|
||||
await ref
|
||||
final count = await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.closeAllTabsByHost(containerId, host);
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||
count: count,
|
||||
);
|
||||
}
|
||||
},
|
||||
// onDoubleTap: () {
|
||||
// ref.read(overlayDialogControllerProvider.notifier).show(
|
||||
@@ -350,6 +366,13 @@ class SingleTabPreview extends HookConsumerWidget {
|
||||
// },
|
||||
onDelete: () async {
|
||||
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 {
|
||||
final result = (entity.totalTabs > 1)
|
||||
? await showDialog<bool?>(
|
||||
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;
|
||||
final tabs = await ref.read(
|
||||
tabDescendantsProvider(entity.rootId).future,
|
||||
);
|
||||
|
||||
if (result == true) {
|
||||
final tabs = await ref.read(
|
||||
tabDescendantsProvider(entity.rootId).future,
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.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);
|
||||
}
|
||||
|
||||
Future<void> closeAllTabsByContainer(String? containerId) async {
|
||||
Future<int> closeAllTabsByContainer(String? containerId) async {
|
||||
final tabIds = await ref
|
||||
.read(tabDatabaseProvider)
|
||||
.containerDao
|
||||
@@ -81,9 +81,11 @@ class TabDataRepository extends _$TabDataRepository {
|
||||
if (tabIds.isNotEmpty) {
|
||||
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
|
||||
.read(tabDatabaseProvider)
|
||||
.containerDao
|
||||
@@ -98,6 +100,8 @@ class TabDataRepository extends _$TabDataRepository {
|
||||
if (filtered.isNotEmpty) {
|
||||
await ref.read(tabRepositoryProvider.notifier).closeTabs(filtered);
|
||||
}
|
||||
|
||||
return filtered.length;
|
||||
}
|
||||
|
||||
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.session.HistoryDelegate
|
||||
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.webnotifications.WebNotificationFeature
|
||||
import mozilla.components.support.base.worker.Frequency
|
||||
@@ -163,7 +164,7 @@ class Core(private val context: Context,
|
||||
DownloadMiddleware(context, DownloadService::class.java, {false}),
|
||||
ThumbnailsMiddleware(thumbnailStorage),
|
||||
ReaderViewMiddleware(),
|
||||
// UndoMiddleware(),
|
||||
UndoMiddleware(),
|
||||
LastAccessMiddleware(),
|
||||
// PromptMiddleware(),
|
||||
SessionPrioritizationMiddleware(),
|
||||
|
||||
Reference in New Issue
Block a user