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

Make bookmarks panel grow as screen permits #3316

Merged
merged 2 commits into from
Sep 23, 2024
Merged
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
4 changes: 4 additions & 0 deletions DuckDuckGo/Bookmarks/View/BookmarkListPopover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ final class BookmarkListPopover: NSPopover {
contentViewController = controller
}

override func show(relativeTo positioningRect: NSRect, of positioningView: NSView, preferredEdge: NSRectEdge) {
viewController.adjustPreferredContentSize(positionedRelativeTo: positioningRect, of: positioningView, at: preferredEdge)
super.show(relativeTo: positioningRect, of: positioningView, preferredEdge: preferredEdge)
}
}

extension BookmarkListPopover: BookmarkListViewControllerDelegate {
Expand Down
36 changes: 34 additions & 2 deletions DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ final class BookmarkListViewController: NSViewController {
}

override func viewDidLoad() {
preferredContentSize = Constants.preferredContentSize

outlineView.setDraggingSourceOperationMask([.move], forLocal: true)
outlineView.registerForDraggedTypes(BookmarkDragDropManager.draggedTypes)
}
Expand All @@ -409,6 +407,40 @@ final class BookmarkListViewController: NSViewController {
cancellables = []
}

func adjustPreferredContentSize(positionedRelativeTo positioningRect: NSRect,
of positioningView: NSView,
at preferredEdge: NSRectEdge) {
_=view // Load view if needed

guard let mainWindow = positioningView.window,
let screenFrame = mainWindow.screen?.visibleFrame else { return }

self.reloadData()

guard outlineView.numberOfRows > 0 else {
preferredContentSize = Constants.preferredContentSize
return
}

let windowRect = positioningView.convert(positioningRect, to: nil)
let screenPosRect = mainWindow.convertToScreen(windowRect)
let bookmarkHeaderHeight = 48.0
let availableHeightBelow = screenPosRect.minY - screenFrame.minY - bookmarkHeaderHeight
let availableHeightAbove = screenFrame.maxY - screenPosRect.maxY - bookmarkHeaderHeight
let availableHeight = max(availableHeightAbove, availableHeightBelow)

let totalHeightForRootBookmarks = (CGFloat(outlineView.numberOfRows) * BookmarkOutlineCellView.rowHeight) + bookmarkHeaderHeight + 12.0
var contentSize = Constants.preferredContentSize

if totalHeightForRootBookmarks > availableHeight {
contentSize.height = availableHeight
} else if totalHeightForRootBookmarks > Constants.preferredContentSize.height {
contentSize.height = totalHeightForRootBookmarks
}

preferredContentSize = contentSize
}

private func subscribeToModelEvents() {
bookmarkManager.listPublisher.receive(on: DispatchQueue.main).sink { [weak self] _ in
self?.reloadData()
Expand Down
Loading