From 1d32954fbe70f6d98784eced88f29c47903f27c7 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 21 Jun 2015 01:37:48 +0200 Subject: Add option to sort favorites by color --- Interfaces/English.lproj/ConnectionView.xib | 30 ++++++++++++++++++++++++++--- Source/SPConnectionController.m | 3 +++ Source/SPConstants.h | 9 +++++---- Source/SPPreferencesUpgrade.m | 16 +++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Interfaces/English.lproj/ConnectionView.xib b/Interfaces/English.lproj/ConnectionView.xib index b95910df..a6bfe95c 100644 --- a/Interfaces/English.lproj/ConnectionView.xib +++ b/Interfaces/English.lproj/ConnectionView.xib @@ -340,6 +340,16 @@ _popUpItemAction: + + + Color + + 2147483647 + + + _popUpItemAction: + + YES @@ -368,7 +378,7 @@ - -1 + 10 YES 1 YES @@ -1524,7 +1534,6 @@ 268 {{328, 12}, {29, 24}} - YES 67108864 @@ -2282,7 +2291,7 @@ {{328, 12}, {29, 24}} - + YES 67108864 @@ -3991,6 +4000,14 @@ nQE-St-ai8 + + + sortFavorites: + + + + Q9D-q1-jts + delegate @@ -6068,6 +6085,7 @@ + @@ -7477,12 +7495,18 @@ + + 25V-E5-s4p + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index aca3e982..5af38274 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -1432,6 +1432,9 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, case SPFavoritesSortTypeItem: sortKey = SPFavoriteTypeKey; break; + case SPFavoritesSortColorItem: + sortKey = SPFavoriteColorIndexKey; + break; case SPFavoritesSortUnsorted: return; } diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 6a8afeea..5e34ef56 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -129,10 +129,11 @@ typedef enum // Sort by constants typedef enum { - SPFavoritesSortUnsorted = -1, - SPFavoritesSortNameItem = 0, - SPFavoritesSortHostItem = 1, - SPFavoritesSortTypeItem = 2 + SPFavoritesSortUnsorted = -1, + SPFavoritesSortNameItem = 0, + SPFavoritesSortHostItem = 1, + SPFavoritesSortTypeItem = 2, + SPFavoritesSortColorItem = 3 } SPFavoritesSortItem; // Text and link cell draw states diff --git a/Source/SPPreferencesUpgrade.m b/Source/SPPreferencesUpgrade.m index d88dc4c8..6d0a3393 100644 --- a/Source/SPPreferencesUpgrade.m +++ b/Source/SPPreferencesUpgrade.m @@ -30,6 +30,8 @@ #import "SPPreferencesUpgrade.h" #import "SPKeychain.h" +#import "SPFavoritesController.h" +#import "SPTreeNode.h" static NSString *SPOldFavoritesKey = @"favorites"; static NSString *SPOldDefaultEncodingKey = @"DefaultEncoding"; @@ -344,6 +346,20 @@ void SPApplyRevisionChanges(void) if (recordedVersionNumber < 4049) { [prefs removeObjectForKey:SPOldFavoritesKey]; } + + // For versions prior to r4485, add a default colorIndex to fix sorting favorites by color + if (recordedVersionNumber < 4485) { + SPFavoritesController *ctrl = [SPFavoritesController sharedFavoritesController]; + NSMutableArray *favs = [(SPTreeNode *)[[[ctrl favoritesTree] childNodes] objectAtIndex:0] descendants]; + for(SPTreeNode *node in favs) { + if([node isGroup]) + continue; + NSMutableDictionary *data = [[node representedObject] nodeFavorite]; + if(![data objectForKey:SPFavoriteColorIndexKey]) + [data setObject:@(-1) forKey:SPFavoriteColorIndexKey]; + } + [ctrl saveFavorites]; + } // Display any important release notes, if any. Call this after a slight delay to prevent double help // menus - see http://www.cocoabuilder.com/archive/cocoa/6200-two-help-menus-why.html . -- cgit v1.2.3