From 1a6d5114b9b2de3045b250a63155aa688e75def7 Mon Sep 17 00:00:00 2001 From: michael starke Date: Sun, 1 Dec 2013 02:29:37 +0100 Subject: [PATCH] IconSelectionView now can be used to set default icons. Setting other Icons is broken for now. Setting custom icons doesn't work at all. --- MacPass/IconSelection.xib | 1 + MacPass/KPKNode+IconImage.m | 4 + MacPass/MPAutotypeContext.h | 5 +- MacPass/MPAutotypeContext.m | 33 +- MacPass/MPAutotypeDaemon.m | 2 +- MacPass/MPEntryViewController.m | 9 +- MacPass/MPIconSelectViewController.h | 9 + MacPass/MPIconSelectViewController.m | 19 +- MacPass/MPInspectorViewController.m | 26 +- MacPass/WorkflowSettings.xib | 976 ++++----------------------- 10 files changed, 227 insertions(+), 857 deletions(-) diff --git a/MacPass/IconSelection.xib b/MacPass/IconSelection.xib index ab9cf547..51df2973 100644 --- a/MacPass/IconSelection.xib +++ b/MacPass/IconSelection.xib @@ -86,6 +86,7 @@ + diff --git a/MacPass/KPKNode+IconImage.m b/MacPass/KPKNode+IconImage.m index b51b3dae..63184865 100644 --- a/MacPass/KPKNode+IconImage.m +++ b/MacPass/KPKNode+IconImage.m @@ -14,6 +14,10 @@ @implementation KPKNode (IconImage) ++ (NSSet *)keyPathsForValuesAffectingIconImage { + return [NSSet setWithArray:@[@"customIcon", @"icon"]]; +} + - (NSImage *)iconImage { if(self.customIcon) { return self.customIcon.image; diff --git a/MacPass/MPAutotypeContext.h b/MacPass/MPAutotypeContext.h index e6f72d4b..dca05f68 100644 --- a/MacPass/MPAutotypeContext.h +++ b/MacPass/MPAutotypeContext.h @@ -14,8 +14,9 @@ @interface MPAutotypeContext : NSObject @property (nonatomic, strong) KPKEntry *entry; -@property (nonatomic, copy) NSString *commandsSequence; -@property (nonatomic, assign) NSUInteger value; +@property (nonatomic, copy) NSString *command; +@property (nonatomic, assign, readonly) BOOL isCommand; +@property (nonatomic, assign) NSInteger value; /** * Designated initializer diff --git a/MacPass/MPAutotypeContext.m b/MacPass/MPAutotypeContext.m index af12b58d..5bc52ee7 100644 --- a/MacPass/MPAutotypeContext.m +++ b/MacPass/MPAutotypeContext.m @@ -12,6 +12,12 @@ #import "KPKEntry.h" #import "KPKWindowAssociation.h" +@interface MPAutotypeContext () + +@property (nonatomic, assign) BOOL isCommand; + +@end + @implementation MPAutotypeContext - (instancetype)initWithWindowAssociation:(KPKWindowAssociation *)association { @@ -38,20 +44,35 @@ } else { self.entry = entry; - self.commandsSequence = sequence; - NSRegularExpression *regexp = [[NSRegularExpression alloc] initWithPattern:@"{[a-z]+([0-9]*)}" options:NSRegularExpressionIgnoreMetacharacters error:0]; + NSError *error; + NSRegularExpression *regexp = [[NSRegularExpression alloc] initWithPattern:@"\\{([a-z]+) ?([0-9]*)\\}" options:NSRegularExpressionCaseInsensitive error:&error]; if(regexp) { - NSArray *matches = [regexp matchesInString:self.commandsSequence options:0 range:NSMakeRange(0, [self.commandsSequence length])]; - if(matches) { - } + [regexp enumerateMatchesInString:sequence options:0 range:NSMakeRange(0, [sequence length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { + NSRange commandRange = [result rangeAtIndex:1]; + NSRange valueRange = [result rangeAtIndex:2]; + if(commandRange.location != NSNotFound && commandRange.length != 0) { + self.command = [sequence substringWithRange:commandRange]; + self.isCommand = YES; + } + if(valueRange.location != NSNotFound && valueRange.length != 0) { + self.value = [[sequence substringWithRange:valueRange] integerValue]; + } + else { + self.value = NSNotFound; + } + }]; } + else { + NSLog(@"Error while trying to parse Autotype sequence: %@", [error localizedDescription]); + } + } } return self; } - (id)copyWithZone:(NSZone *)zone { - MPAutotypeContext *copy = [[MPAutotypeContext alloc] initWithEntry:self.entry andSequence:self.commandsSequence]; + MPAutotypeContext *copy = [[MPAutotypeContext alloc] initWithEntry:self.entry andSequence:self.command]; return copy; } diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index c390384a..30dfcecb 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -67,7 +67,7 @@ NSString *const kMPApplciationNameKey = @"applicationName"; if(candiates > 1) { // open Dialog to select from possible entries } - /* Oder the Applciation to the front that we may have put to the background */ + /* Just in case it's not there anymore, order the app for the window we want to autotype back to the foreground! */ [self _orderApplicationToFront:applicationName]; /* Implement! diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 9cc1ca08..7bcc5080 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -125,7 +125,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; - (void)didLoadView { [[self view] setWantsLayer:YES]; [self _hideFilterBarAnimated]; - + [_bottomBar setBorderType:HNHBorderTop]; [self.addEntryButton setAction:[MPActionHelper actionOfType:MPActionAddEntry]]; @@ -192,7 +192,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; [self _setupHeaderMenu]; [parentColumn setHidden:YES]; - } - (NSResponder *)reconmendedFirstResponder { @@ -676,7 +675,13 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; KPKEntry *selectedEntry = [self _clickedOrSelectedEntry]; if(selectedEntry && [selectedEntry.url length] > 0) { NSURL *webURL = [NSURL URLWithString:selectedEntry.url]; + NSString *scheme = [webURL scheme]; + if(!scheme) { + webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", selectedEntry.url]]; + } [[NSWorkspace sharedWorkspace] openURL:webURL]; + /* Add custom browser support */ + //[[NSWorkspace sharedWorkspace] openURLs:@[webURL] withAppBundleIdentifier:@"org.mozilla.firefox" options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifiers:NULL]; } } diff --git a/MacPass/MPIconSelectViewController.h b/MacPass/MPIconSelectViewController.h index af028216..1994cd63 100644 --- a/MacPass/MPIconSelectViewController.h +++ b/MacPass/MPIconSelectViewController.h @@ -8,11 +8,20 @@ #import "MPViewController.h" +extern NSInteger const kMPDefaultIcon; + @interface MPIconSelectViewController : MPViewController +/** + * Is the selected Icon, kMPDefaultIcon if the default icons was selected + */ +@property (nonatomic, assign) NSInteger selectedIcon; + @property (weak) IBOutlet NSCollectionView *iconCollectionView; @property (weak) IBOutlet NSButton *imageButton; +@property (weak) NSPopover *popover; +- (void)reset; - (IBAction)useDefault:(id)sender; @end diff --git a/MacPass/MPIconSelectViewController.m b/MacPass/MPIconSelectViewController.m index 74644320..bc018547 100644 --- a/MacPass/MPIconSelectViewController.m +++ b/MacPass/MPIconSelectViewController.m @@ -8,6 +8,10 @@ #import "MPIconSelectViewController.h" #import "MPIconHelper.h" +#import "MPDocument.h" + + +NSInteger const kMPDefaultIcon = -1; @interface MPIconSelectViewController () @end @@ -32,9 +36,22 @@ [self.iconCollectionView setSelectable:YES]; [self.iconCollectionView setAllowsMultipleSelection:NO]; [self.iconCollectionView setContent:[MPIconHelper databaseIcons]]; - } - (IBAction)useDefault:(id)sender { + self.selectedIcon = kMPDefaultIcon; + [self.popover performClose:self]; } + +- (void)reset { + self.selectedIcon = kMPDefaultIcon; +} + +- (IBAction)_selectImage:(id)sender { + NSButton *button = sender; + NSImage *image = [button image]; + self.selectedIcon = [[self.iconCollectionView content] indexOfObject:image]; + [self.popover performClose:self]; +} + @end diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index 0f7dcdd5..a943e54b 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -18,6 +18,8 @@ #import "KPKTree.h" #import "KPKMetaData.h" +#import "KPKGroup.h" +#import "KPKEntry.h" #import "HNHGradientView.h" #import "MPPopupImageView.h" @@ -34,6 +36,8 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { NSPopover *_popover; } +@property (strong) MPIconSelectViewController *iconSelectionViewController; + @property (nonatomic, strong) NSDate *modificationDate; @property (nonatomic, strong) NSDate *creationDate; @@ -160,11 +164,31 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { _popover = [[NSPopover alloc] init]; _popover.delegate = self; _popover.behavior = NSPopoverBehaviorTransient; - _popover.contentViewController = [[MPIconSelectViewController alloc] init]; + if(!self.iconSelectionViewController) { + self.iconSelectionViewController = [[MPIconSelectViewController alloc] init]; + } + [self.iconSelectionViewController reset]; + self.iconSelectionViewController.popover = _popover; + _popover.contentViewController = self.iconSelectionViewController; [_popover showRelativeToRect:NSZeroRect ofView:self.itemImageView preferredEdge:NSMinYEdge]; } - (void)popoverDidClose:(NSNotification *)notification { + MPIconSelectViewController *viewController = (MPIconSelectViewController *)_popover.contentViewController; + MPDocument *document = [[self windowController] document]; + BOOL useDefault = (viewController.selectedIcon == -1); + switch (self.activeTab) { + case MPGroupTab: + document.selectedGroup.icon = useDefault ? MPIconFolder : viewController.selectedIcon; + break; + + case MPEntryTab: + document.selectedEntry.icon = useDefault ? MPIconPassword : viewController.selectedIcon; + break; + + default: + break; + } _popover = nil; } diff --git a/MacPass/WorkflowSettings.xib b/MacPass/WorkflowSettings.xib index e4cf150d..858d67e1 100644 --- a/MacPass/WorkflowSettings.xib +++ b/MacPass/WorkflowSettings.xib @@ -1,844 +1,132 @@ - - - - 1080 - 12E55 - 3084 - 1187.39 - 626.00 - - com.apple.InterfaceBuilder.CocoaPlugin - 3084 - - - IBNSLayoutConstraint - NSBox - NSCustomObject - NSCustomView - NSMenu - NSMenuItem - NSPopUpButton - NSPopUpButtonCell - NSTextField - NSTextFieldCell - - - com.apple.InterfaceBuilder.CocoaPlugin - - - PluginDependencyRecalculationVersion - - - - - MPWorkflowSettingsController - - - FirstResponder - - - NSApplication - - - - 268 - - - - 12 - - - - 274 - - - - 268 - {{19, 47}, {138, 17}} - - - - _NS:1535 - YES - - 68157504 - 272630784 - Double-click on URL: - - LucidaGrande - 13 - 1044 - - _NS:1535 - - - 6 - System - controlColor - - 3 - MC42NjY2NjY2NjY3AA - - - - 6 - System - controlTextColor - - 3 - MAA - - - - NO - - - - 268 - {{160, 42}, {106, 26}} - - - - _NS:9 - YES - - -1539309504 - 2048 - - _NS:9 - - 109199360 - 129 - - - 400 - 75 - - - Copies URL - - 1048576 - 2147483647 - 1 - - NSImage - NSMenuCheckmark - - - NSImage - NSMenuMixedState - - _popUpItemAction: - - - YES - - OtherViews - - - - - Opens URL - - 1048576 - 2147483647 - - - _popUpItemAction: - - - - - - -1 - 1 - YES - YES - 2 - - NO - - - - 268 - {{15, 16}, {142, 17}} - - - - _NS:1535 - YES - - 605028416 - 272630784 - Double-click on Title: - - _NS:1535 - - - - - NO - - - - 268 - {{160, 11}, {138, 26}} - - - _NS:9 - YES - - -1539309504 - 2048 - - _NS:9 - - 109199360 - 129 - - - 400 - 75 - - - Opens Inspector - - 1048576 - 2147483647 - 1 - - - _popUpItemAction: - - - YES - - OtherViews - - - - - is Ignored - - 1048576 - 2147483647 - - - _popUpItemAction: - - - - - - -1 - 1 - YES - YES - 2 - - NO - - - {{1, 1}, {364, 76}} - - - - _NS:11 - - - {{17, 16}, {366, 92}} - - - - _NS:9 - {0, 0} - - 67108864 - 0 - Entry Table - - LucidaGrande - 11 - 3100 - - - 6 - System - textBackgroundColor - - 3 - MQA - - - - 3 - MCAwLjgwMDAwMDAxMTkAA - - - - 1 - 0 - 2 - NO - - - {400, 128} - - - - NSView - - - - - - - view - - - - 52 - - - - - - 0 - - - - - - -2 - - - File's Owner - - - -1 - - - First Responder - - - -3 - - - Application - - - 1 - - - - - - 4 - 0 - - 4 - 1 - - 20 - - 1000 - - 8 - 29 - 3 - - - - 6 - 0 - - 6 - 1 - - 20 - - 1000 - - 8 - 29 - 3 - - - - 5 - 0 - - 5 - 1 - - 20 - - 1000 - - 8 - 29 - 3 - - - - 3 - 0 - - 3 - 1 - - 20 - - 1000 - - 8 - 29 - 3 - - - - 8 - 0 - - 0 - 1 - - 128 - - 1000 - - 9 - 40 - 1 - - - - 7 - 0 - - 0 - 1 - - 400 - - 1000 - - 9 - 40 - 1 - - - - - - 2 - - - - - 4 - 0 - - 4 - 1 - - 11 - - 1000 - - 8 - 29 - 3 - - - - 5 - 0 - - 6 - 1 - - 8 - - 1000 - - 6 - 24 - 3 - - - - 5 - 0 - - 6 - 1 - - 8 - - 1000 - - 6 - 24 - 3 - - - - 5 - 0 - - 5 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - - - - 3 - 0 - - 3 - 1 - - 25 - - 1000 - - 8 - 29 - 3 - - - - 10 - 0 - - 10 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - - - - 10 - 0 - - 10 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - - - - 5 - 0 - - 5 - 1 - - 16 - - 1000 - - 8 - 29 - 3 - - - - - - - - - - 3 - - - - - 5 - - - - - 8 - - - - - 9 - - - - - - - - 10 - - - - - 13 - - - - - - - - 14 - - - - - - - - 15 - - - - - - - - - 16 - - - - - 17 - - - - - 29 - - - - - 31 - - - - - 36 - - - - - - - - 37 - - - - - 38 - - - - - 40 - - - - - - - - 41 - - - - - - - - 42 - - - - - - - - - 43 - - - - - 44 - - - - - 46 - - - - - 47 - - - - - 48 - - - - - 49 - - - - - 50 - - - - - 51 - - - - - 53 - - - - - 54 - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - - - - - 54 - - - - - MPViewController - NSViewController - - IBProjectSource - ./Classes/MPViewController.h - - - - MPWorkflowSettingsController - MPViewController - - IBProjectSource - ./Classes/MPWorkflowSettingsController.h - - - - NSLayoutConstraint - NSObject - - IBProjectSource - ./Classes/NSLayoutConstraint.h - - - - - 0 - IBCocoaFramework - YES - 3 - - {11, 11} - {10, 3} - - YES - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file