瀏覽代碼

Merge pull request #509 from marynate/PR-script-editor-replace-dialog

Script editor: Add selected text in replace dialog automatically
reduz 11 年之前
父節點
當前提交
6cb3c94b03
共有 1 個文件被更改,包括 14 次插入5 次删除
  1. 14 5
      tools/editor/code_editor.cpp

+ 14 - 5
tools/editor/code_editor.cpp

@@ -102,12 +102,21 @@ void FindReplaceDialog::popup_replace() {
 	bool do_selection=(text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line());
 	bool do_selection=(text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line());
 	set_replace_selection_only(do_selection);
 	set_replace_selection_only(do_selection);
 
 
+	if (!do_selection && text_edit->is_selection_active()) {
+		search_text->set_text(text_edit->get_selection_text());
+	}
+
 	replace_mc->show();
 	replace_mc->show();
 	replace_label->show();
 	replace_label->show();
 	replace_vb->show();
 	replace_vb->show();
 	popup_centered(Point2(300,300));
 	popup_centered(Point2(300,300));
-	search_text->grab_focus();
-	search_text->select_all();
+	if (search_text->get_text()!="" && replace_text->get_text()=="") {
+		search_text->select(0,0);
+		replace_text->grab_focus();
+	} else {
+		search_text->grab_focus();
+		search_text->select_all();
+	}
 	error_label->set_text("");
 	error_label->set_text("");
 
 
 	if (prompt->is_pressed()) {
 	if (prompt->is_pressed()) {
@@ -372,7 +381,7 @@ void FindReplaceDialog::_bind_methods() {
 
 
 FindReplaceDialog::FindReplaceDialog() {
 FindReplaceDialog::FindReplaceDialog() {
 
 
-	set_self_opacity(0.6);
+	set_self_opacity(0.8);
 
 
 	VBoxContainer *vb = memnew( VBoxContainer );
 	VBoxContainer *vb = memnew( VBoxContainer );
 	add_child(vb);
 	add_child(vb);
@@ -382,7 +391,7 @@ FindReplaceDialog::FindReplaceDialog() {
 	search_text = memnew( LineEdit );
 	search_text = memnew( LineEdit );
 	vb->add_margin_child("Search",search_text);
 	vb->add_margin_child("Search",search_text);
 	search_text->connect("text_entered", this,"_search_text_entered");
 	search_text->connect("text_entered", this,"_search_text_entered");
-	search_text->set_self_opacity(0.7);
+	//search_text->set_self_opacity(0.7);
 
 
 
 
 
 
@@ -396,7 +405,7 @@ FindReplaceDialog::FindReplaceDialog() {
 	replace_text->set_anchor( MARGIN_RIGHT, ANCHOR_END );
 	replace_text->set_anchor( MARGIN_RIGHT, ANCHOR_END );
 	replace_text->set_begin( Point2(15,132) );
 	replace_text->set_begin( Point2(15,132) );
 	replace_text->set_end( Point2(15,135) );
 	replace_text->set_end( Point2(15,135) );
-	replace_text->set_self_opacity(0.7);
+	//replace_text->set_self_opacity(0.7);
 	replace_mc->add_child(replace_text);
 	replace_mc->add_child(replace_text);