From 46636445a470a8400045938ef96ebe179e5a3f04 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 11 Mar 2013 02:43:23 +0100 Subject: [PATCH] Popover for image selection now gets created correctly NSPopupimageview now sends action on mouse clicks --- MacPass/IconSelection.xib | 434 ++++++++++--------------- MacPass/InspectorTabView.xib | 10 +- MacPass/MPIconSelectViewController.h | 2 +- MacPass/MPIconSelectViewController.m | 7 +- MacPass/MPInspectorTabViewController.m | 15 + MacPass/MPPopupImageView.m | 51 ++- MacPass/MacPass-Info.plist | 2 +- 7 files changed, 217 insertions(+), 304 deletions(-) diff --git a/MacPass/IconSelection.xib b/MacPass/IconSelection.xib index 48334397..c663fbbf 100644 --- a/MacPass/IconSelection.xib +++ b/MacPass/IconSelection.xib @@ -30,7 +30,7 @@ - NSObject + MPIconSelectViewController FirstResponder @@ -42,21 +42,21 @@ 268 - + 268 - - + + 2304 - - + + 274 - {277, 219} - + {220, 258} + - + _NS:80 {0, 0} {0, 0} @@ -77,12 +77,12 @@ 0 - {{1, 1}, {277, 219}} - + {{1, 1}, {220, 258}} + - + _NS:78 - + 6 System @@ -91,127 +91,117 @@ 4 - - + + -2147483392 {{234, 1}, {15, 143}} - + - + _NS:82 NO - + _doScroller: 1 0.89655172824859619 - - + + -2147483392 {{1, 144}, {233, 15}} - + - _NS:91 NO 1 - + _doScroller: 0.63157892227172852 - {{20, 20}, {279, 221}} + {{8, 6}, {222, 260}} - + _NS:76 133682 - - - + + + 0.25 4 1 - {319, 261} + {237, 274} - + NSView - + 268 - - - - 268 - - Apple PDF pasteboard type - Apple PICT pasteboard type - Apple PNG pasteboard type - NSFilenamesPboardType - NeXT Encapsulated PostScript v1.2 pasteboard type - NeXT TIFF v4.0 pasteboard type - - {{2, 2}, {40, 40}} - - - - _NS:9 - YES - - 134217728 - 33554432 - - NSImage - NSActionTemplate - - _NS:9 - 0 - 3 - 2 - NO - - NO - YES - - - {44, 44} + + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + NSFilenamesPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT TIFF v4.0 pasteboard type + + {48, 48} - _NS:9 - NSView + YES + + 134217728 + 33554432 + _NS:9 + 0 + 0 + 2 + NO + + NO + YES + + + view + + + + 56 + itemPrototype - + - 8 + 63 view - + - 50 + 73 imageView - + - 51 + 74 @@ -244,228 +234,136 @@ 1 - - - - 4 - 0 - - 4 - 1 - - 20 - - 1000 - - 8 - 29 - 3 - - + + 6 0 - + 6 1 - - 20 + + 7 1000 - 8 - 29 + 3 + 9 3 - - - 5 + + + 4 0 - - 5 + + 4 1 - - 20 + + 6 1000 - 8 - 29 + 3 + 9 3 - - + + 3 0 3 1 - - 20 + + 8 1000 - 8 - 29 + 3 + 9 + 3 + + + + 5 + 0 + + 5 + 1 + + 8 + + 1000 + + 3 + 9 3 - 2 - + 57 + - - - + + + - 3 - - + 58 + + - 4 - - + 59 + + - 5 - - + 60 + + - 6 + 61 - 11 - + 65 + - 13 - + 68 + - 14 - + 69 + - 15 - + 70 + - 16 - + 71 + - - - 10 - 0 - - 10 - 1 - - 0.0 - - 1000 - - 5 - 22 - 2 - - - - 9 - 0 - - 9 - 1 - - 0.0 - - 1000 - - 5 - 22 - 2 - - + - 17 - - - - - - 8 - 0 - - 0 - 1 - - 34 - - 1000 - - 3 - 9 - 1 - - - - 7 - 0 - - 0 - 1 - - 34 - - 1000 - - 3 - 9 - 1 - - - - - - 18 - - - - - 30 - - - - - 44 - - - - - 48 - - - - - 49 - - + 72 + + @@ -474,47 +372,49 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - - - + + + + com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - - - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - 51 + 74 + + MPIconSelectViewController + MPViewController + + IBProjectSource + ./Classes/MPIconSelectViewController.h + + + + MPViewController + NSViewController + + IBProjectSource + ./Classes/MPViewController.h + + NSLayoutConstraint NSObject @@ -529,10 +429,6 @@ IBCocoaFramework YES 3 - - NSActionTemplate - {15, 15} - YES diff --git a/MacPass/InspectorTabView.xib b/MacPass/InspectorTabView.xib index b416c820..85ed6515 100644 --- a/MacPass/InspectorTabView.xib +++ b/MacPass/InspectorTabView.xib @@ -61,7 +61,7 @@ YES 67108864 - 0 + 32768 LucidaGrande 12 @@ -147,7 +147,7 @@ YES 134217728 - 33554432 + 0 NSImage NSApplicationIcon @@ -167,7 +167,6 @@ {{0, -2}, {280, 482}} - _NS:9 @@ -399,7 +398,6 @@ {{86, 285}, {135, 22}} - _NS:9 YES @@ -1929,7 +1927,7 @@ MPInspectorTabViewController MPViewController - NSImageView + MPPopupImageView NSTextField NSSegmentedControl NSTabView @@ -1937,7 +1935,7 @@ itemImageView - NSImageView + MPPopupImageView itemNameTextfield diff --git a/MacPass/MPIconSelectViewController.h b/MacPass/MPIconSelectViewController.h index 1072fe69..3585ab32 100644 --- a/MacPass/MPIconSelectViewController.h +++ b/MacPass/MPIconSelectViewController.h @@ -8,6 +8,6 @@ #import "MPViewController.h" -@interface MPIconSelectViewController : MPViewController +@interface MPIconSelectViewController : MPViewController @end diff --git a/MacPass/MPIconSelectViewController.m b/MacPass/MPIconSelectViewController.m index 2eb5c56d..ee67a7f6 100644 --- a/MacPass/MPIconSelectViewController.m +++ b/MacPass/MPIconSelectViewController.m @@ -14,11 +14,16 @@ @implementation MPIconSelectViewController + +- (id)init { + return [self initWithNibName:@"IconSelection" bundle:nil]; +} + - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { - // Initialization code here. + } return self; diff --git a/MacPass/MPInspectorTabViewController.m b/MacPass/MPInspectorTabViewController.m index 10ca3bc3..1064df12 100644 --- a/MacPass/MPInspectorTabViewController.m +++ b/MacPass/MPInspectorTabViewController.m @@ -13,6 +13,7 @@ #import "MPShadowBox.h" #import "MPIconHelper.h" #import "MPPopupImageView.h" +#import "MPIconSelectViewController.h" #import "KdbLib.h" @interface MPInspectorTabViewController () @@ -28,6 +29,7 @@ - (void)_updateContent; - (void)_clearContent; - (void)_setInputEnabled:(BOOL)enabled; +- (void)_showImagePopup:(id)sender; @end @@ -58,6 +60,7 @@ [[self.itemImageView cell] setBackgroundStyle:NSBackgroundStyleRaised]; [self.tabControl bind:NSSelectedIndexBinding toObject:self withKeyPath:@"selectedTabIndex" options:nil]; [self.tabView bind:NSSelectedIndexBinding toObject:self withKeyPath:@"selectedTabIndex" options:nil]; + [self.itemImageView setTarget:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didChangeSelectedEntry:) @@ -85,11 +88,23 @@ } - (void)_setInputEnabled:(BOOL)enabled { + + [self.itemImageView setAction: enabled ? @selector(_showImagePopup:) : NULL ]; [self.itemImageView setEnabled:enabled]; [self.itemNameTextfield setTextColor: enabled ? [NSColor controlTextColor] : [NSColor disabledControlTextColor] ]; [self.itemNameTextfield setEnabled:enabled]; } +#pragma mark Actions + +- (void)_showImagePopup:(id)sender { + NSPopover *popover = [[NSPopover alloc] init]; + popover.behavior = NSPopoverBehaviorTransient; + popover.contentViewController = [[[MPIconSelectViewController alloc] init] autorelease]; + [popover showRelativeToRect:NSZeroRect ofView:self.itemImageView preferredEdge:NSMinYEdge]; + [popover release]; +} + #pragma mark Notificiations - (void)_didChangeSelectedEntry:(NSNotification *)notification { diff --git a/MacPass/MPPopupImageView.m b/MacPass/MPPopupImageView.m index e98bb634..d4ee020a 100644 --- a/MacPass/MPPopupImageView.m +++ b/MacPass/MPPopupImageView.m @@ -8,15 +8,15 @@ #import "MPPopupImageView.h" +#define MPTRIANGLE_HEIGHT 8 +#define MPTRIANGLE_WIDTH 10 +#define MPTRIANGLE_OFFSET 2 + @interface MPPopupImageView () @property (assign) BOOL showOverlay; -@property (retain) NSString *overlayText; -@property (retain) NSDictionary *fontAttributes; -@property (assign) NSSize textSize; - (void)_setupView; -- (NSRect)_centeredFontRectangle; @end @@ -41,20 +41,32 @@ - (void)drawRect:(NSRect)dirtyRect { [super drawRect:dirtyRect]; - if(self.showOverlay) { + if(self.showOverlay && [self isEnabled]) { [[NSGraphicsContext currentContext] saveGraphicsState]; - NSRect rect = NSInsetRect([self bounds], 2, 14); - rect.origin.x = 2; - rect.origin.y = 14; - [[NSColor greenColor] set]; + + + [[NSColor colorWithCalibratedWhite:0 alpha:0.2] set]; + [[NSBezierPath bezierPathWithRoundedRect:[self bounds] xRadius:4 yRadius:4] fill]; + NSShadow *shadow = [[NSShadow alloc] init]; [shadow setShadowBlurRadius:2]; [shadow setShadowOffset:NSMakeSize(0, -1)]; [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0 alpha:0.5]]; [shadow set]; + + NSBezierPath *triangle = [NSBezierPath bezierPath]; + NSPoint left = NSMakePoint([self bounds].size.width - MPTRIANGLE_OFFSET - MPTRIANGLE_WIDTH, MPTRIANGLE_OFFSET + MPTRIANGLE_HEIGHT); + NSPoint right = NSMakePoint(left.x + MPTRIANGLE_WIDTH, left.y); + NSPoint bottom = NSMakePoint(left.x + 0.5 * MPTRIANGLE_WIDTH, MPTRIANGLE_OFFSET); + + [triangle moveToPoint:left]; + [triangle lineToPoint:right]; + [triangle lineToPoint:bottom]; + [triangle closePath]; + [[NSColor whiteColor] set]; - NSRectFill([self _centeredFontRectangle]); - [self.overlayText drawInRect:[self _centeredFontRectangle] withAttributes:self.fontAttributes]; + [triangle fill]; + [shadow release]; [[NSGraphicsContext currentContext] restoreGraphicsState]; } @@ -73,24 +85,11 @@ [super mouseExited:theEvent]; } -- (NSRect)_centeredFontRectangle { - CGFloat leftMargin = floor( 0.5 * [self bounds].size.width - self.textSize.width ); - CGFloat bottomMargin = floor( 0.5 * [self bounds].size.height - self.textSize.height); - return NSMakeRect(leftMargin, bottomMargin, self.textSize.width, self.textSize.height); +- (void)mouseDown:(NSEvent *)theEvent { + [self sendAction:[self action] to:[self target]]; } - (void)_setupView { - /* Setup font for drawing an precalulate some things */ - _overlayText = [NSLocalizedString(@"CHANGE_IMAGE", @"Overlay text for popup image") retain]; - NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; - paragraphStyle.alignment = NSCenterTextAlignment; - _fontAttributes = [@{ - NSFontAttributeName :[NSFont boldSystemFontOfSize:11], - NSForegroundColorAttributeName : [NSColor whiteColor], - } retain]; - [paragraphStyle release]; - _textSize = [self.overlayText sizeWithAttributes:_fontAttributes]; - /* Add tracking area for mouse events */ NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow) diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 5963ed38..8458b52b 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 53C + 550 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright