aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-10-01 04:12:05 +0200
committerMax <post@wickenrode.com>2015-10-01 04:12:05 +0200
commitc5878bdad37e353b5411d4b1a3e5233213d72a1b (patch)
tree20de42bb61aa26b1d698abdd5167fbb56c164962
parent730f1d66bee8532d35f7f52ddafb3dfbed427876 (diff)
downloadsequelpro-c5878bdad37e353b5411d4b1a3e5233213d72a1b.tar.gz
sequelpro-c5878bdad37e353b5411d4b1a3e5233213d72a1b.tar.bz2
sequelpro-c5878bdad37e353b5411d4b1a3e5233213d72a1b.zip
Fix two cases of "UI manipulation from background thread" (relates to #2248)
-rw-r--r--Source/SPDataImport.m51
-rw-r--r--Source/SPFunctions.h33
-rw-r--r--Source/SPFunctions.m41
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj14
4 files changed, 115 insertions, 24 deletions
diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m
index aa50a827..5cf67976 100644
--- a/Source/SPDataImport.m
+++ b/Source/SPDataImport.m
@@ -47,6 +47,7 @@
#import "SPFileHandle.h"
#import "SPEncodingPopupAccessory.h"
#import "SPThreadAdditions.h"
+#import "SPFunctions.h"
#import <SPMySQL/SPMySQL.h>
@@ -401,18 +402,20 @@
BOOL useIndeterminate = NO;
if ([sqlFileHandle compressionFormat] == SPBzip2Compression) useIndeterminate = YES;
- // Reset progress interface
- [errorsView setString:@""];
- [[singleProgressTitle onMainThread] setStringValue:NSLocalizedString(@"Importing SQL", @"text showing that the application is importing SQL")];
- [[singleProgressText onMainThread] setStringValue:NSLocalizedString(@"Reading...", @"text showing that app is reading dump")];
- [[singleProgressBar onMainThread] setIndeterminate:useIndeterminate];
- [[singleProgressBar onMainThread] setMaxValue:fileTotalLength];
- [[singleProgressBar onMainThread] setUsesThreadedAnimation:YES];
- [[singleProgressBar onMainThread] startAnimation:self];
-
- // Open the progress sheet
- [[NSApp onMainThread] beginSheet:singleProgressSheet modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:nil contextInfo:nil];
- [[singleProgressSheet onMainThread] makeKeyWindow];
+ SPMainQSync(^{
+ // Reset progress interface
+ [errorsView setString:@""];
+ [singleProgressTitle setStringValue:NSLocalizedString(@"Importing SQL", @"text showing that the application is importing SQL")];
+ [singleProgressText setStringValue:NSLocalizedString(@"Reading...", @"text showing that app is reading dump")];
+ [singleProgressBar setIndeterminate:useIndeterminate];
+ [singleProgressBar setMaxValue:fileTotalLength];
+ [singleProgressBar setUsesThreadedAnimation:YES];
+ [singleProgressBar startAnimation:self];
+
+ // Open the progress sheet
+ [NSApp beginSheet:singleProgressSheet modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:nil contextInfo:nil];
+ [singleProgressSheet makeKeyWindow];
+ });
[tableDocumentInstance setQueryMode:SPImportExportQueryMode];
@@ -568,18 +571,18 @@
// If not set to ignore errors, ask what to do. Use NSAlert rather than
// SPBeginWaitingAlertSheet as there is already a modal sheet in progress.
if (!ignoreSQLErrors) {
- NSInteger sqlImportErrorSheetReturnCode;
-
- NSAlert *sqlErrorAlert = [NSAlert
- alertWithMessageText:NSLocalizedString(@"An error occurred while importing SQL", @"sql import error message")
- defaultButton:NSLocalizedString(@"Continue", @"continue button")
- alternateButton:NSLocalizedString(@"Ignore All Errors", @"ignore errors button")
- otherButton:NSLocalizedString(@"Stop", @"stop button")
- informativeTextWithFormat:NSLocalizedString(@"[ERROR in query %ld] %@\n", @"error text when multiple custom query failed"), (long)(queriesPerformed+1), [mySQLConnection lastErrorMessage]
- ];
- [sqlErrorAlert setAlertStyle:NSWarningAlertStyle];
- sqlImportErrorSheetReturnCode = [sqlErrorAlert runModal];
-
+ __block NSInteger sqlImportErrorSheetReturnCode;
+
+ SPMainQSync(^{
+ NSAlert *sqlErrorAlert = [NSAlert alertWithMessageText:NSLocalizedString(@"An error occurred while importing SQL", @"sql import error message")
+ defaultButton:NSLocalizedString(@"Continue", @"continue button")
+ alternateButton:NSLocalizedString(@"Ignore All Errors", @"ignore errors button")
+ otherButton:NSLocalizedString(@"Stop", @"stop button")
+ informativeTextWithFormat:NSLocalizedString(@"[ERROR in query %ld] %@\n", @"error text when multiple custom query failed"), (long)(queriesPerformed+1), [mySQLConnection lastErrorMessage]];
+ [sqlErrorAlert setAlertStyle:NSWarningAlertStyle];
+ sqlImportErrorSheetReturnCode = [sqlErrorAlert runModal];
+ });
+
switch (sqlImportErrorSheetReturnCode) {
// On "continue", no additional action is required
diff --git a/Source/SPFunctions.h b/Source/SPFunctions.h
new file mode 100644
index 00000000..f2ca9c7e
--- /dev/null
+++ b/Source/SPFunctions.h
@@ -0,0 +1,33 @@
+//
+// SPFunctions.h
+// sequel-pro
+//
+// Created by Max Lohrmann on 01.10.15.
+// Copyright (c) 2015 Max Lohrmann. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// More info at <https://github.com/sequelpro/sequelpro>
+
+
+void SPMainQSync(void (^block)(void));
+
diff --git a/Source/SPFunctions.m b/Source/SPFunctions.m
new file mode 100644
index 00000000..f485d36a
--- /dev/null
+++ b/Source/SPFunctions.m
@@ -0,0 +1,41 @@
+//
+// SPFunctions.m
+// sequel-pro
+//
+// Created by Max Lohrmann on 01.10.15.
+// Copyright (c) 2015 Max Lohrmann. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// More info at <https://github.com/sequelpro/sequelpro>
+
+#import "SPFunctions.h"
+
+void SPMainQSync(void (^block)(void))
+{
+ if(dispatch_get_current_queue() == dispatch_get_main_queue()) {
+ block();
+ }
+ else {
+ dispatch_sync(dispatch_get_main_queue(), block);
+ }
+}
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index 0958501d..1dddeaca 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -189,6 +189,7 @@
503B02D21AE95E010060CAB1 /* SPConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 173284E91088FEDE0062E892 /* SPConstants.m */; };
503CDBB21ACDC204004F8A2F /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 503CDBB11ACDC204004F8A2F /* Quartz.framework */; };
506CE9311A311C6C0039F736 /* SPTableContentFilterController.m in Sources */ = {isa = PBXBuildFile; fileRef = 506CE9301A311C6C0039F736 /* SPTableContentFilterController.m */; };
+ 507FF1121BBCC57600104523 /* SPFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 507FF1111BBCC57600104523 /* SPFunctions.m */; };
50A9F8B119EAD4B90053E571 /* SPGotoDatabaseController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */; };
50D3C3491A75B8A800B5429C /* GotoDatabaseDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50D3C34B1A75B8A800B5429C /* GotoDatabaseDialog.xib */; };
50D3C3521A77135F00B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; };
@@ -901,6 +902,8 @@
503CDBB11ACDC204004F8A2F /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; };
506CE92F1A311C6C0039F736 /* SPTableContentFilterController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableContentFilterController.h; sourceTree = "<group>"; };
506CE9301A311C6C0039F736 /* SPTableContentFilterController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableContentFilterController.m; sourceTree = "<group>"; };
+ 507FF1101BBCC4C400104523 /* SPFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFunctions.h; sourceTree = "<group>"; };
+ 507FF1111BBCC57600104523 /* SPFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFunctions.m; sourceTree = "<group>"; };
50A9F8AF19EAD4B90053E571 /* SPGotoDatabaseController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPGotoDatabaseController.h; sourceTree = "<group>"; };
50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPGotoDatabaseController.m; sourceTree = "<group>"; };
50D3C34A1A75B8A800B5429C /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/GotoDatabaseDialog.xib; sourceTree = "<group>"; };
@@ -2069,6 +2072,7 @@
17E6416E0EF01F3B001BC333 /* Other */ = {
isa = PBXGroup;
children = (
+ 507FF10E1BBCC4A900104523 /* Utility */,
1198F5B01174EDA700670590 /* Database Actions */,
583CE39511722B70008F148E /* File Compression */,
173284E51088FEC20062E892 /* Data */,
@@ -2369,6 +2373,15 @@
path = UnitTests;
sourceTree = "<group>";
};
+ 507FF10E1BBCC4A900104523 /* Utility */ = {
+ isa = PBXGroup;
+ children = (
+ 507FF1101BBCC4C400104523 /* SPFunctions.h */,
+ 507FF1111BBCC57600104523 /* SPFunctions.m */,
+ );
+ name = Utility;
+ sourceTree = "<group>";
+ };
50D3C3591A771C2300B5429C /* Other */ = {
isa = PBXGroup;
children = (
@@ -3141,6 +3154,7 @@
17E641460EF01EB5001BC333 /* main.m in Sources */,
17E641560EF01EF6001BC333 /* SPCustomQuery.m in Sources */,
17E641570EF01EF6001BC333 /* SPAppController.m in Sources */,
+ 507FF1121BBCC57600104523 /* SPFunctions.m in Sources */,
17E641580EF01EF6001BC333 /* SPGrowlController.m in Sources */,
17E641590EF01EF6001BC333 /* SPTableContent.m in Sources */,
17E6415A0EF01EF6001BC333 /* SPDatabaseDocument.m in Sources */,