diff --git a/Butter.xcodeproj/project.xcworkspace/xcshareddata/Butter.xcscmblueprint b/Butter.xcodeproj/project.xcworkspace/xcshareddata/Butter.xcscmblueprint new file mode 100644 index 0000000..139f7c7 --- /dev/null +++ b/Butter.xcodeproj/project.xcworkspace/xcshareddata/Butter.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "1BE2EC80BAFB45464F850DCF6C22CB755957A826", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "74A9F3FD7617A9D8DBE0A59D7180A8FB90CAF746" : 9223372036854775807, + "1BE2EC80BAFB45464F850DCF6C22CB755957A826" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "C5D60C9A-8331-4F11-AB25-B2A5E1F71B98", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "74A9F3FD7617A9D8DBE0A59D7180A8FB90CAF746" : "", + "1BE2EC80BAFB45464F850DCF6C22CB755957A826" : "Butter\/" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "Butter", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Butter.xcodeproj", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/ButterKit\/Butter.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "1BE2EC80BAFB45464F850DCF6C22CB755957A826" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "ssh:\/\/xyndl.de:7451\/opt\/git\/avirem_mac", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "74A9F3FD7617A9D8DBE0A59D7180A8FB90CAF746" + } + ] +} \ No newline at end of file diff --git a/Butter/BTRActivityIndicator.h b/Butter/BTRActivityIndicator.h index 27b1e4b..72f70e7 100644 --- a/Butter/BTRActivityIndicator.h +++ b/Butter/BTRActivityIndicator.h @@ -18,12 +18,12 @@ typedef NS_ENUM(NSInteger, BTRActivityIndicatorStyle) { @interface BTRActivityIndicator : BTRView // Returns an activity indicator sized to the default indicator size. -- (instancetype)initWithActivityIndicatorStyle:(BTRActivityIndicatorStyle)style; +- (id)initWithActivityIndicatorStyle:(BTRActivityIndicatorStyle)style; // Initializes the activity indicator with the default indicator style (BTRActivityIndicatorStyleGray). -- (instancetype)initWithFrame:(NSRect)frameRect; +- (id)initWithFrame:(NSRect)frameRect; -- (instancetype)initWithFrame:(NSRect)frameRect activityIndicatorStyle:(BTRActivityIndicatorStyle)style NS_DESIGNATED_INITIALIZER; +- (id)initWithFrame:(NSRect)frameRect activityIndicatorStyle:(BTRActivityIndicatorStyle)style; // Starts and ends the animation of the activity indicator. - (void)startAnimating; diff --git a/Butter/BTRActivityIndicator.m b/Butter/BTRActivityIndicator.m index 79b0d34..80e1dea 100644 --- a/Butter/BTRActivityIndicator.m +++ b/Butter/BTRActivityIndicator.m @@ -23,42 +23,39 @@ @interface BTRActivityIndicator() @implementation BTRActivityIndicator @synthesize progressShapeLayer = _progressShapeLayer; -//- (instancetype)initWithFrame:(NSRect)frame layerHosted:(BOOL)hostsLayer { -// return [super initWithFrame:frame layerHosted:hostsLayer]; -//} - - (instancetype)initWithFrame:(NSRect)frame { - return [self initWithFrame:frame activityIndicatorStyle:BTRActivityIndicatorStyleGray]; + return [self initWithFrame:frame activityIndicatorStyle:BTRActivityIndicatorStyleGray]; } - (instancetype)initWithActivityIndicatorStyle:(BTRActivityIndicatorStyle)style { - CGFloat length = BTRActivityIndicatorDefaultFrameLength; - return [self initWithFrame:CGRectMake(0, 0, length, length) activityIndicatorStyle:style]; + CGFloat length = BTRActivityIndicatorDefaultFrameLength; + return [self initWithFrame:CGRectMake(0, 0, length, length) activityIndicatorStyle:style]; } - (instancetype)initWithFrame:(NSRect)frame activityIndicatorStyle:(BTRActivityIndicatorStyle)style { - self = [super initWithFrame:frame layerHosted:YES]; - if (self == nil) return nil; - - _activityIndicatorStyle = style; - _progressShapeColor = (style == BTRActivityIndicatorStyleGray ? [NSColor grayColor] : [NSColor whiteColor]); - _progressShapeCount = 12; - - CGFloat minLength = fminf(CGRectGetWidth(frame), CGRectGetHeight(frame)); - _progressShapeLength = ceilf(minLength / 4); - _progressShapeThickness = ceilf(minLength / _progressShapeCount); - _progressShapeSpread = _progressShapeLength; - _progressAnimationDuration = 1.f; - - [self.layer addSublayer:self.replicatorLayer]; - self.progressShapeLayer.opacity = 0.f; - - [self accessibilitySetOverrideValue:NSAccessibilityProgressIndicatorRole forAttribute:NSAccessibilityRoleAttribute]; - [self accessibilitySetOverrideValue:NSAccessibilityRoleDescription(NSAccessibilityProgressIndicatorRole, nil) forAttribute:NSAccessibilityRoleDescriptionAttribute]; - - return self; + self = [super initWithFrame:frame layerHosted:YES]; + if (self == nil) return nil; + + _activityIndicatorStyle = style; + _progressShapeColor = (style == BTRActivityIndicatorStyleGray ? [NSColor grayColor] : [NSColor whiteColor]); + _progressShapeCount = 12; + + CGFloat minLength = fminf(CGRectGetWidth(frame), CGRectGetHeight(frame)); + _progressShapeLength = ceilf(minLength / 4); + _progressShapeThickness = ceilf(minLength / _progressShapeCount); + _progressShapeSpread = _progressShapeLength; + _progressAnimationDuration = 1.f; + + [self.layer addSublayer:self.replicatorLayer]; + self.progressShapeLayer.opacity = 0.f; + + [self accessibilitySetOverrideValue:NSAccessibilityProgressIndicatorRole forAttribute:NSAccessibilityRoleAttribute]; + [self accessibilitySetOverrideValue:NSAccessibilityRoleDescription(NSAccessibilityProgressIndicatorRole, nil) forAttribute:NSAccessibilityRoleDescriptionAttribute]; + + return self; } + - (void)setActivityIndicatorStyle:(BTRActivityIndicatorStyle)style { self.progressShapeColor = (style == BTRActivityIndicatorStyleGray ? [NSColor grayColor] : [NSColor whiteColor]); } diff --git a/Butter/BTRButton.h b/Butter/BTRButton.h index 3c5d739..11f5fda 100644 --- a/Butter/BTRButton.h +++ b/Butter/BTRButton.h @@ -21,8 +21,8 @@ @property (nonatomic, assign) BTRViewContentMode imageContentMode; // Subclassing hooks -@property (readonly) CGRect backgroundImageFrame; -@property (readonly) CGRect imageFrame; -@property (readonly) CGRect labelFrame; +- (CGRect)backgroundImageFrame; +- (CGRect)imageFrame; +- (CGRect)labelFrame; @end diff --git a/Butter/BTRButton.m b/Butter/BTRButton.m index ca780ea..e836669 100644 --- a/Butter/BTRButton.m +++ b/Butter/BTRButton.m @@ -32,14 +32,14 @@ static void BTRButtonCommonInit(BTRButton *self) { [self accessibilitySetOverrideValue:NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil) forAttribute:NSAccessibilityRoleDescriptionAttribute]; } -- (instancetype)initWithFrame:(NSRect)frameRect { +- (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; if (self == nil) return nil; BTRButtonCommonInit(self); return self; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self == nil) return nil; BTRButtonCommonInit(self); diff --git a/Butter/BTRControl.m b/Butter/BTRControl.m index 8cfeb9c..7755926 100644 --- a/Butter/BTRControl.m +++ b/Butter/BTRControl.m @@ -49,14 +49,14 @@ static void BTRControlCommonInit(BTRControl *self) { self.content = [NSMutableDictionary dictionary]; } -- (instancetype)initWithFrame:(NSRect)frame { +- (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self == nil) return nil; BTRControlCommonInit(self); return self; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self == nil) return nil; BTRControlCommonInit(self); diff --git a/Butter/BTRImageView.h b/Butter/BTRImageView.h index 7e390af..aa4c3d8 100644 --- a/Butter/BTRImageView.h +++ b/Butter/BTRImageView.h @@ -33,7 +33,7 @@ typedef NS_ENUM(NSInteger, BTRViewContentMode) { // The dedicated initializer. The bounds of the image view will // be adjusted to match the size of the image. -- (instancetype)initWithImage:(NSImage *)image; +- (id)initWithImage:(NSImage *)image; // The image displayed in the image view. @property (nonatomic, strong) NSImage *image; diff --git a/Butter/BTRImageView.m b/Butter/BTRImageView.m index 5f69ff1..95195df 100644 --- a/Butter/BTRImageView.m +++ b/Butter/BTRImageView.m @@ -22,20 +22,20 @@ @implementation BTRImageView { NSTimer *_animationTimer; } -- (instancetype)initWithFrame:(NSRect)frame { +- (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame layerHosted:YES]; if (self == nil) return nil; BTRImageViewCommonInit(self); return self; } -- (instancetype)initWithImage:(NSImage *)image { +- (id)initWithImage:(NSImage *)image { self = [self initWithFrame:(CGRect){ .size = image.size }]; self.image = image; return self; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self == nil) return nil; self.layer = [CALayer layer]; diff --git a/Butter/BTRLabel.m b/Butter/BTRLabel.m index 0bc08b4..cbef344 100644 --- a/Butter/BTRLabel.m +++ b/Butter/BTRLabel.m @@ -18,14 +18,14 @@ static void BTRLabelCommonInit(BTRLabel *self) { self.selectable = NO; } -- (instancetype)initWithFrame:(NSRect)frame { +- (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self == nil) return nil; BTRLabelCommonInit(self); return self; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self == nil) return nil; BTRLabelCommonInit(self); diff --git a/Butter/BTRPopUpButton.h b/Butter/BTRPopUpButton.h index 25ffeae..07fa26b 100644 --- a/Butter/BTRPopUpButton.h +++ b/Butter/BTRPopUpButton.h @@ -25,7 +25,7 @@ @property (nonatomic, assign) NSTextAlignment textAlignment; - (void)selectItemAtIndex:(NSUInteger)index; -@property (readonly) NSUInteger indexOfSelectedItem; +- (NSUInteger)indexOfSelectedItem; // Adjust the width of the view to fit the content - (void)sizeToFit; @@ -35,22 +35,22 @@ // Can be overriden by subclasses to customize layout // The frame of the image view -@property (readonly) NSRect imageFrame; +- (NSRect)imageFrame; // The frame of the text label -@property (readonly) NSRect labelFrame; +- (NSRect)labelFrame; // The frame of the arrow image view -@property (readonly) NSRect arrowFrame; +- (NSRect)arrowFrame; // The padding between each element (between image and label, and label and arrow) -@property (readonly) CGFloat interElementSpacing; +- (CGFloat)interElementSpacing; // The distance between the pop up button content and the view edges -@property (readonly) CGFloat edgeInset; +- (CGFloat)edgeInset; // The width to fit all the content in the view (used by -sizeToFit) -@property (readonly) CGFloat widthToFit; +- (CGFloat)widthToFit; // Returns the arrow image for the current `BTRControlState` @property (nonatomic, strong, readonly) NSImage *currentArrowImage; diff --git a/Butter/BTRPopUpButton.m b/Butter/BTRPopUpButton.m index 6c055e9..9dbf92d 100644 --- a/Butter/BTRPopUpButton.m +++ b/Butter/BTRPopUpButton.m @@ -11,6 +11,7 @@ @interface BTRPopUpButtonLabel : BTRLabel @end + @interface BTRPopUpButtonImageView : BTRImageView @end @@ -29,8 +30,7 @@ @interface BTRPopUpButtonContent : BTRControlContent @end @implementation BTRPopUpButton - -@dynamic menu; +@synthesize menu = _menu; #pragma mark - Initialization @@ -153,6 +153,7 @@ - (NSUInteger)indexOfSelectedItem { #pragma mark - Accessors +/* - (void)setMenu:(NSMenu *)menu { if (self.menu != menu) { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; @@ -162,7 +163,10 @@ - (void)setMenu:(NSMenu *)menu { } self.selectedItem = nil; super.menu = menu; - if (self.menu) { + + //NSLog(@"%@", self.menu); + if (self.menu) + { self.menu.autoenablesItems = self.autoenablesItems; // Register for notifications for when the menu closes. This is important // because mouseUp: and mouseExited: are not normally called if the menu is closed @@ -181,8 +185,9 @@ - (void)setMenu:(NSMenu *)menu { // Force a menu update from the delegate once the menu is initially set [self forceMenuUpdate]; } + //self.menu = menu; } -} +}*/ - (void)setSelectedItem:(NSMenuItem *)selectedItem { if (_selectedItem != selectedItem) { diff --git a/Butter/BTRScrollView.h b/Butter/BTRScrollView.h index 4021627..64fd535 100644 --- a/Butter/BTRScrollView.h +++ b/Butter/BTRScrollView.h @@ -28,6 +28,6 @@ // Returns the scroll view's content view that is an instance of BTRClipView, or // nil if it does not exist. -@property (readonly, strong) BTRClipView *clipView; +- (BTRClipView *)clipView; @end diff --git a/Butter/BTRScrollView.m b/Butter/BTRScrollView.m index 3365154..f7f5d72 100644 --- a/Butter/BTRScrollView.m +++ b/Butter/BTRScrollView.m @@ -24,7 +24,7 @@ @implementation BTRScrollView #pragma mark Lifecycle -- (instancetype)initWithFrame:(NSRect)frameRect { +- (id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; if (self == nil) return nil; diff --git a/Butter/BTRSecureTextField.m b/Butter/BTRSecureTextField.m index 923e20b..9fb5ac5 100644 --- a/Butter/BTRSecureTextField.m +++ b/Butter/BTRSecureTextField.m @@ -57,14 +57,14 @@ @implementation BTRSecureTextField { @synthesize state = _state; @synthesize clickCount = _clickCount; -- (instancetype)initWithFrame:(NSRect)frame { +- (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self == nil) return nil; BTRSecureTextFieldCommonInit(self); return self; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self == nil) return nil; BTRSecureTextFieldCommonInit(self); @@ -438,7 +438,7 @@ - (void)sendActionsForControlEvents:(BTRControlEvents)events { if (action.block != nil) { action.block(events); } else if (action.action != nil) { // the target can be nil - [NSApp sendAction:action.action to:action.target]; + [NSApp sendAction:action.action to:action.target from:self]; } } } @@ -452,15 +452,25 @@ - (BOOL)isFirstResponder { } - (BOOL)becomeFirstResponder { - [self.layer addAnimation:[self shadowOpacityAnimation] forKey:nil]; - self.layer.shadowOpacity = 1.f; - self.highlighted = YES; - return [super becomeFirstResponder]; + + BOOL success = [super becomeFirstResponder]; + if (success){ + [self.layer addAnimation:[self shadowOpacityAnimation] forKey:nil]; + self.layer.shadowOpacity = 1.f; + self.highlighted = YES; + + NSTextView* textField = (NSTextView*) [self currentEditor]; + if( [textField respondsToSelector: @selector(setInsertionPointColor:)] ) + [textField setInsertionPointColor: [NSColor whiteColor]]; + } + + return success; } - (void)textDidEndEditing:(NSNotification *)notification { [self.layer addAnimation:[self shadowOpacityAnimation] forKey:nil]; self.layer.shadowOpacity = 0.f; + [self sendActionsForControlEvents:BTRControlEventValueChanged]; [super textDidEndEditing:notification]; self.highlighted = NO; } diff --git a/Butter/BTRTextField.m b/Butter/BTRTextField.m index 2ca2425..ed77f1e 100644 --- a/Butter/BTRTextField.m +++ b/Butter/BTRTextField.m @@ -57,14 +57,34 @@ @implementation BTRTextField { @synthesize state = _state; @synthesize clickCount = _clickCount; -- (instancetype)initWithFrame:(NSRect)frame { +/* +- (void)keyUp:(NSEvent *)theEvent{ + + switch ([theEvent keyCode]) { + + case 48: + //[self nextKeyView] = _NSClipViewOverhangView + //[[self nextKeyView] nextKeyView] = NSTokenField (in my case) + // or something different + [[self nextKeyView] becomeFirstResponder]; + //also http://stackoverflow.com/a/3008622/1067147 + break; + + + default:// allow NSTextView to handle everything else + [super keyDown:theEvent]; + break; + } +}*/ + +- (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self == nil) return nil; BTRTextFieldCommonInit(self); return self; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self == nil) return nil; BTRTextFieldCommonInit(self); @@ -106,6 +126,8 @@ static void BTRTextFieldCommonInit(BTRTextField *textField) { textField.drawsFocusRing = YES; textField.drawsBackground = YES; textField.bezeled = NO; + + } // It appears that on some layer-backed view hierarchies that are @@ -438,7 +460,7 @@ - (void)sendActionsForControlEvents:(BTRControlEvents)events { if (action.block != nil) { action.block(events); } else if (action.action != nil) { // the target can be nil - [NSApp sendAction:action.action to:action.target]; + [NSApp sendAction:action.action to:action.target from:self]; } } } @@ -452,16 +474,34 @@ - (BOOL)isFirstResponder { } - (BOOL)becomeFirstResponder { - [self.layer addAnimation:[self shadowOpacityAnimation] forKey:nil]; - self.layer.shadowOpacity = 1.f; - self.highlighted = YES; - return [super becomeFirstResponder]; + + BOOL success =[super becomeFirstResponder]; + + if (success){ + [self.layer addAnimation:[self shadowOpacityAnimation] forKey:nil]; + self.layer.shadowOpacity = 1.f; + self.highlighted = YES; + + NSTextView* textField = (NSTextView*) [self currentEditor]; + if( [textField respondsToSelector: @selector(setInsertionPointColor:)] ) + [textField setInsertionPointColor: [NSColor whiteColor]]; + + } + return success; + + /* + [self.layer addAnimation:[self shadowOpacityAnimation] forKey:nil]; + self.layer.shadowOpacity = 1.f; + self.highlighted = YES; + + return [super becomeFirstResponder];*/ } - (void)textDidEndEditing:(NSNotification *)notification { + [super textDidEndEditing:notification]; [self.layer addAnimation:[self shadowOpacityAnimation] forKey:nil]; self.layer.shadowOpacity = 0.f; - [super textDidEndEditing:notification]; + [self sendActionsForControlEvents:BTRControlEventValueChanged]; self.highlighted = NO; } @@ -473,6 +513,8 @@ - (void)textDidChange:(NSNotification *)notification { [fieldEditor.textStorage addAttribute:NSShadowAttributeName value:self.textShadow range:NSMakeRange(0, fieldEditor.textStorage.length)]; } + + // This hack is needed because in certain cases (e.g. when inside a popover), a layer backed text view will not redraw by itself [self setNeedsDisplay:YES]; } @@ -533,6 +575,7 @@ - (NSRect)drawingRectForBounds:(NSRect)theRect { newRect.size.height -= heightDelta; newRect.origin.y += ceil(heightDelta / 2); } + } return [(BTRTextField *)[self controlView] drawingRectForProposedDrawingRect:newRect]; } diff --git a/Butter/BTRView.h b/Butter/BTRView.h index dc185cc..982b82f 100644 --- a/Butter/BTRView.h +++ b/Butter/BTRView.h @@ -13,7 +13,7 @@ // Optional initializer which opts to provide the option to create a // layer-hosted view instead of a layer-backed view. -- (instancetype)initWithFrame:(NSRect)frame layerHosted:(BOOL)hostsLayer; +- (id)initWithFrame:(NSRect)frame layerHosted:(BOOL)hostsLayer; // A background color for the view, or nil if none has been set. @property (nonatomic, strong) NSColor *btr_backgroundColor; diff --git a/Butter/BTRView.m b/Butter/BTRView.m index 311f361..b33f8bf 100644 --- a/Butter/BTRView.m +++ b/Butter/BTRView.m @@ -31,7 +31,7 @@ - (BOOL)isFlipped #pragma mark Lifecycle -- (instancetype)initWithFrame:(NSRect)frame layerHosted:(BOOL)hostsLayer { +- (id)initWithFrame:(NSRect)frame layerHosted:(BOOL)hostsLayer { self = [super initWithFrame:frame]; if (self == nil) return nil; @@ -45,11 +45,11 @@ - (instancetype)initWithFrame:(NSRect)frame layerHosted:(BOOL)hostsLayer { return self; } -- (instancetype)initWithFrame:(NSRect)frame { +- (id)initWithFrame:(NSRect)frame { return [self initWithFrame:frame layerHosted:NO]; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self == nil) return nil; @@ -127,7 +127,7 @@ - (void)setAnimatesContents:(BOOL)animate { return animation; } - return [super actionForLayer:layer forKey:event]; + return nil;//[super actionForLayer:layer forKey:event]; } #pragma mark - View controller