From 50a0f185400bb4dd315000e3e7488798f0c48b23 Mon Sep 17 00:00:00 2001 From: Abhi Beckert Date: Sun, 5 Jun 2016 12:07:41 +1000 Subject: #2434 now use NSTitlebarAccessoryViewController if available --- Interfaces/English.lproj/DBView.xib | 20 ++++++++++---------- Source/SPDatabaseDocument.h | 2 +- Source/SPDatabaseDocument.m | 37 +++++++++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 88902161..2ce00e2d 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -1,10 +1,10 @@ - + - - + + @@ -885,7 +885,7 @@ - + @@ -3440,7 +3440,7 @@ Gw - + @@ -3479,7 +3479,7 @@ Gw - + @@ -3512,7 +3512,7 @@ Gw - + @@ -3584,7 +3584,7 @@ Gw - + @@ -3705,7 +3705,7 @@ Gw - + @@ -4843,7 +4843,7 @@ Gw - + diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index c708cd9f..6596ca8c 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -106,7 +106,7 @@ IBOutlet NSView *parentView; - IBOutlet id titleAccessoryView; + IBOutlet NSView *titleAccessoryView; IBOutlet id titleImageView; IBOutlet id titleStringView; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index bd4233ae..2931ba9f 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -3943,17 +3943,34 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; if (newIsVisible == windowTitleStatusViewIsVisible) return; if (newIsVisible) { - NSView *windowFrame = [[parentWindow contentView] superview]; - NSRect av = [titleAccessoryView frame]; - NSRect initialAccessoryViewFrame = NSMakeRect( - [windowFrame frame].size.width - av.size.width - 30, - [windowFrame frame].size.height - av.size.height, - av.size.width, - av.size.height); - [titleAccessoryView setFrame:initialAccessoryViewFrame]; - [windowFrame addSubview:titleAccessoryView]; + if (NSClassFromString(@"NSTitlebarAccessoryViewController")) { // OS X 10.11 and later + [titleAccessoryView setFrame:NSMakeRect(0, 0, titleAccessoryView.frame.size.width, 120)]; // make it really tall, so that it's on the top right of the title/toolbar area, instead of the bottom right (AppKit will not prevent it from going behind the toolbar) + + NSTitlebarAccessoryViewController *accessoryViewController = [[[NSTitlebarAccessoryViewController alloc] init] autorelease]; + accessoryViewController.view = titleAccessoryView; + accessoryViewController.layoutAttribute = NSLayoutAttributeRight; + [parentWindow addTitlebarAccessoryViewController:accessoryViewController]; + } else { + NSView *windowFrame = [[parentWindow contentView] superview]; + NSRect av = [titleAccessoryView frame]; + NSRect initialAccessoryViewFrame = NSMakeRect( + [windowFrame frame].size.width - av.size.width - 30, + [windowFrame frame].size.height - av.size.height, + av.size.width, + av.size.height); + [titleAccessoryView setFrame:initialAccessoryViewFrame]; + [windowFrame addSubview:titleAccessoryView]; + } } else { - [titleAccessoryView removeFromSuperview]; + if (NSClassFromString(@"NSTitlebarAccessoryViewController")) { // OS X 10.11 and later + [parentWindow.titlebarAccessoryViewControllers enumerateObjectsUsingBlock:^(__kindof NSTitlebarAccessoryViewController * _Nonnull accessoryViewController, NSUInteger idx, BOOL * _Nonnull stop) { + if (accessoryViewController.view == titleAccessoryView) { + [parentWindow removeTitlebarAccessoryViewControllerAtIndex:idx]; + } + }]; + } else { + [titleAccessoryView removeFromSuperview]; + } } windowTitleStatusViewIsVisible = newIsVisible; -- cgit v1.2.3