Skip to content

Commit

Permalink
Made CPImageView accept image drag and drop.
Browse files Browse the repository at this point in the history
Reviewed by me.

Conflicts:

	AppKit/CPPasteboard.j
  • Loading branch information
Francisco Ryan Tolmasky I committed Jun 24, 2009
1 parent 2474774 commit 343b3e4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
48 changes: 46 additions & 2 deletions AppKit/CPImageView.j
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ var LEFT_SHADOW_INSET = 3.0,

BOOL _hasShadow;
CPView _shadowView;


BOOL _isEditable;

CGRect _imageRect;
}

Expand Down Expand Up @@ -339,11 +341,47 @@ var LEFT_SHADOW_INSET = 3.0,
[[self nextResponder] mouseDown:anEvent];
}

- (void)setEditable:(BOOL)shouldBeEditable
{
if (_isEditable === shouldBeEditable)
return _isEditable;

_isEditable = shouldBeEditable;

if (_isEditable)
[self registerForDraggedTypes:[CPImagesPboardType]];

else
{
var draggedTypes = [self registeredDraggedTypes];

[self unregisterDraggedTypes];

[draggedTypes removeObjectIdenticalTo:CPImagesPboardType];

[self registerForDraggedTypes:draggedTypes];
}
}

- (BOOL)isEditable
{
return _isEditable;
}

- (void)performDragOperation:(CPDraggingInfo)aSender
{
var images = [CPKeyedUnarchiver unarchiveObjectWithData:[[aSender draggingPasteboard] dataForType:CPImagesPboardType]];

if ([images count])
[self setImage:images[0]];
}

@end

var CPImageViewImageKey = @"CPImageViewImageKey",
CPImageViewImageScalingKey = @"CPImageViewImageScalingKey",
CPImageViewHasShadowKey = @"CPImageViewHasShadowKey";
CPImageViewHasShadowKey = @"CPImageViewHasShadowKey",
CPImageViewIsEditableKey = @"CPImageViewIsEditableKey";

@implementation CPImageView (CPCoding)

Expand Down Expand Up @@ -372,6 +410,9 @@ var CPImageViewImageKey = @"CPImageViewImageKey",

[self setHasShadow:[aCoder decodeBoolForKey:CPImageViewHasShadowKey]];

if ([aCoder decodeBoolForKey:CPImageViewIsEditableKey] || NO)
[self setEditable:YES];

[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
Expand Down Expand Up @@ -402,6 +443,9 @@ var CPImageViewImageKey = @"CPImageViewImageKey",
_subviews = actualSubviews;

[aCoder encodeBool:_hasShadow forKey:CPImageViewHasShadowKey];

if (_isEditable)
[aCoder encodeBool:_isEditable forKey:CPImageViewIsEditableKey];
}

@end
4 changes: 4 additions & 0 deletions AppKit/CPPasteboard.j
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ CPFontPboardType = @"CPFontPboardType";
CPHTMLPboardType = @"CPHTMLPboardType";
CPStringPboardType = @"CPStringPboardType";
CPURLPboardType = @"CPURLPboardType";
CPImagesPboardType = @"CPImagesPboardType";
CPVideosPboardType = @"CPVideosPboardType";

// Deprecated
CPImagePboardType = @"CPImagePboardType";

var CPPasteboards = nil;
Expand Down
2 changes: 1 addition & 1 deletion AppKit/CPView.j
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ setBoundsOrigin:
*/
- (void)registerForDraggedTypes:(CPArray)pasteboardTypes
{
if (!pasteboardTypes)
if (!pasteboardTypes || ![pasteboardTypes count])
return;

var theWindow = [self window];
Expand Down
2 changes: 2 additions & 0 deletions Tools/Rake/lib/objective-j/bundletask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ def BundleTask.compact(path, *patterns)

list.each do |fileName|

fileName = File.expand_path(fileName)

File.open(fileName) do |file|

if fileName.index(platform_absolute_path) == 0
Expand Down
1 change: 1 addition & 0 deletions Tools/nib2cib/NSImageView.j
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
var cell = [aCoder decodeObjectForKey:@"NSCell"];

_imageScaling = [cell imageScaling];
_isEditable = [cell isEditable];
}

return self;
Expand Down

0 comments on commit 343b3e4

Please sign in to comment.