summaryrefslogtreecommitdiff
path: root/editor/editor_settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_settings.cpp')
-rw-r--r--editor/editor_settings.cpp46
1 files changed, 36 insertions, 10 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 755ac75180..07af60d634 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -216,17 +216,43 @@ Variant _EDITOR_DEF(const String &p_var, const Variant &p_default) {
return p_default;
}
+static Dictionary _get_builtin_script_templates() {
+ Dictionary templates;
+
+ //No Comments
+ templates["no_comments.gd"] =
+ "extends %BASE%\n"
+ "\n"
+ "func _ready():\n"
+ "%TS%pass\n";
+
+ //Empty
+ templates["empty.gd"] =
+ "extends %BASE%"
+ "\n"
+ "\n";
+
+ return templates;
+}
+
static void _create_script_templates(const String &p_path) {
- FileAccess *file = FileAccess::open(p_path.plus_file("no_comments.gd"), FileAccess::WRITE);
- ERR_FAIL_COND(!file);
- String script = String("extends %BASE%\n\nfunc _ready():\n%TS%pass\n");
- file->store_string(script);
- file->close();
- file->reopen(p_path.plus_file("empty.gd"), FileAccess::WRITE);
- script = "extends %BASE%\n\n";
- file->store_string(script);
- file->close();
+ Dictionary templates = _get_builtin_script_templates();
+ List<Variant> keys;
+ templates.get_key_list(&keys);
+ FileAccess *file = FileAccess::create(FileAccess::ACCESS_FILESYSTEM);
+
+ DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ dir->change_dir(p_path);
+ for (int i = 0; i < keys.size(); i++) {
+ if (!dir->file_exists(keys[i])) {
+ file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE);
+ ERR_FAIL_COND(!file);
+ file->store_string(templates[keys[i]]);
+ file->close();
+ }
+ }
+
memdelete(file);
}
@@ -308,10 +334,10 @@ void EditorSettings::create() {
if (dir->change_dir("script_templates") != OK) {
dir->make_dir("script_templates");
- _create_script_templates(dir->get_current_dir() + "/script_templates");
} else {
dir->change_dir("..");
}
+ _create_script_templates(dir->get_current_dir() + "/script_templates");
if (dir->change_dir("tmp") != OK) {
dir->make_dir("tmp");