mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:52:43 +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.
 | ||||
| @interface OutlineItemWrapper : NSObject | ||||
| 
 | ||||
| - (BOOL)isGroupItem; | ||||
| - (Optional<u32>)page; | ||||
| 
 | ||||
| @end | ||||
|  |  | |||
|  | @ -8,7 +8,9 @@ | |||
| 
 | ||||
| @interface OutlineItemWrapper () | ||||
| { | ||||
|     // Only one of those two is set. | ||||
|     RefPtr<PDF::OutlineItem> _item; | ||||
|     NSString* _groupName; | ||||
| } | ||||
| @end | ||||
| 
 | ||||
|  | @ -18,11 +20,27 @@ | |||
|     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<u32>)page | ||||
| { | ||||
|     if ([self isGroupItem]) | ||||
|         return {}; | ||||
|     return _item->dest.page.map([](u32 page_index) { return page_index + 1; }); | ||||
| } | ||||
| 
 | ||||
|  | @ -33,11 +51,15 @@ | |||
| 
 | ||||
| - (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 @@ | |||
|     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 @@ | |||
|     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 | ||||
|  |  | |||
|  | @ -69,6 +69,7 @@ | |||
| { | ||||
|     _outlineView = [[NSOutlineView alloc] initWithFrame:NSZeroRect]; | ||||
| 
 | ||||
|     _outlineView.floatsGroupRows = NO; | ||||
|     _outlineView.focusRingType = NSFocusRingTypeNone; | ||||
|     _outlineView.headerView = nil; | ||||
| 
 | ||||
|  | @ -179,6 +180,16 @@ | |||
| 
 | ||||
| #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 | ||||
| { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nico Weber
						Nico Weber