Add clipboard support for Windows (#8978)

EricApostal and Mikayla Maki created

Release Notes:

- Added Read / Write clipboard support to Windows via copypasta

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>

Change summary

.gitignore                                   |  2 +-
crates/gpui/Cargo.toml                       |  4 ++--
crates/gpui/src/platform/windows/platform.rs | 13 +++++++++----
3 files changed, 12 insertions(+), 7 deletions(-)

Detailed changes

.gitignore 🔗

@@ -22,4 +22,4 @@ DerivedData/
 **/*.db
 .pytest_cache
 .venv
-.blob_store
+.blob_store

crates/gpui/Cargo.toml 🔗

@@ -103,6 +103,7 @@ blade-macros.workspace = true
 blade-rwh.workspace = true
 bytemuck = "1"
 cosmic-text = "0.10.0"
+copypasta = "0.10.1"
 
 [target.'cfg(target_os = "linux")'.dependencies]
 open = "5.0.1"
@@ -116,7 +117,6 @@ xkbcommon = { version = "0.7", features = ["wayland", "x11"] }
 as-raw-xcb-connection = "1"
 calloop = "0.12.4"
 calloop-wayland-source = "0.2.0"
-copypasta = "0.10.1"
 oo7 = "0.3.0"
 
 [target.'cfg(windows)'.dependencies]
@@ -128,4 +128,4 @@ path = "examples/hello_world.rs"
 
 [[example]]
 name = "image"
-path = "examples/image/image.rs"
+path = "examples/image/image.rs"

crates/gpui/src/platform/windows/platform.rs 🔗

@@ -13,6 +13,7 @@ use std::{
 
 use anyhow::{anyhow, Result};
 use async_task::Runnable;
+use copypasta::{ClipboardContext, ClipboardProvider};
 use futures::channel::oneshot::Receiver;
 use parking_lot::Mutex;
 use time::UtcOffset;
@@ -493,14 +494,18 @@ impl Platform for WindowsPlatform {
         false
     }
 
-    // todo(windows)
     fn write_to_clipboard(&self, item: ClipboardItem) {
-        unimplemented!()
+        let mut ctx = ClipboardContext::new().unwrap();
+        ctx.set_contents(item.text().to_owned()).unwrap();
     }
 
-    // todo(windows)
     fn read_from_clipboard(&self) -> Option<ClipboardItem> {
-        unimplemented!()
+        let mut ctx = ClipboardContext::new().unwrap();
+        let content = ctx.get_contents().unwrap();
+        Some(ClipboardItem {
+            text: content,
+            metadata: None,
+        })
     }
 
     // todo(windows)