Removed unused View stubs

Cleaned the deselectoin/selection behavior on click/select/open/close of databases
This commit is contained in:
michael starke
2013-03-09 16:13:04 +01:00
parent 55a6df90e2
commit 816fb9f29e
26 changed files with 292 additions and 618 deletions

28
MacPass/MPActionHelper.h Normal file
View File

@@ -0,0 +1,28 @@
//
// MPActionHelper.h
// MacPass
//
// Created by Michael Starke on 09.03.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef enum {
MPActionAddEntry, // Add an new entry
MPActionAddGroup, // Add a new group
MPActionEdit, // Edit entry or group
MPActionDelete, // Delete entry or group
MPActionCopyUsername, // copy username to pasteboard
MPActionCopyPassword, // copy password to pasteboard
MPActionCopyURL, // copy url to pasteboard
MPActionOpenURL, // open url in default browser
MPActionToggleInspector,
}
MPActionType;
@interface MPActionHelper : NSObject
+ (SEL)actionOfType:(MPActionType)type;
@end

32
MacPass/MPActionHelper.m Normal file
View File

@@ -0,0 +1,32 @@
//
// MPActionHelper.m
// MacPass
//
// Created by Michael Starke on 09.03.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPActionHelper.h"
@implementation MPActionHelper
+ (SEL)actionOfType:(MPActionType)type {
static NSDictionary *actionDict;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
actionDict = [@{
@(MPActionAddEntry) : @"createEntry:",
@(MPActionAddGroup) : @"createGroup:",
@(MPActionCopyPassword) : @"copyPassword:",
@(MPActionCopyURL) : @"copyURL:",
@(MPActionCopyUsername) : @"copyUsername:",
@(MPActionDelete) : @"deleteEntry:",
@(MPActionEdit) : @"editEntry:",
@(MPActionOpenURL) : @"openURL:",
@(MPActionToggleInspector) : @"toggleInspector:"
} retain];
});
return NSSelectorFromString(actionDict[@(type)]);
}
@end

View File

@@ -11,6 +11,7 @@
#import "MPMainWindowController.h"
#import "MPSettingsController.h"
#import "MPDatabaseController.h"
#import "MPActionHelper.h"
@interface MPAppDelegate ()
@@ -70,8 +71,14 @@
NSMutableArray *items = [NSMutableArray arrayWithCapacity:7];
if(insertCreate) {
NSMenuItem *newGroup = [[NSMenuItem alloc] initWithTitle:@"New Group" action:@selector(createGroup:) keyEquivalent:@"G"];
NSMenuItem *newEntry = [[NSMenuItem alloc] initWithTitle:@"New Entry" action:@selector(createEntry:) keyEquivalent:@"E"];
NSMenuItem *newGroup = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"ADD_GROUP", @"")
action:[MPActionHelper actionOfType:MPActionAddGroup]
keyEquivalent:@"G"];
NSMenuItem *newEntry = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"ADD_ENTRY", @"")
action:[MPActionHelper actionOfType:MPActionAddEntry]
keyEquivalent:@"E"];
[items addObjectsFromArray:@[ newGroup, newEntry ]];
[newEntry release];
[newGroup release];
@@ -80,7 +87,9 @@
if([items count] > 0) {
[items addObject:[NSMenuItem separatorItem]];
}
NSMenuItem *delete = [[NSMenuItem alloc] initWithTitle:@"Delete" action:@selector(deleteEntry:) keyEquivalent:@""];
NSMenuItem *delete = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DELETE", @"")
action:[MPActionHelper actionOfType:MPActionDelete]
keyEquivalent:@""];
[items addObject:delete];
[delete release];
}
@@ -88,13 +97,34 @@
if([items count] > 0) {
[items addObject:[NSMenuItem separatorItem]];
}
NSMenuItem *copyUsername = [[NSMenuItem alloc] initWithTitle:@"Copy Username" action:@selector(copyUsername:) keyEquivalent:@"C"];
NSMenuItem *copyPassword = [[NSMenuItem alloc] initWithTitle:@"Copy Password" action:@selector(copyPassword:) keyEquivalent:@"c"];
NSMenuItem *openURL = [[NSMenuItem alloc] initWithTitle:@"Open URL" action:@selector(openURL:) keyEquivalent:@"U"];
[items addObjectsFromArray:@[ copyUsername, copyPassword, openURL]];
NSMenuItem *copyUsername = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"COPY_USERNAME", @"")
action:[MPActionHelper actionOfType:MPActionCopyUsername]
keyEquivalent:@"C"];
NSMenuItem *copyPassword = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"COPY_PASSWORD", @"")
action:[MPActionHelper actionOfType:MPActionCopyPassword]
keyEquivalent:@"c"];
NSMenu *urlMenu = [[NSMenu alloc] init];
NSMenuItem *urlItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"URL", @"")
action:0
keyEquivalent:@""];
[urlItem setSubmenu:urlMenu];
[urlMenu release];
NSMenuItem *copyURL = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"COPY_URL", @"")
action:[MPActionHelper actionOfType:MPActionCopyURL]
keyEquivalent:@"u"];
NSMenuItem *openURL = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"OPEN_URL", @"")
action:[MPActionHelper actionOfType:MPActionOpenURL]
keyEquivalent:@"U"];
[urlMenu addItem:copyURL];
[urlMenu addItem:openURL];
[openURL release];
[copyURL release];
[items addObjectsFromArray:@[ copyUsername, copyPassword, urlItem]];
[urlItem release];
[copyPassword release];
[copyUsername release];
[openURL release];
}
return items;
}

