views: Make acceleratros work.

This commit is contained in:
Cheng Zhao 2014-07-04 16:54:10 +08:00
parent 0a38f3321e
commit 3c892b8591
9 changed files with 78 additions and 18 deletions

View file

@ -4,7 +4,7 @@
#include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/api/atom_api_window.h"
#include "atom/browser/native_window.h"
#include "atom/browser/ui/accelerator_util.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "native_mate/constructor.h"
@ -157,6 +157,10 @@ void Menu::MenuWillShow(ui::SimpleMenuModel* source) {
"menuWillShow", -1);
}
void Menu::AttachToWindow(Window* window) {
window->window()->SetMenu(model_.get());
}
void Menu::InsertItemAt(
int index, int command_id, const base::string16& label) {
model_->InsertItemAt(index, command_id, label);
@ -246,9 +250,7 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isItemCheckedAt", &Menu::IsItemCheckedAt)
.SetMethod("isEnabledAt", &Menu::IsEnabledAt)
.SetMethod("isVisibleAt", &Menu::IsVisibleAt)
#if defined(OS_WIN) || defined(OS_LINUX)
.SetMethod("_attachToWindow", &Menu::AttachToWindow)
#endif
#if defined(OS_WIN)
.SetMethod("_updateStates", &Menu::UpdateStates)
#endif

View file

@ -53,6 +53,7 @@ class Menu : public mate::Wrappable,
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE;
virtual void AttachToWindow(Window* window);
virtual void Popup(Window* window) = 0;
scoped_ptr<ui::SimpleMenuModel> model_;
@ -87,10 +88,6 @@ class Menu : public mate::Wrappable,
virtual void UpdateStates() = 0;
#endif
#if defined(OS_WIN) || defined(OS_LINUX)
virtual void AttachToWindow(Window* window) = 0;
#endif
DISALLOW_COPY_AND_ASSIGN(Menu);
};

View file

@ -38,10 +38,6 @@ void MenuGtk::Popup(Window* window) {
*/
}
void MenuGtk::AttachToWindow(Window* window) {
// static_cast<NativeWindowGtk*>(window->window())->SetMenu(model_.get());
}
// static
mate::Wrappable* Menu::Create() {
return new MenuGtk();

View file

@ -19,7 +19,6 @@ class MenuGtk : public Menu,
protected:
virtual void Popup(Window* window) OVERRIDE;
virtual void AttachToWindow(Window* window) OVERRIDE;
private:
scoped_ptr<::MenuGtk> menu_gtk_;