diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 3efe0c2e..f35d6799 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -230,6 +230,7 @@ 4CD884B715BD47080042BBF8 /* DocumentWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */; }; 4CDA35751EBA0CF2003CD59F /* NSString+MPComposedCharacterAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDA35741EBA0CF2003CD59F /* NSString+MPComposedCharacterAdditions.m */; }; 4CDF01A316D1B76700D0AC08 /* MPEntryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */; }; + 4CE082C31F6FCD2A0034FF56 /* MPCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE082C21F6FCD2A0034FF56 /* MPCollectionView.m */; }; 4CE2961518429AA5005F01CE /* MPAutotypeKeyPress.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */; }; 4CE296191842A166005F01CE /* MPAutotypePaste.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE296181842A166005F01CE /* MPAutotypePaste.m */; }; 4CE298EB1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE298EA1795FC2A00DF7BDB /* MPEntryContextMenuDelegate.m */; }; @@ -695,6 +696,8 @@ 4CDA35741EBA0CF2003CD59F /* NSString+MPComposedCharacterAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MPComposedCharacterAdditions.m"; sourceTree = ""; }; 4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = ""; }; 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = ""; }; + 4CE082C11F6FCD2A0034FF56 /* MPCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCollectionView.h; sourceTree = ""; }; + 4CE082C21F6FCD2A0034FF56 /* MPCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPCollectionView.m; sourceTree = ""; }; 4CE2961318429AA5005F01CE /* MPAutotypeKeyPress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeKeyPress.h; sourceTree = ""; }; 4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeKeyPress.m; sourceTree = ""; }; 4CE296171842A166005F01CE /* MPAutotypePaste.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypePaste.h; sourceTree = ""; }; @@ -896,6 +899,8 @@ 4C5FE9AD17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m */, 4CCEDE28179F203B008402BE /* MPOutlineView.h */, 4CCEDE29179F203B008402BE /* MPOutlineView.m */, + 4CE082C11F6FCD2A0034FF56 /* MPCollectionView.h */, + 4CE082C21F6FCD2A0034FF56 /* MPCollectionView.m */, ); name = Views; sourceTree = ""; @@ -1776,6 +1781,7 @@ 4C46B88517063A070046109A /* NSString+MPPasswordCreation.m in Sources */, 4C5A11FE1708DE8700223D8A /* MPPasswordCreatorViewController.m in Sources */, 4CE5B54B173AFBA700207B39 /* MPDocument.m in Sources */, + 4CE082C31F6FCD2A0034FF56 /* MPCollectionView.m in Sources */, 4C4A100F176286FD00BBF2CA /* MPTableView.m in Sources */, 4C8913661A422C8C0071A4CB /* MPFileWatcher.m in Sources */, 4CA334CA18AD60D1008A3322 /* MPWindowAssociationsTableViewDelegate.m in Sources */, diff --git a/MacPass/Base.lproj/IconSelection.xib b/MacPass/Base.lproj/IconSelection.xib index f4d855c9..4c6c8d75 100644 --- a/MacPass/Base.lproj/IconSelection.xib +++ b/MacPass/Base.lproj/IconSelection.xib @@ -23,7 +23,7 @@ - + diff --git a/MacPass/MPActionHelper.h b/MacPass/MPActionHelper.h index d561acbc..c1475247 100644 --- a/MacPass/MPActionHelper.h +++ b/MacPass/MPActionHelper.h @@ -46,8 +46,7 @@ typedef NS_ENUM(NSUInteger, MPActionType) { MPActionShowEntryHistory, // show history MPActionHideEntryHistory, // exit history MPActionPerformAutotypeForSelectedEntry, // Perform Autotype for selected Entry - MPActionRemoveAttachment, // Remove an attachment - MPActionDeleteCustomIcon // delte a custom icon + MPActionRemoveAttachment // Remove an attachment }; /** * Helper to retrieve commonly used actions diff --git a/MacPass/MPCollectionView.h b/MacPass/MPCollectionView.h new file mode 100644 index 00000000..83e475a4 --- /dev/null +++ b/MacPass/MPCollectionView.h @@ -0,0 +1,15 @@ +// +// MPCollectionView.h +// MacPass +// +// Created by Michael Starke on 18.09.17. +// Copyright © 2017 HicknHack Software GmbH. All rights reserved. +// + +#import + +@interface MPCollectionView : NSCollectionView + +@property NSUInteger contextMenuIndex; // the index the context menu was last opened. NSNotFound if invalid + +@end diff --git a/MacPass/MPCollectionView.m b/MacPass/MPCollectionView.m new file mode 100644 index 00000000..7f4014d1 --- /dev/null +++ b/MacPass/MPCollectionView.m @@ -0,0 +1,44 @@ +// +// MPCollectionView.m +// MacPass +// +// Created by Michael Starke on 18.09.17. +// Copyright © 2017 HicknHack Software GmbH. All rights reserved. +// + +#import "MPCollectionView.h" + +@implementation MPCollectionView + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if(self) { + _contextMenuIndex = NSNotFound; + } + return self; +} + +- (instancetype)initWithFrame:(NSRect)frameRect { + self = [super initWithFrame:frameRect]; + if(self) { + _contextMenuIndex = NSNotFound; + } + return self; +} + +- (NSMenu *)menuForEvent:(NSEvent *)event { + self.contextMenuIndex = NSNotFound; + NSPoint point = [self convertPoint:event.locationInWindow fromView:nil]; + NSUInteger count = self.content.count; + for (NSUInteger i = 0; i < count; i++) { + NSRect itemFrame = [self frameForItemAtIndex:i]; + if (NSMouseInRect(point, itemFrame, self.isFlipped)) { + self.contextMenuIndex = i; + break; + } + } + + return [super menuForEvent:event]; +} + +@end diff --git a/MacPass/MPIconSelectViewController.m b/MacPass/MPIconSelectViewController.m index a55c1f59..84b3c027 100644 --- a/MacPass/MPIconSelectViewController.m +++ b/MacPass/MPIconSelectViewController.m @@ -23,12 +23,13 @@ #import "MPIconSelectViewController.h" #import "MPIconHelper.h" #import "MPDocument.h" +#import "MPCollectionView.h" #import "MPCollectionViewItem.h" @interface MPIconSelectViewController () /* UI properties */ -@property (weak) IBOutlet NSCollectionView *iconCollectionView; +@property (weak) IBOutlet MPCollectionView *iconCollectionView; @property (weak) IBOutlet NSButton *imageButton; @end @@ -46,6 +47,10 @@ self.iconCollectionView.delegate = self; [self.iconCollectionView registerForDraggedTypes:@[(NSString *)kUTTypeURL, (NSString *)kUTTypeFileURL]]; + NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; + [menu addItem:[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DELETE", @"") action:@selector(deleteIcon:) keyEquivalent:@""]]; + self.iconCollectionView.menu = menu; + [self _updateCollectionViewContent]; } @@ -95,7 +100,15 @@ } - (void)deleteIcon:(id)sender { - + NSUInteger index = self.iconCollectionView.contextMenuIndex; + NSUInteger firstCustomIndex = [MPIconHelper databaseIcons].count; + if(index < firstCustomIndex) { + return; + } + MPDocument *document = [NSDocumentController sharedDocumentController].currentDocument; + KPKIcon *icon = self.iconCollectionView.content[index]; + [document.tree.metaData removeCustomIcon:icon]; + [self _updateCollectionViewContent]; }