diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.h b/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.h index a91b4cedb2fd77d..b8e0d9779abe949 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.h +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN // Objective-C wrapper of PDF::OutlineItem, to launder it through the NSOutlineViewDataSource protocol. @interface OutlineItemWrapper : NSObject +- (BOOL)isGroupItem; - (Optional)page; @end diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.mm index 6dcf6b6e0f81f8a..c2623c4ca0c0779 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFOutlineViewDataSource.mm @@ -8,7 +8,9 @@ @interface OutlineItemWrapper () { + // Only one of those two is set. RefPtr _item; + NSString* _groupName; } @end @@ -18,11 +20,27 @@ - (instancetype)initWithItem:(NonnullRefPtr)item if (self = [super init]; !self) return nil; _item = move(item); + _groupName = nil; return self; } +- (instancetype)initWithGroupName:(nonnull NSString*)groupName +{ + if (self = [super init]; !self) + return nil; + _groupName = groupName; + return self; +} + +- (BOOL)isGroupItem +{ + return _groupName != nil; +} + - (Optional)page { + if ([self isGroupItem]) + return {}; return _item->dest.page.map([](u32 page_index) { return page_index + 1; }); } @@ -33,11 +51,15 @@ - (OutlineItemWrapper*)child:(NSInteger)index - (NSInteger)numberOfChildren { + if ([self isGroupItem]) + return 0; return _item->children.size(); } - (NSString*)objectValue { + if (_groupName) + return _groupName; return [NSString stringWithFormat:@"%s", _item->title.characters()]; // FIXME: encoding? } @end @@ -65,7 +87,12 @@ - (id)outlineView:(NSOutlineView*)outlineView child:(NSInteger)index ofItem:(nul if (item) return [(OutlineItemWrapper*)item child:index]; - return [[OutlineItemWrapper alloc] initWithItem:_outline->children[index]]; + if (index == 0) { + bool has_outline = _outline && !_outline->children.is_empty(); + // FIXME: Maybe put filename here instead? + return [[OutlineItemWrapper alloc] initWithGroupName:has_outline ? @"Outline" : @"(No outline)"]; + } + return [[OutlineItemWrapper alloc] initWithItem:_outline->children[index - 1]]; } - (BOOL)outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item @@ -78,7 +105,7 @@ - (NSInteger)outlineView:(NSOutlineView*)outlineView numberOfChildrenOfItem:(nul if (item) return [(OutlineItemWrapper*)item numberOfChildren]; - return _outline ? _outline->children.size() : 0; + return 1 + (_outline ? _outline->children.size() : 0); } - (id)outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(nullable NSTableColumn*)tableColumn byItem:(nullable id)item diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm index 012f93190a79d7c..3125d93b19f612b 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm @@ -70,6 +70,7 @@ - (NSSplitViewItem*)makeSidebarSplitItem _outlineView = [[NSOutlineView alloc] initWithFrame:NSZeroRect]; _outlineView.style = NSTableViewStyleSourceList; + _outlineView.floatsGroupRows = NO; _outlineView.focusRingType = NSFocusRingTypeNone; _outlineView.headerView = nil; @@ -180,6 +181,16 @@ - (NSToolbarItem*)toolbar:(NSToolbar*)toolbar #pragma mark - NSOutlineViewDelegate +- (BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item +{ + return [item isGroupItem]; +} + +- (BOOL)outlineView:(NSOutlineView*)outlineView shouldSelectItem:(id)item +{ + return ![self outlineView:outlineView isGroupItem:item]; +} + // "This method is required if you wish to turn on the use of NSViews instead of NSCells." - (NSView*)outlineView:(NSOutlineView*)outlineView viewForTableColumn:(NSTableColumn*)tableColumn item:(id)item {