diff --git a/DuckDuckGo/Bookmarks/Extensions/Bookmarks+Tab.swift b/DuckDuckGo/Bookmarks/Extensions/Bookmarks+Tab.swift index 78c60f30ea..689cdc742e 100644 --- a/DuckDuckGo/Bookmarks/Extensions/Bookmarks+Tab.swift +++ b/DuckDuckGo/Bookmarks/Extensions/Bookmarks+Tab.swift @@ -28,6 +28,13 @@ extension Tab { } } + @MainActor + static func with(contentsOf bookmarks: [Bookmark], burnerMode: BurnerMode) -> [Tab] { + bookmarks.compactMap { bookmark -> Tab? in + guard let url = bookmark.urlObject else { return nil } + return Tab(content: .url(url, source: .bookmark), shouldLoadInBackground: true, burnerMode: burnerMode) + } + } } extension TabCollection { diff --git a/DuckDuckGo/Bookmarks/Services/BookmarksContextMenu.swift b/DuckDuckGo/Bookmarks/Services/BookmarksContextMenu.swift index 7fe6569ed6..17032a82e5 100644 --- a/DuckDuckGo/Bookmarks/Services/BookmarksContextMenu.swift +++ b/DuckDuckGo/Bookmarks/Services/BookmarksContextMenu.swift @@ -308,13 +308,17 @@ extension BookmarksContextMenu: BookmarkMenuItemSelectors { } @objc func toggleBookmarkAsFavorite(_ sender: NSMenuItem) { - guard let bookmark = sender.representedObject as? Bookmark else { + if let bookmark = sender.representedObject as? Bookmark{ + bookmark.isFavorite.toggle() + bookmarkManager.update(bookmark: bookmark) + } else if let bookmarks = sender.representedObject as? [Bookmark] { + bookmarks.forEach { bookmark in + bookmark.isFavorite.toggle() + bookmarkManager.update(bookmark: bookmark) + } + } else { assertionFailure("Failed to cast menu represented object to Bookmark") - return } - - bookmark.isFavorite.toggle() - bookmarkManager.update(bookmark: bookmark) } @MainActor @@ -424,16 +428,20 @@ extension BookmarksContextMenu: FolderMenuItemSelectors { @MainActor @objc func openInNewTabs(_ sender: NSMenuItem) { - guard let tabCollection = windowControllersManager.lastKeyMainWindowController?.mainViewController.tabCollectionViewModel, - let folder = sender.representedObject as? BookmarkFolder - else { + guard let tabCollection = windowControllersManager.lastKeyMainWindowController?.mainViewController.tabCollectionViewModel else { assertionFailure("Cannot open all in new tabs") return } - let tabs = Tab.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode) - tabCollection.append(tabs: tabs) - PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel() + if let folder = sender.representedObject as? BookmarkFolder { + let tabs = Tab.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode) + tabCollection.append(tabs: tabs) + PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel() + } else if let bookmarks = sender.representedObject as? [Bookmark] { + let tabs = Tab.with(contentsOf: bookmarks, burnerMode: tabCollection.burnerMode) + tabCollection.append(tabs: tabs) + PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel() + } } @MainActor