Skip to content

Commit

Permalink
Fix brave/brave-ios#8169: Count and open all subfolder urls with Open…
Browse files Browse the repository at this point in the history
… All (#) (brave/brave-ios#8400)
  • Loading branch information
tempo810 authored Nov 17, 2023
1 parent 6f039ba commit a24622d
Showing 1 changed file with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,22 +545,15 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco

if bookmarkItem.isFolder {
var actionChildren: [UIAction] = []

let children = bookmarkManager.getChildren(forFolder: bookmarkItem, includeFolders: false) ?? []

let urls: [URL] = children.compactMap { bookmark in
guard let url = bookmark.url else { return nil }
return URL(string: url)
}

let openBatchURLAction = UIAction(
title: String(format: Strings.openAllBookmarks, children.count),
image: UIImage(systemName: "arrow.up.forward.app"),
handler: UIAction.deferredActionHandler { _ in
self.toolbarUrlActionsDelegate?.batchOpen(urls)
})

if children.count > 0 {
let urls: [URL] = self.getAllURLS(forFolder: bookmarkItem)

if urls.count > 0 {
let openBatchURLAction = UIAction(
title: String(format: Strings.openAllBookmarks, urls.count),
image: UIImage(systemName: "arrow.up.forward.app"),
handler: UIAction.deferredActionHandler { _ in
self.toolbarUrlActionsDelegate?.batchOpen(urls)
})
actionChildren.append(openBatchURLAction)
}

Expand Down Expand Up @@ -623,6 +616,23 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco
return actionItemsMenu
}
}

private func getAllURLS(forFolder rootFolder: Bookmarkv2) -> [URL] {
var urls: [URL] = []
guard rootFolder.isFolder else { return urls }
var children = bookmarkManager.getChildren(forFolder: rootFolder, includeFolders: true) ?? []

while !children.isEmpty {
let bookmarkItem = children.removeFirst()
if bookmarkItem.isFolder {
// Follow the order of bookmark manager
children.insert(contentsOf: bookmarkManager.getChildren(forFolder: bookmarkItem, includeFolders: true) ?? [], at: 0)
} else if let bookmarkItemURL = URL(string: bookmarkItem.url ?? "") {
urls.append(bookmarkItemURL)
}
}
return urls
}
}

// MARK: UITableViewDelegate - Editing
Expand Down

0 comments on commit a24622d

Please sign in to comment.