//// BWSplitViewInspector.m// BWToolkit//// Created by Brandon Walkin (www.brandonwalkin.com)// All code is provided under the New BSD license.//#import "BWSplitViewInspector.h"#import "NSView+BWAdditions.h"@interfaceBWSplitViewInspector(BWSVIPrivate)-(void)updateSizeInputFields;-(BOOL)toggleDividerCheckboxVisibilityWithAnimation:(BOOL)shouldAnimate;-(void)updateSizeLabels;-(void)updateUnitPopupSelections;@end@implementationBWSplitViewInspector@synthesizesubviewPopupSelection,subviewPopupContent,collapsiblePopupContent,minUnitPopupSelection,maxUnitPopupSelection,splitView,dividerCheckboxCollapsed;-(NSString*)viewNibName{return@"BWSplitViewInspector";}-(void)awakeFromNib{[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(controlTextDidEndEditing:)name:NSControlTextDidEndEditingNotificationobject:minField];[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(controlTextDidEndEditing:)name:NSControlTextDidEndEditingNotificationobject:maxField];}-(void)updateSizeLabels{if([splitViewisVertical]){[maxLabelsetStringValue:@"Max Width"];[minLabelsetStringValue:@"Min Width"];}else{[maxLabelsetStringValue:@"Max Height"];[minLabelsetStringValue:@"Min Height"];}}-(void)setSplitView:(BWSplitView*)aSplitView{if(splitView!=aSplitView){[splitViewrelease];splitView=[aSplitViewretain];[selftoggleDividerCheckboxVisibilityWithAnimation:NO];}else{[selftoggleDividerCheckboxVisibilityWithAnimation:YES];}}-(void)setDividerCheckboxWantsLayer:(NSString*)flag{if([flagisEqualToString:@"YES"])[dividerCheckboxsetWantsLayer:YES];else[dividerCheckboxsetWantsLayer:NO];}-(BOOL)toggleDividerCheckboxVisibilityWithAnimation:(BOOL)shouldAnimate{// Conditions that must be met for a visibility switch to take place. If any of them fail, we return early.if(dividerCheckboxCollapsed&&[splitViewdividerThickness]>1.01&&[splitViewcollapsiblePopupSelection]!=0){}elseif(!dividerCheckboxCollapsed&&([splitViewdividerThickness]<1.01||[splitViewcollapsiblePopupSelection]==0)){}elsereturnNO;floatduration=0.1,alpha;NSRecttargetFrame=NSZeroRect;if(dividerCheckboxCollapsed){targetFrame=NSMakeRect([[selfview]frame].origin.x,[[selfview]frame].origin.y,[[selfview]frame].size.width,[[selfview]frame].size.height+20);alpha=1.0;}else{targetFrame=NSMakeRect([[selfview]frame].origin.x,[[selfview]frame].origin.y,[[selfview]frame].size.width,[[selfview]frame].size.height-20);alpha=0.0;}[selfperformSelector:@selector(setDividerCheckboxWantsLayer:)withObject:@"YES"afterDelay:0];if(shouldAnimate){[NSAnimationContextbeginGrouping];[[NSAnimationContextcurrentContext]setDuration:duration];[[dividerCheckboxanimator]setAlphaValue:alpha];[[[selfview]animator]setFrame:targetFrame];[NSAnimationContextendGrouping];if(dividerCheckboxCollapsed)[selfperformSelector:@selector(setDividerCheckboxWantsLayer:)withObject:@"NO"afterDelay:duration];}else{[dividerCheckboxsetAlphaValue:alpha];[[selfview]setFrame:targetFrame];if(dividerCheckboxCollapsed)[selfperformSelector:@selector(setDividerCheckboxWantsLayer:)withObject:@"NO"afterDelay:0];}dividerCheckboxCollapsed=!dividerCheckboxCollapsed;returnYES;}-(void)refresh{[superrefresh];if([[selfinspectedObjects]count]>0){[autosizingViewsetSplitView:[[selfinspectedObjects]objectAtIndex:0]];[autosizingViewlayoutButtons];[selfsetSplitView:[[selfinspectedObjects]objectAtIndex:0]];// Populate the subview popup buttonNSMutableArray*content=[[NSMutableArrayalloc]init];for(NSView*subviewin[splitViewsubviews]){intindex=[[splitViewsubviews]indexOfObject:subview];NSString*label=[NSStringstringWithFormat:@"Subview %d",index];if(![[subviewclassName]isEqualToString:@"NSView"])label=[labelstringByAppendingString:[NSStringstringWithFormat:@" - %@",[subviewclassName]]];[contentaddObject:label];}[selfsetSubviewPopupContent:content];// Populate the collapsible popup buttonif([splitViewisVertical])[selfsetCollapsiblePopupContent:[NSMutableArrayarrayWithObjects:@"None",@"Left Pane",@"Right Pane",nil]];else[selfsetCollapsiblePopupContent:[NSMutableArrayarrayWithObjects:@"None",@"Top Pane",@"Bottom Pane",nil]];[selfupdateSizeLabels];[selfupdateSizeInputFields];[selfupdateUnitPopupSelections];}}+(BOOL)supportsMultipleObjectInspection{returnNO;}-(void)setMinUnitPopupSelection:(int)index{minUnitPopupSelection=index;NSNumber*minUnit=[NSNumbernumberWithInt:index];NSMutableDictionary*tempMinUnits=[[[splitViewminUnits]mutableCopy]autorelease];[tempMinUnitssetObject:minUnitforKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]];[splitViewsetMinUnits:tempMinUnits];}-(void)setMaxUnitPopupSelection:(int)index{maxUnitPopupSelection=index;NSNumber*maxUnit=[NSNumbernumberWithInt:index];NSMutableDictionary*tempMaxUnits=[[[splitViewmaxUnits]mutableCopy]autorelease];[tempMaxUnitssetObject:maxUnitforKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]];[splitViewsetMaxUnits:tempMaxUnits];}-(void)updateUnitPopupSelections{minUnitPopupSelection=[[[splitViewminUnits]objectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]]intValue];maxUnitPopupSelection=[[[splitViewmaxUnits]objectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]]intValue];}-(void)controlTextDidEndEditing:(NSNotification*)aNotification{if([aNotificationobject]==minField||aNotification==nil){if([minFieldstringValue]!=nil&&[[minFieldstringValue]isEqualToString:@""]==NO&&[[minFieldstringValue]isEqualToString:@" "]==NO){NSNumber*minValue=[NSNumbernumberWithInt:[minFieldintValue]];NSMutableDictionary*tempMinValues=[[[splitViewminValues]mutableCopy]autorelease];[tempMinValuessetObject:minValueforKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]];[splitViewsetMinValues:tempMinValues];}else{NSMutableDictionary*tempMinValues=[[[splitViewminValues]mutableCopy]autorelease];[tempMinValuesremoveObjectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]];[splitViewsetMinValues:tempMinValues];}}if([aNotificationobject]==maxField||aNotification==nil){if([maxFieldstringValue]!=nil&&[[maxFieldstringValue]isEqualToString:@""]==NO&&[[maxFieldstringValue]isEqualToString:@" "]==NO){NSNumber*maxValue=[NSNumbernumberWithInt:[maxFieldintValue]];NSMutableDictionary*tempMaxValues=[[[splitViewmaxValues]mutableCopy]autorelease];[tempMaxValuessetObject:maxValueforKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]];[splitViewsetMaxValues:tempMaxValues];}else{NSMutableDictionary*tempMaxValues=[[[splitViewmaxValues]mutableCopy]autorelease];[tempMaxValuesremoveObjectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]];[splitViewsetMaxValues:tempMaxValues];}}}-(void)setSubviewPopupSelection:(int)index{// If someone types into the text field and chooses a different subview without hitting return or clicking out of the field,// the controlTextDidEndEditing notification won't fire and the value won't be saved. So we fire it manually here. [selfcontrolTextDidEndEditing:nil];subviewPopupSelection=index;// Update the input text fields with the values in the new subview[selfupdateSizeInputFields];}-(void)updateSizeInputFields{[minFieldsetObjectValue:[[splitViewminValues]objectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]]];[maxFieldsetObjectValue:[[splitViewmaxValues]objectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]]];[selfsetMinUnitPopupSelection:[[[splitViewminUnits]objectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]]intValue]];[selfsetMaxUnitPopupSelection:[[[splitViewmaxUnits]objectForKey:[NSNumbernumberWithInt:[selfsubviewPopupSelection]]]intValue]];}@end