mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-20 15:39:34 +00:00
Moved multiple instances of entry menu delegate to app delegate
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
|
||||
APPKIT_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
|
||||
|
||||
@class MPEntryContextMenuDelegate;
|
||||
|
||||
@interface MPAppDelegate : NSObject <NSApplicationDelegate, NSMenuDelegate>
|
||||
|
||||
@property (strong) IBOutlet NSMenuItem *saveMenuItem;
|
||||
@@ -32,6 +34,8 @@ APPKIT_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
|
||||
@property (strong) IBOutlet NSMenu *itemMenu;
|
||||
@property (strong) IBOutlet NSMenu *importMenu;
|
||||
|
||||
@property (strong, readonly) MPEntryContextMenuDelegate *itemActionMenuDelegate;
|
||||
|
||||
@property (nonatomic, assign) BOOL isAllowedToStoreKeyFile;
|
||||
|
||||
- (IBAction)checkForUpdates:(id)sender;
|
||||
|
||||
@@ -55,8 +55,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
||||
@private
|
||||
MPDockTileHelper *_dockTileHelper;
|
||||
MPUserNotificationCenterDelegate *_userNotificationCenterDelegate;
|
||||
MPEntryContextMenuDelegate *_entryContextMenuDelegate;
|
||||
|
||||
BOOL _shouldOpenFile; // YES if app was started to open a
|
||||
}
|
||||
|
||||
@@ -65,6 +63,8 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
||||
@property (strong, nonatomic) MPPreferencesWindowController *preferencesController;
|
||||
@property (strong, nonatomic) MPPasswordCreatorViewController *passwordCreatorController;
|
||||
|
||||
@property (strong) MPEntryContextMenuDelegate *itemActionMenuDelegate;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPAppDelegate
|
||||
@@ -81,7 +81,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_userNotificationCenterDelegate = [[MPUserNotificationCenterDelegate alloc] init];
|
||||
_entryContextMenuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
||||
self.itemActionMenuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
||||
/* We know that we do not use the variable after instantiation */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
@@ -130,7 +130,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
||||
for(NSMenuItem *item in [MPContextMenuHelper contextMenuItemsWithItems:MPContextMenuFull]) {
|
||||
[self.itemMenu addItem:item];
|
||||
}
|
||||
self.itemMenu.delegate = _entryContextMenuDelegate;
|
||||
self.itemMenu.delegate = self.itemActionMenuDelegate;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#import "MPValueTransformerHelper.h"
|
||||
#import "MPEntryContextMenuDelegate.h"
|
||||
|
||||
#import "NSApplication+MPAdditions.h"
|
||||
|
||||
#import "KeePassKit/KeePassKit.h"
|
||||
#import "KPKNode+IconImage.h"
|
||||
|
||||
@@ -68,8 +70,6 @@ NSString *const _MPTableStringCellView = @"StringCell";
|
||||
NSString *const _MPTableSecurCellView = @"PasswordCell";
|
||||
|
||||
@interface MPEntryViewController () {
|
||||
/* TODO unify delegation */
|
||||
MPEntryContextMenuDelegate *_menuDelegate;
|
||||
BOOL _isDisplayingContextBar;
|
||||
BOOL _didUnlock;
|
||||
}
|
||||
@@ -103,7 +103,6 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
||||
_entryArrayController = [[NSArrayController alloc] init];
|
||||
_dataSource = [[MPEntryTableDataSource alloc] init];
|
||||
_dataSource.viewController = self;
|
||||
_menuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
||||
_contextBarViewController = [[MPContextBarViewController alloc] init];
|
||||
[self _setupEntryBindings];
|
||||
}
|
||||
@@ -604,7 +603,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
|
||||
for(NSMenuItem *item in items) {
|
||||
[menu addItem:item];
|
||||
}
|
||||
menu.delegate = _menuDelegate;
|
||||
menu.delegate = NSApp.mp_delegate.itemActionMenuDelegate;
|
||||
self.entryTable.menu = menu;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPDocument.h"
|
||||
|
||||
#import "NSApplication+MPAdditions.h"
|
||||
#import "MPAppDelegate.h"
|
||||
|
||||
NSString *const MPToolbarItemLock = @"TOOLBAR_LOCK";
|
||||
NSString *const MPToolbarItemAddGroup = @"TOOLBAR_ADD_GROUP";
|
||||
NSString *const MPToolbarItemAddEntry = @"TOOLBAR_ADD_ENTRY";
|
||||
@@ -49,7 +52,6 @@ NSString *const MPToolbarItemAutotype = @"TOOLBAR_AUTOTYPE";
|
||||
|
||||
@interface MPToolbarDelegate() {
|
||||
MPAddEntryContextMenuDelegate *_addEntryMenuDelegate;
|
||||
MPEntryContextMenuDelegate * _entryActionContextMenuDelegate;
|
||||
BOOL _didShowToolbarForSearch;
|
||||
BOOL _didAddSearchfieldForSearch;
|
||||
NSToolbarDisplayMode _displayModeBeforeSearch;
|
||||
@@ -94,7 +96,6 @@ NSString *const MPToolbarItemAutotype = @"TOOLBAR_AUTOTYPE";
|
||||
_toolbarImages = [self createToolbarImages];
|
||||
_toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:[self.toolbarIdentifiers count]];
|
||||
_addEntryMenuDelegate = [[MPAddEntryContextMenuDelegate alloc] init];
|
||||
_entryActionContextMenuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -137,7 +138,7 @@ NSString *const MPToolbarItemAutotype = @"TOOLBAR_AUTOTYPE";
|
||||
|
||||
popupButton.frame = newFrame;
|
||||
popupButton.menu = menu;
|
||||
menu.delegate = _entryActionContextMenuDelegate;
|
||||
menu.delegate = NSApp.mp_delegate.itemActionMenuDelegate;
|
||||
item.menuFormRepresentation = menuRepresentation;
|
||||
item.view = popupButton;
|
||||
}
|
||||
|
||||
@@ -24,10 +24,13 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class MPAppDelegate;
|
||||
|
||||
@interface NSApplication (MPAdditions)
|
||||
|
||||
@property (copy, readonly) NSString *applicationName;
|
||||
@property (copy, readonly, nullable) NSURL *applicationSupportDirectoryURL;
|
||||
@property (nullable, readonly, weak) MPAppDelegate *mp_delegate;
|
||||
|
||||
- (NSURL *_Nullable)applicationSupportDirectoryURL:(BOOL)create;
|
||||
- (void)relaunchAfterDelay:(CGFloat)seconds;
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
@implementation NSApplication (MPAdditions)
|
||||
|
||||
@dynamic mp_delegate;
|
||||
|
||||
- (NSString *)applicationName {
|
||||
return [NSBundle.mainBundle.infoDictionary[@"CFBundleName"] copy];
|
||||
}
|
||||
@@ -60,4 +62,8 @@
|
||||
[self terminate:nil];
|
||||
}
|
||||
|
||||
- (MPAppDelegate *)mp_delegate {
|
||||
return (MPAppDelegate *)self.delegate;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user