View File

@@ -1,52 +0,0 @@
//
// MPButtonBar.h
// MacPass
//
// Created by michael starke on 28.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPGradientView.h"
/*
Notifications and userInfo dictionary keys
*/
APPKIT_EXTERN NSString *const MPButtonBarSelectionChangedNotification;
/*
Key in for the Index of the new selection. NSNumber with NSUInteger
*/
APPKIT_EXTERN NSString *const MPButtonBarSelectionIndexKey;
/*
Exception thrown if an illegal delegate is used.
*/
APPKIT_EXTERN NSString *const MPButtonBarInvalidDelegateException;
@class MPButtonBar;
@protocol MPButtonBarDelegate <NSObject>
@required
- (NSUInteger)buttonsInButtonBar:(MPButtonBar *)buttonBar;
@optional
- (NSImage *)buttonBar:(MPButtonBar *)buttonBar imageAtIndex:(NSUInteger)index;
- (NSString *)buttonBar:(MPButtonBar *)buttonBar labelAtIndex:(NSUInteger)index;
/*
A delegate that implements this function automatically gets registred to recive MPButtonBarSelectionDidChangeNotification
The object in the notification is the buttonbar,
The userDictionary contrains the following keys:
MPButtonBarSelectionIndexKey;
*/
- (void)didChangeButtonSelection:(NSNotification *)notification;
@end
@interface MPButtonBar : MPGradientView
@property (nonatomic, assign) id<MPButtonBarDelegate> delegate;
@property (nonatomic, readonly) NSUInteger selectedIndex;
@property (nonatomic, readonly) BOOL hasSelection;
@end

View File

@@ -1,131 +0,0 @@
//
// MPButtonBar.m
// MacPass
//
// Created by michael starke on 28.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPButtonBar.h"
#import "MPButtonBarButton.h"
#define MPBUTTONBAR_BUTTON_MARGIN 5.0;
NSString *const MPButtonBarSelectionChangedNotification = @"MPButtonBarSelectionChangedNotification";
NSString *const MPButtonBarSelectionIndexKey = @"MPButtonBarSelectionIndexKey";
NSString *const MPButtonBarInvalidDelegateException = @"MPButtonBarInvalidDelegateException";
@interface MPButtonBar ()
@property (retain) NSMutableArray *buttons;
@property (nonatomic, assign) NSUInteger selectedIndex;
@property (assign) BOOL delegateSupportsImage;
@property (assign) BOOL delegateSupportsLabel;
- (void)_updateButtons;
- (void)_didClickButton:(id)sender;
@end
@implementation MPButtonBar
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.selectedIndex = NSNotFound;
self.buttons = [NSMutableArray arrayWithCapacity:5];
self.delegateSupportsImage = NO;
self.delegateSupportsLabel = NO;
[self _updateButtons];
}
return self;
}
# pragma mark Layout
- (void)_updateButtons {
NSUInteger currentButtonCount = [self.buttons count];
NSUInteger newButtonCount = 5;//[self.delegate buttonsInButtonBar:self];
/*
remove unused buttons
*/
if(currentButtonCount > newButtonCount) {
NSRange removalRange = NSMakeRange(newButtonCount - 1, currentButtonCount - newButtonCount);
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:removalRange];
NSArray *obsolteButtons = [self.buttons objectsAtIndexes:indexSet];
for(NSButton *button in obsolteButtons) {
[button removeFromSuperviewWithoutNeedingDisplay];
}
[self.buttons removeObjectsInRange:NSMakeRange(newButtonCount - 1, currentButtonCount - newButtonCount)];
}
CGFloat startPosition = MPBUTTONBAR_BUTTON_MARGIN;
for(NSUInteger buttonIndex = 0; buttonIndex < newButtonCount ; buttonIndex++) {
BOOL needsDisplay = NO;
if(buttonIndex >= currentButtonCount) {
NSButton *newButton= [[MPButtonBarButton alloc] initWithFrame:NSMakeRect(0, 0, 30, 30)];
[self addSubview:newButton];
[self.buttons addObject:newButton];
[newButton release];
[newButton setTarget:self];
[newButton setImage:[NSImage imageNamed:NSImageNameActionTemplate]];
[newButton setAction:@selector(_didClickButton:)];
needsDisplay = YES;
}
NSButton *currentButton = self.buttons[buttonIndex];
if (self.delegateSupportsImage) {
[currentButton setImage:[self.delegate buttonBar:self imageAtIndex:buttonIndex]];
needsDisplay = YES;
}
if(self.delegateSupportsLabel) {
[currentButton setStringValue:[self.delegate buttonBar:self labelAtIndex:buttonIndex]];
needsDisplay = YES;
}
[currentButton sizeToFit];
NSRect frame = [currentButton frame];
frame.size.width += 20;
frame.origin.x = startPosition;
[currentButton setFrame:frame];
startPosition += frame.size.width + MPBUTTONBAR_BUTTON_MARGIN;
[self setNeedsDisplay:needsDisplay];
}
}
#pragma mark Button Events
- (void)_didClickButton:(id)sender {
NSUInteger index = [[self subviews] indexOfObject:sender];
if(index == NSNotFound) {
return; // Nothing we need to know about happened;
}
NSDictionary *userInfo = @{ MPButtonBarSelectionIndexKey: @(index) };
[[NSNotificationCenter defaultCenter] postNotificationName:MPButtonBarSelectionChangedNotification object:self userInfo:userInfo];
}
# pragma mark Properties
- (void)setDelegate:(id<MPButtonBarDelegate>)delegate {
if( ![delegate conformsToProtocol:@protocol(MPButtonBarDelegate)]) {
NSException *invalidDelegateException = [NSException exceptionWithName:MPButtonBarInvalidDelegateException reason:@"The Delegate does not conform to the MPButtonBarDelegate protocoll" userInfo:nil];
@throw invalidDelegateException;
}
if(_delegate != delegate) {
if([_delegate respondsToSelector:@selector(didChangeButtonSelection:)]) {
[[NSNotificationCenter defaultCenter] removeObserver:_delegate];
}
_delegate = delegate;
self.delegateSupportsLabel = [delegate respondsToSelector:@selector(buttonBar:labelAtIndex:)];
self.delegateSupportsImage = [delegate respondsToSelector:@selector(buttonBar:imageAtIndex:)];
if([delegate respondsToSelector:@selector(selectionDidChanged:)]) {
[[NSNotificationCenter defaultCenter] addObserver:self.delegate selector:@selector(didChangeButtonSelection:) name:MPButtonBarSelectionChangedNotification object:self];
}
[self _updateButtons];
}
}
- (BOOL)hasSelection {
return self.selectedIndex != NSNotFound;
}
@end

View File

@@ -1,13 +0,0 @@
//
// MPButtonBarButton.h
// MacPass
//
// Created by Michael Starke on 01.03.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface MPButtonBarButton : NSButton
@end

View File

@@ -1,42 +0,0 @@
//
// MPButtonBarButton.m
// MacPass
//
// Created by Michael Starke on 01.03.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPButtonBarButton.h"
@implementation MPButtonBarButton
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setButtonType:NSPushOnPushOffButton];
[self setBordered:NO];
[[self cell] setHighlightsBy:NSContentsCellMask];
[[self cell] setShowsStateBy:NSNoCellMask];
[[self cell] setBackgroundStyle:NSBackgroundStyleRaised];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
if(self.state == NSOnState) {
NSRect drawingRect = [self bounds];
NSColor *edgeColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.2];
NSColor *middelColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0];
NSGradient *borderGradient = [[NSGradient alloc] initWithColors:@[edgeColor, middelColor]];
drawingRect.size.width = 5;
[borderGradient drawInRect:drawingRect relativeCenterPosition:NSMakePoint(-1.0, 0)];
drawingRect.origin.x = [self bounds].size.width - 5;
[borderGradient drawInRect:drawingRect relativeCenterPosition:NSMakePoint(1.0, 0)];
[borderGradient release];
}
[super drawRect:dirtyRect];
}
@end

View File

@@ -126,7 +126,7 @@ NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
}
- (KdbPassword *)passwordHash {
return [[KdbPassword alloc] initWithPassword:self.password passwordEncoding:NSUTF8StringEncoding keyFile:[self.key path]];
return [[[KdbPassword alloc] initWithPassword:self.password passwordEncoding:NSUTF8StringEncoding keyFile:[self.key path]] autorelease];
}
@end

View File

