Add Tray.destroy() API, fixes #871

This commit is contained in:
Cheng Zhao 2014-11-28 18:06:51 +08:00
parent 86cf5e0028
commit f6c66a7374
3 changed files with 49 additions and 12 deletions

View file

@ -40,34 +40,60 @@ void Tray::OnDoubleClicked() {
Emit("double-clicked"); Emit("double-clicked");
} }
void Tray::SetImage(const gfx::ImageSkia& image) { void Tray::Destroy() {
tray_icon_.reset();
}
void Tray::SetImage(mate::Arguments* args, const gfx::ImageSkia& image) {
if (!CheckTrayLife(args))
return;
tray_icon_->SetImage(image); tray_icon_->SetImage(image);
} }
void Tray::SetPressedImage(const gfx::ImageSkia& image) { void Tray::SetPressedImage(mate::Arguments* args, const gfx::ImageSkia& image) {
if (!CheckTrayLife(args))
return;
tray_icon_->SetPressedImage(image); tray_icon_->SetPressedImage(image);
} }
void Tray::SetToolTip(const std::string& tool_tip) { void Tray::SetToolTip(mate::Arguments* args, const std::string& tool_tip) {
if (!CheckTrayLife(args))
return;
tray_icon_->SetToolTip(tool_tip); tray_icon_->SetToolTip(tool_tip);
} }
void Tray::SetTitle(const std::string& title) { void Tray::SetTitle(mate::Arguments* args, const std::string& title) {
if (!CheckTrayLife(args))
return;
tray_icon_->SetTitle(title); tray_icon_->SetTitle(title);
} }
void Tray::SetHighlightMode(bool highlight) { void Tray::SetHighlightMode(mate::Arguments* args, bool highlight) {
if (!CheckTrayLife(args))
return;
tray_icon_->SetHighlightMode(highlight); tray_icon_->SetHighlightMode(highlight);
} }
void Tray::SetContextMenu(Menu* menu) { void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
if (!CheckTrayLife(args))
return;
tray_icon_->SetContextMenu(menu->model()); tray_icon_->SetContextMenu(menu->model());
} }
bool Tray::CheckTrayLife(mate::Arguments* args) {
if (!tray_icon_) {
args->ThrowError("Tray is already destroyed");
return false;
} else {
return true;
}
}
// static // static
void Tray::BuildPrototype(v8::Isolate* isolate, void Tray::BuildPrototype(v8::Isolate* isolate,
v8::Handle<v8::ObjectTemplate> prototype) { v8::Handle<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype) mate::ObjectTemplateBuilder(isolate, prototype)
.SetMethod("destroy", &Tray::Destroy)
.SetMethod("setImage", &Tray::SetImage) .SetMethod("setImage", &Tray::SetImage)
.SetMethod("setPressedImage", &Tray::SetPressedImage) .SetMethod("setPressedImage", &Tray::SetPressedImage)
.SetMethod("setToolTip", &Tray::SetToolTip) .SetMethod("setToolTip", &Tray::SetToolTip)

View file

@ -15,6 +15,10 @@ namespace gfx {
class ImageSkia; class ImageSkia;
} }
namespace mate {
class Arguments;
}
namespace atom { namespace atom {
class TrayIcon; class TrayIcon;
@ -39,14 +43,17 @@ class Tray : public mate::EventEmitter,
void OnClicked() override; void OnClicked() override;
void OnDoubleClicked() override; void OnDoubleClicked() override;
void SetImage(const gfx::ImageSkia& image); void Destroy();
void SetPressedImage(const gfx::ImageSkia& image); void SetImage(mate::Arguments* args, const gfx::ImageSkia& image);
void SetToolTip(const std::string& tool_tip); void SetPressedImage(mate::Arguments* args, const gfx::ImageSkia& image);
void SetTitle(const std::string& title); void SetToolTip(mate::Arguments* args, const std::string& tool_tip);
void SetHighlightMode(bool highlight); void SetTitle(mate::Arguments* args, const std::string& title);
void SetContextMenu(Menu* menu); void SetHighlightMode(mate::Arguments* args, bool highlight);
void SetContextMenu(mate::Arguments* args, Menu* menu);
private: private:
bool CheckTrayLife(mate::Arguments* args);
scoped_ptr<TrayIcon> tray_icon_; scoped_ptr<TrayIcon> tray_icon_;
DISALLOW_COPY_AND_ASSIGN(Tray); DISALLOW_COPY_AND_ASSIGN(Tray);

View file

@ -54,6 +54,10 @@ Emitted when the tray icon is double clicked.
This is only implmented on OS X. This is only implmented on OS X.
### Tray.destroy()
Destroys the tray icon immediately.
### Tray.setImage(image) ### Tray.setImage(image)
* `image` [Image](image.md) * `image` [Image](image.md)