diff options
author | Max <dmoagx@users.noreply.github.com> | 2018-05-15 23:17:44 +0200 |
---|---|---|
committer | Max <dmoagx@users.noreply.github.com> | 2018-05-15 23:17:44 +0200 |
commit | 67531d3eef6cf819c54b3b55aa9e96261db4cbba (patch) | |
tree | ae6288b7633de3b9daf91c21760816fe5d6a2aa1 | |
parent | 4145d3d4281cfee869754b50325048228f1ee6bd (diff) | |
download | sequelpro-67531d3eef6cf819c54b3b55aa9e96261db4cbba.tar.gz sequelpro-67531d3eef6cf819c54b3b55aa9e96261db4cbba.tar.bz2 sequelpro-67531d3eef6cf819c54b3b55aa9e96261db4cbba.zip |
Fix a drawing issue on 10.6 and move some code
-rw-r--r-- | Interfaces/English.lproj/ContentPaginationView.xib | 37 | ||||
-rw-r--r-- | Interfaces/English.lproj/DBView.xib | 21 | ||||
-rw-r--r-- | Source/SPTableContent.h | 12 | ||||
-rw-r--r-- | Source/SPTableContent.m | 151 |
4 files changed, 138 insertions, 83 deletions
diff --git a/Interfaces/English.lproj/ContentPaginationView.xib b/Interfaces/English.lproj/ContentPaginationView.xib index af90ff3e..ce178ae3 100644 --- a/Interfaces/English.lproj/ContentPaginationView.xib +++ b/Interfaces/English.lproj/ContentPaginationView.xib @@ -6,39 +6,17 @@ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6751"/> </dependencies> <objects> - <customObject id="-2" userLabel="File's Owner" customClass="SPTableContent"> + <customObject id="-2" userLabel="File's Owner" customClass="ContentPaginationViewController"> <connections> - <outlet property="paginationBox" destination="2" id="plQ-Ch-kaG"/> <outlet property="paginationGoButton" destination="cXy-Rp-Edv" id="tIC-S1-mTE"/> <outlet property="paginationPageField" destination="Vtc-V2-j0v" id="cwZ-g9-Qbj"/> - <outlet property="paginationView" destination="1" id="46"/> - <outlet property="paginationViewController" destination="hrG-95-pXC" id="yiZ-Ax-bVs"/> + <outlet property="paginationPageStepper" destination="S7c-s1-KCT" id="c4Q-RA-Dny"/> + <outlet property="view" destination="ZlV-bd-j4D" id="zKu-MD-Rhn"/> </connections> </customObject> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> - <customObject id="-3" userLabel="Application"/> - <customView id="1"> - <rect key="frame" x="0.0" y="0.0" width="330" height="89"/> - <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/> - <subviews> - <box autoresizesSubviews="NO" wantsLayer="YES" boxType="custom" borderType="line" titlePosition="noTitle" id="2"> - <rect key="frame" x="0.0" y="-47" width="330" height="136"/> - <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> - <view key="contentView"> - <rect key="frame" x="1" y="1" width="328" height="134"/> - <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> - </view> - <color key="borderColor" white="0.0" alpha="0.20000000300000001" colorSpace="calibratedWhite"/> - <color key="fillColor" white="0.94758063550000005" alpha="1" colorSpace="calibratedWhite"/> - </box> - </subviews> - </customView> + <customObject id="-3" userLabel="Application" customClass="NSObject"/> <userDefaultsController representsSharedInstance="YES" id="24"/> - <viewController id="hrG-95-pXC" userLabel="Popover View Controller"> - <connections> - <outlet property="view" destination="ZlV-bd-j4D" id="zor-2S-MNt"/> - </connections> - </viewController> <customView id="ZlV-bd-j4D" userLabel="Popover Content View"> <rect key="frame" x="0.0" y="0.0" width="330" height="89"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> @@ -51,7 +29,7 @@ <font key="font" metaFont="smallSystem"/> </buttonCell> <connections> - <action selector="navigatePaginationFromButton:" target="-2" id="28B-A6-zUZ"/> + <action selector="paginationGoAction:" target="-2" id="86K-61-7Jl"/> <binding destination="24" name="enabled" keyPath="values.LimitResults" id="AkR-JA-LEs"/> </connections> </button> @@ -69,6 +47,8 @@ </textFieldCell> <connections> <action selector="performClick:" target="cXy-Rp-Edv" id="4Uu-gW-Xhz"/> + <binding destination="-2" name="maxValue" keyPath="maxPage" id="JKa-ju-VyP"/> + <binding destination="-2" name="value" keyPath="page" previousBinding="JKa-ju-VyP" id="21h-9k-7Xk"/> <binding destination="24" name="enabled" keyPath="values.LimitResults" id="rJH-8j-rCm"/> </connections> </textField> @@ -108,7 +88,8 @@ <font key="font" metaFont="smallSystem"/> </stepperCell> <connections> - <action selector="takeIntValueFrom:" target="Vtc-V2-j0v" id="JYr-Pw-YZ2"/> + <binding destination="-2" name="maxValue" keyPath="maxPage" id="h3F-DA-oCz"/> + <binding destination="-2" name="value" keyPath="page" previousBinding="h3F-DA-oCz" id="W48-Lg-Q7t"/> <binding destination="24" name="enabled" keyPath="values.LimitResults" id="Nl1-31-oLD"/> </connections> </stepper> diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 0ea23312..b55710d3 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -4596,15 +4596,17 @@ Gw <outlet property="contentViewPane" destination="27" id="6661"/> <outlet property="countText" destination="261" id="262"/> <outlet property="duplicateButton" destination="5178" id="7837"/> - <outlet property="ruleFilterController" destination="ki9-Po-bdr" id="5od-0U-9xj"/> <outlet property="filterRuleEditorContainer" destination="9oo-u0-ndW" id="OZb-jI-CMy"/> <outlet property="filterTableController" destination="UBS-cN-3Af" id="FV7-by-Gy1"/> <outlet property="multipleLineEditingButton" destination="5201" id="5203"/> + <outlet property="paginationBox" destination="Cen-HW-aJR" id="cE5-7g-Pzn"/> <outlet property="paginationButton" destination="6653" id="6657"/> <outlet property="paginationNextButton" destination="6647" id="6664"/> <outlet property="paginationPreviousButton" destination="6650" id="6663"/> + <outlet property="paginationView" destination="EmC-GF-Hfu" id="l4X-ze-hG5"/> <outlet property="reloadButton" destination="5176" id="6625"/> <outlet property="removeButton" destination="5177" id="5190"/> + <outlet property="ruleFilterController" destination="ki9-Po-bdr" id="5od-0U-9xj"/> <outlet property="spHistoryControllerInstance" destination="6297" id="6316"/> <outlet property="tableContentContainer" destination="vcX-Xr-0cm" id="Xak-w0-y6x"/> <outlet property="tableContentView" destination="36" id="142"/> @@ -5153,6 +5155,23 @@ Gw </view> <point key="canvasLocation" x="98" y="659.5"/> </window> + <customView id="EmC-GF-Hfu"> + <rect key="frame" x="0.0" y="0.0" width="330" height="89"/> + <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/> + <subviews> + <box autoresizesSubviews="NO" wantsLayer="YES" boxType="custom" borderType="line" titlePosition="noTitle" id="Cen-HW-aJR"> + <rect key="frame" x="0.0" y="-47" width="330" height="136"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> + <view key="contentView" id="yNs-cH-TWp"> + <rect key="frame" x="1" y="1" width="328" height="134"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + </view> + <color key="borderColor" white="0.0" alpha="0.20000000300000001" colorSpace="calibratedWhite"/> + <color key="fillColor" white="0.94758063550000005" alpha="1" colorSpace="calibratedWhite"/> + </box> + </subviews> + <point key="canvasLocation" x="19" y="-25"/> + </customView> </objects> <resources> <image name="NSAdvanced" width="32" height="32"/> diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h index 209b804a..a13da19d 100644 --- a/Source/SPTableContent.h +++ b/Source/SPTableContent.h @@ -46,6 +46,8 @@ @class SPRuleFilterController; @class SPFilterTableController; +@class ContentPaginationViewController; //private + typedef NS_ENUM(NSInteger, SPTableContentFilterSource) { SPTableContentFilterSourceNone = -1, SPTableContentFilterSourceRuleFilter = 0, @@ -82,19 +84,14 @@ typedef NS_ENUM(NSInteger, SPTableContentFilterSource) { IBOutlet NSButton *paginationPreviousButton; #ifndef SP_CODA IBOutlet NSButton *paginationButton; - IBOutlet NSButton *paginationGoButton; #endif IBOutlet NSButton *paginationNextButton; #ifndef SP_CODA IBOutlet NSView *contentViewPane; - IBOutlet NSViewController *paginationViewController; + ContentPaginationViewController *paginationViewController; + NSPopover *paginationPopover; IBOutlet NSView *paginationView; IBOutlet NSBox *paginationBox; - NSPopover *paginationPopover; -#endif - IBOutlet NSTextField *paginationPageField; -#ifndef SP_CODA - IBOutlet NSStepper *paginationPageStepper; IBOutlet SPRuleFilterController *ruleFilterController; IBOutlet SPFilterTableController *filterTableController; @@ -188,7 +185,6 @@ typedef NS_ENUM(NSInteger, SPTableContentFilterSource) { @property (assign) NSButton* reloadButton; @property (assign) NSButton* paginationNextButton; @property (assign) NSButton* paginationPreviousButton; -@property (assign) NSTextField* paginationPageField; @property (assign) SPDatabaseDocument* tableDocumentInstance; @property (assign) SPTablesList* tablesListInstance; @property (assign) SPCopyTable* tableContentView; diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index d600f6e2..c4231655 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -69,6 +69,36 @@ */ static void *TableContentKVOContext = &TableContentKVOContext; +/** + * TODO: + * This class is a temporary workaround, because before SPTableContent was both a child class in one xib + * and an owner class in another xib, which is bad style and causes other complications. + */ +@interface ContentPaginationViewController : NSViewController +{ + id target; + SEL action; + + NSNumber *page; + NSNumber *maxPage; + + IBOutlet NSButton *paginationGoButton; + IBOutlet NSTextField *paginationPageField; + IBOutlet NSStepper *paginationPageStepper; +} +- (IBAction)paginationGoAction:(id)sender; +- (void)makeInputFirstResponder; +- (BOOL)isFirstResponderInside; + +@property (assign, nonatomic) id target; +@property (assign, nonatomic) SEL action; + +// IB Bindings +@property (copy, nonatomic) NSNumber *page; +@property (copy, nonatomic) NSNumber *maxPage; + +@end + @interface SPTableContent () - (BOOL)cancelRowEditing; @@ -93,7 +123,6 @@ static void *TableContentKVOContext = &TableContentKVOContext; @synthesize addButton; @synthesize duplicateButton; @synthesize paginationNextButton; -@synthesize paginationPageField; @synthesize paginationPreviousButton; @synthesize reloadButton; @synthesize removeButton; @@ -127,6 +156,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; #ifndef SP_CODA activeFilter = SPTableContentFilterSourceNone; schemeFilter = nil; + paginationViewController = [[ContentPaginationViewController alloc] init]; // the view itself is lazily loaded paginationPopover = nil; #endif @@ -189,18 +219,9 @@ static void *TableContentKVOContext = &TableContentKVOContext; // Set the double-click action in blank areas of the table to create new rows [tableContentView setEmptyDoubleClickAction:@selector(addRow:)]; - // Load the pagination view, keeping references to the top-level objects for later release - NSArray *paginationViewTopLevelObjects = nil; - NSNib *nibLoader = [[NSNib alloc] initWithNibNamed:@"ContentPaginationView" bundle:[NSBundle mainBundle]]; - - if (![nibLoader instantiateNibWithOwner:self topLevelObjects:&paginationViewTopLevelObjects]) { - NSLog(@"Content pagination nib could not be loaded; pagination will not function correctly."); - } - else { - [nibObjectsToRelease addObjectsFromArray:paginationViewTopLevelObjects]; - } - - [nibLoader release]; + [paginationViewController setTarget:self]; + [paginationViewController setAction:@selector(navigatePaginationFromButton:)]; + [paginationViewController view]; // make sure the nib is actually loaded //let's see if we can use the NSPopover (10.7+) or have to make do with our legacy clone. //this is using reflection right now, as our SDK is 10.8 but our minimum supported version is 10.6 @@ -222,7 +243,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; paginationViewFrame.origin.y = paginationButtonFrame.origin.y + paginationButtonFrame.size.height - 2; paginationViewFrame.size.height = 0; [paginationView setFrame:paginationViewFrame]; - [contentViewPane addSubview:paginationView]; + [[paginationButton superview] addSubview:paginationView]; } #endif @@ -443,7 +464,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; if (newTableName) selectedTable = [[NSString alloc] initWithString:newTableName]; previousTableRowsCount = 0; contentPage = 1; - [paginationPageField setStringValue:@"1"]; + [paginationViewController setPage:@1]; // Clear the selection [tableContentView deselectAll:self]; @@ -1229,7 +1250,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; { BOOL senderIsPaginationButton = (sender == paginationPreviousButton || sender == paginationNextButton #ifndef SP_CODA - || sender == paginationGoButton + || sender == paginationViewController #endif ); @@ -1284,16 +1305,17 @@ static void *TableContentKVOContext = &TableContentKVOContext; // Select the correct pagination value. // If the filter button was used, or if pagination is disabled, reset to page one - if (resetPaging || ![prefs boolForKey:SPLimitResults] || [paginationPageField integerValue] <= 0) { + NSInteger paginationViewPage = [[paginationViewController page] integerValue]; + if (resetPaging || ![prefs boolForKey:SPLimitResults] || paginationViewPage <= 0) { contentPage = 1; } // If the current page is out of bounds, move it within bounds - else if (([paginationPageField integerValue] - 1) * [prefs integerForKey:SPLimitResultsValue] >= maxNumRows) { + else if ((paginationViewPage - 1) * [prefs integerForKey:SPLimitResultsValue] >= maxNumRows) { contentPage = ceilf((CGFloat) maxNumRows / [prefs floatForKey:SPLimitResultsValue]); } // Otherwise, use the pagination value else { - contentPage = [paginationPageField integerValue]; + contentPage = paginationViewPage; } if ([self tableFilterString]) { @@ -1466,10 +1488,10 @@ static void *TableContentKVOContext = &TableContentKVOContext; if (sender == paginationPreviousButton) { if (contentPage <= 1) return; - [paginationPageField setIntegerValue:(contentPage - 1)]; + [paginationViewController setPage:@(contentPage - 1)]; } else if (sender == paginationNextButton) { if ((NSInteger)contentPage * [prefs integerForKey:SPLimitResultsValue] >= maxNumRows) return; - [paginationPageField setIntegerValue:(contentPage + 1)]; + [paginationViewController setPage:@(contentPage + 1)]; } [self filterTable:sender]; @@ -1503,18 +1525,17 @@ static void *TableContentKVOContext = &TableContentKVOContext; if(makeVisible) { [paginationButton setState:NSOnState]; [paginationButton setImage:[NSImage imageNamed:@"button_action"]]; - [[paginationPageField window] makeFirstResponder:paginationPageField]; + [paginationViewController makeInputFirstResponder]; } else { [paginationButton setState:NSOffState]; [paginationButton setImage:[NSImage imageNamed:@"button_pagination"]]; - if ([[paginationPageField window] firstResponder] == paginationPageField - || ([[[paginationPageField window] firstResponder] respondsToSelector:@selector(superview)] - && [(id)[[paginationPageField window] firstResponder] superview] - && [[(id)[[paginationPageField window] firstResponder] superview] respondsToSelector:@selector(superview)] - && [[(id)[[paginationPageField window] firstResponder] superview] superview] == paginationPageField)) - { - [[paginationPageField window] makeFirstResponder:nil]; + // TODO This is only relevant in 10.6 legacy mode. + // When using a modern NSPopover, the view controller's parent window is an _NSPopoverWindow, + // not the SP window and we don't care what the first responder in the popover is. + // (when it is not being displayed anyway). + if (!paginationPopover && [paginationViewController isFirstResponderInside]) { + [[[paginationViewController view] window] makeFirstResponder:nil]; } } @@ -1554,33 +1575,24 @@ static void *TableContentKVOContext = &TableContentKVOContext; } BOOL enabledMode = ![tableDocumentInstance isWorking]; - NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; - [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; - + BOOL limitResults = [prefs boolForKey:SPLimitResults]; // Set up the previous page button - if ([prefs boolForKey:SPLimitResults] && contentPage > 1) - [paginationPreviousButton setEnabled:enabledMode]; - else - [paginationPreviousButton setEnabled:NO]; + [paginationPreviousButton setEnabled:(limitResults && contentPage > 1 ? enabledMode : NO)]; // Set up the next page button - if ([prefs boolForKey:SPLimitResults] && contentPage < maxPage) - [paginationNextButton setEnabled:enabledMode]; - else - [paginationNextButton setEnabled:NO]; + [paginationNextButton setEnabled:(limitResults && contentPage < maxPage ? enabledMode : NO)]; #ifndef SP_CODA // As long as a table is selected (which it will be if this is called), enable pagination detail button [paginationButton setEnabled:enabledMode]; #endif + // "1" is the minimum page, so maxPage must not be less (which it would be for empty tables) + if(maxPage < 1) maxPage = 1; + // Set the values and maximums for the text field and associated pager - [paginationPageField setStringValue:[numberFormatter stringFromNumber:[NSNumber numberWithUnsignedInteger:contentPage]]]; - [[paginationPageField formatter] setMaximum:[NSNumber numberWithUnsignedInteger:maxPage]]; -#ifndef SP_CODA - [paginationPageStepper setIntegerValue:contentPage]; - [paginationPageStepper setMaxValue:maxPage]; -#endif + [paginationViewController setPage:@(contentPage)]; + [paginationViewController setMaxPage:@(maxPage)]; } #pragma mark - @@ -4640,6 +4652,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; for (id retainedObject in nibObjectsToRelease) [retainedObject release]; SPClear(nibObjectsToRelease); SPClear(paginationPopover); + SPClear(paginationViewController); #endif if (selectedTable) SPClear(selectedTable); @@ -4656,3 +4669,49 @@ static void *TableContentKVOContext = &TableContentKVOContext; } @end + +#pragma mark - + +@implementation ContentPaginationViewController + +@synthesize page = page; +@synthesize maxPage = maxPage; +@synthesize target = target; +@synthesize action = action; + +- (instancetype)init +{ + if((self = [super initWithNibName:@"ContentPaginationView" bundle:nil])) { + [self setPage:@1]; + [self setMaxPage:@1]; + } + return self; +} + +- (IBAction)paginationGoAction:(id)sender +{ + if(target && action) [target performSelector:action withObject:self]; +} + +- (void)makeInputFirstResponder +{ + [[paginationPageField window] makeFirstResponder:paginationPageField]; +} + +- (BOOL)isFirstResponderInside +{ + NSResponder *firstResponder = [[paginationPageField window] firstResponder]; + return ( + [firstResponder isKindOfClass:[NSView class]] && + [(NSView *)firstResponder isDescendantOf:[self view]] + ); +} + +- (void)dealloc +{ + [self setPage:nil]; + [self setMaxPage:nil]; + [super dealloc]; +} + +@end |