Skip to content
Snippets Groups Projects
Commit 46eecf84 authored by George Nachman's avatar George Nachman
Browse files

Merge branch 'coredata2'

Conflicts:
	ColorPicker/ColorPicker.xcodeproj/project.xcworkspace/xcuserdata/georgen.xcuserdatad/UserInterfaceState.xcuserstate
	sources/VT100Screen.m
	sources/iTermDirectoriesModel.m
parents cf9f2e64 bfcf47a6
No related branches found
No related tags found
No related merge requests found
Showing
with 270 additions and 186 deletions
Loading
Loading
@@ -22,3 +22,5 @@ Intermediates/
NMSSH.framework.dSYM/
NMSSH/
iTerm2.xcodeproj/xcuserdata/
ColorPicker/ColorPicker.xcodeproj/project.xcworkspace/xcuserdata/
ColorPicker/ColorPicker.xcodeproj/xcuserdata/
No preview for this file type
Loading
Loading
@@ -25,4 +25,7 @@
color:(NSColor *)color
alphaAllowed:(BOOL)alphaAllowed;
 
// Changes the selected color.
- (void)selectColor:(NSColor *)color;
@end
Loading
Loading
@@ -8,8 +8,8 @@
*/
@interface CPKPopover : NSPopover
 
/** Reflects the final selected color. */
@property(nonatomic, readonly) NSColor *selectedColor;
/** Reflects the final selected color. Setter changes color in open popover. */
@property(nonatomic) NSColor *selectedColor;
 
/** Called before popover closes. */
@property(nonatomic, copy) void (^willClose)();
Loading
Loading
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEscapeHatch.tiff

7.96 KiB

ColorPicker/ColorPicker.framework/Versions/A/Resources/EscapeHatch.tiff

7.86 KiB

Loading
Loading
@@ -20,22 +20,26 @@
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>6D570</string>
<string>7A1001</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>14D125</string>
<string>15A278</string>
<key>DTSDKName</key>
<string>macosx10.10</string>
<string>macosx10.11</string>
<key>DTXcode</key>
<string>0630</string>
<string>0701</string>
<key>DTXcodeBuild</key>
<string>6D570</string>
<string>7A1001</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Google. All rights reserved.</string>
</dict>
Loading
Loading
Loading
Loading
@@ -7,6 +7,10 @@
objects = {
 
/* Begin PBXBuildFile section */
1D3368861BCDB60700D3B564 /* EscapeHatch.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D3368841BCDB60700D3B564 /* EscapeHatch.png */; settings = {ASSET_TAGS = (); }; };
1D3368871BCDB60700D3B564 /* EscapeHatch@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D3368851BCDB60700D3B564 /* EscapeHatch@2x.png */; settings = {ASSET_TAGS = (); }; };
1D33688B1BCDB62100D3B564 /* ActiveEscapeHatch.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D3368891BCDB62100D3B564 /* ActiveEscapeHatch.png */; settings = {ASSET_TAGS = (); }; };
1D33688C1BCDB62100D3B564 /* ActiveEscapeHatch@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D33688A1BCDB62100D3B564 /* ActiveEscapeHatch@2x.png */; settings = {ASSET_TAGS = (); }; };
A6184EAE1BA874020088EF3C /* ColorPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = A6184EAD1BA874020088EF3C /* ColorPicker.h */; settings = {ATTRIBUTES = (Public, ); }; };
A6184EB41BA874020088EF3C /* ColorPicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A6184EA81BA874020088EF3C /* ColorPicker.framework */; };
A6184EBB1BA874020088EF3C /* ColorPickerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A6184EBA1BA874020088EF3C /* ColorPickerTests.m */; };
Loading
Loading
@@ -93,6 +97,10 @@
/* End PBXContainerItemProxy section */
 