@@ -43,8 +43,8 @@ typedef enum {
- (void)copyUsername:(id)sender;
- (void)copyPassword:(id)sender;
//- (void)copyURL:(id)sender;
//- (void)createEntry:(id)sender;
- (void)copyURL:(id)sender;
- (void)openURL:(id)sender;
- (void)deleteEntry:(id)sender;
@end

View File

@@ -28,6 +28,12 @@ typedef enum {
MPFilterTitles = 8,
} MPFilterModeType;
typedef enum {
MPOverlayInfoPassword,
MPOverlayInfoUsername,
MPOverlayInfoURL,
} MPOVerlayInfoType;
NSString *const MPEntryTableUserNameColumnIdentifier = @"MPUserNameColumnIdentifier";
NSString *const MPEntryTableTitleColumnIdentifier = @"MPTitleColumnIdentifier";
NSString *const MPEntryTablePasswordColumnIdentifier = @"MPPasswordColumnIdentifier";
@@ -81,7 +87,8 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
- (void)_showFilterBarAnimated:(BOOL)animate;
- (void)_hideStatusBarAnimated:(BOOL)animate;
- (void)_quickCopyEntryData:(id)sender;
- (void)_columnDoubleClick:(id)sender;
- (void)_copyToPasteboard:(NSString *)data overlayInfo:(MPOVerlayInfoType)overlayInfoType;
- (KdbEntry *)_clickedOrSelectedEntry;
@end
@@ -127,7 +134,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
[self _hideStatusBarAnimated:NO];
[self.entryTable setDelegate:self];
[self.entryTable setDoubleAction:@selector(_quickCopyEntryData:)];
[self.entryTable setDoubleAction:@selector(_columnDoubleClick:)];
[self.entryTable setTarget:self];
[self _setupEntryMenu];
@@ -210,6 +217,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
}
MPOutlineViewDelegate *delegate = [notification object];
KdbGroup *group = delegate.selectedGroup;
[self.entryTable deselectAll:nil];
if(group) {
[self.entryArrayController setContent:nil];
[self.entryArrayController addObjects:group.entries];
@@ -235,7 +243,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
}
- (void)deselectAll:(id)sender {
[self.entryTable deselectAll:self];
[self.entryTable deselectAll:nil];
}
- (void)clearFilter {
@@ -298,7 +306,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
}
}
#pragma mark Animation
#pragma mark UI Feedback
- (void)_showFilterBarAnimated:(BOOL)animate {
@@ -365,6 +373,29 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
}
}
- (void)_copyToPasteboard:(NSString *)data overlayInfo:(MPOVerlayInfoType)overlayInfoType {
[[MPPasteBoardController defaultController] copyObjects:@[ data ]];
NSImage *infoImage = nil;
NSString *infoText = nil;
switch (overlayInfoType) {
case MPOverlayInfoPassword:
infoImage = [[NSBundle mainBundle] imageForResource:@"00_PasswordTemplate"];
infoText = NSLocalizedString(@"COPIED_PASSWORD", @"Password was copied to the pasteboard");
break;
case MPOverlayInfoURL:
infoImage = [[NSBundle mainBundle] imageForResource:@"01_PackageNetworkTemplate"];
infoText = NSLocalizedString(@"COPIED_URL", @"URL was copied to the pasteboard");
break;
case MPOverlayInfoUsername:
infoImage = [[NSBundle mainBundle] imageForResource:@"09_IdentityTemplate"];
infoText = NSLocalizedString(@"COPIED_USERNAME", @"Username was copied to the pasteboard");
break;
}
[[MPOverlayWindowController sharedController] displayOverlayImage:infoImage label:infoText atView:self.view];
}
#pragma mark EntryMenu
- (void)_setupEntryMenu {
@@ -394,48 +425,40 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
#pragma mark Actions
- (void)_quickCopyEntryData:(id)sender {
NSTableColumn *column = [self.entryTable tableColumns][[self.entryTable clickedColumn]];
NSString *identifier = [column identifier];
if([identifier isEqualToString:MPEntryTablePasswordColumnIdentifier]) {
[self copyPassword:nil];
}
else if([identifier isEqualToString:MPEntryTableUserNameColumnIdentifier]) {
[self copyUsername:nil];
}
}
- (void)copyPassword:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(!selectedEntry) {
return; // nothing found to work with;
if(selectedEntry) {
[self _copyToPasteboard:selectedEntry.password overlayInfo:MPOverlayInfoPassword];
}
[[MPPasteBoardController defaultController] copyObjects:@[ selectedEntry.password ]];
NSImage *image = [[NSBundle mainBundle] imageForResource:@"00_PasswordTemplate"];
NSString *lable = @"Password copied!";
[[MPOverlayWindowController sharedController] displayOverlayImage:image label:lable atView:self.view];
}
- (void)copyUsername:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(!selectedEntry) {
return; // No entry to work with;
if(selectedEntry) {
[self _copyToPasteboard:selectedEntry.username overlayInfo:MPOverlayInfoUsername];
}
}
- (void)copyURL:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(selectedEntry) {
[self _copyToPasteboard:selectedEntry.url overlayInfo:MPOverlayInfoURL];
}
}
- (void)openURL:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(selectedEntry && [selectedEntry.url length] > 0) {
NSURL *webURL = [NSURL URLWithString:selectedEntry.url];
[[NSWorkspace sharedWorkspace] openURL:webURL];
}
[[MPPasteBoardController defaultController] copyObjects:@[ selectedEntry.username ] ];
[[MPPasteBoardController defaultController] copyObjects:@[ selectedEntry.username ]];
NSImage *image = [[NSBundle mainBundle] imageForResource:@"09_IdentityTemplate"];
NSString *lable = @"Username copied!";
[[MPOverlayWindowController sharedController] displayOverlayImage:image label:lable atView:self.view];
}
- (void)deleteEntry:(id)sender {
KdbEntry *selectedEntry = [self _clickedOrSelectedEntry];
if(!selectedEntry) {
return; // no entry selected
if(selectedEntry) {
[self.entryArrayController removeObject:selectedEntry];
}
//[[selectedEntry parent] removeEntry:selectedEntry];
[self.entryArrayController removeObject:selectedEntry];
}
- (void)_toggleFilterSpace:(id)sender {
@@ -456,6 +479,20 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
}
}
- (void)_columnDoubleClick:(id)sender {
NSTableColumn *column = [self.entryTable tableColumns][[self.entryTable clickedColumn]];
NSString *identifier = [column identifier];
if([identifier isEqualToString:MPEntryTablePasswordColumnIdentifier]) {
[self copyPassword:nil];
}
else if([identifier isEqualToString:MPEntryTableUserNameColumnIdentifier]) {
[self copyUsername:nil];
}
else if([identifier isEqualToString:MPEntryTableURLColumnIdentifier]) {
[self copyURL:nil];
}
}
- (void)setFilterMode:(MPFilterModeType)newFilterMode {
if(_filterMode != newFilterMode) {
if(newFilterMode == MPFilterNone) {

View File

@@ -8,6 +8,8 @@
#import "MPInspectorTabViewController.h"
#import "MPEntryViewController.h"
#import "MPOutlineViewDelegate.h"
#import "MPDatabaseController.h"
#import "MPShadowBox.h"
#import "MPIconHelper.h"
#import "KdbLib.h"
@@ -42,6 +44,11 @@
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)didLoadView {
for( NSTabViewItem *item in [self.tabView tabViewItems]){
@@ -55,6 +62,7 @@
selector:@selector(_didChangeSelectedEntry:)
name:MPDidChangeSelectedEntryNotification
object:nil];
[self _clearContent];
}
@@ -94,7 +102,6 @@
- (void)setSelectedEntry:(KdbEntry *)selectedEntry {
if(_selectedEntry != selectedEntry) {
_selectedEntry = selectedEntry;
if(_selectedEntry) {}
[self _updateContent];
}
}

View File

@@ -217,25 +217,26 @@ static CGFloat _outlineSplitterPosition;
if(menuAction == @selector(toggleOutlineView:)) {
NSView *outlineView = [self.splitView subviews][MPSplitViewOutlineViewIndex];
BOOL outlineIsHidden = [self.splitView isSubviewCollapsed:outlineView];
if(outlineIsHidden) {
[menuItem setTitle:@"Show Outline View"];
}
[menuItem setTitle:@"Hide Outline View"];
NSString *title = outlineIsHidden ? NSLocalizedString(@"SHOW_OUTLINE_VIEW", @"") : NSLocalizedString(@"HIDE_OUTLINE_VIEW", @"Hide the Outline View");
[menuItem setTitle:title];
return YES;
}
if( menuAction == @selector(toggleInspector:) ) {
NSView *inspectorView = [self.splitView subviews][MPSplitViewInspectorViewIndex];
BOOL inspectorIsHidden = [self.splitView isSubviewCollapsed:inspectorView];
if(inspectorIsHidden) {
[menuItem setTitle:@"Show Inspecotr"];
}
[menuItem setTitle:@"Hide Inspector"];
NSString *title = inspectorIsHidden ? NSLocalizedString(@"SHOW_INSPECTOR", @"Show the Inspector") : NSLocalizedString(@"HIDE_INSPECTOR", @"Hide the Inspector");
[menuItem setTitle:title];
return YES;
}
return YES;
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem {
return [self.toolbarDelegate validateToolbarItem:theItem];
}
- (void)performFindPanelAction:(id)sender {
[self.window makeFirstResponder:[self.toolbarDelegate.searchItem view]];
}

View File

@@ -71,6 +71,7 @@
- (void)_didOpenDocument:(NSNotification *)notification {
[self.outlineView deselectAll:nil];
[self.outlineView reloadData];
MPDatabaseController *dbContoller = [MPDatabaseController defaultController];
if(dbContoller.database) {

View File

@@ -1,32 +0,0 @@
//
// MPPathBar.h
// MacPass
//
// Created by michael starke on 22.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPGradientView.h"
@class MPPathBar;
/*
Delegate protocoll
*/
@protocol MPPathBarDelegateProtocoll <NSObject>
@required
- (NSUInteger)numberOfItemsInPathBar:(MPPathBar *)pathBar;
- (NSString *)pathbar:(MPPathBar *)pathbar stringAtIndex:(NSUInteger)index;
@optional
- (NSImage *)pathbar:(MPPathBar *)pathbar imageAtIndex:(NSUInteger)index;
@end
@interface MPPathBar : MPGradientView
@property (assign, nonatomic) id<MPPathBarDelegateProtocoll> delegate;
@end

View File

@@ -1,92 +0,0 @@
//
// MPPathBar.m
// MacPass
//
// Created by michael starke on 22.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPPathBar.h"
#import "MPPathBarItemView.h"
#define INTER_BUTTON_SPACING 5.0
@interface MPPathBar ()
@property (retain) NSMutableArray *itemViews;
@property (assign) BOOL delegateSupportsImage;
- (void)update;
- (void)createViews;
- (MPPathBarItemView *)viewForIndex:(NSUInteger)index;
@end
@implementation MPPathBar
- (id)initWithFrame:(NSRect)frame activeGradient:(NSGradient *)activeGradient inactiveGradient:(NSGradient *)inactiveGradient {
self = [super initWithFrame:frame activeGradient:activeGradient inactiveGradient:inactiveGradient];
if(self) {
_itemViews = [[NSMutableArray alloc] initWithCapacity:5];
_delegateSupportsImage = NO;
[self createViews];
}
return self;
}
- (void)dealloc {
self.itemViews = nil;
[super dealloc];
}
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
[self update];
}
- (void)createViews {
NSUInteger items = 5;//[self.delegate numberOfItemsInPathBar:self];
CGFloat startPosition = 0;
for (NSUInteger iIndex = 0; iIndex < items; iIndex++) {
MPPathBarItemView *textField = [self viewForIndex:iIndex];
[textField setFrame:NSMakeRect(startPosition, 0, 20, 20)];
[self addSubview:textField];
}
[self update];
}
- (void)update {
CGFloat startPosition = 0;
for(MPPathBarItemView *view in self.itemViews) {
[view sizeToFit];
NSRect newFrame = [view frame];
newFrame.origin.x = startPosition;
[view setFrame:newFrame];
startPosition += newFrame.size.width + INTER_BUTTON_SPACING;
}
}
- (void)setDelegate:(id<MPPathBarDelegateProtocoll>)delegate {
if(_delegate != delegate) {
_delegate = delegate;
self.delegateSupportsImage = [_delegate respondsToSelector:@selector(pathbar:imageAtIndex:)];
[self update];
}
}
- (MPPathBarItemView *)viewForIndex:(NSUInteger)index {
MPPathBarItemView *itemView = nil;
if([self.itemViews count] > index) {
itemView = self.itemViews[index];
}
if(!itemView) {
itemView = [[[MPPathBarItemView alloc] initWithFrame:NSMakeRect(0, 0, 50, 24)] autorelease];
}
itemView.text = [NSString stringWithFormat:@"Button %ld", (unsigned long)index ];
itemView.image = [NSImage imageNamed:NSImageNameActionTemplate];
//[itemView setStringValue:[self.delegate pathbar:self stringAtIndex:index]];
[self.itemViews addObject:itemView];
return itemView;
}
@end

View File

@@ -1,18 +0,0 @@
//
// MPPathBarItemView.h
// MacPass
//
// Created by michael starke on 22.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface MPPathBarItemView : NSView
@property (retain, nonatomic) NSImage *image;
@property (retain, nonatomic) NSString *text;
- (void)sizeToFit;
@end

View File

@@ -1,105 +0,0 @@
//
// MPPathBarItemView.m
// MacPass
//
// Created by michael starke on 22.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPPathBarItemView.h"
#define IMAGE_TO_TEXT_MARGIN 5.0
@interface MPPathBarItemView ()
@property (retain) NSImageView *imageView;
@property (retain) NSTextField *textField;
@end
@implementation MPPathBarItemView
- (id)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if(self) {
_imageView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 20, 24)];
[[_imageView cell] setImageAlignment:NSImageAlignCenter];
[[_imageView cell] setBackgroundStyle:NSBackgroundStyleRaised];
[[_imageView cell] setBordered:NO];
[[_imageView cell] setDrawsBackground:NO];
[_imageView setImage:[NSImage imageNamed:NSImageNameActionTemplate ]];
_textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 20, 24)];
[_textField setBordered:NO];
[_textField setFont:[NSFont systemFontOfSize:13]];
[_textField setDrawsBackground:NO];
[_textField setEditable:NO];
[_textField setSelectable:NO];
[[_textField cell] setBackgroundStyle:NSBackgroundStyleRaised];
[_textField setStringValue:@"Boo"];
[self addSubview:_textField];
[self addSubview:_imageView];
[self sizeToFit];
[self needsLayout];
}
return self;
}
- (void)setText:(NSString *)text {
if(_text != text) {
[_text release];
_text = [text retain];
[self.textField setStringValue:text];
[self sizeToFit];
}
}
- (void)setImage:(NSImage *)image {
if(_image != image) {
[_image release];
_image = [image retain];
[_imageView setImage:image];
[self sizeToFit];
}
}
- (void)sizeToFit {
const BOOL isAutoResize = [self autoresizesSubviews];/* Disable autoresizing */
[self setAutoresizesSubviews:NO];
NSRect superFrame = [self frame];
/*
Let our subviews calculate their sizes
*/
[self.textField sizeToFit];
//[self.imageView sizeToFit];
NSRect textFrame = [self.textField frame];
NSRect imageFrame = [self.imageView frame];
/*
Determine our size
*/
CGFloat height = MAX(textFrame.size.height, imageFrame.size.height);
CGFloat width = textFrame.size.width + IMAGE_TO_TEXT_MARGIN + imageFrame.size.width;
[self setFrame:NSMakeRect(superFrame.origin.x, superFrame.origin.y, width, height)];
imageFrame.origin.x = 0;
imageFrame.origin.y = 0;
imageFrame.size.height = height;
textFrame.origin.x = imageFrame.size.width + IMAGE_TO_TEXT_MARGIN;
textFrame.origin.y = 0;
textFrame.size.height = height;
[self.textField setFrame:textFrame];
[self.imageView setFrame:imageFrame];
/* Reset the autoresizing */
[self setAutoresizesSubviews:isAutoResize];
}
@end

