Fix find-in-files and go-to-line dialog (partially)

This commit is contained in:
Poommetee Ketson 2018-09-18 21:10:36 +07:00
parent f148e8eede
commit e74876028e
3 changed files with 26 additions and 33 deletions

View file

@ -44,7 +44,7 @@ void GotoLineDialog::popup_find_line(TextEdit *p_edit) {
line->set_text(itos(text_editor->cursor_get_line()));
line->select_all();
popup_centered(Size2(180, 80));
popup_centered(Size2(180, 80) * EDSCALE);
line->grab_focus();
}
@ -65,16 +65,20 @@ void GotoLineDialog::ok_pressed() {
GotoLineDialog::GotoLineDialog() {
set_title(TTR("Go to Line"));
VBoxContainer *vbc = memnew(VBoxContainer);
vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE);
vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE);
vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE);
vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE);
add_child(vbc);
Label *l = memnew(Label);
l->set_text(TTR("Line Number:"));
l->set_position(Point2(5, 5));
add_child(l);
vbc->add_child(l);
line = memnew(LineEdit);
line->set_anchor(MARGIN_RIGHT, ANCHOR_END);
line->set_begin(Point2(15, 22));
line->set_end(Point2(-15, 35));
add_child(line);
vbc->add_child(line);
register_text_enter(line);
text_editor = NULL;

View file

@ -406,11 +406,8 @@ FindInFilesDialog::FindInFilesDialog() {
HBoxContainer *hbc = memnew(HBoxContainer);
hbc->set_alignment(HBoxContainer::ALIGN_CENTER);
_find_button = memnew(Button);
_find_button->set_text(TTR("Find..."));
_find_button->connect("pressed", this, "_on_find_button_pressed");
_find_button = add_button(TTR("Find..."), false, "find");
_find_button->set_disabled(true);
hbc->add_child(_find_button);
{
Control *placeholder = memnew(Control);
@ -418,11 +415,8 @@ FindInFilesDialog::FindInFilesDialog() {
hbc->add_child(placeholder);
}
_replace_button = memnew(Button);
_replace_button->set_text(TTR("Replace..."));
_replace_button->connect("pressed", this, "_on_replace_button_pressed");
_replace_button = add_button(TTR("Replace..."), false, "replace");
_replace_button->set_disabled(true);
hbc->add_child(_replace_button);
{
Control *placeholder = memnew(Control);
@ -430,10 +424,8 @@ FindInFilesDialog::FindInFilesDialog() {
hbc->add_child(placeholder);
}
Button *cancel_button = memnew(Button);
Button *cancel_button = get_ok();
cancel_button->set_text(TTR("Cancel"));
cancel_button->connect("pressed", this, "hide");
hbc->add_child(cancel_button);
vbc->add_child(hbc);
}
@ -487,14 +479,14 @@ void FindInFilesDialog::_on_folder_button_pressed() {
_folder_dialog->popup_centered_ratio();
}
void FindInFilesDialog::_on_find_button_pressed() {
emit_signal(SIGNAL_FIND_REQUESTED);
hide();
}
void FindInFilesDialog::_on_replace_button_pressed() {
emit_signal(SIGNAL_REPLACE_REQUESTED);
hide();
void FindInFilesDialog::custom_action(const String &p_action) {
if (p_action == "find") {
emit_signal(SIGNAL_FIND_REQUESTED);
hide();
} else if (p_action == "replace") {
emit_signal(SIGNAL_REPLACE_REQUESTED);
hide();
}
}
void FindInFilesDialog::_on_search_text_modified(String text) {
@ -509,7 +501,7 @@ void FindInFilesDialog::_on_search_text_modified(String text) {
void FindInFilesDialog::_on_search_text_entered(String text) {
// This allows to trigger a global search without leaving the keyboard
if (!_find_button->is_disabled())
_on_find_button_pressed();
custom_action("find");
}
void FindInFilesDialog::_on_folder_selected(String path) {
@ -522,8 +514,6 @@ void FindInFilesDialog::_on_folder_selected(String path) {
void FindInFilesDialog::_bind_methods() {
ClassDB::bind_method("_on_folder_button_pressed", &FindInFilesDialog::_on_folder_button_pressed);
ClassDB::bind_method("_on_find_button_pressed", &FindInFilesDialog::_on_find_button_pressed);
ClassDB::bind_method("_on_replace_button_pressed", &FindInFilesDialog::_on_replace_button_pressed);
ClassDB::bind_method("_on_folder_selected", &FindInFilesDialog::_on_folder_selected);
ClassDB::bind_method("_on_search_text_modified", &FindInFilesDialog::_on_search_text_modified);
ClassDB::bind_method("_on_search_text_entered", &FindInFilesDialog::_on_search_text_entered);

View file

@ -91,8 +91,8 @@ class CheckBox;
class FileDialog;
// Prompts search parameters
class FindInFilesDialog : public WindowDialog {
GDCLASS(FindInFilesDialog, WindowDialog)
class FindInFilesDialog : public AcceptDialog {
GDCLASS(FindInFilesDialog, AcceptDialog)
public:
static const char *SIGNAL_FIND_REQUESTED;
static const char *SIGNAL_REPLACE_REQUESTED;
@ -111,11 +111,10 @@ protected:
static void _bind_methods();
void _notification(int p_what);
void custom_action(const String &p_action);
private:
void _on_folder_button_pressed();
void _on_find_button_pressed();
void _on_replace_button_pressed();
void _on_folder_selected(String path);
void _on_search_text_modified(String text);
void _on_search_text_entered(String text);