aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPContentFilterManager.m39
-rw-r--r--Source/SPQueryFavoriteManager.m35
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")]