aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPHistoryController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-02-09 01:20:24 +0000
committerrowanbeentje <rowan@beent.je>2010-02-09 01:20:24 +0000
commitda88e1ea6bac13e52b14e3510db56a18162b2c73 (patch)
tree9b83abbbe4ff7b6e1d185519782fb8e9b3b2f8d8 /Source/SPHistoryController.m
parenta947c6e6c97a31fe18ee168e5c02294706fba164 (diff)
downloadsequelpro-da88e1ea6bac13e52b14e3510db56a18162b2c73.tar.gz
sequelpro-da88e1ea6bac13e52b14e3510db56a18162b2c73.tar.bz2
sequelpro-da88e1ea6bac13e52b14e3510db56a18162b2c73.zip
- Save and restore content table sorting, filter criteria, scroll position and selection when switching tables and databases. This implements Issue #469.
- Fix history bug causing column sorts to always be restored ascending
Diffstat (limited to 'Source/SPHistoryController.m')
-rw-r--r--Source/SPHistoryController.m51
1 files changed, 50 insertions, 1 deletions
diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m
index af92a928..2c1a657f 100644
--- a/Source/SPHistoryController.m
+++ b/Source/SPHistoryController.m
@@ -26,6 +26,7 @@
#import "TableContent.h"
#import "TablesList.h"
#import "SPHistoryController.h"
+#import "SPStringAdditions.h"
@implementation SPHistoryController
@@ -42,6 +43,7 @@
{
if (self = [super init]) {
history = [[NSMutableArray alloc] init];
+ tableContentStates = [[NSMutableDictionary alloc] init];
historyPosition = NSNotFound;
modifyingHistoryState = NO;
}
@@ -56,6 +58,7 @@
- (void) dealloc
{
+ [tableContentStates release];
[history release];
[super dealloc];
}
@@ -194,6 +197,21 @@
NSDictionary *contentFilter = [tableContentInstance filterSettings];
if (!theDatabase) return;
+ // If a table is selected, save state information
+ if (theDatabase && theTable) {
+
+ // Save the table content state
+ NSMutableDictionary *contentState = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithUnsignedInteger:contentPageNumber], @"page",
+ [NSValue valueWithRect:contentViewport], @"viewport",
+ [NSNumber numberWithBool:contentSortColIsAsc], @"sortIsAsc",
+ nil];
+ if (contentSortCol) [contentState setObject:contentSortCol forKey:@"sortCol"];
+ if (contentSelectedIndexSet) [contentState setObject:contentSelectedIndexSet forKey:@"selection"];
+ if (contentFilter) [contentState setObject:contentFilter forKey:@"filter"];
+ [tableContentStates setObject:contentState forKey:[NSString stringWithFormat:@"%@.%@", [theDatabase backtickQuotedString], [theTable backtickQuotedString]]];
+ }
+
// If there's any items after the current history position, remove them
if (historyPosition != NSNotFound && historyPosition < [history count] - 1) {
[history removeObjectsInRange:NSMakeRange(historyPosition + 1, [history count] - historyPosition - 1)];
@@ -287,7 +305,7 @@
NSDictionary *historyEntry = [history objectAtIndex:historyPosition];
// Set table content details for restore
- [tableContentInstance setSortColumnNameToRestore:[historyEntry objectForKey:@"contentSortCol"] isAscending:[[historyEntry objectForKey:@"contentSortCol"] boolValue]];
+ [tableContentInstance setSortColumnNameToRestore:[historyEntry objectForKey:@"contentSortCol"] isAscending:[[historyEntry objectForKey:@"contentSortColIsAsc"] boolValue]];
[tableContentInstance setPageToRestore:[[historyEntry objectForKey:@"contentPageNumber"] integerValue]];
[tableContentInstance setSelectedRowIndexesToRestore:[historyEntry objectForKey:@"contentSelectedIndexSet"]];
[tableContentInstance setViewportToRestore:[[historyEntry objectForKey:@"contentViewport"] rectValue]];
@@ -390,6 +408,37 @@
}
#pragma mark -
+#pragma mark Restoring view states
+
+/**
+ * Check saved view states for the currently selected database and
+ * table (if any), and restore them if present.
+ */
+- (void) restoreViewStates
+{
+ NSString *theDatabase = [theDocument database];
+ NSString *theTable = [theDocument table];
+ NSDictionary *contentState;
+
+ // Return if the history state is currently being modified
+ if (modifyingHistoryState) return;
+
+ // Return if no database or table are selected
+ if (!theDatabase || !theTable) return;
+
+ // Retrieve the saved content state, returning if none was found
+ contentState = [tableContentStates objectForKey:[NSString stringWithFormat:@"%@.%@", [theDatabase backtickQuotedString], [theTable backtickQuotedString]]];
+ if (!contentState) return;
+
+ // Restore the content view state
+ [tableContentInstance setSortColumnNameToRestore:[contentState objectForKey:@"sortCol"] isAscending:[[contentState objectForKey:@"sortIsAsc"] boolValue]];
+ [tableContentInstance setPageToRestore:[[contentState objectForKey:@"page"] unsignedIntegerValue]];
+ [tableContentInstance setSelectedRowIndexesToRestore:[contentState objectForKey:@"selection"]];
+ [tableContentInstance setViewportToRestore:[[contentState objectForKey:@"viewport"] rectValue]];
+ [tableContentInstance setFiltersToRestore:[contentState objectForKey:@"filter"]];
+}
+
+#pragma mark -
#pragma mark History entry details and description
/**