mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 21:42:32 +00:00
added MPCollectionView to track index for context menu
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = "<group>"; };
|
||||
4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = "<group>"; };
|
||||
4CE082C11F6FCD2A0034FF56 /* MPCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPCollectionView.h; sourceTree = "<group>"; };
|
||||
4CE082C21F6FCD2A0034FF56 /* MPCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPCollectionView.m; sourceTree = "<group>"; };
|
||||
4CE2961318429AA5005F01CE /* MPAutotypeKeyPress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeKeyPress.h; sourceTree = "<group>"; };
|
||||
4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeKeyPress.m; sourceTree = "<group>"; };
|
||||
4CE296171842A166005F01CE /* MPAutotypePaste.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypePaste.h; sourceTree = "<group>"; };
|
||||
@@ -896,6 +899,8 @@
|
||||
4C5FE9AD17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m */,
|
||||
4CCEDE28179F203B008402BE /* MPOutlineView.h */,
|
||||
4CCEDE29179F203B008402BE /* MPOutlineView.m */,
|
||||
4CE082C11F6FCD2A0034FF56 /* MPCollectionView.h */,
|
||||
4CE082C21F6FCD2A0034FF56 /* MPCollectionView.m */,
|
||||
);
|
||||
name = Views;
|
||||
sourceTree = "<group>";
|
||||
@@ -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 */,
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="380" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<collectionView focusRingType="none" selectable="YES" id="58">
|
||||
<collectionView focusRingType="none" selectable="YES" id="58" customClass="MPCollectionView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="380" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="primaryBackgroundColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
|
||||
@@ -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
|
||||
|
||||
15
MacPass/MPCollectionView.h
Normal file
15
MacPass/MPCollectionView.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// MPCollectionView.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 18.09.17.
|
||||
// Copyright © 2017 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface MPCollectionView : NSCollectionView
|
||||
|
||||
@property NSUInteger contextMenuIndex; // the index the context menu was last opened. NSNotFound if invalid
|
||||
|
||||
@end
|
||||
44
MacPass/MPCollectionView.m
Normal file
44
MacPass/MPCollectionView.m
Normal file
@@ -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
|
||||
@@ -23,12 +23,13 @@
|
||||
#import "MPIconSelectViewController.h"
|
||||
#import "MPIconHelper.h"
|
||||
#import "MPDocument.h"
|
||||
#import "MPCollectionView.h"
|
||||
#import "MPCollectionViewItem.h"
|
||||
|
||||
@interface MPIconSelectViewController () <NSCollectionViewDelegate>
|
||||
|
||||
/* 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];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user