Skip to content

Commit

Permalink
Merge pull request #2283 from arthurevans/timob-9222
Browse files Browse the repository at this point in the history
[TIMOB-9222][TIMOB-9223] Clipboard fixes in honor of Hal.
  • Loading branch information
Max Stepanov committed May 29, 2012
2 parents ef65d04 + 42a7d99 commit 8d04581
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
38 changes: 38 additions & 0 deletions drillbit/tests/ui.clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe("Ti.UI.Clipboard tests", {
setAndGetText: function() {
Ti.UI.Clipboard.setText('hello');
valueOf(Ti.UI.Clipboard.hasText()).shouldBeTrue();
valueOf(Ti.UI.Clipboard.getText()).shouldBe('hello');
},

clearText: function() {
valueOf(function() {
Ti.UI.Clipboard.clearText();
}).shouldNotThrowException();
valueOf(Ti.UI.Clipboard.hasText()).shouldBeFalse();
// Return value of getText() varies by platform: TIMOB-9224
// So we can't test it, but at least it shouldn't throw an exception.
valueOf(function() {
Ti.UI.Clipboard.getText();
}).shouldNotThrowException();
},

// Using setData to store text with a mime type.
setAndGetHTML: function() {
// Clear all data first.
Ti.UI.Clipboard.clearData();
     Ti.UI.Clipboard.setData('text/html', "<p>How is <em>this</em> for data?</p>");
valueOf(Ti.UI.Clipboard.hasData('text/html')).shouldBeTrue();
valueOf(Ti.UI.Clipboard.getData('text/html'))
.shouldBe("<p>How is <em>this</em> for data?</p>");
},

// Data with mimeType 'text/url-list' or 'url' is treated as a URL on iOS, so
// follows a different code path than plain text or images.
urlData: function() {
Ti.UI.Clipboard.clearData();
Ti.UI.Clipboard.setData('text/url-list', "http://www.appcelerator.com");
valueOf(Ti.UI.Clipboard.getData('text/url-list')).shouldBe("http://www.appcelerator.com");
}

});
4 changes: 2 additions & 2 deletions iphone/Classes/TiUIClipboardProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
-(void)clearText:(id)args;
-(id)getData:(id)args;
-(NSString *)getText:(id)args;
-(BOOL)hasData:(id)args;
-(BOOL)hasText:(id)args;
-(id)hasData:(id)args;
-(id)hasText:(id)args;
-(void)setData:(id)args;
-(void)setText:(id)args;

Expand Down
36 changes: 32 additions & 4 deletions iphone/Classes/TiUIClipboardProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,20 @@ -(void)clearText:(id)args
board.strings = nil;
}

-(id)getData:(id)arg
-(id)getData:(id)args
{
id arg = nil;
if ([args isKindOfClass:[NSArray class]])
{
if ([args count] > 0)
{
arg = [args objectAtIndex:0];
}
}
else
{
arg = args;
}
ENSURE_STRING(arg);
NSString *mimeType = arg;
__block id result;
Expand Down Expand Up @@ -153,8 +165,20 @@ -(NSString *)getText:(id)args
return [self getData: @"text/plain"];
}

-(BOOL)hasData:(id)arg
-(id)hasData:(id)args
{
id arg = nil;
if ([args isKindOfClass:[NSArray class]])
{
if ([args count] > 0)
{
arg = [args objectAtIndex:0];
}
}
else
{
arg = args;
}
ENSURE_STRING_OR_NIL(arg);
NSString *mimeType = arg;
__block BOOL result=NO;
Expand Down Expand Up @@ -187,10 +211,10 @@ -(BOOL)hasData:(id)arg
}
}
}, YES);
return result;
return NUMBOOL(result);
}

-(BOOL)hasText:(id)args
-(id)hasText:(id)args
{
return [self hasData: @"text/plain"];
}
Expand All @@ -202,6 +226,10 @@ -(void)setData:(id)args

NSString *mimeType = [TiUtils stringValue: [args objectAtIndex: 0]];
id data = [args objectAtIndex: 1];
if (data == nil) {
DebugLog(@"[WARN] setData: data object was nil.");
return;
}
UIPasteboard *board = [UIPasteboard generalPasteboard];
ClipboardType dataType = mimeTypeToDataType(mimeType);

Expand Down

0 comments on commit 8d04581

Please sign in to comment.