From fd7a77f6257a4af0050186ef3062190e77ada8a6 Mon Sep 17 00:00:00 2001 From: michael starke Date: Fri, 8 Mar 2013 01:08:36 +0100 Subject: [PATCH] Added a shad to the inspector Inspector now shows selected items (image,title) still no editing --- MacPass.xcodeproj/project.pbxproj | 6 + MacPass/GeneralSettings.xib | 3 +- MacPass/InspectorTabView.xib | 160 +++++++----------------- MacPass/MPEntryViewController.h | 4 +- MacPass/MPEntryViewController.m | 31 +++-- MacPass/MPInspectorTabViewController.m | 71 ++++++++++- MacPass/MPMainWindowSplitViewDelegate.m | 2 - MacPass/MPShadowBox.h | 21 ++++ MacPass/MPShadowBox.m | 68 ++++++++++ MacPass/MacPass-Info.plist | 2 +- 10 files changed, 228 insertions(+), 140 deletions(-) create mode 100644 MacPass/MPShadowBox.h create mode 100644 MacPass/MPShadowBox.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 5c4db135..4a2aef4e 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -106,6 +106,7 @@ 4CE06D7D16DEF3FE00840E3A /* MPButtonBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE06D7C16DEF3FE00840E3A /* MPButtonBar.m */; }; 4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */; }; 4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8247416E2F2B900573141 /* MPOverlayView.m */; }; + 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CFC53BE16E94729007396BE /* MPShadowBox.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -289,6 +290,8 @@ 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayWindowController.m; sourceTree = ""; }; 4CE8247316E2F2B900573141 /* MPOverlayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOverlayView.h; sourceTree = ""; }; 4CE8247416E2F2B900573141 /* MPOverlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayView.m; sourceTree = ""; }; + 4CFC53BD16E94729007396BE /* MPShadowBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPShadowBox.h; sourceTree = ""; }; + 4CFC53BE16E94729007396BE /* MPShadowBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPShadowBox.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -323,6 +326,8 @@ 4C69A73916D589DF00EC1B1A /* MPGradientView.m */, 4CE8247316E2F2B900573141 /* MPOverlayView.h */, 4CE8247416E2F2B900573141 /* MPOverlayView.m */, + 4CFC53BD16E94729007396BE /* MPShadowBox.h */, + 4CFC53BE16E94729007396BE /* MPShadowBox.m */, ); name = Views; sourceTree = ""; @@ -876,6 +881,7 @@ 4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */, 4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */, 4C77547516E55FE800970E02 /* MPInspectorTabViewController.m in Sources */, + 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPass/GeneralSettings.xib b/MacPass/GeneralSettings.xib index 96998bba..499ddc09 100644 --- a/MacPass/GeneralSettings.xib +++ b/MacPass/GeneralSettings.xib @@ -48,7 +48,6 @@ {{146, 91}, {127, 26}} - _NS:9 {750, 751} YES @@ -484,7 +483,7 @@ - 407 + 418 diff --git a/MacPass/InspectorTabView.xib b/MacPass/InspectorTabView.xib index 2d28b2a3..312e2686 100644 --- a/MacPass/InspectorTabView.xib +++ b/MacPass/InspectorTabView.xib @@ -65,7 +65,7 @@ LucidaGrande 12 - 4883 + 16 _NS:9 @@ -259,7 +259,7 @@ {{86, 315}, {135, 22}} - + _NS:9 YES @@ -445,6 +445,7 @@ {{229, 313}, {31, 25}} + _NS:22 YES @@ -480,30 +481,9 @@ 256 - - - - 268 - {{122, 233}, {66, 17}} - - - _NS:1535 - YES - - 68157504 - 272630784 - Advanced - - _NS:1535 - - - - - NO - - + {280, 482} - + _NS:28 Notes @@ -848,41 +828,7 @@ 56 - - - - - 5 - 0 - - 5 - 1 - - 125 - - 1000 - - 3 - 9 - 3 - - - - 10 - 0 - - 10 - 1 - - 0.0 - - 1000 - - 5 - 22 - 2 - - + @@ -1441,21 +1387,6 @@ - - 105 - - - - - 109 - - - - - 110 - - - 131 @@ -1469,21 +1400,11 @@ - - 134 - - - 135 - - 147 - - - 148 @@ -1514,24 +1435,6 @@ - - 208 - - - - - - - - 209 - - - - - 211 - - - 212 @@ -1578,11 +1481,6 @@ - - 237 - - - 238 @@ -1838,6 +1736,31 @@ + + 110 + + + + + 109 + + + + + 134 + + + + + 147 + + + + + 105 + + + @@ -1882,10 +1805,6 @@ 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 @@ -1896,7 +1815,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1956,11 +1874,9 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - - - + MPShadowBox com.apple.InterfaceBuilder.CocoaPlugin + MPShadowBox @@ -2005,7 +1921,7 @@ - 335 + 360 @@ -2041,6 +1957,14 @@ ./Classes/MPInspectorTabViewController.h + + MPShadowBox + NSView + + IBProjectSource + ./Classes/MPShadowBox.h + + MPViewController NSViewController diff --git a/MacPass/MPEntryViewController.h b/MacPass/MPEntryViewController.h index a37cff8e..245ead2b 100644 --- a/MacPass/MPEntryViewController.h +++ b/MacPass/MPEntryViewController.h @@ -14,6 +14,8 @@ APPKIT_EXTERN NSString *const MPEntryTablePasswordColumnIdentifier; APPKIT_EXTERN NSString *const MPEntryTableParentColumnIdentifier; APPKIT_EXTERN NSString *const MPEntryTableURLColumnIdentifier; +APPKIT_EXTERN NSString *const MPDidChangeSelectedEntryNotification; + /* Tags to determine what to copy */ typedef enum { MPCopyUsername, @@ -30,7 +32,7 @@ typedef enum { @property (assign) KdbGroup *activeGroup; -@property (readonly, assign) KdbEntry *selectedEntry; +@property (readonly, assign, nonatomic) KdbEntry *selectedEntry; @property (readonly, retain) NSArrayController *entryArrayController; @property (nonatomic, retain) NSString *filter; diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index fb383df8..fbe0e302 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -17,7 +17,7 @@ #import "MPOverlayWindowController.h" #import "KdbGroup+MPAdditions.h" -#import +NSString *const MPDidChangeSelectedEntryNotification = @"com.macpass.MPDidChangeSelectedEntryNotification"; #define STATUS_BAR_ANIMATION_TIME 0.2 @@ -28,7 +28,6 @@ typedef enum { MPFilterTitles = 8, } MPFilterModeType; - NSString *const MPEntryTableUserNameColumnIdentifier = @"MPUserNameColumnIdentifier"; NSString *const MPEntryTableTitleColumnIdentifier = @"MPTitleColumnIdentifier"; NSString *const MPEntryTablePasswordColumnIdentifier = @"MPPasswordColumnIdentifier"; @@ -62,6 +61,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; @property (assign) KdbEntry *selectedEntry; + @property (assign, nonatomic) MPFilterModeType filterMode; @property (retain, nonatomic) NSDictionary *filterButtonToMode; @@ -78,12 +78,11 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; - (void)_setupEntryMenu; /* Notification handling */ - (void)_didChangeGroupSelectionInOutlineView:(NSNotification *)notification; -- (void)_didChangeEntrySelection:(NSNotification *)notification; - (void)_showFilterBarAnimated:(BOOL)animate; - (void)_hideStatusBarAnimated:(BOOL)animate; - (void)_quickCopyEntryData:(id)sender; -- (KdbEntry *)_selectedEntry; +- (KdbEntry *)_clickedOrSelectedEntry; @end @@ -151,10 +150,8 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; [[urlColumn headerCell] setStringValue:@"URL"]; [self.entryTable bind:NSContentBinding toObject:self.entryArrayController withKeyPath:@"arrangedObjects" options:nil]; - [self.selectedEntry bind:NSValueBinding toObject:self.entryArrayController withKeyPath:NSSelectedObjectBinding options:nil]; [parentColumn setHidden:YES]; } - #pragma mark NSTableViewDelgate - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { @@ -195,6 +192,17 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; return view; } +- (void)tableViewSelectionDidChange:(NSNotification *)notification { + if([self.entryTable selectedRow] < 0) { + self.selectedEntry = nil; + } + else { + self.selectedEntry = [self.entryArrayController arrangedObjects][[self.entryTable selectedRow]]; + } + [[NSNotificationCenter defaultCenter] postNotificationName:MPDidChangeSelectedEntryNotification object:self userInfo:nil]; + +} + #pragma mark Notifications - (void)_didChangeGroupSelectionInOutlineView:(NSNotification *)notification { if([self hasFilter]) { @@ -203,7 +211,8 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; MPOutlineViewDelegate *delegate = [notification object]; KdbGroup *group = delegate.selectedGroup; if(group) { - [self.entryArrayController bind:NSContentArrayBinding toObject:group withKeyPath:@"entries" options:nil]; + [self.entryArrayController setContent:nil]; + [self.entryArrayController addObjects:group.entries]; } else { [self.entryArrayController setContent:nil]; @@ -371,7 +380,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; #pragma makr Action Helper -- (KdbEntry *)_selectedEntry { +- (KdbEntry *)_clickedOrSelectedEntry { NSInteger activeRow = [self.entryTable clickedRow]; /* Fallback to selection e.g. for toolbar actions */ if(activeRow < 0 ) { @@ -397,7 +406,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; } - (void)copyPassword:(id)sender { - KdbEntry *selectedEntry = [self _selectedEntry]; + KdbEntry *selectedEntry = [self _clickedOrSelectedEntry]; if(!selectedEntry) { return; // nothing found to work with; } @@ -408,7 +417,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; } - (void)copyUsername:(id)sender { - KdbEntry *selectedEntry = [self _selectedEntry]; + KdbEntry *selectedEntry = [self _clickedOrSelectedEntry]; if(!selectedEntry) { return; // No entry to work with; } @@ -421,7 +430,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; } - (void)deleteEntry:(id)sender { - KdbEntry *selectedEntry = [self _selectedEntry]; + KdbEntry *selectedEntry = [self _clickedOrSelectedEntry]; if(!selectedEntry) { return; // no entry selected } diff --git a/MacPass/MPInspectorTabViewController.m b/MacPass/MPInspectorTabViewController.m index 190ac558..2bcf8182 100644 --- a/MacPass/MPInspectorTabViewController.m +++ b/MacPass/MPInspectorTabViewController.m @@ -7,6 +7,10 @@ // #import "MPInspectorTabViewController.h" +#import "MPEntryViewController.h" +#import "MPShadowBox.h" +#import "MPIconHelper.h" +#import "KdbLib.h" @interface MPInspectorTabViewController () @@ -14,7 +18,13 @@ @property (assign) IBOutlet NSTextField *itemNameTextfield; @property (assign) IBOutlet NSTabView *tabView; @property (assign) IBOutlet NSSegmentedControl *tabControl; -@property (assign) NSUInteger selectedIndex; +@property (assign) NSUInteger selectedTabIndex; +@property (assign, nonatomic) KdbEntry *selectedEntry; + +- (void)_didChangeSelectedEntry:(NSNotification *)notification; +- (void)_updateContent; +- (void)_clearContent; +- (void)_setInputEnabled:(BOOL)enabled; @end @@ -27,15 +37,66 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { - // init + _selectedEntry = nil; } return self; } - (void)didLoadView { - //[self.tabView bind:NSSelectedIndexBinding toObject:self.tabControl withKeyPath:@"selectedIndex" options:nil]; - [self.tabControl bind:NSSelectedIndexBinding toObject:self withKeyPath:NSSelectedIndexBinding options:nil]; - [self.tabView bind:NSSelectedIndexBinding toObject:self withKeyPath:NSSelectedIndexBinding options:nil]; + + for( NSTabViewItem *item in [self.tabView tabViewItems]){ + ((MPShadowBox *)[item view]).shadowDisplay = MPShadowTop; + } + [[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]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_didChangeSelectedEntry:) + name:MPDidChangeSelectedEntryNotification + object:nil]; + [self _clearContent]; +} + +- (void)_updateContent { + if(self.selectedEntry) { + [self.itemNameTextfield setStringValue:self.selectedEntry.title]; + [self.itemImageView setImage:[MPIconHelper icon:(MPIconType)self.selectedEntry.image ]]; + [self _setInputEnabled:YES]; + } + else { + [self _clearContent]; + } +} + +- (void)_clearContent { + [self _setInputEnabled:NO]; + [self.itemNameTextfield setStringValue:NSLocalizedString(@"INSPECTOR_NO_SELECTION", @"No item selected in inspector")]; + [self.itemImageView setImage:[NSImage imageNamed:NSImageNameActionTemplate]]; +} + +- (void)_setInputEnabled:(BOOL)enabled { + [self.itemImageView setEnabled:enabled]; + [self.itemNameTextfield setTextColor: enabled ? [NSColor controlTextColor] : [NSColor disabledControlTextColor] ]; + [self.itemNameTextfield setEnabled:enabled]; +} + +#pragma mark Notificiations + +- (void)_didChangeSelectedEntry:(NSNotification *)notification { + MPEntryViewController *entryViewController = [notification object]; + if(entryViewController) { + self.selectedEntry = entryViewController.selectedEntry; + } +} + +#pragma mark Properties +- (void)setSelectedEntry:(KdbEntry *)selectedEntry { + if(_selectedEntry != selectedEntry) { + _selectedEntry = selectedEntry; + if(_selectedEntry) {} + [self _updateContent]; + } } @end diff --git a/MacPass/MPMainWindowSplitViewDelegate.m b/MacPass/MPMainWindowSplitViewDelegate.m index 60476884..7e9c3556 100644 --- a/MacPass/MPMainWindowSplitViewDelegate.m +++ b/MacPass/MPMainWindowSplitViewDelegate.m @@ -97,8 +97,6 @@ const CGFloat MPMainWindowSplitViewDelegateMinimumInspectorWidth = 200.0; @throw exception; } } - NSArray *splitterNames = @[ @"Outline", @"Inspector" ]; - NSLog(@"Should Hide %@: %@", splitterNames[dividerIndex], shouldHide ? @"Yes" : @"No" ); return shouldHide; } diff --git a/MacPass/MPShadowBox.h b/MacPass/MPShadowBox.h new file mode 100644 index 00000000..8636cdad --- /dev/null +++ b/MacPass/MPShadowBox.h @@ -0,0 +1,21 @@ +// +// MPShadowBox.h +// MacPass +// +// Created by Michael Starke on 07.03.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +typedef enum { + MPShadowTop = 1 << 0, + MPShadowBottom = 1 << 1, + MPShadowTopAndBottom = MPShadowTop | MPShadowBottom +} MPShadowDisplay; + +@interface MPShadowBox : NSView + +@property (assign, nonatomic) MPShadowDisplay shadowDisplay; + +@end diff --git a/MacPass/MPShadowBox.m b/MacPass/MPShadowBox.m new file mode 100644 index 00000000..f79e6843 --- /dev/null +++ b/MacPass/MPShadowBox.m @@ -0,0 +1,68 @@ +// +// MPShadowBox.m +// MacPass +// +// Created by Michael Starke on 07.03.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#define ELIPSIS_OFFSET 0 +#define ELIPSIS_HEIGHT 20 +#define SHADOW_OFFSET 10 + +#import "MPShadowBox.h" + +@implementation MPShadowBox + +- (id)initWithFrame:(NSRect)frameRect { + self = [super initWithFrame:frameRect]; + if(self) { + _shadowDisplay = MPShadowTopAndBottom; + } + return self; +} + +- (BOOL)isOpaque { + return YES; +} + +- (void)drawRect:(NSRect)dirtyRect { + + dirtyRect = [self bounds]; + [[NSGraphicsContext currentContext] saveGraphicsState]; + + NSColor *topColor = [NSColor colorWithCalibratedWhite:0.9 alpha:1]; + NSColor *bottomColor = [NSColor colorWithCalibratedWhite:0.85 alpha:1]; + NSGradient *gradient = [[NSGradient alloc] initWithColors:@[topColor, bottomColor ]]; + [gradient drawInRect:dirtyRect angle:-90]; + [gradient release]; + + NSShadow *dropShadow = [[NSShadow alloc] init]; + [dropShadow setShadowColor:[NSColor colorWithCalibratedWhite:0 alpha:0.5]]; + [dropShadow setShadowBlurRadius:10]; + [dropShadow set]; + [[NSColor redColor] set]; // Use red to show visual errors + + if(0 != (self.shadowDisplay & MPShadowTop)) { + [dropShadow setShadowOffset:NSMakeSize(0, -SHADOW_OFFSET)]; + NSRect topElispis = NSMakeRect(0, dirtyRect.size.height + ELIPSIS_OFFSET, dirtyRect.size.width, ELIPSIS_HEIGHT); + [[NSBezierPath bezierPathWithOvalInRect:topElispis] fill]; + } + if(0 != (self.shadowDisplay & MPShadowBottom)) { + NSRect bottomElipsis = NSMakeRect(0, - ( ELIPSIS_OFFSET + ELIPSIS_HEIGHT ), dirtyRect.size.width, ELIPSIS_HEIGHT); + [dropShadow setShadowOffset:NSMakeSize(0, SHADOW_OFFSET)]; + [[NSBezierPath bezierPathWithOvalInRect:bottomElipsis] fill]; + } + + [dropShadow release]; + [[NSGraphicsContext currentContext] restoreGraphicsState]; +} + +- (void)setShadowDisplay:(MPShadowDisplay)shadowDisplay { + if(_shadowDisplay != shadowDisplay) { + _shadowDisplay = shadowDisplay; + [self needsDisplay]; + } +} + +@end diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 7c28fe0b..00f96faa 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 42E + 474 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright