Make Accelerator a standalone JS type.

This makes menu and global-shortcut share the same code on accelerator.
This commit is contained in:
Cheng Zhao 2014-08-05 00:00:39 +08:00
parent 28b9df24a6
commit 6dc01945af
9 changed files with 114 additions and 65 deletions

View file

@ -0,0 +1,20 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/common/native_mate_converters/accelerator_converter.h"
#include "atom/browser/ui/accelerator_util.h"
namespace mate {
// static
bool Converter<ui::Accelerator>::FromV8(
v8::Isolate* isolate, v8::Handle<v8::Value> val, ui::Accelerator* out) {
std::string keycode;
if (!ConvertFromV8(isolate, val, &keycode))
return false;
return accelerator_util::StringToAccelerator(keycode, out);
}
} // namespace mate

View file

@ -0,0 +1,24 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_
#include "native_mate/converter.h"
namespace ui {
class Accelerator;
}
namespace mate {
template<>
struct Converter<ui::Accelerator> {
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
ui::Accelerator* out);
};
} // namespace mate
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_