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

Remember value of escape hatch

parent 0d17315f
No related branches found
No related tags found
No related merge requests found
Showing
with 91 additions and 61 deletions
No preview for this file type
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEscapeHatch.tiff

7.96 KiB | W: | H:

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

7.96 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEscapeHatch.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEscapeHatch.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEscapeHatch.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEscapeHatch.tiff
  • 2-up
  • Swipe
  • Onion skin
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEyedropper.tiff

8.46 KiB | W: | H:

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

8.46 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEyedropper.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEyedropper.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEyedropper.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/ActiveEyedropper.tiff
  • 2-up
  • Swipe
  • Onion skin
ColorPicker/ColorPicker.framework/Versions/A/Resources/Add.tiff

7.09 KiB | W: | H:

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

7.09 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/Add.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Add.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Add.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Add.tiff
  • 2-up
  • Swipe
  • Onion skin
ColorPicker/ColorPicker.framework/Versions/A/Resources/EscapeHatch.tiff

7.86 KiB | W: | H:

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

7.86 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/EscapeHatch.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/EscapeHatch.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/EscapeHatch.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/EscapeHatch.tiff
  • 2-up
  • Swipe
  • Onion skin
ColorPicker/ColorPicker.framework/Versions/A/Resources/Eyedropper.tiff

7.87 KiB | W: | H:

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

7.87 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/Eyedropper.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Eyedropper.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Eyedropper.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Eyedropper.tiff
  • 2-up
  • Swipe
  • Onion skin
Loading
Loading
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>14F27</string>
<string>15A284</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Loading
Loading
ColorPicker/ColorPicker.framework/Versions/A/Resources/Remove.tiff

6.98 KiB | W: | H:

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

6.98 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/Remove.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Remove.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Remove.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/Remove.tiff
  • 2-up
  • Swipe
  • Onion skin
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectedColorIndicator.tiff

7.56 KiB | W: | H:

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

7.56 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectedColorIndicator.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectedColorIndicator.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectedColorIndicator.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectedColorIndicator.tiff
  • 2-up
  • Swipe
  • Onion skin
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectionIndicator.tiff

7.16 KiB | W: | H:

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

7.16 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectionIndicator.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectionIndicator.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectionIndicator.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SelectionIndicator.tiff
  • 2-up
  • Swipe
  • Onion skin
ColorPicker/ColorPicker.framework/Versions/A/Resources/SwatchCheckerboard.tiff

7.07 KiB | W: | H:

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

7.07 KiB | W: | H:

ColorPicker/ColorPicker.framework/Versions/A/Resources/SwatchCheckerboard.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SwatchCheckerboard.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SwatchCheckerboard.tiff
ColorPicker/ColorPicker.framework/Versions/A/Resources/SwatchCheckerboard.tiff
  • 2-up
  • Swipe
  • Onion skin
Loading
Loading
@@ -517,7 +517,7 @@
A6184E9F1BA874020088EF3C /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0640;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = Google;
TargetAttributes = {
A6184EA71BA874020088EF3C = {
Loading
Loading
@@ -690,6 +690,7 @@
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Loading
Loading
@@ -766,6 +767,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Loading
Loading
@@ -785,6 +787,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Loading
Loading
@@ -804,6 +807,7 @@
);
INFOPLIST_FILE = ColorPickerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Loading
Loading
@@ -818,6 +822,7 @@
);
INFOPLIST_FILE = ColorPickerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Loading
Loading
@@ -837,6 +842,7 @@
INFOPLIST_FILE = ColorPickerDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Loading
Loading
@@ -852,6 +858,7 @@
INFOPLIST_FILE = ColorPickerDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Loading
Loading
#import "CPKColorWell.h"
#import "CPKControlsView.h"
#import "CPKPopover.h"
#import "NSObject+CPK.h"
 
Loading
Loading
@@ -32,6 +33,8 @@
@property(nonatomic) BOOL open;
@property(nonatomic) CPKPopover *popover;
@property(nonatomic, copy) void (^willClosePopover)(NSColor *);
@property(nonatomic, weak) NSView *savedPresentingView;
@property(nonatomic) NSRect savedPresentationRect;
 
// The most recently selected color from the picker. Differs from self.color if
// the control is not continuous (self.color is the swatch color).
Loading
Loading
@@ -156,7 +159,49 @@
return NSDragOperationGeneric;
}
 
