Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire popover: select/unselect all #2964

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ struct UserText {
return String(format: localized, sites)
}
static let fireDialogDetails = NSLocalizedString("fire.dialog.details", value: "Details", comment: "Button to show more details")
static let fireDialogSelectAll = NSLocalizedString("fire.dialog.select.all", value: "Select All", comment: "Context Menu item to select all domains to burn")
static let fireDialogDeselectAll = NSLocalizedString("fire.dialog.unselect.all", value: "Unselect All", comment: "Context Menu item to unselect all domains to burn")

static let fireDialogWindowWillClose = NSLocalizedString("fire.dialog.window-will-close", value: "Current window will close", comment: "Warning label shown in an expanded view of the fire popover")
static let fireDialogTabWillClose = NSLocalizedString("fire.dialog.tab-will-close", value: "Current tab will close", comment: "Warning label shown in an expanded view of the fire popover")
static let fireDialogPinnedTabWillReload = NSLocalizedString("fire.dialog.tab-will-reload", value: "Pinned tab will reload", comment: "Warning label shown in an expanded view of the fire popover")
Expand Down
12 changes: 12 additions & 0 deletions DuckDuckGo/Fire/View/FirePopoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ final class FirePopoverViewController: NSViewController {
collectionView.register(nib, forItemWithIdentifier: FirePopoverCollectionViewItem.identifier)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.menu = NSMenu {
NSMenuItem(title: UserText.fireDialogSelectAll, action: #selector(selectAll), target: self)
NSMenuItem(title: UserText.fireDialogDeselectAll, action: #selector(deselectAll), target: self)
}

if firePopoverViewModel.tabCollectionViewModel?.isBurner ?? false {
adjustViewForBurnerWindow()
Expand Down Expand Up @@ -130,6 +134,14 @@ final class FirePopoverViewController: NSViewController {
cancelButton.title = UserText.cancel
}

@objc override func selectAll(_ sender: Any?) {
firePopoverViewModel.selectAll()
}

@objc func deselectAll(_ sender: Any?) {
firePopoverViewModel.deselectAll()
}

@IBAction func optionsButtonAction(_ sender: NSPopUpButton) {
guard let tag = sender.selectedItem?.tag, let clearingOption = FirePopoverViewModel.ClearingOption(rawValue: tag) else {
assertionFailure("Clearing option for not found for the selected menu item")
Expand Down
14 changes: 13 additions & 1 deletion DuckDuckGo/Fire/ViewModel/FirePopoverViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ final class FirePopoverViewModel {
Set(0..<selectable.count) == selected
}

private func selectAll() {
func selectAll() {
self.selected = Set(0..<selectable.count)
}

Expand All @@ -155,6 +155,10 @@ final class FirePopoverViewModel {
selected.insert(index)
}

func select(_ indices: Set<Int>) {
self.selected.formUnion(indices)
}

func deselect(index: Int) {
guard index < selectable.count, index >= 0 else {
assertionFailure("Index out of range")
Expand All @@ -163,6 +167,14 @@ final class FirePopoverViewModel {
selected.remove(index)
}

func deselect(_ indices: Set<Int>) {
self.selected.subtract(indices)
}

func deselectAll() {
self.selected = Set()
}

private var selectedDomains: Set<String> {
return Set<String>(selected.compactMap {
guard let selectedDomain = selectable[safe: $0]?.domain else {
Expand Down
Loading