Make it possible to copy the Godot version identifier by clicking it

This closes #24317.
This commit is contained in:
Hugo Locurcio 2019-12-24 01:20:54 +01:00
parent 7e0a42a673
commit be01025376
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
6 changed files with 94 additions and 13 deletions

View file

@ -2371,6 +2371,7 @@ void ProjectManager::_on_search_term_changed(const String &p_term) {
void ProjectManager::_bind_methods() {
ClassDB::bind_method("_unhandled_key_input", &ProjectManager::_unhandled_key_input);
ClassDB::bind_method("_update_project_buttons", &ProjectManager::_update_project_buttons);
ClassDB::bind_method("_version_button_pressed", &ProjectManager::_version_button_pressed);
}
void ProjectManager::_open_asset_library() {
@ -2378,6 +2379,10 @@ void ProjectManager::_open_asset_library() {
tabs->set_current_tab(1);
}
void ProjectManager::_version_button_pressed() {
DisplayServer::get_singleton()->clipboard_set(version_btn->get_text());
}
ProjectManager::ProjectManager() {
// load settings
if (!EditorSettings::get_singleton()) {
@ -2601,15 +2606,30 @@ ProjectManager::ProjectManager() {
settings_hb->set_h_grow_direction(Control::GROW_DIRECTION_BEGIN);
settings_hb->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT);
Label *version_label = memnew(Label);
// A VBoxContainer that contains a dummy Control node to adjust the LinkButton's vertical position.
VBoxContainer *spacer_vb = memnew(VBoxContainer);
settings_hb->add_child(spacer_vb);
Control *v_spacer = memnew(Control);
spacer_vb->add_child(v_spacer);
version_btn = memnew(LinkButton);
String hash = String(VERSION_HASH);
if (hash.length() != 0) {
hash = "." + hash.left(9);
}
version_label->set_text("v" VERSION_FULL_BUILD "" + hash);
version_label->set_self_modulate(Color(1, 1, 1, 0.6));
version_label->set_align(Label::ALIGN_CENTER);
settings_hb->add_child(version_label);
version_btn->set_text("v" VERSION_FULL_BUILD + hash);
// Fade the version label to be less prominent, but still readable.
version_btn->set_self_modulate(Color(1, 1, 1, 0.6));
version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
version_btn->set_tooltip(TTR("Click to copy."));
version_btn->connect("pressed", callable_mp(this, &ProjectManager::_version_button_pressed));
spacer_vb->add_child(version_btn);
// Add a small horizontal spacer between the version and language buttons
// to distinguish them.
Control *h_spacer = memnew(Control);
settings_hb->add_child(h_spacer);
language_btn = memnew(OptionButton);
language_btn->set_flat(true);