Allow to define and load script templates per project

Previously it was only possible to create custom script templates per
editor instance which could lead to certain name collisions, but now one
can create such templates per project tailored for specific use cases.

The default path to search for custom script templates is defined in
project settings via `editor/script_templates_search_path` setting as
`res://script_templates` path, yet this can be configured per project.

Templates have at most two origins now:

1. Project-specific, defined in `ProjectSettings`, for instance:
    - res://script_templates/
2. Editor script templates, for instance:
    - %APPDATA%/Godot/script_templates/

As script templates can have the same name over different paths,
the override mechanism was also added, enabling project-specific
templates over the editor ones.
This commit is contained in:
Andrii Doroshenko (Xrayez)
2019-08-22 18:59:43 +03:00
parent 79a480a55e
commit f013596760
5 changed files with 141 additions and 15 deletions

View File

@@ -78,8 +78,25 @@ class ScriptCreateDialog : public ConfirmationDialog {
int current_language;
int default_language;
bool re_check_path;
enum ScriptOrigin {
SCRIPT_ORIGIN_PROJECT,
SCRIPT_ORIGIN_EDITOR,
};
struct ScriptTemplateInfo {
int id;
ScriptOrigin origin;
String dir;
String name;
String extension;
};
String script_template;
Vector<String> template_list;
Vector<ScriptTemplateInfo> template_list;
Map<String, Vector<int> > template_overrides; // name : indices
void _update_script_templates(const String &p_extension);
String base_type;
void _path_hbox_sorted();