aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPHistoryController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-04-15 01:33:32 +0000
committerrowanbeentje <rowan@beent.je>2010-04-15 01:33:32 +0000
commit03a3560910ec5d18d662706f8dc6c94c15f326b9 (patch)
tree1dfa10832fccbc8a7c9406d142244b5db2249d82 /Source/SPHistoryController.m
parent771c3ff3aa15188771881e2447d491b359d4c5da (diff)
downloadsequelpro-03a3560910ec5d18d662706f8dc6c94c15f326b9.tar.gz
sequelpro-03a3560910ec5d18d662706f8dc6c94c15f326b9.tar.bz2
sequelpro-03a3560910ec5d18d662706f8dc6c94c15f326b9.zip
- Tweak the history controller to track the toolbar item visibility, and only update it when visible - this fixes crashes after the toolbar item is removed from the toolbar and then updated (eg http://spbug.com/l/114 )
Diffstat (limited to 'Source/SPHistoryController.m')
-rw-r--r--Source/SPHistoryController.m68
1 files changed, 67 insertions, 1 deletions
diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m
index 2fbf18b5..dcef796c 100644
--- a/Source/SPHistoryController.m
+++ b/Source/SPHistoryController.m
@@ -56,10 +56,16 @@
{
tableContentInstance = [theDocument valueForKey:@"tableContentInstance"];
tablesListInstance = [theDocument valueForKey:@"tablesListInstance"];
+ toolbarItemVisible = NO;
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toolbarWillAddItem:) name:NSToolbarWillAddItemNotification object:[theDocument valueForKey:@"mainToolbar"]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toolbarDidRemoveItem:) name:NSToolbarDidRemoveItemNotification object:[theDocument valueForKey:@"mainToolbar"]];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTask:) name:SPDocumentTaskStartNotification object:theDocument];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endDocumentTask:) name:SPDocumentTaskEndNotification object:theDocument];
}
- (void) dealloc
{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[tableContentStates release];
[history release];
[super dealloc];
@@ -73,6 +79,11 @@
*/
- (void) updateToolbarItem
{
+
+ // If the toolbar item isn't visible, don't perform any actions - as manipulating
+ // items not on the toolbar can cause crashes.
+ if (!toolbarItemVisible) return;
+
BOOL backEnabled = NO;
BOOL forwardEnabled = NO;
NSInteger i;
@@ -81,7 +92,7 @@
// Set the active state of the segments if appropriate
if ([history count] && historyPosition > 0) backEnabled = YES;
if ([history count] && historyPosition + 1 < [history count]) forwardEnabled = YES;
-
+
[historyControl setEnabled:backEnabled forSegment:0];
[historyControl setEnabled:forwardEnabled forSegment:1];
@@ -175,6 +186,61 @@
return theView;
}
+/**
+ * Set up the toolbar items as appropriate.
+ * State tracking is necessary as manipulating items not on the toolbar
+ * can cause crashes.
+ */
+- (void) setupInterface
+{
+ NSArray *toolbarItems = [[theDocument valueForKey:@"mainToolbar"] items];
+ for (NSToolbarItem *toolbarItem in toolbarItems) {
+ if ([[toolbarItem itemIdentifier] isEqualToString:SPMainToolbarHistoryNavigation]) {
+ toolbarItemVisible = YES;
+ break;
+ }
+ }
+}
+
+/**
+ * Disable the controls during a task.
+ */
+- (void) startDocumentTask:(NSNotification *)aNotification
+{
+ if (toolbarItemVisible) [historyControl setEnabled:NO];
+}
+
+/**
+ * Enable the controls once a task has completed.
+ */
+- (void) endDocumentTask:(NSNotification *)aNotification
+{
+ if (toolbarItemVisible) [historyControl setEnabled:YES];
+}
+
+/**
+ * Update the state when the item is added from the toolbar.
+ * State tracking is necessary as manipulating items not on the toolbar
+ * can cause crashes.
+ */
+- (void) toolbarWillAddItem:(NSNotification *)aNotification {
+ if ([[[[aNotification userInfo] objectForKey:@"item"] itemIdentifier] isEqualToString:SPMainToolbarHistoryNavigation]) {
+ toolbarItemVisible = YES;
+ [self performSelector:@selector(updateToolbarItem) withObject:nil afterDelay:0.1];
+ }
+}
+
+/**
+ * Update the state when the item is removed from the toolbar
+ * State tracking is necessary as manipulating items not on the toolbar
+ * can cause crashes.
+ */
+- (void) toolbarDidRemoveItem:(NSNotification *)aNotification {
+ if ([[[[aNotification userInfo] objectForKey:@"item"] itemIdentifier] isEqualToString:SPMainToolbarHistoryNavigation]) {
+ toolbarItemVisible = NO;
+ }
+}
+
#pragma mark -
#pragma mark Adding or updating history entries