From 20ee3e8640542d34149f8b510ba3a4b4815ff908 Mon Sep 17 00:00:00 2001 From: michael starke Date: Fri, 10 Nov 2017 11:18:14 +0100 Subject: [PATCH] removed obsolte code from MPInspectorBuilderViewController --- MacPass/MPInspectorViewController.h | 10 +--- MacPass/MPInspectorViewController.m | 77 +++++++++++------------------ 2 files changed, 30 insertions(+), 57 deletions(-) diff --git a/MacPass/MPInspectorViewController.h b/MacPass/MPInspectorViewController.h index bafd1254..42a2097c 100644 --- a/MacPass/MPInspectorViewController.h +++ b/MacPass/MPInspectorViewController.h @@ -21,20 +21,14 @@ // #import "MPViewController.h" - -@class HNHUIGradientView; +#import @class MPIconImageView; -@interface MPInspectorViewController : MPViewController +@interface MPInspectorViewController : MPViewController -@property (weak) IBOutlet HNHUIGradientView *bottomBar; -@property (weak) IBOutlet NSTextField *createdTextField; -@property (weak) IBOutlet NSTextField *modifiedTextField; @property (weak) IBOutlet NSTextField *noSelectionInfo; @property (weak) IBOutlet MPIconImageView *itemImageView; @property (weak) IBOutlet NSTextField *itemNameTextField; -@property (weak) IBOutlet NSButton *saveChangesButton; -@property (weak) IBOutlet NSButton *discardChangesButton; - (IBAction)pickIcon:(id)sender; - (IBAction)pickExpiryDate:(id)sender; diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index 28b9b09a..eacbd52d 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -30,15 +30,12 @@ #import "MPIconImageView.h" #import "MPNotifications.h" #import "MPPluginDataViewController.h" +#import "MPPasteBoardController.h" #import "KeePassKit/KeePassKit.h" #import "KPKNode+IconImage.h" -#import "HNHUi/HNHUi.h" - -#import "NSDate+Humanized.h" - typedef NS_ENUM(NSUInteger, MPContentTab) { MPEntryTab, MPGroupTab, @@ -51,15 +48,12 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { @property (strong) MPGroupInspectorViewController *groupViewController; @property (strong) NSPopover *popover; - -@property (nonatomic, strong) NSDate *modificationDate; -@property (nonatomic, strong) NSDate *creationDate; @property (copy) NSString *expiryDateText; @property (nonatomic, assign) NSUInteger activeTab; @property (weak) IBOutlet NSTabView *tabView; @property (weak) IBOutlet NSSplitView *splitView; -@property (unsafe_unretained) IBOutlet NSTextView *notesTextView; +@property (unsafe_unretained) IBOutlet HNHUITextView *notesTextView; @property BOOL didPushHistory; @@ -92,8 +86,6 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { } - (void)awakeFromNib { - self.bottomBar.borderType = (HNHBorderTop|HNHBorderHighlight); - self.noSelectionInfo.cell.backgroundStyle = NSBackgroundStyleRaised; self.itemImageView.cell.backgroundStyle = NSBackgroundStyleRaised; [self.tabView bind:NSSelectedIndexBinding toObject:self withKeyPath:NSStringFromSelector(@selector(activeTab)) options:nil]; @@ -117,11 +109,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { [groupTabView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[groupView]|" options:0 metrics:nil views:views]]; groupTabItem.initialFirstResponder = groupView; - [self.view layout]; - - self.discardChangesButton.hidden = YES; - self.saveChangesButton.hidden = YES; -} + [self.view layout];} - (void)registerNotificationsForDocument:(MPDocument *)document { [[NSNotificationCenter defaultCenter] addObserver:self @@ -142,44 +130,37 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { [self.groupViewController registerNotificationsForDocument:document]; } -#pragma mark - -#pragma mark Properties +#pragma mark - Properties - (void)setActiveTab:(NSUInteger)activeTab { if(_activeTab != activeTab) { _activeTab = activeTab; } } -- (void)setModificationDate:(NSDate *)modificationDate { - _modificationDate = modificationDate; - [self _updateDateStrings]; -} - -- (void)setCreationDate:(NSDate *)creationDate { - _creationDate = creationDate; - [self _updateDateStrings]; -} - -- (void)_updateDateStrings { - - if(!self.creationDate || !self.modificationDate ) { - [self.modifiedTextField setStringValue:@""]; - [self.createdTextField setStringValue:@""]; - return; // No dates, just clear +#pragma mark - TextViewDelegate +- (BOOL)textView:(NSTextView *)textView performAction:(SEL)action { + if(action == @selector(copy:)) { + MPPasteboardOverlayInfoType info = MPPasteboardOverlayInfoCustom; + NSMutableString *selectedString = [[NSMutableString alloc] initWithCapacity:MAX(1,textView.string.length)]; + NSString *string = textView.string; + for(NSValue *rangeValue in textView.selectedRanges) { + if(rangeValue.rangeValue.length != 0) { + [selectedString appendString:[string substringWithRange:rangeValue.rangeValue]]; + } + } + NSString *name = @""; + if(selectedString.length == 0) { + return YES; + } + if(textView == self.notesTextView) { + name = NSLocalizedString(@"NOTES", "Displayed name when notes or part of notes was copied"); + } + [[MPPasteBoardController defaultController] copyObjects:@[selectedString] overlayInfo:info name:name atView:self.view]; + return NO; } - - NSString *creationString = [self.creationDate humanized]; - NSString *modificationString = [self.modificationDate humanized]; - - NSString *modifedAtTemplate = NSLocalizedString(@"MODIFED_AT_%@", @"Modifed at template string. %@ is replaced by locaized date and time"); - NSString *createdAtTemplate = NSLocalizedString(@"CREATED_AT_%@", @"Created at template string. %@ is replaced by locaized date and time"); - - self.modifiedTextField.stringValue = [NSString stringWithFormat:modifedAtTemplate, modificationString]; - self.createdTextField.stringValue = [NSString stringWithFormat:createdAtTemplate, creationString]; + return YES; } - -#pragma mark - -#pragma mark Popup +#pragma mark - Popup - (IBAction)pickIcon:(id)sender { NSAssert([sender isKindOfClass:NSView.class], @""); [self _popupViewController:[[MPIconSelectViewController alloc] init] atView:sender]; @@ -209,16 +190,14 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { } -#pragma mark - -#pragma mark NSPopover Delegate +#pragma mark - NSPopover Delegate - (void)popoverDidClose:(NSNotification *)notification { /* clear out the popover */ self.popover = nil; } -#pragma mark - -#pragma mark MPDocument Notifications +#pragma mark - MPDocument Notifications - (void)_willChangeModelProperty:(NSNotification *)notification { /* TODO use uuids for pushed item? */ if(self.didPushHistory) {