Browse Source

Expose `ScriptEditor::edit` to scripting

Exposes a method in `EditorInterface` to open scripts on a specified
line and column. This method handles if the internal or the external
editor should be used.

(cherry picked from commit 9535831866786adeafbff40f8e46f52fdc62538b)
Raul Santos 3 years ago
parent
commit
a10372fe9a
3 changed files with 17 additions and 1 deletions
  1. 11 1
      doc/classes/EditorInterface.xml
  2. 5 0
      editor/editor_plugin.cpp
  3. 1 0
      editor/editor_plugin.h

+ 11 - 1
doc/classes/EditorInterface.xml

@@ -21,7 +21,17 @@
 			<return type="void" />
 			<return type="void" />
 			<argument index="0" name="resource" type="Resource" />
 			<argument index="0" name="resource" type="Resource" />
 			<description>
 			<description>
-				Edits the given [Resource].
+				Edits the given [Resource]. If the resource is a [Script] you can also edit it with [method edit_script] to specify the line and column position.
+			</description>
+		</method>
+		<method name="edit_script">
+			<return type="void" />
+			<argument index="0" name="script" type="Script" />
+			<argument index="1" name="line" type="int" default="-1" />
+			<argument index="2" name="column" type="int" default="0" />
+			<argument index="3" name="grab_focus" type="bool" default="true" />
+			<description>
+				Edits the given [Script]. The line and column on which to open the script can also be specified. The script will be open with the user-configured editor for the script's language which may be an external editor.
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="get_base_control">
 		<method name="get_base_control">

+ 5 - 0
editor/editor_plugin.cpp

@@ -165,6 +165,10 @@ void EditorInterface::edit_node(Node *p_node) {
 	EditorNode::get_singleton()->edit_node(p_node);
 	EditorNode::get_singleton()->edit_node(p_node);
 }
 }
 
 
+void EditorInterface::edit_script(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus) {
+	ScriptEditor::get_singleton()->edit(p_script, p_line, p_col, p_grab_focus);
+}
+
 void EditorInterface::open_scene_from_path(const String &scene_path) {
 void EditorInterface::open_scene_from_path(const String &scene_path) {
 	if (EditorNode::get_singleton()->is_changing_scene()) {
 	if (EditorNode::get_singleton()->is_changing_scene()) {
 		return;
 		return;
@@ -318,6 +322,7 @@ void EditorInterface::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_editor_scale"), &EditorInterface::get_editor_scale);
 	ClassDB::bind_method(D_METHOD("get_editor_scale"), &EditorInterface::get_editor_scale);
 	ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorInterface::edit_resource);
 	ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorInterface::edit_resource);
 	ClassDB::bind_method(D_METHOD("edit_node", "node"), &EditorInterface::edit_node);
 	ClassDB::bind_method(D_METHOD("edit_node", "node"), &EditorInterface::edit_node);
+	ClassDB::bind_method(D_METHOD("edit_script", "script", "line", "column", "grab_focus"), &EditorInterface::edit_script, DEFVAL(-1), DEFVAL(0), DEFVAL(true));
 	ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorInterface::open_scene_from_path);
 	ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorInterface::open_scene_from_path);
 	ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path);
 	ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path);
 	ClassDB::bind_method(D_METHOD("play_main_scene"), &EditorInterface::play_main_scene);
 	ClassDB::bind_method(D_METHOD("play_main_scene"), &EditorInterface::play_main_scene);

+ 1 - 0
editor/editor_plugin.h

@@ -71,6 +71,7 @@ public:
 	Control *get_editor_viewport();
 	Control *get_editor_viewport();
 	void edit_resource(const Ref<Resource> &p_resource);
 	void edit_resource(const Ref<Resource> &p_resource);
 	void edit_node(Node *p_node);
 	void edit_node(Node *p_node);
+	void edit_script(const Ref<Script> &p_script, int p_line = -1, int p_col = 0, bool p_grab_focus = true);
 	void open_scene_from_path(const String &scene_path);
 	void open_scene_from_path(const String &scene_path);
 	void reload_scene_from_path(const String &scene_path);
 	void reload_scene_from_path(const String &scene_path);