View File

@@ -1,22 +0,0 @@
//
// MPPathControl.m
// MacPass
//
// Created by Michael Starke on 02.03.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPPathControl.h"
@implementation MPPathControl
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[[self cell] setShowsStateBy:NSNoCellMask];
}
return self;
}
@end

View File

@@ -10,6 +10,14 @@
@implementation MPToolbarButton
- (id)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if(self) {
[self setFocusRingType:NSFocusRingTypeNone];
}
return self;
}
- (void)setControlSize:(NSControlSize)controlSize {
[[self cell] setControlSize:controlSize];
switch (controlSize) {

View File

@@ -10,14 +10,16 @@
#import "MPIconHelper.h"
#import "MPAppDelegate.h"
#import "MPToolbarButton.h"
#import "MPToolbarItem.h"
#import "MPActionHelper.h"
NSString *const MPToolbarItemAddGroup = @"AddGroup";
NSString *const MPToolbarItemAddEntry = @"AddEntry";
NSString *const MPToolbarItemEdit = @"Edit";
NSString *const MPToolbarItemDelete =@"Delete";
NSString *const MPToolbarItemAction = @"Action";
NSString *const MPToolbarItemSearch = @"Search";
NSString *const MPToolbarItemInspector = @"Inspector";
NSString *const MPToolbarItemAddGroup = @"TOOLBAR_ADD_GROUP";
NSString *const MPToolbarItemAddEntry = @"TOOLBAR_ADD_ENTRY";
NSString *const MPToolbarItemEdit = @"TOOLBAR_EDIT";
NSString *const MPToolbarItemDelete =@"TOOLBAR_DELETE";
NSString *const MPToolbarItemAction = @"TOOLBAR_ACTION";
NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
NSString *const MPToolbarItemInspector = @"TOOLBAR_INSPECTOR";
@interface MPToolbarDelegate()
@@ -25,6 +27,9 @@ NSString *const MPToolbarItemInspector = @"Inspector";
@property (retain) NSArray *toolbarIdentifiers;
@property (retain) NSDictionary *toolbarImages;
- (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier;
- (SEL)_actionForToolbarItemIdentifier:(NSString *)identifier;
@end
@implementation MPToolbarDelegate
@@ -33,7 +38,7 @@ NSString *const MPToolbarItemInspector = @"Inspector";
- (id)init {
self = [super init];
if (self) {
_toolbarIdentifiers = [@[ MPToolbarItemAddEntry, MPToolbarItemDelete, MPToolbarItemEdit, MPToolbarItemAddGroup, MPToolbarItemAction, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSpaceItemIdentifier, MPToolbarItemInspector, MPToolbarItemSearch ] retain];
_toolbarIdentifiers = [@[ MPToolbarItemAddEntry, MPToolbarItemDelete, MPToolbarItemAddGroup, MPToolbarItemAction, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSpaceItemIdentifier, MPToolbarItemInspector, MPToolbarItemSearch ] retain];
_toolbarImages = [[self createToolbarImages] retain];
_toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:[self.toolbarIdentifiers count]];
}
@@ -50,9 +55,9 @@ NSString *const MPToolbarItemInspector = @"Inspector";
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
NSToolbarItem *item = self.toolbarItems[itemIdentifier];
if(!item) {
item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
NSString *label = NSLocalizedString(itemIdentifier, @"");
if(!item) {
item = [[MPToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
NSString *label = [self _localizedLabelForToolbarItemIdentifier:itemIdentifier];
[item setLabel:label];
if([itemIdentifier isEqualToString:MPToolbarItemSearch]) {
@@ -71,7 +76,7 @@ NSString *const MPToolbarItemInspector = @"Inspector";
[[popupButton cell] setImageScaling:NSImageScaleProportionallyDown];
[popupButton setTitle:@""];
[popupButton sizeToFit];
NSRect newFrame = [popupButton frame];
newFrame.size.width += 20;
@@ -104,13 +109,7 @@ NSString *const MPToolbarItemInspector = @"Inspector";
[button setImage:image];
[button setImagePosition:NSImageOnly];
[button sizeToFit];
if([itemIdentifier isEqualToString:MPToolbarItemEdit]) {
[button setTarget:nil];
[button setAction:@selector(showEditForm:)];
}
else if( [itemIdentifier isEqualToString:MPToolbarItemInspector]) {
[button setAction:@selector(toggleInspector:)];
}
[button setAction:[self _actionForToolbarItemIdentifier:itemIdentifier]];
NSRect fittingRect = [button frame];
fittingRect.size.width = MAX( (CGFloat)32.0,fittingRect.size.width);
@@ -137,11 +136,35 @@ NSString *const MPToolbarItemInspector = @"Inspector";
NSDictionary *imageDict = @{ MPToolbarItemAddEntry: [MPIconHelper icon:MPIconPassword],
MPToolbarItemAddGroup: [MPIconHelper icon:MPIconPassword],
MPToolbarItemDelete: [NSImage imageNamed:NSImageNameRemoveTemplate],
MPToolbarItemEdit: [MPIconHelper icon:MPIconNotepad],
MPToolbarItemAction: [NSImage imageNamed:NSImageNameActionTemplate],
MPToolbarItemInspector: [NSImage imageNamed:NSImageNameInfo],
};
return imageDict;
}
- (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier {
NSDictionary *labelDict = @{
MPToolbarItemAction: NSLocalizedString(@"ACTION", @""),
MPToolbarItemAddEntry: NSLocalizedString(@"ADD_ENTRY", @""),
MPToolbarItemAddGroup: NSLocalizedString(@"ADD_GROUP", @""),
MPToolbarItemDelete: NSLocalizedString(@"DELETE", @""),
MPToolbarItemEdit: NSLocalizedString(@"EDIT", @""),
MPToolbarItemInspector: NSLocalizedString(@"TOGGLE_INSPECTOR", @""),
MPToolbarItemSearch: NSLocalizedString(@"SEARCH", @"")
};
return labelDict[identifier];
}
- (SEL)_actionForToolbarItemIdentifier:(NSString *)identifier {
NSDictionary *actionDict = @{
MPToolbarItemAddEntry: @(MPActionAddEntry),
MPToolbarItemAddGroup: @(MPActionAddGroup),
MPToolbarItemDelete: @(MPActionDelete),
MPToolbarItemEdit: @(MPActionEdit),
MPToolbarItemInspector: @(MPActionToggleInspector)
};
MPActionType actionType = (MPActionType)[actionDict[identifier] integerValue];
return [MPActionHelper actionOfType:actionType];
}
@end

View File

@@ -1,13 +1,13 @@
//
// MPPathControl.h
// MPToolbarItem.h
// MacPass
//
// Created by Michael Starke on 02.03.13.
// Created by Michael Starke on 09.03.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface MPPathControl : NSPathControl
@interface MPToolbarItem : NSToolbarItem
@end

20
MacPass/MPToolbarItem.m Normal file
View File

@@ -0,0 +1,20 @@
//
// MPToolbarItem.m
// MacPass
//
// Created by Michael Starke on 09.03.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPToolbarItem.h"
#import "MPActionHelper.h"
@implementation MPToolbarItem
- (void)validate {
if(![self.view menu]) {
id target = [NSApp targetForAction:[self action] to:nil from:self];
[self setEnabled:( nil != target )];
}
}
@end

View File

@@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>48A</string>
<string>4B8</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>

View File

@@ -56,7 +56,7 @@
<reference key="NSNextResponder" ref="947682332"/>
<int key="NSvFlags">268</int>
<array class="NSMutableArray" key="NSSubviews"/>
<string key="NSFrameSize">{209, 449}</string>
<string key="NSFrameSize">{200, 449}</string>
<reference key="NSSuperview" ref="947682332"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="938782220"/>
@@ -67,7 +67,7 @@
<reference key="NSNextResponder" ref="947682332"/>
<int key="NSvFlags">256</int>
<array class="NSMutableArray" key="NSSubviews"/>
<string key="NSFrame">{{210, 0}, {383, 449}}</string>
<string key="NSFrame">{{201, 0}, {325, 449}}</string>
<reference key="NSSuperview" ref="947682332"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="350501330"/>
@@ -77,7 +77,7 @@
<object class="NSCustomView" id="350501330">
<reference key="NSNextResponder" ref="947682332"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{594, 0}, {133, 449}}</string>
<string key="NSFrame">{{527, 0}, {200, 449}}</string>
<reference key="NSSuperview" ref="947682332"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>

Binary file not shown.