diff --git a/atom/browser/api/atom_api_tray.cc b/atom/browser/api/atom_api_tray.cc index 6bbad738b32d..f2b3b6004119 100644 --- a/atom/browser/api/atom_api_tray.cc +++ b/atom/browser/api/atom_api_tray.cc @@ -74,6 +74,10 @@ void Tray::OnDropFiles(const std::vector& files) { Emit("drop-files", files); } +void Tray::OnDropText(const std::string& text) { + Emit("drop-text", text); +} + void Tray::OnDragEntered() { Emit("drag-enter"); } diff --git a/atom/browser/api/atom_api_tray.h b/atom/browser/api/atom_api_tray.h index 4dd79c467f09..67b56c3b54bf 100644 --- a/atom/browser/api/atom_api_tray.h +++ b/atom/browser/api/atom_api_tray.h @@ -53,6 +53,7 @@ class Tray : public mate::TrackableObject, void OnBalloonClosed() override; void OnDrop() override; void OnDropFiles(const std::vector& files) override; + void OnDropText(const std::string& text) override; void OnDragEntered() override; void OnDragExited() override; void OnDragEnded() override; diff --git a/atom/browser/ui/tray_icon.cc b/atom/browser/ui/tray_icon.cc index fda68b09cd11..7af97b6c0eaa 100644 --- a/atom/browser/ui/tray_icon.cc +++ b/atom/browser/ui/tray_icon.cc @@ -68,6 +68,10 @@ void TrayIcon::NotifyDropFiles(const std::vector& files) { FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDropFiles(files)); } +void TrayIcon::NotifyDropText(const std::string& text) { + FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDropText(text)); +} + void TrayIcon::NotifyDragEntered() { FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragEntered()); } diff --git a/atom/browser/ui/tray_icon.h b/atom/browser/ui/tray_icon.h index 2763e50941b6..278722feea9c 100644 --- a/atom/browser/ui/tray_icon.h +++ b/atom/browser/ui/tray_icon.h @@ -75,6 +75,7 @@ class TrayIcon { int modifiers = 0); void NotifyDrop(); void NotifyDropFiles(const std::vector& files); + void NotifyDropText(const std::string& text); void NotifyDragEntered(); void NotifyDragExited(); void NotifyDragEnded(); diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index 2510d3160cc6..925e4b34c069 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -44,7 +44,10 @@ const CGFloat kVerticalTitleMargin = 2; inMouseEventSequence_ = NO; if ((self = [super initWithFrame: CGRectZero])) { - [self registerForDraggedTypes: @[NSFilenamesPboardType]]; + [self registerForDraggedTypes: @[ + NSFilenamesPboardType, + NSStringPboardType, + ]]; // Create the status item. NSStatusItem * item = [[NSStatusBar systemStatusBar] @@ -306,7 +309,12 @@ const CGFloat kVerticalTitleMargin = 2; dropFiles.push_back(base::SysNSStringToUTF8(file)); trayIcon_->NotifyDropFiles(dropFiles); return YES; + } else if ([[pboard types] containsObject:NSStringPboardType]) { + NSString* dropText = [pboard stringForType:NSStringPboardType]; + trayIcon_->NotifyDropText(base::SysNSStringToUTF8(dropText)); + return YES; } + return NO; } diff --git a/atom/browser/ui/tray_icon_observer.h b/atom/browser/ui/tray_icon_observer.h index ed421ed85452..1782e913d541 100644 --- a/atom/browser/ui/tray_icon_observer.h +++ b/atom/browser/ui/tray_icon_observer.h @@ -24,6 +24,7 @@ class TrayIconObserver { virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {} virtual void OnDrop() {} virtual void OnDropFiles(const std::vector& files) {} + virtual void OnDropText(const std::string& text) {} virtual void OnDragEntered() {} virtual void OnDragExited() {} virtual void OnDragEnded() {} diff --git a/docs/api/tray.md b/docs/api/tray.md index a93e0dbf38d5..5ab68c5e9445 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -122,6 +122,13 @@ Emitted when any dragged items are dropped on the tray icon. Emitted when dragged files are dropped in the tray icon. +#### Event: 'drop-text' _macOS_ + +* `event` Event +* `text` String - the dropped text string + +Emitted when dragged text is dropped in the tray icon. + #### Event: 'drag-enter' _macOS_ Emitted when a drag operation enters the tray icon.