diff options
author | rowanbeentje <rowan@beent.je> | 2013-03-06 23:59:25 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2013-03-06 23:59:25 +0000 |
commit | 1ebe3e3b0c5fc9ea248dfd4a678d3166d5e62c78 (patch) | |
tree | 94300f5f7bc3db97c5116e8993800d9f0ed5026d /Source/SPQueryFavoriteManager.m | |
parent | 9f85aaffb997a8baa41322021e4a76324a50b9a2 (diff) | |
download | sequelpro-1ebe3e3b0c5fc9ea248dfd4a678d3166d5e62c78.tar.gz sequelpro-1ebe3e3b0c5fc9ea248dfd4a678d3166d5e62c78.tar.bz2 sequelpro-1ebe3e3b0c5fc9ea248dfd4a678d3166d5e62c78.zip |
- Alter the content filter manager and the query favourite manager to import items from a file into the Global group if the document is untitled, improving import UX and addressing Issue #1616 and Issue #1645. Also select and scroll to the newly imported items for clarity.
Diffstat (limited to 'Source/SPQueryFavoriteManager.m')
-rw-r--r-- | Source/SPQueryFavoriteManager.m | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index c035f6f8..9e49c6b0 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -821,6 +821,7 @@ NSError *readError = nil; NSString *convError = nil; NSPropertyListFormat format; + NSInteger insertionIndexStart, insertionIndexEnd; NSDictionary *spf = nil; @@ -844,19 +845,31 @@ } if([spf objectForKey:SPQueryFavorites] && [[spf objectForKey:SPQueryFavorites] count]) { - // if([favoritesTableView numberOfSelectedRows] > 0) { - // // Insert imported queries after the last selected favorite - // NSUInteger insertIndex = [[favoritesTableView selectedRowIndexes] lastIndex] + 1; - // NSUInteger i; - // for(i=0; i<[[spf objectForKey:SPQueryFavorites] count]; i++) { - // [favorites insertObject:[[spf objectForKey:SPQueryFavorites] objectAtIndex:i] atIndex:insertIndex+i]; - // } - // } else { - // // If no selection add them - [favorites addObjectsFromArray:[spf objectForKey:SPQueryFavorites]]; - // } + + // If the DatabaseDocument is an on-disk document, add the favourites to the bottom of it + if (![tableDocumentInstance isUntitled]) { + insertionIndexStart = [favorites count]; + [favorites addObjectsFromArray:[spf objectForKey:SPQueryFavorites]]; + insertionIndexEnd = [favorites count] - 1; + } + + // Otherwise, add to the bottom of the Global array + else { + NSUInteger i, l; + insertionIndexStart = 1; + while (![[favorites objectAtIndex:insertionIndexStart] objectForKey:@"headerOfFileURL"]) { + insertionIndexStart++; + } + for (i = 0, l = [[spf objectForKey:SPQueryFavorites] count]; i < l; i++) { + [favorites insertObject:[[spf objectForKey:SPQueryFavorites] objectAtIndex:i] atIndex:insertionIndexStart + i]; + } + insertionIndexEnd = insertionIndexStart + i; + } + [favoritesArrayController rearrangeObjects]; [favoritesTableView reloadData]; + [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(insertionIndexStart, insertionIndexEnd - insertionIndexStart)] byExtendingSelection:NO]; + [favoritesTableView scrollRowToVisible:insertionIndexEnd]; [spf release]; } else { NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:NSLocalizedString(@"Error while reading data file", @"error while reading data file")] |