Add support for dropped text in osx

This commit is contained in:
Wilson Page 2016-07-14 18:21:39 +01:00
parent 43e9f30b21
commit 90f8a7e828
7 changed files with 27 additions and 1 deletions

View file

@ -74,6 +74,10 @@ void Tray::OnDropFiles(const std::vector<std::string>& files) {
Emit("drop-files", files); Emit("drop-files", files);
} }
void Tray::OnDropText(const std::string& text) {
Emit("drop-text", text);
}
void Tray::OnDragEntered() { void Tray::OnDragEntered() {
Emit("drag-enter"); Emit("drag-enter");
} }

View file

@ -53,6 +53,7 @@ class Tray : public mate::TrackableObject<Tray>,
void OnBalloonClosed() override; void OnBalloonClosed() override;
void OnDrop() override; void OnDrop() override;
void OnDropFiles(const std::vector<std::string>& files) override; void OnDropFiles(const std::vector<std::string>& files) override;
void OnDropText(const std::string& text) override;
void OnDragEntered() override; void OnDragEntered() override;
void OnDragExited() override; void OnDragExited() override;
void OnDragEnded() override; void OnDragEnded() override;

View file

@ -68,6 +68,10 @@ void TrayIcon::NotifyDropFiles(const std::vector<std::string>& files) {
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDropFiles(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() { void TrayIcon::NotifyDragEntered() {
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragEntered()); FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragEntered());
} }

View file

@ -75,6 +75,7 @@ class TrayIcon {
int modifiers = 0); int modifiers = 0);
void NotifyDrop(); void NotifyDrop();
void NotifyDropFiles(const std::vector<std::string>& files); void NotifyDropFiles(const std::vector<std::string>& files);
void NotifyDropText(const std::string& text);
void NotifyDragEntered(); void NotifyDragEntered();
void NotifyDragExited(); void NotifyDragExited();
void NotifyDragEnded(); void NotifyDragEnded();

View file

@ -44,7 +44,10 @@ const CGFloat kVerticalTitleMargin = 2;
inMouseEventSequence_ = NO; inMouseEventSequence_ = NO;
if ((self = [super initWithFrame: CGRectZero])) { if ((self = [super initWithFrame: CGRectZero])) {
[self registerForDraggedTypes: @[NSFilenamesPboardType]]; [self registerForDraggedTypes: @[
NSFilenamesPboardType,
NSStringPboardType,
]];
// Create the status item. // Create the status item.
NSStatusItem * item = [[NSStatusBar systemStatusBar] NSStatusItem * item = [[NSStatusBar systemStatusBar]
@ -306,7 +309,12 @@ const CGFloat kVerticalTitleMargin = 2;
dropFiles.push_back(base::SysNSStringToUTF8(file)); dropFiles.push_back(base::SysNSStringToUTF8(file));
trayIcon_->NotifyDropFiles(dropFiles); trayIcon_->NotifyDropFiles(dropFiles);
return YES; return YES;
} else if ([[pboard types] containsObject:NSStringPboardType]) {
NSString* dropText = [pboard stringForType:NSStringPboardType];
trayIcon_->NotifyDropText(base::SysNSStringToUTF8(dropText));
return YES;
} }
return NO; return NO;
} }

View file

@ -24,6 +24,7 @@ class TrayIconObserver {
virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {} virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {}
virtual void OnDrop() {} virtual void OnDrop() {}
virtual void OnDropFiles(const std::vector<std::string>& files) {} virtual void OnDropFiles(const std::vector<std::string>& files) {}
virtual void OnDropText(const std::string& text) {}
virtual void OnDragEntered() {} virtual void OnDragEntered() {}
virtual void OnDragExited() {} virtual void OnDragExited() {}
virtual void OnDragEnded() {} virtual void OnDragEnded() {}

View file

@ -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. 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_ #### Event: 'drag-enter' _macOS_
Emitted when a drag operation enters the tray icon. Emitted when a drag operation enters the tray icon.