Repository: godotengine/godot
File: editor/docks/scene_tree_dock.cpp (C++)

Code before:
		menu->add_icon_shortcut(get_editor_theme_icon(SNAME("ShowInFileSystem")), ED_GET_SHORTCUT("scene_tree/show_in_file_system"), TOOL_SHOW_IN_FILE_SYSTEM);
	}

	menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), TTR("Open Documentation"), TOOL_OPEN_DOCUMENTATION);

	if (profile_allow_editing) {
		menu->add_separator();
		menu->add_icon_shortcut(get_editor_theme_icon(SNAME("Remove")), ED_GET_SHORTCUT("scene_tree/delete"), TOOL_ERASE);
	}

	Vector<String> p_paths;
	Node *root = EditorNode::get_singleton()->get_edited_scene();
	for (const List<Node *>::Element *E = selection.front(); E; E = E->next()) {
		String node_path = String(root->get_path().rel_path_to(E->get()->get_path()));
		p_paths.push_back(node_path);
	}
	EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_paths);

	menu->reset_size();
	menu->set_position(p_menu_pos);
	menu->popup();
}

void SceneTreeDock::_update_tree_menu() {
	PopupMenu *tree_menu = button_tree_menu->get_popup();
	tree_menu->clear();

	tree_menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND);
	tree_menu->set_item_checked(-1, EDITOR_GET("docks/scene_tree/auto_expand_to_selected"));

	tree_menu->add_check_item(TTR("Center Node on Reparent"), TOOL_CENTER_PARENT);
	tree_menu->set_item_checked(-1, EDITOR_GET("docks/scene_tree/center_node_on_reparent"));
	tree_menu->set_item_tooltip(-1, TTR("If enabled, Reparent to New Node will create the new node in the center of the selected nodes, if possible."));

	tree_menu->add_check_item(TTR("Hide Filtered Out Parents"), TOOL_HIDE_FILTERED_OUT_PARENTS);
	tree_menu->set_item_checked(-1, EDITOR_GET("docks/scene_tree/hide_filtered_out_parents"));

	tree_menu->add_separator();
	tree_menu->add_check_item(TTR("Show Accessibility Warnings"), TOOL_ACCESSIBILITY_WARNINGS);
	tree_menu->set_item_checked(tree_menu->get_item_index(TOOL_ACCESSIBILITY_WARNINGS), EDITOR_GET("docks/scene_tree/accessibility_warnings"));

	PopupMenu *resource_list = memnew(PopupMenu);
	resource_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
	resource_list->connect("about_to_popup", callable_mp(this, &SceneTreeDock::_list_all_subresources).bind(resource_list));
	resource_list->connect("index_pressed", callable_mp(this, &SceneTreeDock::_edit_subresource).bind(resource_list));
	tree_menu->add_submenu_node_item(TTR("All Scene Sub-Resources"), resource_list);

	_append_filter_options_to(tree_menu, true);
}

void SceneTreeDock::_filter_changed(const String &p_filter) {

Review comment (suggestion):
I just realized that this menu doesn't need to be re-created every time. Only needs to update the checkboxes.
You could change it, but idk if it's within scope of this PR.

Code after:
		menu->add_icon_shortcut(get_editor_theme_icon(SNAME("ShowInFileSystem")), ED_GET_SHORTCUT("scene_tree/show_in_file_system"), TOOL_SHOW_IN_FILE_SYSTEM);
	}

	menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), TTR("Open Documentation"), TOOL_OPEN_DOCUMENTATION);

	if (profile_allow_editing) {
		menu->add_separator();
		menu->add_icon_shortcut(get_editor_theme_icon(SNAME("Remove")), ED_GET_SHORTCUT("scene_tree/delete"), TOOL_ERASE);
	}

	Vector<String> p_paths;
	Node *root = EditorNode::get_singleton()->get_edited_scene();
	for (const List<Node *>::Element *E = selection.front(); E; E = E->next()) {
		String node_path = String(root->get_path().rel_path_to(E->get()->get_path()));
		p_paths.push_back(node_path);
	}
	EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_paths);

	menu->reset_size();
	menu->set_position(p_menu_pos);
	menu->popup();
}

void SceneTreeDock::_update_tree_menu() {
	PopupMenu *tree_menu = button_tree_menu->get_popup();
	tree_menu->clear();

	tree_menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND);
	tree_menu->set_item_checked(-1, EDITOR_GET("docks/scene_tree/auto_expand_to_selected"));

	tree_menu->add_check_item(TTR("Center Node on Reparent"), TOOL_CENTER_PARENT);
	tree_menu->set_item_checked(-1, EDITOR_GET("docks/scene_tree/center_node_on_reparent"));
	tree_menu->set_item_tooltip(-1, TTR("If enabled, Reparent to New Node will create the new node in the center of the selected nodes, if possible."));

	tree_menu->add_check_item(TTR("Hide Filtered Out Parents"), TOOL_HIDE_FILTERED_OUT_PARENTS);
	tree_menu->set_item_checked(-1, EDITOR_GET("docks/scene_tree/hide_filtered_out_parents"));

	tree_menu->add_separator();
	tree_menu->add_check_item(TTR("Show Accessibility Warnings"), TOOL_ACCESSIBILITY_WARNINGS);
	tree_menu->set_item_checked(tree_menu->get_item_index(TOOL_ACCESSIBILITY_WARNINGS), EDITOR_GET("docks/scene_tree/accessibility_warnings"));

	PopupMenu *resource_list = memnew(PopupMenu);
	resource_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
	resource_list->connect("about_to_popup", callable_mp(this, &SceneTreeDock::_list_all_subresources).bind(resource_list));
	resource_list->connect("index_pressed", callable_mp(this, &SceneTreeDock::_edit_subresource).bind(resource_list));
	tree_menu->add_submenu_node_item(TTR("All Scene Sub-Resources"), resource_list);

	_append_filter_options_to(tree_menu);
}

void SceneTreeDock::_filter_changed(const String &p_filter) {