aboutsummaryrefslogtreecommitdiffstats
path: root/Source/NSNotificationAdditions.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-11-21 22:18:27 +0000
committerrowanbeentje <rowan@beent.je>2009-11-21 22:18:27 +0000
commit7ead84b0868975752f445d1917bc693a5bf502b7 (patch)
tree8bb28e0a7b5482fc13276bc192e738d6e9761b8b /Source/NSNotificationAdditions.m
parentf184235a7f7996e68f4f6548ec8932b289e3d3c1 (diff)
downloadsequelpro-7ead84b0868975752f445d1917bc693a5bf502b7.tar.gz
sequelpro-7ead84b0868975752f445d1917bc693a5bf502b7.tar.bz2
sequelpro-7ead84b0868975752f445d1917bc693a5bf502b7.zip
- Relocate the table changed notification, allowing table info pane to update early in the change process, but ensure the change notification occurs on the main thread for stability. Added NSNotificationAdditions from the Colloquy project for this.
- Change the design of the progress indicator layer, and tweak task progress for improved feedback and less flickering by correctly updating interface as appropriate, and delaying status changes for a short time. This partially addresses Issue #455.
Diffstat (limited to 'Source/NSNotificationAdditions.m')
-rw-r--r--Source/NSNotificationAdditions.m75
1 files changed, 75 insertions, 0 deletions
diff --git a/Source/NSNotificationAdditions.m b/Source/NSNotificationAdditions.m
new file mode 100644
index 00000000..2e075ed3
--- /dev/null
+++ b/Source/NSNotificationAdditions.m
@@ -0,0 +1,75 @@
+//
+// $Id$
+//
+// NSNotificationAdditions.m
+// sequel-pro
+//
+// Copied from the Colloquy project; original code available from Trac at
+// http://colloquy.info/project/browser/trunk/Additions/NSNotificationAdditions.m
+//
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "NSNotificationAdditions.h"
+#import <pthread.h>
+
+@implementation NSNotificationCenter (NSNotificationCenterAdditions)
+- (void) postNotificationOnMainThread:(NSNotification *) notification {
+ if( pthread_main_np() ) return [self postNotification:notification];
+ [self postNotificationOnMainThread:notification waitUntilDone:NO];
+}
+
+- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait {
+ if( pthread_main_np() ) return [self postNotification:notification];
+ [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait];
+}
+
++ (void) _postNotification:(NSNotification *) notification {
+ [[self defaultCenter] postNotification:notification];
+}
+
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object {
+ if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil];
+ [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO];
+}
+
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo {
+ if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo];
+ [self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO];
+}
+
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait {
+ if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo];
+
+ NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:3];
+ if( name ) [info setObject:name forKey:@"name"];
+ if( object ) [info setObject:object forKey:@"object"];
+ if( userInfo ) [info setObject:userInfo forKey:@"userInfo"];
+
+ [[self class] performSelectorOnMainThread:@selector( _postNotificationName: ) withObject:info waitUntilDone:wait];
+
+ [info release];
+}
+
++ (void) _postNotificationName:(NSDictionary *) info {
+ NSString *name = [info objectForKey:@"name"];
+ id object = [info objectForKey:@"object"];
+ NSDictionary *userInfo = [info objectForKey:@"userInfo"];
+
+ [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo];
+}
+@end