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

Code before:

void TextControlEditor::_font_selected(int p_id) {
	_set_font();
}

void TextControlEditor::_font_style_selected(int p_id) {
	_set_font();
}

void TextControlEditor::_set_font() {
	if (!edited_control) {
		return;
	}

	UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
	ur->create_action(TTR("Set Font"));

	if (font_list->get_selected_id() == FONT_INFO_THEME_DEFAULT) {
		// Remove font override.
		ur->add_do_method(edited_control, "remove_theme_font_override", edited_font);
	} else if (font_list->get_selected_id() == FONT_INFO_USER_CUSTOM) {
		// Restore "custom_font".
		ur->add_do_method(edited_control, "add_theme_font_override", edited_font, custom_font);
	} else {
		// Load new font resource using selected name and style.
		String name = font_list->get_item_text(font_list->get_selected());
		String style = font_style_list->get_item_text(font_style_list->get_selected());
		if (style.is_empty()) {
			style = "Default";
		}

		if (fonts.has(name)) {
			Ref<FontData> fd = ResourceLoader::load(fonts[name][style]);
			if (fd.is_valid()) {
				Ref<Font> font;
				font.instantiate();
				font->add_data(fd);
				ur->add_do_method(edited_control, "add_theme_font_override", edited_font, font);
			}
		}
	}

	if (edited_control->has_theme_font_override(edited_font)) {
		ur->add_undo_method(edited_control, "add_theme_font_override", edited_font, edited_control->get_theme_font(edited_font));
	} else {
		ur->add_undo_method(edited_control, "remove_theme_font_override", edited_font);
	}

	ur->add_do_method(this, "_update_control");
	ur->add_undo_method(this, "_update_control");


Review comment (suggestion):
This (and line 225) can wrap the string literal in `SNAME` to get a statically allocated StringName instead of an implicit coercion.

Code after:
								break;
							}
						}
					} else {
						custom_font = font;
						if (i > 0) {
							same_font = same_font && (font_selected == FONT_INFO_USER_CUSTOM);
							same_style = same_style && (style_selected == 0);
						}

						font_selected = FONT_INFO_USER_CUSTOM;
						style_selected = 0;
					}
				}
			} else {
				if (i > 0) {
					same_font = same_font && (font_selected == FONT_INFO_THEME_DEFAULT);
					same_style = same_style && (style_selected == 0);
				}

				font_selected = FONT_INFO_THEME_DEFAULT;
				style_selected = 0;
			}

			int current_font_size = edited_control->get_theme_font_size(edited_font_size);
			int current_outline_size = edited_control->get_theme_constant("outline_size");
			Color current_font_color = edited_control->get_theme_color(edited_color);
			Color current_outline_color = edited_control->get_theme_color("font_outline_color");
			if (i > 0) {
				same_font_size = same_font_size && (font_size == current_font_size);
				same_outline_size = same_outline_size && (outline_size == current_outline_size);
				same_font_color = same_font_color && (font_color == current_font_color);
				same_outline_color = same_outline_color && (outline_color == current_outline_color);
			}

			font_size = current_font_size;
			outline_size = current_outline_size;
			font_color = current_font_color;
			outline_color = current_outline_color;
		}

		_update_fonts_menu();
		if (same_font) {
			font_list->select(font_selected);
		} else {
			font_list->select(-1);
		}

		_update_styles_menu();
		if (same_style) {
			font_style_list->select(style_selected);