Skip to content

Commit 330a19f

Browse files
committed
[Editor HelpBit] Open online documentation if script editor is not available.
1 parent 3edd256 commit 330a19f

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

editor/doc/editor_help.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,9 +4218,63 @@ void EditorHelpBit::_update_labels() {
42184218
}
42194219
}
42204220

4221+
void EditorHelpBit::_go_to_url(const String &p_what) {
4222+
Vector<String> parts;
4223+
{
4224+
int from = 0;
4225+
int buffer_start = 0;
4226+
while (true) {
4227+
const int pos = p_what.find_char(':', from);
4228+
if (pos < 0) {
4229+
parts.push_back(p_what.substr(buffer_start));
4230+
break;
4231+
}
4232+
4233+
if (pos + 1 < p_what.length() && p_what[pos + 1] == ':') {
4234+
// `::` used in built-in scripts.
4235+
from = pos + 2;
4236+
} else {
4237+
parts.push_back(p_what.substr(buffer_start, pos - buffer_start));
4238+
from = pos + 1;
4239+
buffer_start = from;
4240+
}
4241+
}
4242+
}
4243+
4244+
const String what = parts[0]; // `parts` is always non-empty.
4245+
const String clss = (parts.size() > 1) ? parts[1].to_lower() : String();
4246+
const String name = (parts.size() > 2) ? parts[2].to_lower().replace_chars("/_", '-') : String();
4247+
4248+
String section = "";
4249+
if (what == "class_desc") {
4250+
section = "#description";
4251+
} else if (what == "class_signal") {
4252+
section = vformat("#class-%s-signal-%s", clss, name);
4253+
} else if (what == "class_method" || what == "class_method_desc") {
4254+
section = vformat("#class-%s-method-%s", clss, name);
4255+
} else if (what == "class_property") {
4256+
section = vformat("#class-%s-property-%s", clss, name);
4257+
} else if (what == "class_enum") {
4258+
section = vformat("#enum-%s-%s", clss, name);
4259+
} else if (what == "class_theme_item") {
4260+
section = vformat("#class-%s-theme-%s", clss, name);
4261+
} else if (what == "class_constant") {
4262+
section = vformat("#class-%s-constant-%s", clss, name);
4263+
} else if (what == "class_annotation") {
4264+
section = vformat("#%s", clss);
4265+
}
4266+
4267+
String doc_url = clss.is_empty() ? String(GODOT_VERSION_DOCS_URL "/") : vformat(GODOT_VERSION_DOCS_URL "/classes/class_%s.html%s", clss, section);
4268+
OS::get_singleton()->shell_open(doc_url);
4269+
}
4270+
42214271
void EditorHelpBit::_go_to_help(const String &p_what) {
4222-
EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
4223-
ScriptEditor::get_singleton()->goto_help(p_what);
4272+
if (ScriptEditor::get_singleton()) {
4273+
EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
4274+
ScriptEditor::get_singleton()->goto_help(p_what);
4275+
} else {
4276+
_go_to_url(p_what);
4277+
}
42244278
emit_signal(SNAME("request_hide"));
42254279
}
42264280

editor/doc/editor_help.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ class EditorHelpBit : public VBoxContainer {
344344
void _add_type_to_title(const DocType &p_doc_type);
345345
void _update_labels();
346346
void _go_to_help(const String &p_what);
347+
void _go_to_url(const String &p_what);
347348
void _meta_clicked(const String &p_select);
348349

349350
protected:

0 commit comments

Comments
 (0)