Repository: godotengine/godot
File: editor/plugins/path_2d_editor_plugin.cpp (C++)

Code before:
	curve_del->set_theme_type_variation("FlatButton");
	curve_del->set_toggle_mode(true);
	curve_del->set_focus_mode(Control::FOCUS_NONE);
	curve_del->set_tooltip_text(TTR("Delete Point"));
	curve_del->connect("pressed", callable_mp(this, &Path2DEditor::_mode_selected).bind(MODE_DELETE));
	add_child(curve_del);

	curve_close = memnew(Button);
	curve_close->set_theme_type_variation("FlatButton");
	curve_close->set_focus_mode(Control::FOCUS_NONE);
	curve_close->set_tooltip_text(TTR("Close Curve"));
	curve_close->connect("pressed", callable_mp(this, &Path2DEditor::_mode_selected).bind(ACTION_CLOSE));
	add_child(curve_close);

	PopupMenu *menu;

	handle_menu = memnew(MenuButton);
	handle_menu->set_flat(false);
	handle_menu->set_theme_type_variation("FlatMenuButton");
	handle_menu->set_text(TTR("Options"));
	add_child(handle_menu);

	menu = handle_menu->get_popup();
	menu->add_check_item(TTR("Mirror Handle Angles"));
	menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);
	menu->add_check_item(TTR("Mirror Handle Lengths"));
	menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);
	menu->connect("id_pressed", callable_mp(this, &Path2DEditor::_handle_option_pressed));
}

void Path2DEditorPlugin::edit(Object *p_object) {
	path2d_editor->edit(Object::cast_to<Node>(p_object));
}

bool Path2DEditorPlugin::handles(Object *p_object) const {
	return p_object->is_class("Path2D");
}

void Path2DEditorPlugin::make_visible(bool p_visible) {
	if (p_visible) {
		path2d_editor->show();

	} else {
		path2d_editor->hide();
		path2d_editor->edit(nullptr);
	}
}

Path2DEditorPlugin::Path2DEditorPlugin() {
	path2d_editor = memnew(Path2DEditor);
	CanvasItemEditor::get_singleton()->add_control_to_menu_panel(path2d_editor);

Review comment (suggestion):
```suggestion
void Path2DEditor::restore_curve_points(Path2D *p_path2d, const PackedVector2Array &p_points) {
```

Code after:
	if (curve->get_point_count() == 0) {
		return;
	}
	curve->clear_points();

	if (node == p_path2d) {
		_mode_selected(MODE_CREATE);
	}
}

void Path2DEditor::_restore_curve_points(Path2D *p_path2d, const PackedVector2Array &p_points) {
	if (!p_path2d || p_path2d->get_curve().is_null()) {
		return;
	}
	Ref<Curve2D> curve = p_path2d->get_curve();

	if (curve->get_point_count() > 0) {
		curve->clear_points();
	}

	for (int i = 0; i < p_points.size(); i += 3) {
		curve->add_point(p_points[i + 2], p_points[i], p_points[i + 1]); // The Curve2D::points pattern is [point_in, point_out, point_position].
	}

	if (node == p_path2d) {
		_mode_selected(MODE_EDIT);
	}
}

Path2DEditor::Path2DEditor() {
	canvas_item_editor = nullptr;
	mirror_handle_angle = true;
	mirror_handle_length = true;
	on_edge = false;

	mode = MODE_EDIT;
	action = ACTION_NONE;

	curve_edit = memnew(Button);
	curve_edit->set_theme_type_variation("FlatButton");
	curve_edit->set_toggle_mode(true);
	curve_edit->set_pressed(true);
	curve_edit->set_focus_mode(Control::FOCUS_NONE);
	curve_edit->set_tooltip_text(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL) + TTR("Click: Add Point") + "\n" + TTR("Left Click: Split Segment (in curve)") + "\n" + TTR("Right Click: Delete Point"));
	curve_edit->connect("pressed", callable_mp(this, &Path2DEditor::_mode_selected).bind(MODE_EDIT));
	add_child(curve_edit);

	curve_edit_curve = memnew(Button);
	curve_edit_curve->set_theme_type_variation("FlatButton");
	curve_edit_curve->set_toggle_mode(true);
	curve_edit_curve->set_focus_mode(Control::FOCUS_NONE);