summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/tests/test_string.cpp31
-rw-r--r--core/ustring.cpp8
-rw-r--r--scene/gui/line_edit.cpp7
-rw-r--r--tools/editor/property_editor.cpp53
-rw-r--r--tools/editor/property_editor.h2
5 files changed, 96 insertions, 5 deletions
diff --git a/bin/tests/test_string.cpp b/bin/tests/test_string.cpp
index 78fb9a9ddb..66238b066d 100644
--- a/bin/tests/test_string.cpp
+++ b/bin/tests/test_string.cpp
@@ -479,6 +479,36 @@ bool test_26() {
return captures.size();
};
+struct test_27_data {
+ char const * data;
+ char const * begin;
+ bool expected;
+};
+
+bool test_27() {
+
+ OS::get_singleton()->print("\n\nTest 26: begins_with\n");
+ test_27_data tc[] = {
+ {"res://foobar", "res://", true},
+ {"res", "res://", false},
+ {"abc", "abc", true}
+ };
+ size_t count = sizeof(tc) / sizeof(tc[0]);
+ bool state = true;
+ for (size_t i = 0;state && i < count; ++i) {
+ String s = tc[i].data;
+ state = s.begins_with(tc[i].begin) == tc[i].expected;
+ if (state) {
+ String sb = tc[i].begin;
+ state = s.begins_with(sb) == tc[i].expected;
+ }
+ if (!state) {
+ OS::get_singleton()->print("\n\t Failure on:\n\t\tstring: ", tc[i].data, "\n\t\tbegin: ", tc[i].begin, "\n\t\texpected: ", tc[i].expected ? "true" : "false", "\n");
+ }
+ };
+ return state;
+};
+
typedef bool (*TestFunc)(void);
TestFunc test_funcs[] = {
@@ -509,6 +539,7 @@ TestFunc test_funcs[] = {
test_24,
test_25,
test_26,
+ test_27,
0
};
diff --git a/core/ustring.cpp b/core/ustring.cpp
index b0f06c6ab6..2384ce5bd6 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -2491,19 +2491,21 @@ bool String::begins_with(const String& p_string) const {
const CharType *src=&p_string[0];
const CharType *str=&operator[](0);
- for (int i=0;i<l;i++) {
+ int i = 0;
+ for (;i<l;i++) {
if (src[i]!=str[i])
return false;
}
- return true;
+ // only if i == l the p_string matches the beginning
+ return i == l;
}
bool String::begins_with(const char* p_string) const {
int l=length();
- if (l==0)
+ if (l==0||!p_string)
return false;
const CharType *str=&operator[](0);
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index ad1b7fd66b..22316acaba 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -748,6 +748,11 @@ bool LineEdit::is_secret() const {
void LineEdit::select(int p_from, int p_to) {
+ if (p_from==0 && p_to==0) {
+ selection_clear();
+ return;
+ }
+
int len = text.length();
if (p_from<0)
p_from=0;
@@ -786,7 +791,7 @@ void LineEdit::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_editable"),&LineEdit::is_editable);
ObjectTypeDB::bind_method(_MD("set_secret","enabled"),&LineEdit::set_secret);
ObjectTypeDB::bind_method(_MD("is_secret"),&LineEdit::is_secret);
- ObjectTypeDB::bind_method(_MD("select","from","to"),&LineEdit::is_secret,DEFVAL(0),DEFVAL(-1));
+ ObjectTypeDB::bind_method(_MD("select","from","to"),&LineEdit::select,DEFVAL(0),DEFVAL(-1));
ADD_SIGNAL( MethodInfo("text_changed", PropertyInfo( Variant::STRING, "text" )) );
ADD_SIGNAL( MethodInfo("text_entered", PropertyInfo( Variant::STRING, "text" )) );
diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp
index 6b34e3f555..1cce161d08 100644
--- a/tools/editor/property_editor.cpp
+++ b/tools/editor/property_editor.cpp
@@ -51,7 +51,7 @@ void CustomPropertyEditor::_notification(int p_what) {
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( 10,10,60, get_size().height-20 ), v );
}*/
- }
+ }
}
@@ -1397,6 +1397,53 @@ void CustomPropertyEditor::_modified(String p_string) {
updating=false;
}
+void CustomPropertyEditor::_focus_enter() {
+ switch(type) {
+ case Variant::REAL:
+ case Variant::STRING:
+ case Variant::VECTOR2:
+ case Variant::RECT2:
+ case Variant::VECTOR3:
+ case Variant::PLANE:
+ case Variant::QUAT:
+ case Variant::_AABB:
+ case Variant::MATRIX32:
+ case Variant::MATRIX3:
+ case Variant::TRANSFORM: {
+ for (int i=0;i<MAX_VALUE_EDITORS;++i) {
+ if (value_editor[i]->has_focus()) {
+ value_editor[i]->select_all();
+ break;
+ }
+ }
+ } break;
+ default: {}
+ }
+
+}
+
+void CustomPropertyEditor::_focus_exit() {
+ switch(type) {
+ case Variant::REAL:
+ case Variant::STRING:
+ case Variant::VECTOR2:
+ case Variant::RECT2:
+ case Variant::VECTOR3:
+ case Variant::PLANE:
+ case Variant::QUAT:
+ case Variant::_AABB:
+ case Variant::MATRIX32:
+ case Variant::MATRIX3:
+ case Variant::TRANSFORM: {
+ for (int i=0;i<MAX_VALUE_EDITORS;++i) {
+ value_editor[i]->select(0, 0);
+ }
+ } break;
+ default: {}
+ }
+
+}
+
void CustomPropertyEditor::config_action_buttons(const List<String>& p_strings) {
int w=100;
@@ -1456,6 +1503,8 @@ void CustomPropertyEditor::config_value_editors(int p_amount, int p_columns,int
void CustomPropertyEditor::_bind_methods() {
+ ObjectTypeDB::bind_method("_focus_enter", &CustomPropertyEditor::_focus_enter);
+ ObjectTypeDB::bind_method("_focus_exit", &CustomPropertyEditor::_focus_exit);
ObjectTypeDB::bind_method("_modified",&CustomPropertyEditor::_modified);
ObjectTypeDB::bind_method("_scroll_modified",&CustomPropertyEditor::_scroll_modified);
ObjectTypeDB::bind_method("_action_pressed",&CustomPropertyEditor::_action_pressed);
@@ -1487,6 +1536,8 @@ CustomPropertyEditor::CustomPropertyEditor() {
value_editor[i]->hide();
value_label[i]->hide();
value_editor[i]->connect("text_entered", this,"_modified");
+ value_editor[i]->connect("focus_enter", this, "_focus_enter");
+ value_editor[i]->connect("focus_exit", this, "_focus_exit");
}
for(int i=0;i<4;i++) {
diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h
index fc0330c25d..7ee14679c1 100644
--- a/tools/editor/property_editor.h
+++ b/tools/editor/property_editor.h
@@ -105,6 +105,8 @@ class CustomPropertyEditor : public Popup {
void _file_selected(String p_file);
void _scroll_modified(double p_value);
void _modified(String p_string);
+ void _focus_enter();
+ void _focus_exit();
void _action_pressed(int p_which);
void _type_create_selected(int p_idx);