Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#2658: Perform duplicate database operation on a background thread. F…
…urther changes after feedback.
  • Loading branch information
stuconnolly committed Jun 20, 2018
1 parent 5d99aca commit 6aa4fa5
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Source/SPDatabaseDocument.m
Expand Up @@ -90,6 +90,7 @@
#include <libkern/OSAtomic.h>

// Constants
static NSString *SPCopyDatabaseAction = @"SPCopyDatabase";
static NSString *SPConfirmCopyDatabaseAction = @"SPConfirmCopyDatabase";
static NSString *SPRenameDatabaseAction = @"SPRenameDatabase";
static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
Expand Down Expand Up @@ -898,11 +899,11 @@ - (IBAction)copyDatabase:(id)sender
[databaseCopyNameField setStringValue:selectedDatabase];
[copyDatabaseMessageField setStringValue:selectedDatabase];

[parentWindow beginSheet:databaseCopySheet completionHandler:^(NSInteger returnCode) {
if (returnCode == NSOKButton) {
[self _copyDatabase];
}
}];
[NSApp beginSheet:databaseCopySheet
modalForWindow:parentWindow
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:SPCopyDatabaseAction];
}

/**
Expand Down Expand Up @@ -1110,14 +1111,19 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt
}
}
}
else if ([contextInfo isEqualToString:SPCopyDatabaseAction]) {
if (returnCode == NSOKButton) {
[self _copyDatabase];
}
}
else if ([contextInfo isEqualToString:SPRenameDatabaseAction]) {
if (returnCode == NSOKButton) {
[self _renameDatabase];
}
}
else if([contextInfo isEqualToString:SPAlterDatabaseAction]) {
else if ([contextInfo isEqualToString:SPAlterDatabaseAction]) {
[alterDatabaseCharsetHelper setEnabled:NO];
if(returnCode == NSOKButton) {
if (returnCode == NSOKButton) {
[self _alterDatabase];
}
}
Expand Down Expand Up @@ -5993,6 +5999,8 @@ - (void)setIsSavedInBundle:(BOOL)savedInBundle

/**
* Copies the current database (and optionally it's content) on a separate thread.
*
* This method *MUST* be called from the UI thread!
*/
- (void)_copyDatabase
{
Expand Down Expand Up @@ -6030,11 +6038,11 @@ - (void)_copyDatabaseWithDetails:(NSDictionary *)databaseDetails

[databaseCopy setConnection:[self getConnection]];

NSString *newDatabaseName = databaseDetails[SPNewDatabaseName];
NSString *newDatabaseName = [databaseDetails objectForKey:SPNewDatabaseName];

BOOL success = [databaseCopy copyDatabaseFrom:databaseDetails[SPNewDatabaseDetails]
BOOL success = [databaseCopy copyDatabaseFrom:[databaseDetails objectForKey:SPNewDatabaseDetails]
to:newDatabaseName
withContent:[databaseDetails[SPNewDatabaseCopyContent] boolValue]];
withContent:[[databaseDetails objectForKey:SPNewDatabaseCopyContent] boolValue]];

[databaseCopy release];

Expand All @@ -6047,15 +6055,13 @@ - (void)_copyDatabaseWithDetails:(NSDictionary *)databaseDetails
[self endTask];

if (!success) {
SPMainQSync(^{
SPOnewayAlertSheet(
NSLocalizedString(@"Unable to copy database", @"unable to copy database message"),
parentWindow,
[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to copy the database '%@' to '%@'.", @"unable to copy database message informative message"),
[databaseDetails[SPNewDatabaseDetails] databaseName],
newDatabaseName]
);
});
SPOnewayAlertSheet(
NSLocalizedString(@"Unable to copy database", @"unable to copy database message"),
parentWindow,
[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to copy the database '%@' to '%@'.", @"unable to copy database message informative message"),
[databaseDetails[SPNewDatabaseDetails] databaseName],
newDatabaseName]
);
}
}
}
Expand Down

0 comments on commit 6aa4fa5

Please sign in to comment.