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 | |
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')
-rw-r--r-- | Source/SPContentFilterManager.m | 39 | ||||
-rw-r--r-- | Source/SPQueryFavoriteManager.m | 35 |
2 files changed, 52 insertions, 22 deletions
diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m index f30f885a..d47b2c90 100644 --- a/Source/SPContentFilterManager.m +++ b/Source/SPContentFilterManager.m @@ -840,6 +840,7 @@ NSError *readError = nil; NSString *convError = nil; NSPropertyListFormat format; + NSInteger insertionIndexStart, insertionIndexEnd; NSDictionary *spf = nil; @@ -863,19 +864,35 @@ } if([[spf objectForKey:SPContentFilters] objectForKey:filterType] && [[[spf objectForKey:SPContentFilters] objectForKey:filterType] count]) { - // if([contentFilterTableView numberOfSelectedRows] > 0) { - // // Insert imported filters after the last selected filter - // NSUInteger insertIndex = [[contentFilterTableView selectedRowIndexes] lastIndex] + 1; - // NSUInteger i; - // for(i=0; i<[[[spf objectForKey:SPContentFilters] objectForKey:filterType] count]; i++) { - // [contentFilters insertObject:[[spf objectForKey:SPQueryFavorites] objectAtIndex:i] atIndex:insertIndex+i]; - // } - // } else { - // // If no selection add them - [contentFilters addObjectsFromArray:[[spf objectForKey:SPContentFilters] objectForKey:filterType]]; - // } + +#ifndef SP_CODA + // If the DatabaseDocument is an on-disk document, add the favourites to the bottom of it + if (![tableDocumentInstance isUntitled]) { + insertionIndexStart = [contentFilters count]; + [contentFilters addObjectsFromArray:[[spf objectForKey:SPContentFilters] objectForKey:filterType]]; + insertionIndexEnd = [contentFilters count] - 1; + } + + // Otherwise, add to the bottom of the Global array + else { +#endif + NSUInteger i, l; + insertionIndexStart = 1; + while (![[contentFilters objectAtIndex:insertionIndexStart] objectForKey:@"headerOfFileURL"]) { + insertionIndexStart++; + } + for (i = 0, l = [[[spf objectForKey:SPContentFilters] objectForKey:filterType] count]; i < l; i++) { + [contentFilters insertObject:[[[spf objectForKey:SPContentFilters] objectForKey:filterType] objectAtIndex:i] atIndex:insertionIndexStart + i]; + } + insertionIndexEnd = insertionIndexStart + i; +#ifndef SP_CODA + } +#endif + [contentFilterArrayController rearrangeObjects]; [contentFilterTableView reloadData]; + [contentFilterTableView selectRowIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(insertionIndexStart, insertionIndexEnd - insertionIndexStart)] byExtendingSelection:NO]; + [contentFilterTableView scrollRowToVisible:insertionIndexEnd]; [spf release]; } else { NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:SP_FILE_PARSER_ERROR_TITLE_STRING] 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")] |