@papercraftgames/estragon 0.1.0-beta.6 → 0.1.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -261,9 +261,9 @@ static func creation_check(path: String) -> Dictionary:
|
|
|
261
261
|
if not path.begins_with("res://") or path.get_extension() != "gogo" or "\\" in relative or ":" in relative:
|
|
262
262
|
return {"ok":false,"message":"Choose a .gogo file beneath res://."}
|
|
263
263
|
for part in relative.split("/"):
|
|
264
|
-
if part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":"This path is excluded from Gogo compilation. Choose a configured source root."}
|
|
264
|
+
if part.is_empty() or not part.is_valid_filename() or part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":"This path is invalid or excluded from Gogo compilation. Choose a valid filename in a configured source root."}
|
|
265
265
|
if FileAccess.file_exists(path) or DirAccess.dir_exists_absolute(path):
|
|
266
|
-
return {"ok":false,"message":"A file or directory already exists. New Gogo
|
|
266
|
+
return {"ok":false,"message":"A file or directory already exists. New Gogo Component never overwrites existing source; choose another filename."}
|
|
267
267
|
if not DirAccess.dir_exists_absolute(path.get_base_dir()): return {"ok":false,"message":"Create/select an existing project directory first."}
|
|
268
268
|
var check := new()
|
|
269
269
|
check._project = ProjectSettings.globalize_path("res://").trim_suffix("/")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends EditorContextMenuPlugin
|
|
3
|
+
## Parsed only when the public native context-menu API is available.
|
|
4
|
+
var create: Callable
|
|
5
|
+
var root_context := false
|
|
6
|
+
func _popup_menu(paths: PackedStringArray) -> void:
|
|
7
|
+
root_context = paths.is_empty()
|
|
8
|
+
add_context_menu_item("New Gogo Component…" if paths.is_empty() else "Gogo Component…",_selected)
|
|
9
|
+
func _selected(paths: PackedStringArray) -> void:
|
|
10
|
+
# The engine supplies a current directory to callbacks even when popup
|
|
11
|
+
# paths were empty. Empty-space creation deliberately starts at project root.
|
|
12
|
+
if create.is_valid(): create.call(paths[0] if not root_context and not paths.is_empty() else "res://")
|
|
@@ -20,13 +20,15 @@ func start(parent: Node) -> void:
|
|
|
20
20
|
# 4.0 registers EditorFileDialog abstract; do not reference its unavailable
|
|
21
21
|
# constructor even in a dead branch. Both paths use public native dialogs.
|
|
22
22
|
dialog = ClassDB.instantiate("EditorFileDialog") if ClassDB.can_instantiate("EditorFileDialog") else FileDialog.new()
|
|
23
|
-
dialog.name = "
|
|
23
|
+
dialog.name = "NewGogoComponent"
|
|
24
24
|
if dialog is FileDialog: dialog.mode_overrides_title = false
|
|
25
|
-
dialog.title = "New Gogo
|
|
25
|
+
dialog.title = "New Gogo Component"
|
|
26
26
|
dialog.access = EditorFileDialog.ACCESS_RESOURCES
|
|
27
27
|
dialog.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE
|
|
28
28
|
if dialog is EditorFileDialog: dialog.disable_overwrite_warning = true
|
|
29
|
-
|
|
29
|
+
# Native save filters append their suffix even to explicit wrong extensions
|
|
30
|
+
# (Bad.txt becomes Bad.txt.gogo). Let the shared validator own suffixes.
|
|
31
|
+
dialog.add_filter("*","Gogo Component (.gogo)")
|
|
30
32
|
dimension = OptionButton.new()
|
|
31
33
|
dimension.name = "GogoTemplate"
|
|
32
34
|
dimension.add_item("Node2D — native layout and text")
|
|
@@ -35,22 +37,14 @@ func start(parent: Node) -> void:
|
|
|
35
37
|
dialog.file_selected.connect(_selected)
|
|
36
38
|
parent.add_child(dialog)
|
|
37
39
|
error = AcceptDialog.new()
|
|
38
|
-
error.title = "New Gogo
|
|
40
|
+
error.title = "New Gogo Component"
|
|
39
41
|
parent.add_child(error)
|
|
40
|
-
func show_dialog() -> void:
|
|
42
|
+
func show_dialog(context_directory: String = "") -> void:
|
|
41
43
|
if not active: return
|
|
42
|
-
var directory := interface.get_current_directory()
|
|
43
|
-
if not directory.begins_with("res://"): directory = "res://"
|
|
44
|
-
if FileAccess.file_exists("res://gogo.config.json"):
|
|
45
|
-
var config = JSON.parse_string(FileAccess.get_file_as_string("res://gogo.config.json"))
|
|
46
|
-
if config is Dictionary and config.get("source_roots") is Array and not config.source_roots.is_empty():
|
|
47
|
-
var root = config.source_roots[0]
|
|
48
|
-
if root is String:
|
|
49
|
-
var preferred: String = "res://"+root
|
|
50
|
-
if preferred.ends_with(".gogo"): preferred = preferred.get_base_dir()
|
|
51
|
-
if DirAccess.dir_exists_absolute(preferred): directory = preferred
|
|
44
|
+
var directory := context_directory if not context_directory.is_empty() else interface.get_current_directory()
|
|
45
|
+
if not directory.begins_with("res://") or not DirAccess.dir_exists_absolute(directory): directory = "res://"
|
|
52
46
|
dialog.current_dir = directory
|
|
53
|
-
dialog.current_file = "
|
|
47
|
+
dialog.current_file = "NewComponent.gogo"
|
|
54
48
|
dialog.popup_centered_ratio(0.65)
|
|
55
49
|
static func template(path: String, spatial: bool) -> String:
|
|
56
50
|
var directory := Build.output_for(path).get_base_dir()
|
|
@@ -12,6 +12,7 @@ const NewScript = preload("new_script.gd")
|
|
|
12
12
|
var _services: Node
|
|
13
13
|
var _navigation: RefCounted
|
|
14
14
|
var _new_script: RefCounted
|
|
15
|
+
var _creation_menu: RefCounted
|
|
15
16
|
const TEXT_EXTENSIONS_SETTING := "docks/filesystem/textfile_extensions"
|
|
16
17
|
|
|
17
18
|
var _highlighter: EditorSyntaxHighlighter
|
|
@@ -54,7 +55,15 @@ func _enter_tree() -> void:
|
|
|
54
55
|
_highlighter_association.start(_interface)
|
|
55
56
|
_new_script = NewScript.new(_interface,_navigation)
|
|
56
57
|
_new_script.start(self)
|
|
57
|
-
add_tool_menu_item("New Gogo
|
|
58
|
+
add_tool_menu_item("New Gogo Component…",_new_script.show_dialog)
|
|
59
|
+
# Never parse a script extending a newer native class on Godot 4.0.
|
|
60
|
+
if has_method("add_context_menu_plugin") and has_method("remove_context_menu_plugin") and ClassDB.class_exists("EditorContextMenuPlugin") and "CONTEXT_SLOT_FILESYSTEM_CREATE" in ClassDB.class_get_integer_constant_list("EditorContextMenuPlugin"):
|
|
61
|
+
var adapter := GDScript.new()
|
|
62
|
+
adapter.source_code = FileAccess.get_file_as_string((get_script() as Script).resource_path.get_base_dir().path_join("creation_menu.gd.txt"))
|
|
63
|
+
if adapter.reload() == OK:
|
|
64
|
+
_creation_menu = adapter.new()
|
|
65
|
+
_creation_menu.create = _new_script.show_dialog
|
|
66
|
+
call("add_context_menu_plugin",3,_creation_menu) # CONTEXT_SLOT_FILESYSTEM_CREATE
|
|
58
67
|
add_tool_menu_item("Add Missing Gogo Imports",_services.add_missing_imports)
|
|
59
68
|
_timer = Timer.new()
|
|
60
69
|
_timer.one_shot = true
|
|
@@ -235,7 +244,11 @@ func _show_report() -> void:
|
|
|
235
244
|
|
|
236
245
|
func _exit_tree() -> void:
|
|
237
246
|
_active = false
|
|
238
|
-
remove_tool_menu_item("New Gogo
|
|
247
|
+
remove_tool_menu_item("New Gogo Component…")
|
|
248
|
+
if _creation_menu != null:
|
|
249
|
+
call("remove_context_menu_plugin",_creation_menu)
|
|
250
|
+
_creation_menu.create = Callable()
|
|
251
|
+
_creation_menu = null
|
|
239
252
|
remove_tool_menu_item("Add Missing Gogo Imports")
|
|
240
253
|
if _navigation != null: _navigation.stop()
|
|
241
254
|
if _new_script != null: _new_script.stop(); _new_script = null
|
package/package.json
CHANGED