From c936f9ccc68c7986d9a3bfb11cbdaea1e1fb321c Mon Sep 17 00:00:00 2001 From: hsoft Date: Wed, 28 Oct 2009 15:48:19 +0000 Subject: [PATCH] [#9 state:port] implemented drag&drop for directories on the cocoa side. --HG-- extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40222 --- base/cocoa/DirectoryPanel.h | 11 +++++- base/cocoa/DirectoryPanel.m | 52 ++++++++++++++++++++++++-- base/cocoa/xib/DirectoryPanel.xib | 62 +++++++++++++++++++------------ 3 files changed, 96 insertions(+), 29 deletions(-) diff --git a/base/cocoa/DirectoryPanel.h b/base/cocoa/DirectoryPanel.h index a606aebc..9beb3928 100644 --- a/base/cocoa/DirectoryPanel.h +++ b/base/cocoa/DirectoryPanel.h @@ -11,10 +11,19 @@ http://www.hardcoded.net/licenses/hs_license #import "Outline.h" #import "PyDupeGuru.h" +@interface DirectoryOutline : OutlineView +{ +} +@end + +@protocol DirectoryOutlineDelegate +- (void)outlineView:(NSOutlineView *)outlineView addDirectory:(NSString *)directory; +@end + @interface DirectoryPanelBase : NSWindowController { IBOutlet NSPopUpButton *addButtonPopUp; - IBOutlet OutlineView *directories; + IBOutlet DirectoryOutline *directories; IBOutlet NSButton *removeButton; PyDupeGuruBase *_py; diff --git a/base/cocoa/DirectoryPanel.m b/base/cocoa/DirectoryPanel.m index 66f99a29..6df9e329 100644 --- a/base/cocoa/DirectoryPanel.m +++ b/base/cocoa/DirectoryPanel.m @@ -11,6 +11,48 @@ http://www.hardcoded.net/licenses/hs_license #import "Utils.h" #import "AppDelegate.h" +@implementation DirectoryOutline +- (void)doInit +{ + [super doInit]; + [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; +} + +- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index +{ + NSPasteboard *pboard; + NSDragOperation sourceDragMask; + sourceDragMask = [info draggingSourceOperationMask]; + pboard = [info draggingPasteboard]; + if ([[pboard types] containsObject:NSFilenamesPboardType]) + { + if (sourceDragMask & NSDragOperationLink) + return NSDragOperationLink; + } + return NSDragOperationNone; +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index +{ + NSPasteboard *pboard; + NSDragOperation sourceDragMask; + sourceDragMask = [info draggingSourceOperationMask]; + pboard = [info draggingPasteboard]; + if ( [[pboard types] containsObject:NSFilenamesPboardType] ) + { + NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType]; + if (!(sourceDragMask & NSDragOperationLink)) + return NO; + if (([self delegate] == nil) || (![[self delegate] respondsToSelector:@selector(outlineView:addDirectory:)])) + return NO; + for (NSString *filename in filenames) + [[self delegate] outlineView:self addDirectory:filename]; + } + return YES; +} + +@end + @implementation DirectoryPanelBase - (id)initWithParentApp:(id)aParentApp { @@ -104,10 +146,7 @@ http://www.hardcoded.net/licenses/hs_license - (IBAction)toggleVisible:(id)sender { - if ([[self window] isVisible]) - [[self window] close]; - else - [[self window] makeKeyAndOrderFront:nil]; + [[self window] makeKeyAndOrderFront:nil]; } /* Public */ @@ -154,6 +193,11 @@ http://www.hardcoded.net/licenses/hs_license /* Delegate */ +- (void)outlineView:(NSOutlineView *)outlineView addDirectory:(NSString *)directory +{ + [self addDirectory:directory]; +} + - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item { OVNode *node = item; diff --git a/base/cocoa/xib/DirectoryPanel.xib b/base/cocoa/xib/DirectoryPanel.xib index 9f8f8e7a..b14f503d 100644 --- a/base/cocoa/xib/DirectoryPanel.xib +++ b/base/cocoa/xib/DirectoryPanel.xib @@ -12,7 +12,7 @@ YES - + YES @@ -39,19 +39,17 @@ NSApplication - 27 + 11 2 {{387, 290}, {369, 269}} - -260571136 + 1886913536 Directories - - NSPanel - + NSWindow View {1.79769e+308, 1.79769e+308} - {213, 113} + {369, 269} 256 @@ -404,7 +402,7 @@ {{0, 0}, {1440, 878}} - {213, 129} + {369, 291} {1.79769e+308, 1.79769e+308} @@ -731,6 +729,11 @@ 18.ImportedFromIB2 31.IBPluginDependency 31.ImportedFromIB2 + 45.IBPluginDependency + 46.IBPluginDependency + 47.IBPluginDependency + 48.IBPluginDependency + 49.IBPluginDependency 49.IBShouldRemoveOnLegacySave 5.IBEditorWindowLastContentRect 5.IBPluginDependency @@ -738,8 +741,12 @@ 5.ImportedFromIB2 5.windowTemplate.hasMinSize 5.windowTemplate.minSize + 50.IBPluginDependency + 51.IBPluginDependency 51.IBShouldRemoveOnLegacySave + 52.IBPluginDependency 52.IBShouldRemoveOnLegacySave + 53.IBPluginDependency 53.IBShouldRemoveOnLegacySave 6.IBPluginDependency 6.ImportedFromIB2 @@ -756,7 +763,7 @@ com.apple.InterfaceBuilder.CocoaPlugin - OutlineView + DirectoryOutline com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -771,15 +778,24 @@ com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{88, 571}, {369, 269}} com.apple.InterfaceBuilder.CocoaPlugin {{88, 571}, {369, 269}} - {213, 113} + {369, 269} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -812,6 +828,14 @@ YES + + DirectoryOutline + OutlineView + + IBProjectSource + dgbase/DirectoryPanel.h + + DirectoryPanel DirectoryPanelBase @@ -895,17 +919,15 @@ YES NSPopUpButton - OutlineView + DirectoryOutline NSButton - - IBProjectSource - dgbase/DirectoryPanel.h - + FirstResponder + NSObject IBUserSource @@ -1328,14 +1350,6 @@ NSTableView - - NSPanel - NSWindow - - IBFrameworkSource - AppKit.framework/Headers/NSPanel.h - - NSPopUpButton NSButton @@ -1485,7 +1499,7 @@ YES - ../dupeguru.xcodeproj + ../../dupeguru.xcodeproj 3