Merge pull request #1303 from atom/write-image
Add clipboard.writeImage API
This commit is contained in:
commit
e2bdbae262
4 changed files with 39 additions and 13 deletions
|
@ -69,6 +69,11 @@ gfx::Image ReadImage(ui::ClipboardType type) {
|
||||||
return gfx::Image::CreateFrom1xBitmap(bitmap);
|
return gfx::Image::CreateFrom1xBitmap(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteImage(const gfx::Image& image, ui::ClipboardType type) {
|
||||||
|
ui::ScopedClipboardWriter writer(type);
|
||||||
|
writer.WriteImage(image.AsBitmap());
|
||||||
|
}
|
||||||
|
|
||||||
void Clear(ui::ClipboardType type) {
|
void Clear(ui::ClipboardType type) {
|
||||||
ui::Clipboard::GetForCurrentThread()->Clear(type);
|
ui::Clipboard::GetForCurrentThread()->Clear(type);
|
||||||
}
|
}
|
||||||
|
@ -81,6 +86,7 @@ void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||||
dict.SetMethod("_readText", &ReadText);
|
dict.SetMethod("_readText", &ReadText);
|
||||||
dict.SetMethod("_writeText", &WriteText);
|
dict.SetMethod("_writeText", &WriteText);
|
||||||
dict.SetMethod("_readImage", &ReadImage);
|
dict.SetMethod("_readImage", &ReadImage);
|
||||||
|
dict.SetMethod("_writeImage", &WriteImage);
|
||||||
dict.SetMethod("_clear", &Clear);
|
dict.SetMethod("_clear", &Clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
if process.platform is 'linux' and process.type is 'renderer'
|
binding = process.atomBinding 'clipboard'
|
||||||
# On Linux we could not access clipboard in renderer process.
|
module.exports =
|
||||||
module.exports = require('remote').require 'clipboard'
|
has: (format, type='standard') -> binding._has format, type
|
||||||
else
|
read: (format, type='standard') -> binding._read format, type
|
||||||
binding = process.atomBinding 'clipboard'
|
readText: (type='standard') -> binding._readText type
|
||||||
|
writeText: (text, type='standard') -> binding._writeText text, type
|
||||||
module.exports =
|
readImage: (type='standard') -> binding._readImage type
|
||||||
has: (format, type='standard') -> binding._has format, type
|
writeImage: (image, type='standard') -> binding._writeImage image, type
|
||||||
read: (format, type='standard') -> binding._read format, type
|
clear: (type='standard') -> binding._clear type
|
||||||
readText: (type='standard') -> binding._readText type
|
|
||||||
writeText: (text, type='standard') -> binding._writeText text, type
|
|
||||||
readImage: (type='standard') -> binding._readImage type
|
|
||||||
clear: (type='standard') -> binding._clear type
|
|
||||||
|
|
|
@ -30,6 +30,19 @@ Returns the content in clipboard as plain text.
|
||||||
|
|
||||||
Writes the `text` into clipboard as plain text.
|
Writes the `text` into clipboard as plain text.
|
||||||
|
|
||||||
|
## clipboard.readImage([type])
|
||||||
|
|
||||||
|
* `type` String
|
||||||
|
|
||||||
|
Returns the content in clipboard as [NativeImage](native-image.md).
|
||||||
|
|
||||||
|
## clipboard.writeImage(image[, type])
|
||||||
|
|
||||||
|
* `image` [NativeImage](native-image.md)
|
||||||
|
* `type` String
|
||||||
|
|
||||||
|
Writes the `image` into clipboard.
|
||||||
|
|
||||||
## clipboard.clear([type])
|
## clipboard.clear([type])
|
||||||
|
|
||||||
* `type` String
|
* `type` String
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
assert = require 'assert'
|
assert = require 'assert'
|
||||||
clipboard = require 'clipboard'
|
clipboard = require 'clipboard'
|
||||||
|
nativeImage = require 'native-image'
|
||||||
|
path = require 'path'
|
||||||
|
|
||||||
describe 'clipboard module', ->
|
describe 'clipboard module', ->
|
||||||
|
fixtures = path.resolve __dirname, 'fixtures'
|
||||||
|
|
||||||
|
describe 'clipboard.readImage()', ->
|
||||||
|
it 'returns NativeImage intance', ->
|
||||||
|
p = path.join fixtures, 'assets', 'logo.png'
|
||||||
|
i = nativeImage.createFromPath p
|
||||||
|
clipboard.writeImage p
|
||||||
|
assert.equal clipboard.readImage().toDataUrl(), i.toDataUrl()
|
||||||
|
|
||||||
describe 'clipboard.readText()', ->
|
describe 'clipboard.readText()', ->
|
||||||
it 'returns unicode string correctly', ->
|
it 'returns unicode string correctly', ->
|
||||||
text = '千江有水千江月,万里无云万里天'
|
text = '千江有水千江月,万里无云万里天'
|
||||||
|
|
Loading…
Reference in a new issue