godot-engine.file-editor/addons/file-editor/scripts/FileScene.gd

70 lines
2.0 KiB
GDScript3
Raw Normal View History

2019-09-24 00:42:50 +02:00
tool
extends VBoxContainer
onready var ReadOnly = $FileInfo/Readonly
onready var TextEditor = $TextEditor
onready var LastModified = $FileInfo/lastmodified
onready var FileList = get_parent().get_parent().get_parent().get_node("FileList")
2019-10-03 16:06:46 +02:00
onready var ClosingFile = get_parent().get_parent().get_parent().get_node("ConfirmationDialog")
onready var LastModifiedIcon = $FileInfo/lastmodified_icon
2019-09-24 00:42:50 +02:00
var current_path = ""
var current_filename = ""
2019-10-03 16:06:46 +02:00
var old_file_content = ""
2019-09-24 17:03:49 +02:00
var Preview = load("res://addons/file-editor/scenes/Preview.tscn")
2019-10-08 00:25:16 +02:00
signal text_changed()
2019-09-24 00:42:50 +02:00
func _ready():
2019-10-03 16:06:46 +02:00
ClosingFile.connect("confirmed",self,"queue_free")
2019-09-24 00:42:50 +02:00
ReadOnly.connect("toggled",self,"_on_Readonly_toggled")
2019-10-03 16:06:46 +02:00
ReadOnly.set("custom_icons/checked",IconLoader.load_icon_from_name("read"))
ReadOnly.set("custom_icons/unchecked",IconLoader.load_icon_from_name("edit"))
2019-09-24 00:42:50 +02:00
2019-10-08 00:25:16 +02:00
func clean_editor():
TextEditor.set_text("")
LastModifiedIcon.texture = IconLoader.load_icon_from_name("save")
LastModified.set_text("")
2019-09-24 00:42:50 +02:00
FileList.invalidate()
2019-10-08 00:25:16 +02:00
func new_file_open(file_content, last_modified):
TextEditor.set_text(file_content)
update_lastmodified(last_modified,"save")
2019-09-24 00:42:50 +02:00
FileList.invalidate()
2019-10-08 00:25:16 +02:00
func update_lastmodified(last_modified : Dictionary, icon : String):
2019-09-24 00:42:50 +02:00
LastModified.set_text(str(last_modified.hour)+":"+str(last_modified.minute)+" "+str(last_modified.day)+"/"+str(last_modified.month)+"/"+str(last_modified.year))
2019-10-08 00:25:16 +02:00
LastModifiedIcon.texture = IconLoader.load_icon_from_name(icon)
2019-09-24 00:42:50 +02:00
2019-10-08 00:25:16 +02:00
func new_file_create(file_name):
TextEditor.set_text("")
2019-09-24 00:42:50 +02:00
FileList.invalidate()
func close_editor():
2019-10-03 16:06:46 +02:00
if old_file_content != TextEditor.get_text():
ClosingFile.popup()
else:
queue_free()
2019-09-24 00:42:50 +02:00
func _on_Readonly_toggled(button_pressed):
if button_pressed:
ReadOnly.set_text("Read Only")
TextEditor.readonly = (true)
else:
ReadOnly.set_text("Can Edit")
2019-10-03 16:06:46 +02:00
TextEditor.readonly = (false)
func _on_TextEditor_text_changed():
LastModifiedIcon.texture = IconLoader.load_icon_from_name("saveas")
2019-10-08 00:25:16 +02:00
emit_signal("text_changed")