aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--Source/SPHistoryController.h4
-rw-r--r--Source/SPHistoryController.m51
-rw-r--r--Source/TablesList.m3
3 files changed, 57 insertions, 1 deletions
diff --git a/Source/SPHistoryController.h b/Source/SPHistoryController.h
index 4497c283..0b2d50d9 100644
--- a/Source/SPHistoryController.h
+++ b/Source/SPHistoryController.h
@@ -43,6 +43,7 @@ enum sphistory_view_types
TableContent *tableContentInstance;
TablesList *tablesListInstance;
NSMutableArray *history;
+ NSMutableDictionary *tableContentStates;
NSUInteger historyPosition;
BOOL modifyingHistoryState;
}
@@ -67,6 +68,9 @@ enum sphistory_view_types
- (void) abortEntryLoadWithPool:(NSAutoreleasePool *)pool;
- (void) loadEntryFromMenuItem:(id)theMenuItem;
+// Restoring view states
+- (void) restoreViewStates;
+
// History entry details and description
- (NSMenuItem *) menuEntryForHistoryEntryAtIndex:(NSInteger)theIndex;
- (NSString *) nameForHistoryEntryDetails:(NSDictionary *)theEntry;
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
/**
diff --git a/Source/TablesList.m b/Source/TablesList.m
index 2a9a7657..dd675c43 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -679,6 +679,9 @@
// Notify listeners of the table change now that the state is fully set up.
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:tableDocumentInstance];
+ // Restore view states as appropriate
+ [spHistoryControllerInstance restoreViewStates];
+
if( selectedTableType == SP_TABLETYPE_VIEW || selectedTableType == SP_TABLETYPE_TABLE) {
if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
[tableSourceInstance loadTable:selectedTableName];