/* Begin PBXFileReference section */
1D3368841BCDB60700D3B564 /* EscapeHatch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = EscapeHatch.png; path = Images.xcassets/EscapeHatch/EscapeHatch.png; sourceTree = "<group>"; };
1D3368851BCDB60700D3B564 /* EscapeHatch@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "EscapeHatch@2x.png"; path = "Images.xcassets/EscapeHatch/EscapeHatch@2x.png"; sourceTree = "<group>"; };
1D3368891BCDB62100D3B564 /* ActiveEscapeHatch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ActiveEscapeHatch.png; path = Images.xcassets/ActiveEscapeHatch/ActiveEscapeHatch.png; sourceTree = "<group>"; };
1D33688A1BCDB62100D3B564 /* ActiveEscapeHatch@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "ActiveEscapeHatch@2x.png"; path = "Images.xcassets/ActiveEscapeHatch/ActiveEscapeHatch@2x.png"; sourceTree = "<group>"; };
A6184EA81BA874020088EF3C /* ColorPicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ColorPicker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A6184EAC1BA874020088EF3C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A6184EAD1BA874020088EF3C /* ColorPicker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorPicker.h; sourceTree = "<group>"; };
Loading
Loading
@@ -107,9 +115,9 @@
A6184ED11BA874190088EF3C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
A6184ED41BA874190088EF3C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
A6184EEC1BA876390088EF3C /* CPKMainViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPKMainViewController.h; sourceTree = "<group>"; };
A6184EED1BA876390088EF3C /* CPKMainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPKMainViewController.m; sourceTree = "<group>"; };
A6184EED1BA876390088EF3C /* CPKMainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = CPKMainViewController.m; sourceTree = "<group>"; };
A6184EF01BA876E50088EF3C /* CPKRGBView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPKRGBView.h; sourceTree = "<group>"; };
A6184EF11BA876E50088EF3C /* CPKRGBView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPKRGBView.m; sourceTree = "<group>"; };
A6184EF11BA876E50088EF3C /* CPKRGBView.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = CPKRGBView.m; sourceTree = "<group>"; };
A6184EF41BA87A770088EF3C /* CPKPopover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPKPopover.h; sourceTree = "<group>"; };
A6184EF51BA87A770088EF3C /* CPKPopover.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPKPopover.m; sourceTree = "<group>"; };
A6184EF81BA8801D0088EF3C /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Loading
Loading
@@ -128,7 +136,7 @@
A6184F181BA8F40C0088EF3C /* CPKEyedropperWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPKEyedropperWindow.h; sourceTree = "<group>"; };
A6184F191BA8F40C0088EF3C /* CPKEyedropperWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPKEyedropperWindow.m; sourceTree = "<group>"; };
A6184F1C1BA90BB40088EF3C /* CPKColorWell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPKColorWell.h; sourceTree = "<group>"; };
A6184F1D1BA90BB40088EF3C /* CPKColorWell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPKColorWell.m; sourceTree = "<group>"; };
A6184F1D1BA90BB40088EF3C /* CPKColorWell.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = CPKColorWell.m; sourceTree = "<group>"; };
A6184F201BA911980088EF3C /* CPKEyedropperView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPKEyedropperView.h; sourceTree = "<group>"; };
A6184F211BA911980088EF3C /* CPKEyedropperView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPKEyedropperView.m; sourceTree = "<group>"; };
A6184F2F1BA9D5700088EF3C /* Add.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Add.png; sourceTree = "<group>"; };
Loading
Loading
@@ -193,6 +201,24 @@
/* End PBXFrameworksBuildPhase section */
 
