Browse files

Show the actual current color in the ‘copy as’ menu

  • Loading branch information...
1 parent b49a1f3 commit 232aa03e42613c4816150c1f31421d921323c0a7 @alloy alloy committed Mar 30, 2010
Showing with 23 additions and 6 deletions.
  1. +4 −0 ApplicationController.h
  2. +8 −1 ApplicationController.m
  3. +2 −1 FTColorPanel.h
  4. +7 −3 FTColorPanel.m
  5. +2 −1 NSColorAdditions.m
View
4 ApplicationController.h
@@ -1,10 +1,14 @@
#import <Cocoa/Cocoa.h>
#import "FTColorPanel.h"
+#define COPY_AS_MENU @"Copy as…"
+
@interface ApplicationController : NSObject <NSWindowDelegate> {
FTColorPanel *panel;
}
+-(BOOL)validateMenuItem:(NSMenuItem *)item;
+
-(IBAction)copy:(id)sender;
-(IBAction)copyAs:(id)sender;
-(IBAction)paste:(id)sender;
View
9 ApplicationController.m
@@ -7,8 +7,15 @@ -(void)awakeFromNib {
[panel makeKeyAndOrderFront: self];
}
+-(BOOL)validateMenuItem:(NSMenuItem *)item {
+ if ([[[item menu] title] isEqualToString: COPY_AS_MENU]) {
+ [item setTitle: [panel representationStringOfColorInMode:[item tag] shortVersion:NO]];
+ }
+ return YES;
+}
+
-(IBAction)copy:(id)sender {
- NSArray *contents = [NSArray arrayWithObject: [panel representationStringOfColor: NO]];
+ NSArray *contents = [NSArray arrayWithObject: [panel representationStringOfCurrentColorMode: NO]];
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
View
3 FTColorPanel.h
@@ -19,6 +19,7 @@
-(int)colorMode;
-(void)setColorMode:(int)colorMode;
--(NSString *)representationStringOfColor:(BOOL)shortVersion;
+-(NSString *)representationStringOfCurrentColorMode:(BOOL)shortVersion;
+-(NSString *)representationStringOfColorInMode:(int)colorMode shortVersion:(BOOL)shortVersion;
-(void)updateStringRepresentationOfColor;
@end
View
10 FTColorPanel.m
@@ -71,10 +71,14 @@ -(void)setColor:(NSColor *)color {
[self updateStringRepresentationOfColor];
}
--(NSString *)representationStringOfColor:(BOOL)shortVersion {
+-(NSString *)representationStringOfCurrentColorMode:(BOOL)shortVersion {
+ return [self representationStringOfColorInMode:_colorMode shortVersion:shortVersion];
+}
+
+-(NSString *)representationStringOfColorInMode:(int)colorMode shortVersion:(BOOL)shortVersion {
NSColor *color = [self color];
- switch (_colorMode) {
+ switch (colorMode) {
case HEX_COLOR_MODE: return [color toHexString];
case RGB_COLOR_MODE: return [color toRGBString: shortVersion];
case RGBA_COLOR_MODE: return [color toRGBAString: shortVersion];
@@ -88,6 +92,6 @@ -(NSString *)representationStringOfColor:(BOOL)shortVersion {
}
-(void)updateStringRepresentationOfColor {
- [colorCodeField setStringValue: [self representationStringOfColor: YES]];
+ [colorCodeField setStringValue: [self representationStringOfCurrentColorMode: YES]];
}
@end
View
3 NSColorAdditions.m
@@ -169,8 +169,9 @@ -(NSString *)toObjcNSColor:(BOOL)shortVersion {
}
-(NSString *)toMacRubyNSColor:(BOOL)shortVersion {
- if (shortVersion)
+ if (shortVersion) {
return [self toObjcNSColor: YES];
+ }
NSColor *color = [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace];

0 comments on commit 232aa03

Please sign in to comment.