editor_version_button.cpp 3.7 KB

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