When duplicating a file with a YYYY-MM-DD date we bump the date

This is instead of adding “copy” to the base name.

This is useful when you use a previous (dated) document as template for a new one, e.g. an invoice, meeting minutes, or similar.
This commit is contained in:
Allan Odgaard
2015-03-23 18:01:47 +07:00
parent eca7d839f3
commit daa32482bf

View File

@@ -301,6 +301,21 @@ NSString* const OakFileManagerPathKey = @"directory";
NSNumber* isDirectory = @NO;
[srcURL getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil];
NSURL* dst = [NSURL fileURLWithPath:[NSString stringWithCxxString:path::unique([[srcURL path] fileSystemRepresentation], " copy")] isDirectory:[isDirectory boolValue]];
if(![isDirectory boolValue])
{
NSString* srcPath = [srcURL path];
NSDateFormatter* formatter = [NSDateFormatter new];
formatter.dateFormat = @"yyyy-MM-dd";
NSString* todaysDate = [formatter stringFromDate:[NSDate date]];
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"\\b\\d{4}(-\\d{2}){2}\\b" options:0 error:nullptr];
NSString* newPath = [regex stringByReplacingMatchesInString:srcPath options:0 range:NSMakeRange(0, [srcPath length]) withTemplate:todaysDate];
if(![srcPath isEqualToString:newPath] && ![[NSFileManager defaultManager] fileExistsAtPath:newPath])
dst = [NSURL fileURLWithPath:newPath];
}
if([self doCreateCopy:dst ofURL:srcURL view:view])
{
[[view undoManager] setActionName:[self expandFormat:@"Duplicate of “%@”" withURL:srcURL]];