mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-23 20:59:27 +00:00
Searching for a workaround for NSOpenPanel validation bug
This commit is contained in:
17
MacPass/KPKFormat+MPUTIDetection.h
Normal file
17
MacPass/KPKFormat+MPUTIDetection.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// KPKFormat+MPUTIDetection.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 19/11/14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKFormat.h"
|
||||
|
||||
@interface KPKFormat (MPUTIDetection)
|
||||
|
||||
- (NSString *)typeForData:(NSData *)data;
|
||||
|
||||
- (NSString *)typeForContentOfURL:(NSURL *)url;
|
||||
|
||||
@end
|
||||
37
MacPass/KPKFormat+MPUTIDetection.m
Normal file
37
MacPass/KPKFormat+MPUTIDetection.m
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// KPKFormat+MPUTIDetection.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 19/11/14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKFormat+MPUTIDetection.h"
|
||||
|
||||
#import "MPConstants.h"
|
||||
|
||||
@implementation KPKFormat (MPUTIDetection)
|
||||
|
||||
- (NSDictionary *)_typeToUTIdictionary {
|
||||
static NSDictionary *typeToUTI;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
typeToUTI = @{
|
||||
@(KPKLegacyVersion) : MPLegacyDocumentUTI,
|
||||
@(KPKXmlVersion) : MPXMLDocumentUTI
|
||||
};
|
||||
});
|
||||
return typeToUTI;
|
||||
}
|
||||
|
||||
- (NSString *)typeForData:(NSData *)data {
|
||||
KPKVersion version = [self databaseVersionForData:data];
|
||||
return [self _typeToUTIdictionary][@(version)];
|
||||
}
|
||||
|
||||
- (NSString *)typeForContentOfURL:(NSURL *)url {
|
||||
NSData *data = [NSData dataWithContentsOfURL:url];
|
||||
return [self typeForData:data];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -7,9 +7,13 @@
|
||||
//
|
||||
|
||||
#import "MPDocumentController.h"
|
||||
#import "MPConstants.h"
|
||||
|
||||
#import "HNHCommon.h"
|
||||
|
||||
#import "KPKFormat.h"
|
||||
#import "KPKFormat+MPUTIDetection.h"
|
||||
|
||||
@interface MPDocumentController ()
|
||||
|
||||
@property (strong) IBOutlet NSView *accessoryView;
|
||||
@@ -43,8 +47,18 @@
|
||||
- (IBAction)toggleAllowAllFilesButton:(id)sender {
|
||||
NSButton *button = (NSButton *)sender;
|
||||
self.allowAllFiles = HNHBoolForState(button.state);
|
||||
self.openPanel.allowedFileTypes = self.allowAllFiles ? nil : @[@".kdb", @".kdbx"];
|
||||
//self.openPanel.directoryURL = self.openPanel.directoryURL;
|
||||
self.openPanel.allowedFileTypes = self.allowAllFiles ? nil : @[MPLegacyDocumentUTI, MPXMLDocumentUTI];
|
||||
self.openPanel.canChooseDirectories = self.allowAllFiles;
|
||||
self.openPanel.delegate = self.allowAllFiles ? self : nil;
|
||||
[self.openPanel validateVisibleColumns];
|
||||
}
|
||||
|
||||
- (NSString *)typeForContentsOfURL:(NSURL *)url error:(NSError *__autoreleasing *)outError {
|
||||
NSString *detectedType = [[KPKFormat sharedFormat] typeForContentOfURL:url];
|
||||
if(nil != detectedType) {
|
||||
return detectedType;
|
||||
}
|
||||
return [super typeForContentsOfURL:url error:outError];
|
||||
}
|
||||
|
||||
#pragma mark NSOpenSavePanelDelegate
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
|
||||
- (void)_showCustomBrowserSelection:(id)sender {
|
||||
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
||||
NSURL *applicationURL = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSSystemDomainMask][0];
|
||||
NSURL *applicationURL = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSLocalDomainMask][0];
|
||||
[openPanel setDirectoryURL:applicationURL];
|
||||
[openPanel setAllowsMultipleSelection:NO];
|
||||
[openPanel setCanChooseDirectories:NO];
|
||||
|
||||
Reference in New Issue
Block a user