aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/ConnectionView.xib9
-rw-r--r--Source/SPConnectionController.m67
-rw-r--r--Source/SPConnectionControllerDelegate.m49
3 files changed, 84 insertions, 41 deletions
diff --git a/Interfaces/English.lproj/ConnectionView.xib b/Interfaces/English.lproj/ConnectionView.xib
index 63800035..196cc9a9 100644
--- a/Interfaces/English.lproj/ConnectionView.xib
+++ b/Interfaces/English.lproj/ConnectionView.xib
@@ -21,7 +21,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="5782"/>
+ <integer value="4915"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -109,8 +109,8 @@
</object>
</object>
<object class="NSTextFieldCell" key="NSDataCell" id="93569184">
- <int key="NSCellFlags">69336641</int>
- <int key="NSCellFlags2">137216</int>
+ <int key="NSCellFlags">337772097</int>
+ <int key="NSCellFlags2">137472</int>
<string key="NSContents">Text Cell</string>
<reference key="NSSupport" ref="26"/>
<reference key="NSControlView" ref="1012579052"/>
@@ -498,7 +498,6 @@
</object>
</object>
</object>
- <int key="NSSelectedIndex">2</int>
<bool key="NSPullDown">YES</bool>
<int key="NSPreferredEdge">1</int>
<bool key="NSUsesItemFromMenu">YES</bool>
@@ -7171,7 +7170,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
- <string>{{160, 101}, {131, 54}}</string>
+ <string>{{160, 101}, {128, 54}}</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 2bad361f..c12f1ac4 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -46,6 +46,7 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist";
- (BOOL)_checkHost;
- (void)_sortFavorites;
+- (void)_sortTreeNode:(SPTreeNode *)node usingKey:(NSString *)key;
- (void)_favoriteTypeDidChange;
- (void)_reloadFavoritesViewData;
- (void)_restoreConnectionInterface;
@@ -56,6 +57,8 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist";
- (void)_updateFavoritePasswordsFromField:(NSControl *)control;
+static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, void *key);
+
@end
@implementation SPConnectionController
@@ -1177,19 +1180,67 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist";
sortKey = SPFavoriteTypeKey;
break;
}
+
+ [self _sortTreeNode:[[favoritesRoot childNodes] objectAtIndex:0] usingKey:sortKey];
+
+ [favoritesController saveFavorites];
- // First sort the contents of all groups
- for (SPTreeNode *node in [[[favoritesRoot childNodes] objectAtIndex:0] groupChildren])
+ [self _reloadFavoritesViewData];
+}
+
+/**
+ * Sorts the supplied tree node using the supplied sort key.
+ *
+ * @param node The tree node to sort
+ * @param key The sort key to sort by
+ */
+- (void)_sortTreeNode:(SPTreeNode *)node usingKey:(NSString *)key
+{
+ NSMutableArray *nodes = [[node mutableChildNodes] mutableCopy];
+
+ for (SPTreeNode *node in nodes)
{
- [[node mutableChildNodes] sortUsingSelector:@selector(compare:)];
+ if ([node isGroup]) {
+ [self _sortTreeNode:node usingKey:key];
+ }
}
- // Secondly sort the root's leaf nodes
- [[[[favoritesRoot childNodes] objectAtIndex:0] childLeafs] sortUsingSelector:@selector(compare:)];
+ NSMutableArray *groupNodes = [[NSMutableArray alloc] init];
- [favoritesController saveFavorites];
-
- [self _reloadFavoritesViewData];
+ for (node in nodes)
+ {
+ if ([node isGroup]) {
+ [groupNodes addObject:node];
+ [nodes removeObject:node];
+ }
+ }
+
+ [nodes sortUsingFunction:compareFavoritesUsingKey context:key];
+
+ [nodes addObjectsFromArray:groupNodes];
+
+ [[node mutableChildNodes] setArray:nodes];
+
+ [groupNodes release];
+}
+
+/**
+ * Sort function used by NSMutableArray's sortUsingFunction:
+ *
+ * @param favorite1 The first of the favorites to compare (and determine sort order)
+ * @param favorite2 The second of the favorites to compare
+ * @param key The sort key to perform the comparison by
+ *
+ * @return An integer (NSComparisonResult) indicating the order of the comparison
+ */
+static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, void *key)
+{
+ NSString *dictKey = (NSString *)key;
+
+ id value1 = [[(SPFavoriteNode *)[(SPTreeNode *)favorite1 representedObject] nodeFavorite] objectForKey:dictKey];
+ id value2 = [[(SPFavoriteNode *)[(SPTreeNode *)favorite2 representedObject] nodeFavorite] objectForKey:dictKey];
+
+ return [value1 compare:value2];
}
/**
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
index 449a2cb2..3318958e 100644
--- a/Source/SPConnectionControllerDelegate.m
+++ b/Source/SPConnectionControllerDelegate.m
@@ -109,7 +109,7 @@
#pragma mark Outline view delegate methods
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
-{
+{
return ([[(SPTreeNode *)item parentNode] parentNode] == nil);
}
@@ -160,7 +160,7 @@
- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
{
- return ((SPTreeNode *)[[item parentNode] parentNode] == nil) ? 22 : 17;
+ return (![[item parentNode] parentNode]) ? 22 : 17;
}
- (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn item:(id)item mouseLocation:(NSPoint)mouseLocation
@@ -185,7 +185,7 @@
#pragma mark -
#pragma mark Outline view drag & drop
-/*- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
+- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
{
[pboard declareTypes:[NSArray arrayWithObject:SPFavoritesPasteboardDragType] owner:self];
[pboard setData:[NSData data] forType:SPFavoritesPasteboardDragType];
@@ -197,6 +197,9 @@
{
NSDragOperation result = NSDragOperationNone;
+ // Prevent dropping favorites on other favorites (non-groups)
+ if ((index == NSOutlineViewDropOnItemIndex) && (![item isGroup])) return result;
+
if ([info draggingSource] == outlineView) {
[outlineView setDropItem:item dropChildIndex:index];
@@ -211,46 +214,39 @@
BOOL acceptedDrop = NO;
if ((!item) || ([info draggingSource] != outlineView)) return acceptedDrop;
-
+
SPTreeNode *node = (item) ? item : [[[[favoritesRoot childNodes] objectAtIndex:0] childNodes] objectAtIndex:0];
-
- // TODO: Fix me
-
+
// Disable all automatic sorting
- //currentSortItem = -1;
- //reverseFavoritesSort = NO;
-
- //[prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
- //[prefs setBool:NO forKey:SPFavoritesSortedInReverse];
+ currentSortItem = -1;
+ reverseFavoritesSort = NO;
- // Remove sort descriptors
- //[favorites sortUsingDescriptors:[NSArray array]];
+ [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
+ [prefs setBool:NO forKey:SPFavoritesSortedInReverse];
// Uncheck sort by menu items
for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray])
{
[menuItem setState:NSOffState];
}
-
+
NSArray *nodes = [self selectedFavoriteNodes];
if ([node isGroup]) {
if (index == NSOutlineViewDropOnItemIndex) {
index = 0;
}
- else {
- SPTreeNode *oldNode = node;
-
- node = [node parentNode];
- index = ([[node childNodes] indexOfObject:oldNode] + 1);
- }
}
else {
if (index == NSOutlineViewDropOnItemIndex) {
index = 0;
}
}
-
+
+ if (![[node representedObject] nodeName]) {
+ node = [[favoritesRoot childNodes] objectAtIndex:0];
+ }
+
NSMutableArray *childNodeArray = [node mutableChildNodes];
for (SPTreeNode *treeNode in nodes)
@@ -270,12 +266,12 @@
else {
[[[treeNode parentNode] mutableChildNodes] removeObject:treeNode];
}
-
+
[childNodeArray insertObject:treeNode atIndex:newIndex];
newIndex++;
}
-
+
[favoritesController saveFavorites];
[self _reloadFavoritesViewData];
@@ -285,7 +281,7 @@
acceptedDrop = YES;
return acceptedDrop;
-}*/
+}
#pragma mark -
#pragma mark Textfield delegate methods
@@ -466,9 +462,6 @@
if ((action == @selector(sortFavorites:)) || (action == @selector(reverseSortFavorites:))) {
- // TODO: Fix me
- return NO;
-
// Loop all the items in the sort by menu only checking the currently selected one
for (NSMenuItem *item in [[menuItem menu] itemArray])
{