diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.m | 3 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegate.m | 70 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 2 |
3 files changed, 65 insertions, 10 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 7eb15dd6..93b7dc36 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -1329,6 +1329,9 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, [favoritesController removeFavoriteNode:node]; [self _reloadFavoritesViewData]; + + // Clear the selection + [favoritesOutlineView selectRowIndexes:nil byExtendingSelection:NO]; [connectionResizeContainer setHidden:NO]; [connectionInstructionsTextField setStringValue:NSLocalizedString(@"Enter connection details below, or choose a favorite", @"enter connection details label")]; diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index 35b69aeb..796edc12 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -141,11 +141,28 @@ static NSString *SPDatabaseImage = @"database-small"; toolTip = ([favoriteHostname length]) ? [NSString stringWithFormat:@"%@ (%@)", favoriteName, favoriteHostname] : favoriteName; } - // Only display a tooltip for group nodes that are a child of the root node + + // Only display a tooltip for group nodes that are a descendant of the root node else if ([[node parentNode] parentNode]) { - NSUInteger favCount = [[node childNodes] count]; - - toolTip = [NSString stringWithFormat:@"%@ - %d %@", [[node representedObject] nodeName], favCount, (favCount == 1) ? NSLocalizedString(@"favorite", @"favorite singular label") : NSLocalizedString(@"favorites", @"favorites plural label")]; + NSUInteger favCount = 0; + NSUInteger groupCount = 0; + for (SPTreeNode *eachNode in [node childNodes]) { + if ([eachNode isGroup]) { + groupCount++; + } else { + favCount++; + } + } + + NSMutableArray *tooltipParts = [NSMutableArray arrayWithCapacity:2]; + if (favCount || !groupCount) { + [tooltipParts addObject:[NSString stringWithFormat:@"%d %@", favCount, (favCount == 1) ? NSLocalizedString(@"favorite", @"favorite singular label") : NSLocalizedString(@"favorites", @"favorites plural label")]]; + } + if (groupCount) { + [tooltipParts addObject:[NSString stringWithFormat:@"%d %@", groupCount, (groupCount == 1) ? NSLocalizedString(@"group", @"favorite group singular label") : NSLocalizedString(@"groups", @"favorite groups plural label")]]; + } + + toolTip = [NSString stringWithFormat:@"%@ - %@", [[node representedObject] nodeName], [tooltipParts componentsJoinedByString:@", "]]; } return toolTip; @@ -156,6 +173,16 @@ static NSString *SPDatabaseImage = @"database-small"; return ([[item parentNode] parentNode] != nil); } +- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item +{ + return ([[item parentNode] parentNode] != nil); +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item +{ + return ([[item parentNode] parentNode] != nil); +} + - (void)outlineViewItemDidCollapse:(NSNotification *)notification { [self _setNodeIsExpanded:NO fromNotification:notification]; @@ -170,7 +197,13 @@ static NSString *SPDatabaseImage = @"database-small"; #pragma mark Outline view drag & drop - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard -{ +{ + + // Prevent a drag which includes the outline title group from taking place + for (id item in items) { + if (![[item parentNode] parentNode]) return NO; + } + // If the user is in the process of changing a node's name, trigger a save and prevent dragging. if (isEditing) { [favoritesController saveFavorites]; @@ -197,7 +230,16 @@ static NSString *SPDatabaseImage = @"database-small"; // Prevent dropping favorites on other favorites (non-groups) if ((childIndex == NSOutlineViewDropOnItemIndex) && (![item isGroup])) return result; - + + // Ensure that none of the dragged nodes are being dragged into children of themselves; if they are, + // prevent the drag. + id itemToCheck = item; + do { + if ([draggedNodes containsObject:itemToCheck]) { + return result; + } + } while ((itemToCheck = [itemToCheck parentNode])); + if ([info draggingSource] == outlineView) { [outlineView setDropItem:item dropChildIndex:childIndex]; @@ -214,7 +256,10 @@ static NSString *SPDatabaseImage = @"database-small"; if ((!item) || ([info draggingSource] != outlineView)) return acceptedDrop; SPTreeNode *node = item ? item : [[[[favoritesRoot childNodes] objectAtIndex:0] childNodes] objectAtIndex:0]; - + + // Cache the selected nodes for selection restoration afterwards + NSArray *preDragSelection = [self selectedFavoriteNodes]; + // Disable all automatic sorting currentSortItem = -1; reverseFavoritesSort = NO; @@ -275,7 +320,14 @@ static NSString *SPDatabaseImage = @"database-small"; [self _reloadFavoritesViewData]; [[[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup]; - + + // Update the selection to account for rearranged faourites + NSMutableIndexSet *restoredSelection = [NSMutableIndexSet indexSet]; + for (SPTreeNode *eachNode in preDragSelection) { + [restoredSelection addIndex:[favoritesOutlineView rowForItem:eachNode]]; + } + [favoritesOutlineView selectRowIndexes:restoredSelection byExtendingSelection:NO]; + acceptedDrop = YES; return acceptedDrop; @@ -490,7 +542,7 @@ static NSString *SPDatabaseImage = @"database-small"; } // Rename selected favorite/group - if (action == @selector(renameFavorite:)) { + if (action == @selector(renameNode:)) { return ([favoritesOutlineView numberOfSelectedRows] == 1); } diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index f8f1585b..90f9985a 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -3484,7 +3484,7 @@ static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; // If validation for the sort favorites tableview items reaches here then the preferences window isn't // open return NO. - if (([menuItem action] == @selector(sortFavorites:)) || ([menuItem action] == @selector(reverseFavoritesSortOrder:))) { + if (([menuItem action] == @selector(sortFavorites:)) || ([menuItem action] == @selector(reverseSortFavorites:))) { return NO; } |