aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionControllerDelegate.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-01-26 21:44:29 +0000
committerstuconnolly <stuart02@gmail.com>2011-01-26 21:44:29 +0000
commitfa7cff57548edc51420693e6909fe2adb3c18951 (patch)
tree71840428efea0962ae1025f18aa50573b9691890 /Source/SPConnectionControllerDelegate.m
parent9533093c9d107acaaf26110a2ae43f484a101419 (diff)
downloadsequelpro-fa7cff57548edc51420693e6909fe2adb3c18951.tar.gz
sequelpro-fa7cff57548edc51420693e6909fe2adb3c18951.tar.bz2
sequelpro-fa7cff57548edc51420693e6909fe2adb3c18951.zip
Fix and enable drag and drop in the connection favorites outline view.
Diffstat (limited to 'Source/SPConnectionControllerDelegate.m')
-rw-r--r--Source/SPConnectionControllerDelegate.m49
1 files changed, 21 insertions, 28 deletions
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])
{