@@ -26,6 +26,10 @@ protocol BookmarkOutlineCellViewDelegate: AnyObject {
26
26
final class BookmarkOutlineCellView : NSTableCellView {
27
27
28
28
private static let sizingCellIdentifier = NSUserInterfaceItemIdentifier ( " sizing " )
29
+ static func identifier( for mode: BookmarkOutlineViewDataSource . ContentMode ) -> NSUserInterfaceItemIdentifier {
30
+ NSUserInterfaceItemIdentifier ( " \( mode) _ \( self . className ( ) ) " )
31
+ }
32
+
29
33
static let sizingCell = BookmarkOutlineCellView ( identifier: BookmarkOutlineCellView . sizingCellIdentifier)
30
34
31
35
static let rowHeight : CGFloat = 28
@@ -51,7 +55,18 @@ final class BookmarkOutlineCellView: NSTableCellView {
51
55
}
52
56
}
53
57
54
- var shouldShowMenuButton = false
58
+ var contentMode : BookmarkOutlineViewDataSource . ContentMode ? {
59
+ BookmarkOutlineViewDataSource . ContentMode. allCases. first { mode in
60
+ Self . identifier ( for: mode) == self . identifier
61
+ }
62
+ }
63
+
64
+ var shouldShowMenuButton : Bool {
65
+ contentMode != . foldersOnly
66
+ }
67
+ var shouldShowChevron : Bool {
68
+ contentMode == . bookmarksMenu
69
+ }
55
70
56
71
weak var delegate : BookmarkOutlineCellViewDelegate ?
57
72
@@ -222,7 +237,9 @@ final class BookmarkOutlineCellView: NSTableCellView {
222
237
}
223
238
if !titleLabel. isEnabled {
224
239
titleLabel. textColor = . disabledControlTextColor
225
- } else if highlight && isInKeyWindow {
240
+ } else if highlight,
241
+ isInKeyWindow,
242
+ contentMode != . foldersOnly {
226
243
titleLabel. textColor = . selectedMenuItemTextColor
227
244
urlLabel. textColor = . selectedMenuItemTextColor
228
245
} else {
@@ -253,19 +270,19 @@ final class BookmarkOutlineCellView: NSTableCellView {
253
270
|| representedObject is PseudoFolder || representedObject is MenuItemNode else { return 0 }
254
271
255
272
sizingCell. frame = . zero
256
- sizingCell. update ( from: representedObject, isMenuPopover : true )
273
+ sizingCell. update ( from: representedObject)
257
274
sizingCell. layoutSubtreeIfNeeded ( )
258
275
259
276
return sizingCell. frame. width + 6
260
277
}
261
278
262
- func update( from object: Any , isSearch: Bool = false , isMenuPopover : Bool ) {
279
+ func update( from object: Any , isSearch: Bool = false ) {
263
280
let representedObject = ( object as? BookmarkNode ) ? . representedObject ?? object
264
281
switch representedObject {
265
282
case let bookmark as Bookmark :
266
283
update ( from: bookmark, isSearch: isSearch, showURL: identifier != Self . sizingCellIdentifier)
267
284
case let folder as BookmarkFolder :
268
- update ( from: folder, isSearch: isSearch, showChevron : isMenuPopover )
285
+ update ( from: folder, isSearch: isSearch)
269
286
case let folder as PseudoFolder :
270
287
update ( from: folder)
271
288
case let menuItem as MenuItemNode :
@@ -298,18 +315,18 @@ final class BookmarkOutlineCellView: NSTableCellView {
298
315
updateConstraints ( isSearch: isSearch)
299
316
}
300
317
301
- func update( from folder: BookmarkFolder , isSearch: Bool = false , showChevron : Bool ) {
318
+ func update( from folder: BookmarkFolder , isSearch: Bool = false ) {
302
319
faviconImageView. image = . folder
303
320
faviconImageView. isHidden = false
304
321
titleLabel. stringValue = folder. title
305
322
titleLabel. isEnabled = true
306
- favoriteImageView. image = showChevron ? . chevronMediumRight16 : nil
323
+ favoriteImageView. image = shouldShowChevron ? . chevronMediumRight16 : nil
307
324
favoriteImageView. isHidden = favoriteImageView. image == nil
308
325
urlLabel. stringValue = " "
309
326
self . toolTip = nil
310
327
311
328
let totalChildBookmarks = folder. totalChildBookmarks
312
- if totalChildBookmarks > 0 && !showChevron {
329
+ if totalChildBookmarks > 0 && !shouldShowChevron {
313
330
countLabel. stringValue = String ( totalChildBookmarks)
314
331
countLabel. isHidden = false
315
332
} else {
@@ -373,12 +390,12 @@ extension BookmarkOutlineCellView {
373
390
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
374
391
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
375
392
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
393
+ BookmarkOutlineCellView ( identifier: BookmarkOutlineCellView . identifier ( for: . bookmarksMenu) ) ,
376
394
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
377
395
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
378
396
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
379
- BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
380
- BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
381
- BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
397
+ BookmarkOutlineCellView ( identifier: BookmarkOutlineCellView . identifier ( for: . bookmarksMenu) ) ,
398
+ BookmarkOutlineCellView ( identifier: BookmarkOutlineCellView . identifier ( for: . bookmarksMenu) ) ,
382
399
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
383
400
BookmarkOutlineCellView ( identifier: . init( " " ) ) ,
384
401
]
@@ -397,22 +414,22 @@ extension BookmarkOutlineCellView {
397
414
let bkm2 = Bookmark ( id: " 3 " , url: " http://a.b " , title: " Bookmark with longer title to test width " , isFavorite: false )
398
415
cells [ 2 ] . update ( from: bkm2, showURL: false )
399
416
400
- cells [ 3 ] . update ( from: BookmarkFolder ( id: " 4 " , title: " Bookmark Folder with a reasonably long name " ) , showChevron : true )
401
- cells [ 4 ] . update ( from: BookmarkFolder ( id: " 5 " , title: " Bookmark Folder with 42 bookmark children " , children: Array ( repeating: Bookmark ( id: " 2 " , url: " http://a.b " , title: " DuckDuckGo " , isFavorite: true ) , count: 42 ) ) , showChevron : false )
417
+ cells [ 3 ] . update ( from: BookmarkFolder ( id: " 4 " , title: " Bookmark Folder with a reasonably long name " ) )
418
+ cells [ 4 ] . update ( from: BookmarkFolder ( id: " 5 " , title: " Bookmark Folder with 42 bookmark children " , children: Array ( repeating: Bookmark ( id: " 2 " , url: " http://a.b " , title: " DuckDuckGo " , isFavorite: true ) , count: 42 ) ) )
402
419
PseudoFolder . favorites. count = 64
403
420
cells [ 5 ] . update ( from: PseudoFolder . favorites)
404
421
PseudoFolder . bookmarks. count = 256
405
422
cells [ 6 ] . update ( from: PseudoFolder . bookmarks)
406
423
407
424
let node = BookmarkNode ( representedObject: MenuItemNode ( identifier: " " , title: UserText . bookmarksOpenInNewTabs, isEnabled: true ) , parent: BookmarkNode . genericRootNode ( ) )
408
- cells [ 7 ] . update ( from: node, isMenuPopover : true )
425
+ cells [ 7 ] . update ( from: node)
409
426
410
427
let emptyNode = BookmarkNode ( representedObject: MenuItemNode ( identifier: " " , title: UserText . bookmarksBarFolderEmpty, isEnabled: false ) , parent: BookmarkNode . genericRootNode ( ) )
411
- cells [ 8 ] . update ( from: emptyNode, isMenuPopover : true )
428
+ cells [ 8 ] . update ( from: emptyNode)
412
429
413
430
let sbkm = Bookmark ( id: " 3 " , url: " http://a.b " , title: " Bookmark in Search mode " , isFavorite: false )
414
431
cells [ 9 ] . update ( from: sbkm, isSearch: true , showURL: false )
415
- cells [ 10 ] . update ( from: BookmarkFolder ( id: " 5 " , title: " Folder in Search mode " , children: Array ( repeating: Bookmark ( id: " 2 " , url: " http://a.b " , title: " DuckDuckGo " , isFavorite: true ) , count: 42 ) ) , isSearch: true , showChevron : false )
432
+ cells [ 10 ] . update ( from: BookmarkFolder ( id: " 5 " , title: " Folder in Search mode " , children: Array ( repeating: Bookmark ( id: " 2 " , url: " http://a.b " , title: " DuckDuckGo " , isFavorite: true ) , count: 42 ) ) , isSearch: true )
416
433
417
434
widthAnchor. constraint ( equalToConstant: 258 ) . isActive = true
418
435
heightAnchor. constraint ( equalToConstant: CGFloat ( ( 28 + 1 ) * cells. count) ) . isActive = true
0 commit comments