mirror of
https://github.com/RGBCube/serenity
synced 2025-06-04 13:58:15 +00:00
MacPF: Add a small group header in front of the outline
This has to be part of the data source, which makes things a bit annoying. For PDFs that have no outline, it says "(No outline)".
This commit is contained in:
parent
fee50cb387
commit
a75f876ec0
3 changed files with 41 additions and 2 deletions
|
@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
// Objective-C wrapper of PDF::OutlineItem, to launder it through the NSOutlineViewDataSource protocol.
|
// Objective-C wrapper of PDF::OutlineItem, to launder it through the NSOutlineViewDataSource protocol.
|
||||||
@interface OutlineItemWrapper : NSObject
|
@interface OutlineItemWrapper : NSObject
|
||||||
|
|
||||||
|
- (BOOL)isGroupItem;
|
||||||
- (Optional<u32>)page;
|
- (Optional<u32>)page;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
@interface OutlineItemWrapper ()
|
@interface OutlineItemWrapper ()
|
||||||
{
|
{
|
||||||
|
// Only one of those two is set.
|
||||||
RefPtr<PDF::OutlineItem> _item;
|
RefPtr<PDF::OutlineItem> _item;
|
||||||
|
NSString* _groupName;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -18,11 +20,27 @@
|
||||||
if (self = [super init]; !self)
|
if (self = [super init]; !self)
|
||||||
return nil;
|
return nil;
|
||||||
_item = move(item);
|
_item = move(item);
|
||||||
|
_groupName = nil;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithGroupName:(nonnull NSString*)groupName
|
||||||
|
{
|
||||||
|
if (self = [super init]; !self)
|
||||||
|
return nil;
|
||||||
|
_groupName = groupName;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isGroupItem
|
||||||
|
{
|
||||||
|
return _groupName != nil;
|
||||||
|
}
|
||||||
|
|
||||||
- (Optional<u32>)page
|
- (Optional<u32>)page
|
||||||
{
|
{
|
||||||
|
if ([self isGroupItem])
|
||||||
|
return {};
|
||||||
return _item->dest.page.map([](u32 page_index) { return page_index + 1; });
|
return _item->dest.page.map([](u32 page_index) { return page_index + 1; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,11 +51,15 @@
|
||||||
|
|
||||||
- (NSInteger)numberOfChildren
|
- (NSInteger)numberOfChildren
|
||||||
{
|
{
|
||||||
|
if ([self isGroupItem])
|
||||||
|
return 0;
|
||||||
return _item->children.size();
|
return _item->children.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*)objectValue
|
- (NSString*)objectValue
|
||||||
{
|
{
|
||||||
|
if (_groupName)
|
||||||
|
return _groupName;
|
||||||
return [NSString stringWithFormat:@"%s", _item->title.characters()]; // FIXME: encoding?
|
return [NSString stringWithFormat:@"%s", _item->title.characters()]; // FIXME: encoding?
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -65,7 +87,12 @@
|
||||||
if (item)
|
if (item)
|
||||||
return [(OutlineItemWrapper*)item child:index];
|
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
|
- (BOOL)outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item
|
||||||
|
@ -78,7 +105,7 @@
|
||||||
if (item)
|
if (item)
|
||||||
return [(OutlineItemWrapper*)item numberOfChildren];
|
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
|
- (id)outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(nullable NSTableColumn*)tableColumn byItem:(nullable id)item
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
{
|
{
|
||||||
_outlineView = [[NSOutlineView alloc] initWithFrame:NSZeroRect];
|
_outlineView = [[NSOutlineView alloc] initWithFrame:NSZeroRect];
|
||||||
|
|
||||||
|
_outlineView.floatsGroupRows = NO;
|
||||||
_outlineView.focusRingType = NSFocusRingTypeNone;
|
_outlineView.focusRingType = NSFocusRingTypeNone;
|
||||||
_outlineView.headerView = nil;
|
_outlineView.headerView = nil;
|
||||||
|
|
||||||
|
@ -179,6 +180,16 @@
|
||||||
|
|
||||||
#pragma mark - NSOutlineViewDelegate
|
#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."
|
// "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
|
- (NSView*)outlineView:(NSOutlineView*)outlineView viewForTableColumn:(NSTableColumn*)tableColumn item:(id)item
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue