Skip to content

Commit 6aa4fa5

Browse files
committed
#2658: Perform duplicate database operation on a background thread. Further changes after feedback.
1 parent 5d99aca commit 6aa4fa5

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

Source/SPDatabaseDocument.m

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#include <libkern/OSAtomic.h>
9191

9292
// Constants
93+
static NSString *SPCopyDatabaseAction = @"SPCopyDatabase";
9394
static NSString *SPConfirmCopyDatabaseAction = @"SPConfirmCopyDatabase";
9495
static NSString *SPRenameDatabaseAction = @"SPRenameDatabase";
9596
static NSString *SPAlterDatabaseAction = @"SPAlterDatabase";
@@ -898,11 +899,11 @@ - (IBAction)copyDatabase:(id)sender
898899
[databaseCopyNameField setStringValue:selectedDatabase];
899900
[copyDatabaseMessageField setStringValue:selectedDatabase];
900901

901-
[parentWindow beginSheet:databaseCopySheet completionHandler:^(NSInteger returnCode) {
902-
if (returnCode == NSOKButton) {
903-
[self _copyDatabase];
904-
}
905-
}];
902+
[NSApp beginSheet:databaseCopySheet
903+
modalForWindow:parentWindow
904+
modalDelegate:self
905+
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
906+
contextInfo:SPCopyDatabaseAction];
906907
}
907908

908909
/**
@@ -1110,14 +1111,19 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt
11101111
}
11111112
}
11121113
}
1114+
else if ([contextInfo isEqualToString:SPCopyDatabaseAction]) {
1115+
if (returnCode == NSOKButton) {
1116+
[self _copyDatabase];
1117+
}
1118+
}
11131119
else if ([contextInfo isEqualToString:SPRenameDatabaseAction]) {
11141120
if (returnCode == NSOKButton) {
11151121
[self _renameDatabase];
11161122
}
11171123
}
1118-
else if([contextInfo isEqualToString:SPAlterDatabaseAction]) {
1124+
else if ([contextInfo isEqualToString:SPAlterDatabaseAction]) {
11191125
[alterDatabaseCharsetHelper setEnabled:NO];
1120-
if(returnCode == NSOKButton) {
1126+
if (returnCode == NSOKButton) {
11211127
[self _alterDatabase];
11221128
}
11231129
}
@@ -5993,6 +5999,8 @@ - (void)setIsSavedInBundle:(BOOL)savedInBundle
59935999

59946000
/**
59956001
* Copies the current database (and optionally it's content) on a separate thread.
6002+
*
6003+
* This method *MUST* be called from the UI thread!
59966004
*/
59976005
- (void)_copyDatabase
59986006
{
@@ -6030,11 +6038,11 @@ - (void)_copyDatabaseWithDetails:(NSDictionary *)databaseDetails
60306038

60316039
[databaseCopy setConnection:[self getConnection]];
60326040

6033-
NSString *newDatabaseName = databaseDetails[SPNewDatabaseName];
6041+
NSString *newDatabaseName = [databaseDetails objectForKey:SPNewDatabaseName];
60346042

6035-
BOOL success = [databaseCopy copyDatabaseFrom:databaseDetails[SPNewDatabaseDetails]
6043+
BOOL success = [databaseCopy copyDatabaseFrom:[databaseDetails objectForKey:SPNewDatabaseDetails]
60366044
to:newDatabaseName
6037-
withContent:[databaseDetails[SPNewDatabaseCopyContent] boolValue]];
6045+
withContent:[[databaseDetails objectForKey:SPNewDatabaseCopyContent] boolValue]];
60386046

60396047
[databaseCopy release];
60406048

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

60496057
if (!success) {
6050-
SPMainQSync(^{
6051-
SPOnewayAlertSheet(
6052-
NSLocalizedString(@"Unable to copy database", @"unable to copy database message"),
6053-
parentWindow,
6054-
[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to copy the database '%@' to '%@'.", @"unable to copy database message informative message"),
6055-
[databaseDetails[SPNewDatabaseDetails] databaseName],
6056-
newDatabaseName]
6057-
);
6058-
});
6058+
SPOnewayAlertSheet(
6059+
NSLocalizedString(@"Unable to copy database", @"unable to copy database message"),
6060+
parentWindow,
6061+
[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to copy the database '%@' to '%@'.", @"unable to copy database message informative message"),
6062+
[databaseDetails[SPNewDatabaseDetails] databaseName],
6063+
newDatabaseName]
6064+
);
60596065
}
60606066
}
60616067
}

0 commit comments

Comments
 (0)