feat: add SetText for TextField
This commit is contained in:
parent
70e17b5f8f
commit
a11182ca84
2 changed files with 19 additions and 1 deletions
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include "atom/common/api/constructor.h"
|
#include "atom/common/api/constructor.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "ui/views/controls/textfield/textfield.h"
|
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
|
@ -20,6 +19,14 @@ TextField::TextField() : View(new views::Textfield()) {
|
||||||
|
|
||||||
TextField::~TextField() {}
|
TextField::~TextField() {}
|
||||||
|
|
||||||
|
void TextField::SetText(const base::string16& new_text) {
|
||||||
|
text_field()->SetText(new_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
base::string16 TextField::GetText() const {
|
||||||
|
return text_field()->text();
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::WrappableBase* TextField::New(mate::Arguments* args) {
|
mate::WrappableBase* TextField::New(mate::Arguments* args) {
|
||||||
// Constructor call.
|
// Constructor call.
|
||||||
|
@ -32,6 +39,9 @@ mate::WrappableBase* TextField::New(mate::Arguments* args) {
|
||||||
void TextField::BuildPrototype(v8::Isolate* isolate,
|
void TextField::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "TextField"));
|
prototype->SetClassName(mate::StringToV8(isolate, "TextField"));
|
||||||
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
|
.SetMethod("setText", &TextField::SetText)
|
||||||
|
.SetMethod("getText", &TextField::GetText);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_view.h"
|
#include "atom/browser/api/atom_api_view.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
#include "ui/views/controls/textfield/textfield.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -19,10 +20,17 @@ class TextField : public View {
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
|
void SetText(const base::string16& new_text);
|
||||||
|
base::string16 GetText() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextField();
|
TextField();
|
||||||
~TextField() override;
|
~TextField() override;
|
||||||
|
|
||||||
|
views::Textfield* text_field() const {
|
||||||
|
return static_cast<views::Textfield*>(view());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(TextField);
|
DISALLOW_COPY_AND_ASSIGN(TextField);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue