From 0f11cb74639d17a2fe512ed81d67ccf33601b605 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 10 May 2015 01:24:34 +0200 Subject: * Fix an exception that would occur if a user tried to export favorites when no favorites are selected * Select "Quick Connect" after deleting a favorite --- Source/SPConnectionController.m | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'Source/SPConnectionController.m') diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 7cde1e4e..25049d44 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -1039,10 +1039,17 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, */ - (IBAction)exportFavorites:(id)sender { - NSSavePanel *savePanel = [NSSavePanel savePanel]; + // additional empty selection check + if(![[self selectedFavoriteNodes] count]) return; - NSString *fileName = [[self selectedFavoriteNodes] count] > 1 ? SPExportFavoritesFilename : [[[self selectedFavorite] objectForKey:SPFavoriteNameKey] stringByAppendingPathExtension:@"plist"]; + NSSavePanel *savePanel = [NSSavePanel savePanel]; + // suggest the name of the favorite or a default name for multiple selection + NSString *fileName = ([[self selectedFavoriteNodes] count] == 1)? [[[self selectedFavorite] objectForKey:SPFavoriteNameKey] stringByAppendingPathExtension:@"plist"] : nil; + // This if() is so we can also catch nil due to favorite corruption (NSSavePanel will @throw if nil is passed in) + if(!fileName) + fileName = SPExportFavoritesFilename; + [savePanel setAccessoryView:exportPanelAccessoryView]; [savePanel setNameFieldStringValue:fileName]; @@ -1652,7 +1659,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, { [favoritesOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[favoritesOutlineView rowForItem:node]] byExtendingSelection:NO]; [self _scrollToSelectedNode]; - } +} /** * Scroll to the currently selected node. @@ -1663,7 +1670,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, if ([favoritesOutlineView selectedRow] == -1) return; [favoritesOutlineView scrollRowToVisible:[favoritesOutlineView selectedRow]]; - } +} /** * Removes the supplied tree node. @@ -1678,9 +1685,8 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, [self _reloadFavoritesViewData]; - // Clear the selection and update the interface to match - [favoritesOutlineView selectRowIndexes:nil byExtendingSelection:NO]; - [self updateFavoriteSelection:self]; + // Select Quick Connect item to prevent empty selection + [self _selectNode:quickConnectItem]; [connectionResizeContainer setHidden:NO]; [connectionInstructionsTextField setStringValue:NSLocalizedString(@"Enter connection details below, or choose a favorite", @"enter connection details label")]; -- cgit v1.2.3