-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open all files in script editor #19225
Open all files in script editor #19225
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing!
It is funny that I was just starting to basically do the exact same thing. #19220
I came to almost the same conclusions but I would have implemented it with a little less code (I was lazy and was not sure how much this even would be used.)
So it looks really good to me and makes a lot of sense.
Also Thank you! for you timing so I didn't yet spend any time on it.
It is not really a review but more a bunch of questions which would make me super happy if I get an explanation.
Thank you! this pr is amazing
@@ -1661,11 +1687,13 @@ void ScriptEditor::_update_script_names() { | |||
_update_script_colors(); | |||
} | |||
|
|||
bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus) { | |||
bool ScriptEditor::edit(const RES &p_script, int p_line, int p_col, bool p_grab_focus) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also rename the actual prop name to p_resource
@@ -116,7 +117,7 @@ class ScriptEditorBase : public Control { | |||
}; | |||
|
|||
typedef SyntaxHighlighter *(*CreateSyntaxHighlighterFunc)(); | |||
typedef ScriptEditorBase *(*CreateScriptEditorFunc)(const Ref<Script> &p_script); | |||
typedef ScriptEditorBase *(*CreateScriptEditorFunc)(const RES &p_script); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same here. I would make it really obvious for ppl who work on it, that any resource "could be" edited. so calling the property p_resource
makes sense to me?
|
||
#include "script_editor_plugin.h" | ||
|
||
class TextEditor : public ScriptEditorBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this class is just phenomenal and makes soo much more sense.
scene/resources/text_file.cpp
Outdated
} | ||
|
||
bool ResourceFormatLoaderTextFile::handles_type(const String &p_type) const { | ||
return (p_type == "TextFile"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still did not completely get the idea of handles_type
Is passed when the editor is searching for a ui element to handle a specific resource? so I could edit a tscn with the type TextFile and with the type Scene and based on that the editor would behave differently?
I think I got it wrong because than it would make no sense why it is in ResourceFormatLoaderTextFile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handles_type
is used to select a resource loader.
When calling:
ResourceLoader::load("bla.txt")
it will select the first ResourceFormatLoader
that supports the extension txt
.
If However you call it like so:
ResourceLoader::load("bla.txt", "TextFile")
it will select the first ResourceFormatLoader
that supports the extension txt
and handles_type
of TextFile
.
So even if infinite ResourceFormatLoader
support txt
only ones that handles_type
of TextFile
will be selected. If none handle TextFile
the resource will not be loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay Thank you!
so it is basically load(file_on_disc, as_resource_type)
(if possible ;) )
Does it mean we can also edit shaders there? |
b9de0b2
to
c5f9c6f
Compare
Renamed @Zylann Sort of, the shader editor grabs focus if it is open or has been opened. |
Moving it shouldn't be to hard if we decide that it is a nicer workflow. But since you usually want to see your result it should stay at in the bottom panel. |
May related to #5311 |
I am against hacking ResourceLoader/Saver for this. Just harcode this support into the editor plugin, even if its considerably more code. |
c5f9c6f
to
724762c
Compare
Integrated the changes from #19166 into Adjusted to no longer use To allow Opening/Save As, it uses its own |
724762c
to
a05ae24
Compare
a05ae24
to
8cd2e48
Compare
8cd2e48
to
8ff7471
Compare
I just want to share this from our PR meeting where we agreed to merge this:
I can only agree. Huge thanks for this! |
This PR allows editing any file in the script editor.
Firstly, a new
ResourceFormat
calledTextFile
. TheTextFile
format can take any type of file (providing its utf_8).As
TextFile
can take any type theresource_loader
andresource_saver
methods had to be changed. They will only loadTextFile
formats when explicitly asked for. This does however means that we have have to wait for the initial loading call to fail before trying again. This ensures that nothing else can load it. As loader order is "random".To make editing all files possible, the hint type passed into
InspectorDock::_load_resource
is now passed all the way through the system. The script editor passes typeScript
. This is used to indicate that if the resource is not loaded we can safely try usingTextFile
. Allowing editing scene files within theScriptEditor
.Secondly, I've Generalised
ScriptEditorPlugin
andScriptEditorBase
to take and edit any resource.Thirdly, introduced a new
TextEditor
class extendingScriptEditorBase
to edit theTextFile
resources. Currently this is is fairly lightweight.Lastly, I moved some of the text manipulation into CodeTexteditor reducing duplication from the
ShaderTextEditor
,ScriptTextEditor
and would beTextEditor
.The changes from #19166 will have to be replicated into
TextEditor
.closes #1390
I'm unsure about the
resource_loader
changes, weather the loader should internally check forScript
or force the caller to handle the failed load?The
TextEditor
class will also need a icon to use in the script list.