Path: blob/master/editor/gui/editor_version_button.cpp
9896 views
/**************************************************************************/1/* editor_version_button.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "editor_version_button.h"3132#include "core/os/time.h"33#include "core/version.h"3435String _get_version_string(EditorVersionButton::VersionFormat p_format) {36String main;37switch (p_format) {38case EditorVersionButton::FORMAT_BASIC: {39return GODOT_VERSION_FULL_CONFIG;40} break;41case EditorVersionButton::FORMAT_WITH_BUILD: {42main = "v" GODOT_VERSION_FULL_BUILD;43} break;44case EditorVersionButton::FORMAT_WITH_NAME_AND_BUILD: {45main = GODOT_VERSION_FULL_NAME;46} break;47default: {48ERR_FAIL_V_MSG(GODOT_VERSION_FULL_NAME, "Unexpected format: " + itos(p_format));49} break;50}5152String hash = GODOT_VERSION_HASH;53if (!hash.is_empty()) {54hash = vformat(" [%s]", hash.left(9));55}56return main + hash;57}5859void EditorVersionButton::_notification(int p_what) {60switch (p_what) {61case NOTIFICATION_POSTINITIALIZE: {62// This can't be done in the constructor because theme cache is not ready yet.63set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);64set_text(_get_version_string(format));65} break;6667case NOTIFICATION_TRANSLATION_CHANGED: {68String build_date;69if (GODOT_VERSION_TIMESTAMP > 0) {70build_date = Time::get_singleton()->get_datetime_string_from_unix_time(GODOT_VERSION_TIMESTAMP, true) + " UTC";71} else {72build_date = TTR("(unknown)");73}74set_tooltip_text(vformat(TTR("Git commit date: %s\nClick to copy the version information."), build_date));75} break;76}77}7879void EditorVersionButton::pressed() {80DisplayServer::get_singleton()->clipboard_set(_get_version_string(FORMAT_WITH_BUILD));81}8283EditorVersionButton::EditorVersionButton(VersionFormat p_format) {84format = p_format;85set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);86}878889