Merge pull request #643 from atom/mac-tray
Add some OS X only Tray APIs
This commit is contained in:
commit
ba439b6824
8 changed files with 79 additions and 1 deletions
|
@ -36,6 +36,10 @@ void Tray::OnClicked() {
|
|||
Emit("clicked");
|
||||
}
|
||||
|
||||
void Tray::OnDoubleClicked() {
|
||||
Emit("double-clicked");
|
||||
}
|
||||
|
||||
void Tray::SetImage(const gfx::ImageSkia& image) {
|
||||
tray_icon_->SetImage(image);
|
||||
}
|
||||
|
@ -48,6 +52,14 @@ void Tray::SetToolTip(const std::string& tool_tip) {
|
|||
tray_icon_->SetToolTip(tool_tip);
|
||||
}
|
||||
|
||||
void Tray::SetTitle(const std::string& title) {
|
||||
tray_icon_->SetTitle(title);
|
||||
}
|
||||
|
||||
void Tray::SetHighlightMode(bool highlight) {
|
||||
tray_icon_->SetHighlightMode(highlight);
|
||||
}
|
||||
|
||||
void Tray::SetContextMenu(Menu* menu) {
|
||||
tray_icon_->SetContextMenu(menu->model());
|
||||
}
|
||||
|
@ -59,6 +71,8 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("setImage", &Tray::SetImage)
|
||||
.SetMethod("setPressedImage", &Tray::SetPressedImage)
|
||||
.SetMethod("setToolTip", &Tray::SetToolTip)
|
||||
.SetMethod("setTitle", &Tray::SetTitle)
|
||||
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
|
||||
.SetMethod("_setContextMenu", &Tray::SetContextMenu);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,10 +37,13 @@ class Tray : public mate::EventEmitter,
|
|||
|
||||
// TrayIcon implementations:
|
||||
virtual void OnClicked() OVERRIDE;
|
||||
virtual void OnDoubleClicked() OVERRIDE;
|
||||
|
||||
void SetImage(const gfx::ImageSkia& image);
|
||||
void SetPressedImage(const gfx::ImageSkia& image);
|
||||
void SetToolTip(const std::string& tool_tip);
|
||||
void SetTitle(const std::string& title);
|
||||
void SetHighlightMode(bool highlight);
|
||||
void SetContextMenu(Menu* menu);
|
||||
|
||||
private:
|
||||
|
|
|
@ -12,8 +12,18 @@ TrayIcon::TrayIcon() {
|
|||
TrayIcon::~TrayIcon() {
|
||||
}
|
||||
|
||||
void TrayIcon::SetTitle(const std::string& title) {
|
||||
}
|
||||
|
||||
void TrayIcon::SetHighlightMode(bool highlight) {
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyClicked() {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked());
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyDoubleClicked() {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDoubleClicked());
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -31,12 +31,21 @@ class TrayIcon {
|
|||
// status icon (e.g. Ubuntu Unity).
|
||||
virtual void SetToolTip(const std::string& tool_tip) = 0;
|
||||
|
||||
// Sets the title displayed aside of the status icon in the status bar. This
|
||||
// only works on OS X.
|
||||
virtual void SetTitle(const std::string& title);
|
||||
|
||||
// Sets whether the status icon is highlighted when it is clicked. This only
|
||||
// works on OS X.
|
||||
virtual void SetHighlightMode(bool highlight);
|
||||
|
||||
// Set the context menu for this icon.
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
|
||||
|
||||
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
|
||||
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
|
||||
void NotifyClicked();
|
||||
void NotifyDoubleClicked();
|
||||
|
||||
protected:
|
||||
TrayIcon();
|
||||
|
|
|
@ -25,6 +25,8 @@ class TrayIconCocoa : public TrayIcon {
|
|||
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
||||
virtual void SetTitle(const std::string& title) OVERRIDE;
|
||||
virtual void SetHighlightMode(bool highlight) OVERRIDE;
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
|
||||
|
||||
private:
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
}
|
||||
- (id)initWithIcon:(atom::TrayIconCocoa*)icon;
|
||||
- (void)handleClick:(id)sender;
|
||||
- (void)handleDoubleClick:(id)sender;
|
||||
|
||||
@end // @interface StatusItemController
|
||||
|
||||
|
@ -24,10 +25,13 @@
|
|||
}
|
||||
|
||||
- (void)handleClick:(id)sender {
|
||||
DCHECK(trayIcon_);
|
||||
trayIcon_->NotifyClicked();
|
||||
}
|
||||
|
||||
- (void)handleDoubleClick:(id)sender {
|
||||
trayIcon_->NotifyDoubleClicked();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace atom {
|
||||
|
@ -40,6 +44,7 @@ TrayIconCocoa::TrayIconCocoa() {
|
|||
[item_ setEnabled:YES];
|
||||
[item_ setTarget:controller_];
|
||||
[item_ setAction:@selector(handleClick:)];
|
||||
[item_ setDoubleAction:@selector(handleDoubleClick:)];
|
||||
[item_ setHighlightMode:YES];
|
||||
}
|
||||
|
||||
|
@ -68,6 +73,14 @@ void TrayIconCocoa::SetToolTip(const std::string& tool_tip) {
|
|||
[item_ setToolTip:base::SysUTF8ToNSString(tool_tip)];
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetTitle(const std::string& title) {
|
||||
[item_ setTitle:base::SysUTF8ToNSString(title)];
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetHighlightMode(bool highlight) {
|
||||
[item_ setHighlightMode:highlight];
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
menu_.reset([[AtomMenuController alloc] initWithModel:menu_model]);
|
||||
[item_ setMenu:[menu_ menu]];
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace atom {
|
|||
class TrayIconObserver {
|
||||
public:
|
||||
virtual void OnClicked() {}
|
||||
virtual void OnDoubleClicked() {}
|
||||
|
||||
protected:
|
||||
virtual ~TrayIconObserver() {}
|
||||
|
|
|
@ -48,6 +48,12 @@ Creates a new tray icon associated with the `image`.
|
|||
|
||||
Emitted when the tray icon is clicked.
|
||||
|
||||
### Event: 'double-clicked'
|
||||
|
||||
Emitted when the tray icon is double clicked.
|
||||
|
||||
This is only implmented on OS X.
|
||||
|
||||
### Tray.setImage(image)
|
||||
|
||||
* `image` [Image](image.md)
|
||||
|
@ -64,8 +70,28 @@ Sets the `image` associated with this tray icon when pressed.
|
|||
|
||||
* `toolTip` String
|
||||
|
||||
Sets the hover text for this tray icon.
|
||||
|
||||
### Tray.setTitle(title)
|
||||
|
||||
* `title` String
|
||||
|
||||
Sets the title displayed aside of the tray icon in the status bar.
|
||||
|
||||
This is only implmented on OS X.
|
||||
|
||||
### Tray.setHighlightMode(highlight)
|
||||
|
||||
* `highlight` String
|
||||
|
||||
Sets whether the tray icon is highlighted when it is clicked.
|
||||
|
||||
This is only implmented on OS X.
|
||||
|
||||
### Tray.setContextMenu(menu)
|
||||
|
||||
* `menu` Menu
|
||||
|
||||
Set the context menu for this icon.
|
||||
|
||||
[event-emitter]: http://nodejs.org/api/events.html#events_class_events_eventemitter
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue