diff --git a/doc/classes/LinkButton.xml b/doc/classes/LinkButton.xml
index bb30d3703fb..fe43c798af8 100644
--- a/doc/classes/LinkButton.xml
+++ b/doc/classes/LinkButton.xml
@@ -18,7 +18,16 @@
The button's text that will be displayed inside the button's area.
- Determines when to show the underline. See [enum UnderlineMode] for options.
+ The underline mode to use for the text. See [enum LinkButton.UnderlineMode] for the available modes.
+
+
+ The [url=https://en.wikipedia.org/wiki/Uniform_Resource_Identifier]URI[/url] for this [LinkButton]. If set to a valid URI, pressing the button opens the URI using the operating system's default program for the protocol (via [method OS.shell_open]). HTTP and HTTPS URLs open the default web browser.
+ [b]Examples:[/b]
+ [codeblock]
+ uri = "https://godotengine.org" # Opens the URL in the default web browser.
+ uri = "C:\SomeFolder" # Opens the file explorer at the given path.
+ uri = "C:\SomeImage.png" # Opens the given image in the default viewing app.
+ [/codeblock]
diff --git a/editor/editor_property_name_processor.cpp b/editor/editor_property_name_processor.cpp
index 1add0cfefe7..782493322a7 100644
--- a/editor/editor_property_name_processor.cpp
+++ b/editor/editor_property_name_processor.cpp
@@ -230,6 +230,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["tcp"] = "TCP";
capitalize_string_remaps["tls"] = "TLS";
capitalize_string_remaps["ui"] = "UI";
+ capitalize_string_remaps["uri"] = "URI";
capitalize_string_remaps["url"] = "URL";
capitalize_string_remaps["urls"] = "URLs";
capitalize_string_remaps["us"] = String::utf8("(µs)"); // Unit.
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index 9042b210a09..5a98d535189 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -30,6 +30,7 @@
#include "link_button.h"
+#include "core/os/os.h"
#include "core/translation.h"
void LinkButton::set_text(const String &p_text) {
@@ -47,6 +48,14 @@ String LinkButton::get_text() const {
return text;
}
+void LinkButton::set_uri(const String &p_uri) {
+ uri = p_uri;
+}
+
+String LinkButton::get_uri() const {
+ return uri;
+}
+
void LinkButton::set_underline_mode(UnderlineMode p_underline_mode) {
underline_mode = p_underline_mode;
update();
@@ -56,6 +65,14 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
return underline_mode;
}
+void LinkButton::pressed() {
+ if (uri.empty()) {
+ return;
+ }
+
+ OS::get_singleton()->shell_open(uri);
+}
+
Size2 LinkButton::get_minimum_size() const {
return get_font("font")->get_string_size(xl_text);
}
@@ -129,7 +146,8 @@ void LinkButton::_notification(int p_what) {
void LinkButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_text", "text"), &LinkButton::set_text);
ClassDB::bind_method(D_METHOD("get_text"), &LinkButton::get_text);
-
+ ClassDB::bind_method(D_METHOD("set_uri", "uri"), &LinkButton::set_uri);
+ ClassDB::bind_method(D_METHOD("get_uri"), &LinkButton::get_uri);
ClassDB::bind_method(D_METHOD("set_underline_mode", "underline_mode"), &LinkButton::set_underline_mode);
ClassDB::bind_method(D_METHOD("get_underline_mode"), &LinkButton::get_underline_mode);
@@ -139,6 +157,7 @@ void LinkButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text");
ADD_PROPERTY(PropertyInfo(Variant::INT, "underline", PROPERTY_HINT_ENUM, "Always,On Hover,Never"), "set_underline_mode", "get_underline_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "uri"), "set_uri", "get_uri");
}
LinkButton::LinkButton() {
diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h
index 2aa728e508d..3866f197ee9 100644
--- a/scene/gui/link_button.h
+++ b/scene/gui/link_button.h
@@ -48,8 +48,10 @@ private:
String text;
String xl_text;
UnderlineMode underline_mode;
+ String uri;
protected:
+ virtual void pressed();
virtual Size2 get_minimum_size() const;
void _notification(int p_what);
static void _bind_methods();
@@ -57,6 +59,8 @@ protected:
public:
void set_text(const String &p_text);
String get_text() const;
+ void set_uri(const String &p_uri);
+ String get_uri() const;
void set_underline_mode(UnderlineMode p_underline_mode);
UnderlineMode get_underline_mode() const;