Adding support to write RTF to clipboard.
authorVjekoslav Ratkajec <vjeko@labtiva.com>
Thu, 4 Feb 2016 18:38:47 +0000 (19:38 +0100)
committerVjekoslav Ratkajec <vjeko@labtiva.com>
Thu, 4 Feb 2016 18:38:47 +0000 (19:38 +0100)
atom/common/api/atom_api_clipboard.cc
docs/api/clipboard.md

index 0837a3d..5060db1 100644 (file)
@@ -60,6 +60,11 @@ void Write(const mate::Dictionary& data,
   if (data.Get("text", &text))
     writer.WriteText(text);
 
+  if (data.Get("rtf", &text)) {
+    std::string rtf = base::UTF16ToUTF8(text);
+    writer.WriteRTF(rtf);
+  }
+
   if (data.Get("html", &html))
     writer.WriteHTML(html, std::string());
 
@@ -88,6 +93,11 @@ void WriteText(const base::string16& text, mate::Arguments* args) {
   writer.WriteText(text);
 }
 
+void WriteRtf(const std::string& text, mate::Arguments* args) {
+  ui::ScopedClipboardWriter writer(GetClipboardType(args));
+  writer.WriteRTF(text);
+}
+
 base::string16 ReadHtml(mate::Arguments* args) {
   base::string16 data;
   base::string16 html;
@@ -129,6 +139,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
   dict.SetMethod("write", &Write);
   dict.SetMethod("readText", &ReadText);
   dict.SetMethod("writeText", &WriteText);
+  dict.SetMethod("writeRtf", &WriteRtf);
   dict.SetMethod("readHtml", &ReadHtml);
   dict.SetMethod("writeHtml", &WriteHtml);
   dict.SetMethod("readImage", &ReadImage);
index 7cb5b84..a655977 100644 (file)
@@ -61,6 +61,12 @@ Returns the content in the clipboard as a [NativeImage](native-image.md).
 
 Writes `image` to the clipboard.
 
+### `clipboard.writeRtf(text)`
+
+* `text` String
+
+Writes the `text` into the clipboard in RTF.
+
 ### `clipboard.clear([type])`
 
 * `type` String (optional)