- (void)colorPanelColorDidChange:(id)sender {
[self.delegate colorChangedByDrag:[sender color]];
}
- (void)useColorPicker:(id)sender {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kCPKUseSystemColorPicker];
[[NSColorPanel sharedColorPanel] close];
[[NSColorPanel sharedColorPanel] setAccessoryView:nil];
if (self.savedPresentingView.window) {
[self openPopOverRelativeToRect:self.savedPresentationRect ofView:self.savedPresentingView];
}
}
- (void)showSystemColorPicker {
NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
// Add an accessory view to use ColorPicker.
NSImage *image = [self cpk_imageNamed:@"ActiveEscapeHatch"];
NSRect frame;
frame.origin = NSZeroPoint;
frame.size = image.size;
NSButton *button = [[NSButton alloc] initWithFrame:frame];
button.bordered = NO;
button.image = image;
button.imagePosition = NSImageOnly;
[button setTarget:self];
[button setAction:@selector(useColorPicker:)];
colorPanel.accessoryView = button;
[colorPanel setTarget:self];
[colorPanel setAction:@selector(colorPanelColorDidChange:)];
[colorPanel orderFront:nil];
colorPanel.showsAlpha = self.alphaAllowed;
colorPanel.color = self.selectedColor;
}
- (void)openPopOverRelativeToRect:(NSRect)presentationRect ofView:(NSView *)presentingView {
self.savedPresentationRect = presentationRect;
self.savedPresentingView = presentingView;
if ([[NSUserDefaults standardUserDefaults] boolForKey:kCPKUseSystemColorPicker]) {
[self showSystemColorPicker];
return;
}
__weak __typeof(self) weakSelf = self;
self.selectedColor = self.color;
self.popover =
Loading
Loading
@@ -166,6 +211,11 @@
initialColor:self.color
alphaAllowed:self.alphaAllowed
selectionDidChange:^(NSColor *color) {
if (!color) {
[weakSelf.popover close];
[self showSystemColorPicker];
return;
}
weakSelf.selectedColor = color;
if (weakSelf.delegate.isContinuous) {
weakSelf.color = color;
Loading
Loading
#import <Cocoa/Cocoa.h>
 
// User defaults key with BOOL value.
extern NSString *const kCPKUseSystemColorPicker;
/**
* Draws a row of controls: add favorite, remove favorite, pick color, and swatch.
*/
Loading
Loading
@@ -17,8 +20,14 @@
/** 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);
/** Replace popover with native color picker. */
@property(nonatomic, copy) void (^useNativeColorPicker)();
/**
* Use the system color picker? Setting this to YES opens the picker and adjusts the icon to
* indicate it's active.
*/
@property(nonatomic) BOOL useSystemColorPicker;
 
/** Reports this view's nominal height */
+ (CGFloat)desiredHeight;
Loading
Loading
Loading
Loading
@@ -8,13 +8,13 @@ static const CGFloat kLeftMargin = 8;
static const CGFloat kRightMargin = 8;
static const CGFloat kTopMargin = 0;
static const CGFloat kBottomMargin = 8;
NSString *const kCPKUseSystemColorPicker = @"kCPKUseSystemColorPicker";
 
@interface CPKControlsView()
@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
@@ -62,7 +62,6 @@ static const CGFloat kBottomMargin = 8;
kRightMargin,
NSHeight(self.addFavorite.frame))];
[self addSubview:self.swatch];
}
return self;
}
Loading
Loading
@@ -102,10 +101,19 @@ static const CGFloat kBottomMargin = 8;
}
 
- (void)setUseSystemColorPicker:(BOOL)useSystemColorPicker {
_useSystemColorPicker = useSystemColorPicker;
if (useSystemColorPicker == _useSystemColorPicker) {
return;
}
[[NSUserDefaults standardUserDefaults] setBool:useSystemColorPicker
forKey:kCPKUseSystemColorPicker];
_useSystemColorPicker = useSystemColorPicker;
self.escapeHatch.image =
self.useSystemColorPicker ? [self cpk_imageNamed:@"ActiveEscapeHatch"] :
[self cpk_imageNamed:@"EscapeHatch"];
if (_useNativeColorPicker) {
__weak __typeof(self) weakSelf = self;
weakSelf.useNativeColorPicker(useSystemColorPicker);
}
}
 
#pragma mark - Actions
Loading
Loading
@@ -133,10 +141,7 @@ static const CGFloat kBottomMargin = 8;
}
 
- (void)escapeHatch:(id)sender {
if (_toggleNativePickerBlock) {
self.useSystemColorPicker = !self.useSystemColorPicker;
_toggleNativePickerBlock(self.useSystemColorPicker);
}
}
 
@end
Loading
Loading
@@ -14,6 +14,7 @@ const CGFloat kFavoritesHeight = 100;
static const CGFloat kLeftMargin = 8;
static const CGFloat kRightMargin = 8;
static const CGFloat kBottomMargin = 8;
static NSInteger gSystemColorPickerReferenceCount = 0;
 
@interface CPKMainViewController ()
@property(nonatomic, copy) void (^block)(NSColor *);
Loading
Loading
@@ -22,7 +23,6 @@ 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
@@ -98,22 +98,9 @@ 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.controlsView.useNativeColorPicker = ^() {
if (weakSelf.block) {
weakSelf.block(nil);
}
};
self.favoritesView =
Loading
Loading
@@ -148,37 +135,9 @@ 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)viewDidAppear {
self.controlsView.useSystemColorPicker =
[[NSUserDefaults standardUserDefaults] boolForKey:kCPKUseSystemColorPicker];
}
 
- (void)selectColor:(NSColor *)color {
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.googlecode.iterm2.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Loading
Loading
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