From 03d912e7c49ec8f6fe78cf4a4fdd5e76c10c9b2d Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sat, 8 Oct 2016 11:04:13 +0200 Subject: [PATCH] Bump date of find/replace pasteboard history items when they are used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently this bumping is limited to the Find dialog and happens when executing a search. Selecting from the Show Find History or subsequently using ⌘G, does not bump the date of the selected item (but probably should). --- Frameworks/Find/src/FindWindowController.mm | 19 +++++++++++++------ Frameworks/OakAppKit/src/OakPasteboard.h | 1 + Frameworks/OakAppKit/src/OakPasteboard.mm | 1 - 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Frameworks/Find/src/FindWindowController.mm b/Frameworks/Find/src/FindWindowController.mm index 270e753b..2047c6c4 100644 --- a/Frameworks/Find/src/FindWindowController.mm +++ b/Frameworks/Find/src/FindWindowController.mm @@ -540,17 +540,24 @@ static NSButton* OakCreateStopSearchButton () if(OakNotEmptyString(_findString)) { OakPasteboardEntry* oldEntry = [[OakPasteboard pasteboardWithName:NSFindPboard] current]; - if(!oldEntry || ![oldEntry.string isEqualToString:_findString]) + if(oldEntry && [oldEntry.string isEqualToString:_findString]) + { + if(![oldEntry.options isEqualToDictionary:newOptions]) + oldEntry.options = newOptions; + oldEntry.date = [NSDate date]; + } + else + { [[OakPasteboard pasteboardWithName:NSFindPboard] addEntryWithString:_findString andOptions:newOptions]; - else if(![oldEntry.options isEqualToDictionary:newOptions]) - oldEntry.options = newOptions; + } } if(_replaceString) { - NSString* oldReplacement = [[[OakPasteboard pasteboardWithName:OakReplacePboard] current] string]; - if(!oldReplacement || ![oldReplacement isEqualToString:_replaceString]) - [[OakPasteboard pasteboardWithName:OakReplacePboard] addEntryWithString:_replaceString]; + OakPasteboardEntry* oldEntry = [[OakPasteboard pasteboardWithName:OakReplacePboard] current]; + if(oldEntry && [oldEntry.string isEqualToString:_replaceString]) + oldEntry.date = [NSDate date]; + else [[OakPasteboard pasteboardWithName:OakReplacePboard] addEntryWithString:_replaceString]; } return res; diff --git a/Frameworks/OakAppKit/src/OakPasteboard.h b/Frameworks/OakAppKit/src/OakPasteboard.h index bd0c7945..07048731 100644 --- a/Frameworks/OakAppKit/src/OakPasteboard.h +++ b/Frameworks/OakAppKit/src/OakPasteboard.h @@ -14,6 +14,7 @@ extern PUBLIC NSString* const OakFindRegularExpressionOption; PUBLIC @interface OakPasteboardEntry : NSManagedObject @property (nonatomic) NSString* string; @property (nonatomic) NSDictionary* options; +@property (nonatomic) NSDate* date; @property (nonatomic) BOOL fullWordMatch; @property (nonatomic) BOOL ignoreWhitespace; diff --git a/Frameworks/OakAppKit/src/OakPasteboard.mm b/Frameworks/OakAppKit/src/OakPasteboard.mm index b505480b..46736f30 100644 --- a/Frameworks/OakAppKit/src/OakPasteboard.mm +++ b/Frameworks/OakAppKit/src/OakPasteboard.mm @@ -21,7 +21,6 @@ NSString* const OakFindRegularExpressionOption = @"regularExpression"; NSString* const kUserDefaultsDisablePersistentClipboardHistory = @"disablePersistentClipboardHistory"; @interface OakPasteboardEntry () -@property (nonatomic) NSDate* date; @property (nonatomic) OakPasteboard* pasteboard; @property (nonatomic) NSDictionary* primitiveOptions; @end