From 094b7ca1746c8ed94b9a8362929b2532e2fb76f5 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 17 Dec 2012 22:27:00 +0000 Subject: - If the favourite is not an on-disk document, add any new query favourites to the bottom of the Global list if a selection is not active, to address query favorite loss (Issue #1417) --- Source/SPQueryFavoriteManager.m | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index 3d5a2e9a..36740ca7 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -35,6 +35,7 @@ #import "SPEncodingPopupAccessory.h" #import "SPQueryController.h" #import "SPQueryDocumentsController.h" +#import "SPDatabaseDocument.h" #import "SPConnectionController.h" #import "RegexKitLite.h" #import "SPTextView.h" @@ -68,7 +69,7 @@ if(managerDelegate == nil) { NSBeep(); - NSLog(@"Query Favorite Manger was called without a delegate."); + NSLog(@"Query Favorite Manager was called without a delegate."); return nil; } tableDocumentInstance = [managerDelegate valueForKeyPath:@"tableDocumentInstance"]; @@ -208,14 +209,26 @@ // Add a new favorite else favorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Favorite", @"", nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]]; - + + // If a favourite is currently selected, add the new favourite next to it if ([favoritesTableView numberOfSelectedRows] > 0) { insertIndex = [[favoritesTableView selectedRowIndexes] lastIndex]+1; [favorites insertObject:favorite atIndex:insertIndex]; - } - else { - [favorites addObject:favorite]; + } + + // If the DatabaseDocument is an on-disk document, add the favourite to the bottom of it + else if (![tableDocumentInstance isUntitled]) { insertIndex = [favorites count] - 1; + [favorites addObject:favorite]; + } + + // Otherwise, add to the bottom of the Global array by default + else { + insertIndex = 1; + while (![[favorites objectAtIndex:insertIndex] objectForKey:@"headerOfFileURL"]) { + insertIndex++; + } + [favorites insertObject:favorite atIndex:insertIndex]; } [favoritesArrayController rearrangeObjects]; -- cgit v1.2.3