Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some AcceptDialog argument types #89419

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/classes/AcceptDialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
</method>
<method name="register_text_enter">
<return type="void" />
<param index="0" name="line_edit" type="Control" />
<param index="0" name="line_edit" type="LineEdit" />
<description>
Registers a [LineEdit] in the dialog. When the enter key is pressed, the dialog will be accepted.
</description>
</method>
<method name="remove_button">
<return type="void" />
<param index="0" name="button" type="Control" />
<param index="0" name="button" type="Button" />
<description>
Removes the [param button] from the dialog. Does NOT free the [param button]. The [param button] must be a [Button] added with [method add_button] or [method add_cancel_button] method. After removal, pressing the [param button] will no longer emit this dialog's [signal custom_action] or [signal canceled] signals.
</description>
Expand Down
8 changes: 8 additions & 0 deletions misc/extension_api_validation/4.2-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,11 @@ Validate extension JSON: Error: Field 'classes/EditorPlugin/methods/add_control_

Added optional argument to add_control_to_bottom_panel and add_control_to_dock to specify a shortcut that toggles the bottom panel/dock's visibility.
Compatibility method registered.


GH-89419
--------
Validate extension JSON: Error: Field 'classes/AcceptDialog/methods/register_text_enter/arguments/0': type changed value in new API, from "Control" to "LineEdit".
Validate extension JSON: Error: Field 'classes/AcceptDialog/methods/remove_button/arguments/0': type changed value in new API, from "Control" to "Button".

Changed argument type to the more specific one actually expected by the method. Compatibility method registered.
46 changes: 46 additions & 0 deletions scene/gui/dialogs.compat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**************************************************************************/
/* dialogs.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

void AcceptDialog::_register_text_enter_bind_compat_89419(Control *p_line_edit) {
register_text_enter(Object::cast_to<LineEdit>(p_line_edit));
}

void AcceptDialog::_remove_button_bind_compat_89419(Control *p_button) {
remove_button(Object::cast_to<Button>(p_button));
}

void AcceptDialog::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("register_text_enter"), &AcceptDialog::_register_text_enter_bind_compat_89419);
ClassDB::bind_compatibility_method(D_METHOD("remove_button", "quadrant_size"), &AcceptDialog::_remove_button_bind_compat_89419);
}

#endif
35 changes: 16 additions & 19 deletions scene/gui/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "dialogs.h"
#include "dialogs.compat.inc"

#include "core/os/keyboard.h"
#include "core/string/print_string.h"
Expand Down Expand Up @@ -195,12 +196,9 @@ String AcceptDialog::get_ok_button_text() const {
return ok_button->get_text();
}

void AcceptDialog::register_text_enter(Control *p_line_edit) {
void AcceptDialog::register_text_enter(LineEdit *p_line_edit) {
ERR_FAIL_NULL(p_line_edit);
LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
if (line_edit) {
line_edit->connect("text_submitted", callable_mp(this, &AcceptDialog::_text_submitted));
}
p_line_edit->connect("text_submitted", callable_mp(this, &AcceptDialog::_text_submitted));
}

void AcceptDialog::_update_child_rects() {
Expand Down Expand Up @@ -329,31 +327,30 @@ Button *AcceptDialog::add_cancel_button(const String &p_cancel) {
return b;
}

void AcceptDialog::remove_button(Control *p_button) {
Button *button = Object::cast_to<Button>(p_button);
ERR_FAIL_NULL(button);
ERR_FAIL_COND_MSG(button->get_parent() != buttons_hbox, vformat("Cannot remove button %s as it does not belong to this dialog.", button->get_name()));
ERR_FAIL_COND_MSG(button == ok_button, "Cannot remove dialog's OK button.");
void AcceptDialog::remove_button(Button *p_button) {
ERR_FAIL_NULL(p_button);
ERR_FAIL_COND_MSG(p_button->get_parent() != buttons_hbox, vformat("Cannot remove button %s as it does not belong to this dialog.", p_button->get_name()));
ERR_FAIL_COND_MSG(p_button == ok_button, "Cannot remove dialog's OK button.");

Control *right_spacer = Object::cast_to<Control>(button->get_meta("__right_spacer"));
Control *right_spacer = Object::cast_to<Control>(p_button->get_meta("__right_spacer"));
if (right_spacer) {
ERR_FAIL_COND_MSG(right_spacer->get_parent() != buttons_hbox, vformat("Cannot remove button %s as its associated spacer does not belong to this dialog.", button->get_name()));
ERR_FAIL_COND_MSG(right_spacer->get_parent() != buttons_hbox, vformat("Cannot remove button %s as its associated spacer does not belong to this dialog.", p_button->get_name()));
}

button->disconnect("visibility_changed", callable_mp(this, &AcceptDialog::_custom_button_visibility_changed));
if (button->is_connected("pressed", callable_mp(this, &AcceptDialog::_custom_action))) {
button->disconnect("pressed", callable_mp(this, &AcceptDialog::_custom_action));
p_button->disconnect("visibility_changed", callable_mp(this, &AcceptDialog::_custom_button_visibility_changed));
if (p_button->is_connected("pressed", callable_mp(this, &AcceptDialog::_custom_action))) {
p_button->disconnect("pressed", callable_mp(this, &AcceptDialog::_custom_action));
}
if (button->is_connected("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed))) {
button->disconnect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed));
if (p_button->is_connected("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed))) {
p_button->disconnect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed));
}

if (right_spacer) {
buttons_hbox->remove_child(right_spacer);
button->remove_meta("__right_spacer");
p_button->remove_meta("__right_spacer");
right_spacer->queue_free();
}
buttons_hbox->remove_child(button);
buttons_hbox->remove_child(p_button);

child_controls_changed();
if (is_visible()) {
Expand Down
11 changes: 9 additions & 2 deletions scene/gui/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,23 @@ class AcceptDialog : public Window {
void _ok_pressed();
void _cancel_pressed();

#ifndef DISABLE_DEPRECATED
void _register_text_enter_bind_compat_89419(Control *p_line_edit);
void _remove_button_bind_compat_89419(Control *p_button);

static void _bind_compatibility_methods();
#endif

public:
Label *get_label() { return message_label; }
static void set_swap_cancel_ok(bool p_swap);

void register_text_enter(Control *p_line_edit);
void register_text_enter(LineEdit *p_line_edit);

Button *get_ok_button() { return ok_button; }
Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
Button *add_cancel_button(const String &p_cancel = "");
void remove_button(Control *p_button);
void remove_button(Button *p_button);

void set_hide_on_ok(bool p_hide);
bool get_hide_on_ok() const;
Expand Down
Loading