/* Begin PBXGroup section */
1D3368831BCDB5F600D3B564 /* EscapeHatch */ = {
isa = PBXGroup;
children = (
1D3368841BCDB60700D3B564 /* EscapeHatch.png */,
1D3368851BCDB60700D3B564 /* EscapeHatch@2x.png */,
);
name = EscapeHatch;
sourceTree = "<group>";
};
1D3368881BCDB61200D3B564 /* ActiveEscapeHatch */ = {
isa = PBXGroup;
children = (
1D3368891BCDB62100D3B564 /* ActiveEscapeHatch.png */,
1D33688A1BCDB62100D3B564 /* ActiveEscapeHatch@2x.png */,
);
name = ActiveEscapeHatch;
sourceTree = "<group>";
};
A6184E9E1BA874020088EF3C = {
isa = PBXGroup;
children = (
Loading
Loading
@@ -313,6 +339,8 @@
A6184F2D1BA9D55D0088EF3C /* Resources */ = {
isa = PBXGroup;
children = (
1D3368881BCDB61200D3B564 /* ActiveEscapeHatch */,
1D3368831BCDB5F600D3B564 /* EscapeHatch */,
A6184F831BAA93F50088EF3C /* ActiveEyedropper */,
A6184F7E1BAA928A0088EF3C /* Eyedropper */,
A6184F2E1BA9D5700088EF3C /* Add */,
Loading
Loading
@@ -532,16 +560,20 @@
A6184F421BA9D5700088EF3C /* SelectedColorIndicator@2x.png in Resources */,
A6184F821BAA928A0088EF3C /* Eyedropper@2x.png in Resources */,
A6184F3E1BA9D5700088EF3C /* Add@2x.png in Resources */,
1D3368871BCDB60700D3B564 /* EscapeHatch@2x.png in Resources */,
A6184F6D1BAA15B80088EF3C /* SelectionIndicator.png in Resources */,
A6184F811BAA928A0088EF3C /* Eyedropper.png in Resources */,
A6184F3D1BA9D5700088EF3C /* Add.png in Resources */,
A6184F6E1BAA15B80088EF3C /* SelectionIndicator@2x.png in Resources */,
A6184F871BAA93F50088EF3C /* ActiveEyedropper@2x.png in Resources */,
A6184F5D1BAA083F0088EF3C /* SwatchCheckerboard@2x.png in Resources */,
1D33688B1BCDB62100D3B564 /* ActiveEscapeHatch.png in Resources */,
A6184F5C1BAA083F0088EF3C /* SwatchCheckerboard.png in Resources */,
1D3368861BCDB60700D3B564 /* EscapeHatch.png in Resources */,
A6184F761BAA2AC60088EF3C /* Remove@2x.png in Resources */,
A6184F411BA9D5700088EF3C /* SelectedColorIndicator.png in Resources */,
A6184F861BAA93F50088EF3C /* ActiveEyedropper.png in Resources */,
1D33688C1BCDB62100D3B564 /* ActiveEscapeHatch@2x.png in Resources */,
A6184F481BA9D75B0088EF3C /* colors.txt in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Loading
Loading
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ColorPicker/CPKSliderView.m"
timestampString = "464294069.626344"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
landmarkName = "-setSelectedValue:"
landmarkType = "5">
<Locations>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "-[CPKSliderView setSelectedValue:]"
moduleName = "ColorPicker"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/georgen/iTerm2/ColorPicker/ColorPicker/CPKSliderView.m"
timestampString = "464294177.641786"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
offsetFromSymbolStart = "24">
</Location>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "-[CPKSliderView setSelectedValue:]"
moduleName = "ColorPicker"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/georgen/iTerm2/ColorPicker/ColorPicker/CPKSliderView.m"
timestampString = "464294177.642019"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
offsetFromSymbolStart = "115">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A6184EC71BA874190088EF3C"
BuildableName = "ColorPickerDemo.app"
BlueprintName = "ColorPickerDemo"
ReferencedContainer = "container:ColorPicker.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A6184EC71BA874190088EF3C"
BuildableName = "ColorPickerDemo.app"
BlueprintName = "ColorPickerDemo"
ReferencedContainer = "container:ColorPicker.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A6184EC71BA874190088EF3C"
BuildableName = "ColorPickerDemo.app"
BlueprintName = "ColorPickerDemo"
ReferencedContainer = "container:ColorPicker.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A6184EC71BA874190088EF3C"
BuildableName = "ColorPickerDemo.app"
BlueprintName = "ColorPickerDemo"
ReferencedContainer = "container:ColorPicker.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Loading
Loading
@@ -5,9 +5,11 @@
@protocol CPKColorWellViewDelegate
@property(nonatomic, readonly) void (^willOpenPopover)();
@property(nonatomic, readonly) void (^willClosePopover)();
- (NSRect)presentationRect;
- (NSView *)presentingView;
- (BOOL)isContinuous;
- (void)colorChangedByDrag:(NSColor *)color;
@end
 
/** This really should be an NSCell. It provides the implementation of the CPKColorWell. */
Loading
Loading
@@ -26,7 +28,7 @@
 
@end
 
@interface CPKColorWellView() <NSPopoverDelegate>
@interface CPKColorWellView() <NSDraggingDestination, NSDraggingSource, NSPopoverDelegate>
@property(nonatomic) BOOL open;
@property(nonatomic) CPKPopover *popover;
@property(nonatomic, copy) void (^willClosePopover)(NSColor *);
Loading
Loading
@@ -41,6 +43,26 @@
 
@implementation CPKColorWellView
 
- (instancetype)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if (self) {
[self colorWellViewCommonInit];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[self colorWellViewCommonInit];
}
return self;
}
- (void)colorWellViewCommonInit {
[self registerForDraggedTypes:@[ NSPasteboardTypeColor ]];
}
- (void)awakeFromNib {
self.cornerRadius = 3;
self.open = NO;
Loading
Loading
@@ -48,23 +70,103 @@
 
// Use mouseDown so this will work in a NSTableView.
- (void)mouseDown:(NSEvent *)theEvent {
if (!_disabled && !self.open && theEvent.clickCount == 1) {
if (!self.delegate.isContinuous && theEvent.clickCount == 1) {
[self openPopOver];
}
}
- (void)mouseUp:(NSEvent *)theEvent {
if (self.delegate.isContinuous && theEvent.clickCount == 1) {
[self openPopOver];
}
}
- (void)openPopOver {
if (!_disabled && !self.open) {
[self openPopOverRelativeToRect:_delegate.presentationRect
ofView:_delegate.presentingView];
}
}
 
- (void)mouseDragged:(NSEvent *)theEvent {
NSColor *color = self.selectedColor ?: [NSColor clearColor];
NSDraggingItem *dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter:color];
dragItem.imageComponentsProvider = ^NSArray<NSDraggingImageComponent *> *(void) {
NSDraggingImageComponent *imageComponent =
[NSDraggingImageComponent draggingImageComponentWithKey:NSDraggingImageComponentIconKey];
NSImage *snapshot = [[NSImage alloc] initWithSize:self.frame.size];
[snapshot lockFocus];
[self drawRect:self.bounds];
[snapshot unlockFocus];
imageComponent.contents = snapshot;
imageComponent.frame = self.bounds;
return @[ imageComponent ];
};
[self beginDraggingSessionWithItems:@[ dragItem ]
event:theEvent
source:self];
}
#pragma mark - NSDraggingDestination
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
__block NSDragOperation operation = NSDragOperationNone;
[sender enumerateDraggingItemsWithOptions:0
forView:self
classes:@[ [NSColor class] ]
searchOptions:@{}
usingBlock:^(NSDraggingItem * _Nonnull draggingItem, NSInteger idx, BOOL * _Nonnull stop) {
NSColor *color = draggingItem.item;
if (color) {
operation = NSDragOperationGeneric;
*stop = YES;
}
}];
return operation;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
__block BOOL ok = NO;
[sender enumerateDraggingItemsWithOptions:0
forView:self
classes:@[ [NSColor class] ]
searchOptions:@{}
usingBlock:^(NSDraggingItem * _Nonnull draggingItem, NSInteger idx, BOOL * _Nonnull stop) {
NSColor *color = draggingItem.item;
if (color) {
self.popover.selectedColor = color;
self.selectedColor = color;
[self.delegate colorChangedByDrag:color];
ok = YES;
*stop = YES;
}
}];
return ok;
}
#pragma mark - NSDraggingSource
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
return NSDragOperationGeneric;
}
- (void)openPopOverRelativeToRect:(NSRect)presentationRect ofView:(NSView *)presentingView {
__weak __typeof(self) weakSelf = self;
self.selectedColor = self.color;
self.popover =
[CPKPopover presentRelativeToRect:presentationRect
ofView:presentingView
preferredEdge:CGRectMinYEdge
preferredEdge:NSRectEdgeMinY
initialColor:self.color
alphaAllowed:self.alphaAllowed
selectionDidChange:^(NSColor *color) {
self.selectedColor = color;
weakSelf.selectedColor = color;
if (weakSelf.delegate.isContinuous) {
weakSelf.color = color;
if (weakSelf.colorDidChange) {
Loading
Loading
@@ -78,6 +180,7 @@
if (weakSelf.willClosePopover) {
weakSelf.willClosePopover(weakSelf.color);
}
weakSelf.color = weakSelf.selectedColor;
weakSelf.open = NO;
weakSelf.popover = nil;
};
Loading
Loading
@@ -192,4 +295,9 @@
return self;
}
 
- (void)colorChangedByDrag:(NSColor *)color {
[self setColor:color];
[self sendAction:self.action to:self.target];
}
@end
Loading
Loading
@@ -17,10 +17,16 @@
/** Block called when user clicks on the eyedropper. */
@property(nonatomic, copy) void (^startPickingBlock)();
 
/** Block called when user clicks the escape hatch. */
@property(nonatomic, copy) void (^toggleNativePickerBlock)(BOOL);
/** Reports this view's nominal height */
+ (CGFloat)desiredHeight;
 
/** Updates the swatch color. */
- (void)setSwatchColor:(NSColor *)color;
 
/** Call this when the color panel closes. */
- (void)colorPanelDidClose;
@end
Loading
Loading
@@ -13,6 +13,8 @@ static const CGFloat kBottomMargin = 8;
@property(nonatomic) NSButton *addFavorite;
@property(nonatomic) NSButton *removeFavorite;
@property(nonatomic) NSButton *eyedropperMode;
@property(nonatomic) NSButton *escapeHatch;
@property(nonatomic) BOOL useSystemColorPicker;
@property(nonatomic) CPKSwatchView *swatch;
@end
 
Loading
Loading
@@ -41,14 +43,21 @@ static const CGFloat kBottomMargin = 8;
[self.eyedropperMode setTarget:self];
[self.eyedropperMode setAction:@selector(eyedropperMode:)];
 
origin = NSMakePoint(NSMaxX(self.eyedropperMode.frame) + kMarginBetweenButtonsAndSwatch,
origin = NSMakePoint(NSMaxX(self.eyedropperMode.frame) + kMarginBetweenButtons,
kTopMargin);
self.escapeHatch = [self addButtonWithImage:[self cpk_imageNamed:@"EscapeHatch"]
origin:origin];
[self.escapeHatch setTarget:self];
[self.escapeHatch setAction:@selector(escapeHatch:)];
origin = NSMakePoint(NSMaxX(self.escapeHatch.frame) + kMarginBetweenButtonsAndSwatch,
kTopMargin);
self.swatch =
[[CPKSwatchView alloc] initWithFrame:NSMakeRect(NSMaxX(self.eyedropperMode.frame) +
[[CPKSwatchView alloc] initWithFrame:NSMakeRect(NSMaxX(self.escapeHatch.frame) +
kMarginBetweenButtonsAndSwatch,
kTopMargin,
NSWidth(frameRect) -
NSMaxX(self.eyedropperMode.frame) -
NSMaxX(self.escapeHatch.frame) -
kMarginBetweenButtonsAndSwatch -
kRightMargin,
NSHeight(self.addFavorite.frame))];
Loading
Loading
@@ -88,6 +97,17 @@ static const CGFloat kBottomMargin = 8;
return YES;
}
 
- (void)colorPanelDidClose {
self.useSystemColorPicker = NO;
}
- (void)setUseSystemColorPicker:(BOOL)useSystemColorPicker {
_useSystemColorPicker = useSystemColorPicker;
self.escapeHatch.image =
self.useSystemColorPicker ? [self cpk_imageNamed:@"ActiveEscapeHatch"] :
[self cpk_imageNamed:@"EscapeHatch"];
}
#pragma mark - Actions
 
- (void)addFavorite:(id)sender {
Loading
Loading
@@ -112,4 +132,11 @@ static const CGFloat kBottomMargin = 8;
}
}
 
- (void)escapeHatch:(id)sender {
if (_toggleNativePickerBlock) {
self.useSystemColorPicker = !self.useSystemColorPicker;
_toggleNativePickerBlock(self.useSystemColorPicker);
}
}
@end
Loading
Loading
@@ -25,4 +25,7 @@
color:(NSColor *)color
alphaAllowed:(BOOL)alphaAllowed;
 
// Changes the selected color.
- (void)selectColor:(NSColor *)color;
@end
Loading
Loading
@@ -22,6 +22,7 @@ static const CGFloat kBottomMargin = 8;
@property(nonatomic) CPKRGBView *rgbView;
@property(nonatomic) CPKControlsView *controlsView;
@property(nonatomic) CPKFavoritesView *favoritesView;
@property(nonatomic) NSColorPanel *colorPanel;
@property(nonatomic) BOOL alphaAllowed;
@end
 
Loading
Loading
@@ -57,10 +58,7 @@ static const CGFloat kBottomMargin = 8;
__weak __typeof(self) weakSelf = self;
self.rgbView = [[CPKRGBView alloc] initWithFrame:self.view.bounds
block: ^(NSColor *color) {
weakSelf.selectedColor = color;
weakSelf.controlsView.swatchColor = color;
_block(color);
[weakSelf.favoritesView selectColor:color];
[weakSelf selectColor:color];
}
color:_selectedColor
alphaAllowed:self.alphaAllowed];
Loading
Loading
@@ -100,7 +98,24 @@ static const CGFloat kBottomMargin = 8;
weakSelf.rgbView.selectedColor = color;
}
};
self.controlsView.toggleNativePickerBlock = ^(BOOL open) {
if (open) {
weakSelf.colorPanel = [NSColorPanel sharedColorPanel];
weakSelf.colorPanel.showsAlpha = weakSelf.alphaAllowed;
weakSelf.colorPanel.color = weakSelf.selectedColor;
[weakSelf.colorPanel setTarget:weakSelf];
[weakSelf.colorPanel setAction:@selector(colorPanelColorDidChange:)];
[weakSelf.colorPanel orderFront:nil];
NSRect frame = weakSelf.colorPanel.frame;
frame.origin = self.view.window.frame.origin;
[weakSelf.colorPanel setFrame:frame display:YES];
} else {
weakSelf.colorPanel = [NSColorPanel sharedColorPanel];
weakSelf.colorPanel.target = nil;
[weakSelf.colorPanel orderOut:nil];
weakSelf.colorPanel = nil;
}
};
self.favoritesView =
[[CPKFavoritesView alloc] initWithFrame:NSMakeRect(kLeftMargin,
NSMaxY(self.controlsView.frame),
Loading
Loading
@@ -133,4 +148,44 @@ static const CGFloat kBottomMargin = 8;
return kFavoritesHeight;
}
 
- (void)viewWillDisappear {
__weak NSColorPanel *colorPanel = self.colorPanel;
dispatch_async(dispatch_get_main_queue(), ^{
[colorPanel setTarget:nil];
[colorPanel orderOut:nil];
});
self.colorPanel = nil;
}
- (void)colorPanelColorDidChange:(id)sender {
NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
self.rgbView.selectedColor = [colorPanel color];
}
- (void)setColorPanel:(NSColorPanel *)colorPanel {
if (colorPanel) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(colorPanelDidClose:)
name:NSWindowWillCloseNotification
object:_colorPanel];
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSWindowWillCloseNotification
object:_colorPanel];
}
_colorPanel = colorPanel;
}
- (void)colorPanelDidClose:(NSNotification *)notification {
[self.controlsView colorPanelDidClose];
self.colorPanel = nil;
}
- (void)selectColor:(NSColor *)color {
self.selectedColor = color;
self.controlsView.swatchColor = color;
_block(color);
[self.favoritesView selectColor:color];
}
@end
Loading
Loading
@@ -8,8 +8,8 @@
*/
@interface CPKPopover : NSPopover
 
/** Reflects the final selected color. */
@property(nonatomic, readonly) NSColor *selectedColor;
/** Reflects the final selected color. Setter changes color in open popover. */
@property(nonatomic) NSColor *selectedColor;
 
/** Called before popover closes. */
@property(nonatomic, copy) void (^willClose)();
Loading
Loading
Loading
Loading
@@ -32,6 +32,10 @@
return self.mainViewController.selectedColor;
}
 
- (void)setSelectedColor:(NSColor *)selectedColor {
[self.mainViewController selectColor:selectedColor];
}
#pragma mark - NSPopoverDelegate
 
- (void)popoverWillClose:(NSNotification *)notification {
Loading
Loading
Loading
Loading
@@ -255,7 +255,7 @@ static const CGFloat kMarginBetweenSliders = 8;
 
#pragma mark - NSControlTextEditingDelegate
 
- (void)controlTextDidEndEditing:(NSNotification *)obj {
- (void)controlTextDidChange:(NSNotification *)obj {
NSTextField *textField = [obj object];
NSScanner *scanner = [NSScanner scannerWithString:textField.stringValue];
int i;
Loading
Loading
@@ -264,8 +264,6 @@ static const CGFloat kMarginBetweenSliders = 8;
NSColor *color = [self colorWithHexString:self.hexTextField.stringValue];
if (color) {
self.selectedColor = color;
} else {
self.selectedColor = _selectedColor;
}
} else if (textField == self.redTextField) {
if (isInteger) {
Loading
Loading
@@ -273,8 +271,6 @@ static const CGFloat kMarginBetweenSliders = 8;
green:_selectedColor.greenComponent
blue:_selectedColor.blueComponent
alpha:_selectedColor.alphaComponent];
} else {
self.selectedColor = _selectedColor;
}
} else if (textField == self.greenTextField) {
if (isInteger) {
Loading
Loading
@@ -282,8 +278,6 @@ static const CGFloat kMarginBetweenSliders = 8;
green:i / 255.0
blue:_selectedColor.blueComponent
alpha:_selectedColor.alphaComponent];
} else {
self.selectedColor = _selectedColor;
}
} else if (textField == self.blueTextField) {
if (isInteger) {
Loading
Loading
@@ -291,8 +285,6 @@ static const CGFloat kMarginBetweenSliders = 8;
green:_selectedColor.greenComponent
blue:i / 255.0
alpha:_selectedColor.alphaComponent];
} else {
self.selectedColor = _selectedColor;
}
} else if (self.alphaAllowed && textField == self.alphaTextField) {
if (isInteger) {
Loading
Loading
@@ -300,8 +292,6 @@ static const CGFloat kMarginBetweenSliders = 8;
green:_selectedColor.greenComponent
blue:_selectedColor.blueComponent
alpha:i / 255.0];
} else {
self.selectedColor = _selectedColor;
}
}
}
Loading
Loading
@@ -315,14 +305,7 @@ static const CGFloat kMarginBetweenSliders = 8;
int r;
int g;
int b;
if (hexString.length == 3) {
r = (value >> 8) & 0x0f;
r |= r << 4;
g = (value >> 4) & 0x0f;
g |= g << 4;
b = (value >> 0) & 0x0f;
b |= b << 4;
} else if (hexString.length == 6) {
if (hexString.length == 6) {
r = (value >> 16) & 0xff;
g = (value >> 8) & 0xff;
b = (value >> 0) & 0xff;
Loading
Loading
ColorPicker/ColorPicker/Images.xcassets/ActiveEscapeHatch/ActiveEscapeHatch.png

455 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment