Merge remote-tracking branch 'mstarke/master'

This commit is contained in:
m0yP
2017-01-10 14:51:56 -06:00
20 changed files with 101 additions and 94 deletions

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPEntryInspectorViewController">
@@ -95,10 +96,10 @@
<rect key="frame" x="20" y="26" width="253" height="432"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="F3N-QI-Di5">
<rect key="frame" x="1" y="1" width="251" height="430"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowHeight="36" rowSizeStyle="automatic" viewBased="YES" id="137">
<rect key="frame" x="0.0" y="0.0" width="251" height="0.0"/>
<rect key="frame" x="0.0" y="0.0" width="251" height="430"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="alternateSelectedControlTextColor" catalog="System" colorSpace="catalog"/>
@@ -215,7 +216,6 @@
</tableColumns>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="100" id="KFw-Ma-DSd"/>
@@ -275,10 +275,10 @@
<rect key="frame" x="16" y="26" width="261" height="432"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="k8G-zp-BXZ">
<rect key="frame" x="1" y="1" width="259" height="430"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="54" rowSizeStyle="automatic" viewBased="YES" id="193">
<rect key="frame" x="0.0" y="0.0" width="259" height="0.0"/>
<rect key="frame" x="0.0" y="0.0" width="259" height="430"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -399,7 +399,6 @@
</tableColumns>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="100" id="Car-Dj-KWv"/>
@@ -489,7 +488,7 @@
<constraint firstAttribute="height" constant="22" id="0l5-fD-0eW"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="68">
<font key="font" metaFont="system"/>
<font key="font" size="13" name="Menlo-Regular"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
@@ -743,7 +742,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="caM-L6-UHC">
<rect key="frame" x="0.0" y="0.0" width="259" height="0.0"/>
<rect key="frame" x="0.0" y="0.0" width="259" height="158"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -768,6 +767,7 @@
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JgP-7K-Ugw">
<rect key="frame" x="0.0" y="0.0" width="256" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="dyA-lo-PGa">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -784,7 +784,6 @@
</tableColumns>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="160" id="B8z-Sq-4j9"/>

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPContextBarViewController">

View File

@@ -12,11 +12,17 @@
@property (readonly, copy) NSData *keyData;
/**
Use this method to retrieve the data, since deallocation of a hotkey unregisters it, this could yield unwanted behaviour!
@return data for the default hot key.
*/
+ (NSData *)hotKeyDataWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags;
+ (NSData *)defaultHotKeyData;
+ (instancetype)defaultHotKey;
+ (instancetype)defaultHotKeyWithTask:(DDHotKeyTask)task;
- (instancetype)initWithKeyData:(NSData *)data task:(DDHotKeyTask)task;
- (instancetype)initWithKeyData:(NSData *)data;
+ (instancetype)hotKeyWithKeyData:(NSData *)data task:(DDHotKeyTask)task;
+ (instancetype)hotKeyWithKeyData:(NSData *)data;
@end

View File

@@ -14,45 +14,48 @@
@implementation DDHotKey (MPKeydata)
+ (NSData *)hotKeyDataWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags {
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeInt:keyCode forKey:NSStringFromSelector(@selector(keyCode))];
[archiver encodeInteger:flags forKey:NSStringFromSelector(@selector(modifierFlags))];
[archiver finishEncoding];
return [data copy];
}
+ (NSData *)defaultHotKeyData {
return [self hotKeyDataWithKeyCode:kVK_ANSI_M modifierFlags:kCGEventFlagMaskControl|kCGEventFlagMaskAlternate];
}
+ (instancetype)defaultHotKey {
return [DDHotKey defaultHotKeyWithTask:nil];
}
+ (instancetype)defaultHotKeyWithTask:(DDHotKeyTask)task {
return [[DDHotKey alloc] initWithKeyData:nil task:task];
return [DDHotKey hotKeyWithKeyData:nil task:task];
}
- (instancetype)initWithKeyData:(NSData *)data {
self = [self initWithKeyData:data task:nil];
return self;
+ (instancetype)hotKeyWithKeyData:(NSData *)data {
return [self hotKeyWithKeyData:data task:nil];
}
- (instancetype)initWithKeyData:(NSData *)data task:(DDHotKeyTask)task{
+ (instancetype)hotKeyWithKeyData:(NSData *)data task:(DDHotKeyTask)task {
NSUInteger modifierFlags;
unsigned short keyCode;
if(!data) {
self = [DDHotKey hotKeyWithKeyCode:kVK_ANSI_M modifierFlags:kCGEventFlagMaskControl|kCGEventFlagMaskAlternate task:task];
return [DDHotKey hotKeyWithKeyCode:kVK_ANSI_M modifierFlags:kCGEventFlagMaskControl|kCGEventFlagMaskAlternate task:task];
}
else if([self _getKeyCode:&keyCode modifierFlags:&modifierFlags fromData:data]) {
self = [DDHotKey hotKeyWithKeyCode:keyCode modifierFlags:modifierFlags task:task];
if([self _getKeyCode:&keyCode modifierFlags:&modifierFlags fromData:data]) {
return [DDHotKey hotKeyWithKeyCode:keyCode modifierFlags:modifierFlags task:task];
}
else {
self = nil;
}
return self;
return nil;
}
- (NSData *)keyData {
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeInt:self.keyCode forKey:NSStringFromSelector(@selector(keyCode))];
[archiver encodeInteger:self.modifierFlags forKey:NSStringFromSelector(@selector(modifierFlags))];
[archiver finishEncoding];
return [data copy];
return [self.class hotKeyDataWithKeyCode:self.keyCode modifierFlags:self.modifierFlags];
}
- (BOOL)_getKeyCode:(unsigned short *)keyCode modifierFlags:(NSUInteger *)modifierFlags fromData:(NSData *)data {
+ (BOOL)_getKeyCode:(unsigned short *)keyCode modifierFlags:(NSUInteger *)modifierFlags fromData:(NSData *)data {
if(keyCode == NULL || modifierFlags == NULL || data == nil) {
return NO;
}

View File

@@ -52,7 +52,7 @@
KPKEntry *entry = document.selectedEntries.count == 1 ? document.selectedEntries.lastObject : nil;
NSPasteboard *draggingPasteBoard = [info draggingPasteboard];
NSArray *arrayOfURLs = [draggingPasteBoard readObjectsForClasses:@[[NSArray class]] options:nil];
NSArray *arrayOfURLs = [draggingPasteBoard readObjectsForClasses:@[[NSURL class]] options:nil];
for(NSURL *fileUrl in arrayOfURLs) {
[document addAttachment:fileUrl toEntry:entry];

View File

@@ -147,16 +147,32 @@ static MPAutotypeDaemon *_sharedInstance;
return; // We do not perform Autotype on ourselves
}
NSArray *documents = [self _findAutotypeDocuments];
/* find autotype documents */
NSArray *documents = [NSApp orderedDocuments];
/* No open document, inform the user and return without any action */
if(documents.count == 0) {
/* We do not have a document. This can be
a) there is none - nothing happens
b) there is at least one, but locked - we get called again after the document has been unlocked
*/
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = NSApp.applicationName;
notification.informativeText = NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_DOCUMENTS", "");
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
return;
}
NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
MPDocument *document = evaluatedObject;
return !document.encrypted;}];
NSArray *unlockedDocuments = [documents filteredArrayUsingPredicate:filterPredicate];
/* We look for all unlocked documents, if all open documents are locked, we pop the front most and try to search again */
if(unlockedDocuments.count == 0) {
[NSApp activateIgnoringOtherApps:YES];
[NSApp.mainWindow makeKeyAndOrderFront:self];
/* show the actual document window to the user */
[documents.firstObject showWindows];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil];
return; // wait for the unlock to happen
}
MPAutotypeContext *context = [self _autotypeContextForDocuments:documents forWindowTitle:self.targetWindowTitle preferredEntry:entryOrNil];
/* TODO: that's popping up if the mulit seleciton dialog goes up! */
/* TODO: that's popping up if the mulit selection dialog goes up! */
if(!entryOrNil) {
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = NSApp.applicationName;
@@ -171,22 +187,6 @@ static MPAutotypeDaemon *_sharedInstance;
[self _performAutotypeForContext:context];
}
- (NSArray<MPDocument *> *)_findAutotypeDocuments {
NSArray *documents = [NSApp orderedDocuments];
NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id _Nonnull evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
MPDocument *document = evaluatedObject;
return !document.encrypted;}];
NSArray *unlockedDocuments = [documents filteredArrayUsingPredicate:filterPredicate];
/* We look for all unlocked documents, if all open documents are locked, we pop the front most and try to search again */
if(unlockedDocuments.count == 0 && documents.count > 0) {
[NSApp activateIgnoringOtherApps:YES];
[NSApp.mainWindow makeKeyAndOrderFront:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:nil];
}
return unlockedDocuments;
}
- (MPAutotypeContext *)_autotypeContextForDocuments:(NSArray<MPDocument *> *)documents forWindowTitle:(NSString *)windowTitle preferredEntry:(KPKEntry *)entry {
/*
Query the document to generate a autotype command list for the window title
@@ -230,22 +230,18 @@ static MPAutotypeDaemon *_sharedInstance;
#pragma mark -
#pragma mark Hotkey Registration
- (void)_registerHotKey {
if(!self.hotKeyData) {
return;
}
__weak MPAutotypeDaemon *welf = self;
DDHotKeyTask aTask = ^(NSEvent *event) {
[welf _didPressHotKey];
};
DDHotKey *storedHotkey;
if(nil == self.hotKeyData) {
storedHotkey = [DDHotKey defaultHotKeyWithTask:aTask];
}
else {
storedHotkey = [[DDHotKey alloc] initWithKeyData:self.hotKeyData task:aTask];
}
self.registredHotKey = [[DDHotKeyCenter sharedHotKeyCenter] registerHotKey:storedHotkey];
self.registredHotKey = [[DDHotKeyCenter sharedHotKeyCenter] registerHotKey:[DDHotKey hotKeyWithKeyData:self.hotKeyData task:aTask]];
}
- (void)_unregisterHotKey {
if(nil != self.registredHotKey) {
if(self.registredHotKey) {
[[DDHotKeyCenter sharedHotKeyCenter] unregisterHotKey:self.registredHotKey];
self.registredHotKey = nil;
}

View File

@@ -361,11 +361,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
self.encryptedData = nil;
self.unlockCount += 1;
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidUnlockDatabaseNotification object:self];
/* Make sure to only store */
MPAppDelegate *delegate = (MPAppDelegate *)[NSApp delegate];
if(self.compositeKey.hasKeyFile && self.compositeKey.hasPassword && delegate.isAllowedToStoreKeyFile) {
[self _storeKeyURL:keyFileURL];
}
[self _storeKeyURL:keyFileURL];
}
else {
self.compositeKey = nil; // clear the key?
@@ -768,17 +764,21 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
}
- (void)_storeKeyURL:(NSURL *)keyURL {
if(nil == keyURL) {
return; // no URL to store in the first place
}
MPAppDelegate *delegate = (MPAppDelegate *)[NSApp delegate];
NSAssert(delegate.isAllowedToStoreKeyFile, @"We can only store if we are allowed to do so!");
NSMutableDictionary *keysForFiles = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases] mutableCopy];
if(nil == keysForFiles) {
keysForFiles = [[NSMutableDictionary alloc] initWithCapacity:1];
MPAppDelegate *delegate = (MPAppDelegate *)[NSApp delegate];
if(!delegate.isAllowedToStoreKeyFile || nil == keyURL) {
/* user has removed the keyfile or we should not safe it so remove it */
[keysForFiles removeObjectForKey:self.fileURL.path.sha1HexDigest];
}
else if(self.compositeKey.hasPassword && self.compositeKey.hasKeyFile) {
if(nil == keysForFiles) {
keysForFiles = [[NSMutableDictionary alloc] initWithCapacity:1];
}
keysForFiles[self.fileURL.path.sha1HexDigest] = keyURL.path;
}
if(keysForFiles) {
[[NSUserDefaults standardUserDefaults] setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases];
}
keysForFiles[self.fileURL.path.sha1HexDigest] = keyURL.path;
[[NSUserDefaults standardUserDefaults] setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases];
}
- (void)_cleanupLock {

View File

@@ -350,6 +350,11 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
options:0
metrics:nil
views:views]];
[clipView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]"
options:0
metrics:nil
views:views]];
[[self view] layoutSubtreeIfNeeded];
}
@@ -399,10 +404,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(uuid)), NSStringFromSelector(@selector(UUIDString))]
options:@{ NSConditionallySetsEditableBindingOption: @NO }];
self.uuidTextField.editable = NO;
/*for(id item in items) {
[item bind:NSEnabledBinding toObject:self.entryController withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil];
}*/
}
- (void)_bindAttachments {

View File

@@ -410,7 +410,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
return; // we are showing the correct object right now.
}
}
self.representedObject = document.selectedGroups.count == 1 ? document.selectedGroups.firstObject : nil;
self.representedObject = document.selectedGroups.count == 1 ? document.selectedGroups.lastObject : nil;
}
[self _updateContextBar];
}

View File

@@ -58,7 +58,7 @@
}
- (void)willShowTab {
_hotKey = [[DDHotKey alloc] initWithKeyData:[[NSUserDefaults standardUserDefaults] dataForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]];
_hotKey = [DDHotKey hotKeyWithKeyData:[[NSUserDefaults standardUserDefaults] dataForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]];
/* Change any invalid hotkeys to valid ones? */
self.hotKeyTextField.hotKey = self.hotKey;
}

View File

@@ -110,7 +110,7 @@ NSString *const kMPDeprecatedSettingsKeyDefaultPasswordRounds = @"Ke
kMPSettingsKeyRememberKeyFilesForDatabases: @NO,
kMPSettingsKeySendCommandForControlKey: @YES,
kMPSettingsKeyEnableGlobalAutotype: @NO,
kMPSettingsKeyGlobalAutotypeKeyDataKey: [[DDHotKey defaultHotKey] keyData],
kMPSettingsKeyGlobalAutotypeKeyDataKey: [DDHotKey defaultHotKeyData],
kMPSettingsKeyDefaultGlobalAutotypeSequence: @"{USERNAME}{TAB}{PASSWORD}{ENTER}",
kMPSettingsKeyAutotypeMatchTitle: @YES,
kMPSettingsKeyAutotypeMatchURL: @NO,

View File

@@ -80,7 +80,6 @@
[contentView.subviews.firstObject removeFromSuperview];
}
[contentView addSubview:tabView];
[contentView layout];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[tabView]-0-|"
options:0
metrics:nil
@@ -90,6 +89,7 @@
metrics:nil
views:NSDictionaryOfVariableBindings(tabView)]];
[contentView layout];
[contentView layoutSubtreeIfNeeded];
if([tab respondsToSelector:@selector(didShowTab)]) {
[tab didShowTab];

View File

@@ -292,9 +292,9 @@ NSString *const MPToolbarItemCopyPassword = @"TOOLBAR_COPY_PASSWORD";
_didShowToolbarForSearch = YES;
self.toolbar.visible = YES;
}
_displayModeBeforeSearch = [self.toolbar displayMode];
_displayModeBeforeSearch = self.toolbar.displayMode;
if(_displayModeBeforeSearch == NSToolbarDisplayModeLabelOnly) {
[self.toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
self.toolbar.displayMode = NSToolbarDisplayModeIconAndLabel;
}
/* only make the searchfield first responder if it's not already in an active search */
if(![self.searchField currentEditor]) {

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.