2020-09-13 18:40:44 +02:00
|
|
|
extends TextEdit
|
|
|
|
|
2020-10-06 10:38:31 +02:00
|
|
|
signal saved
|
|
|
|
|
2020-09-13 18:40:44 +02:00
|
|
|
var path
|
2020-09-21 15:36:09 +02:00
|
|
|
|
|
|
|
var _server
|
|
|
|
var _client_connection
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
# Initialize TCP server for fake editor.
|
|
|
|
_server = TCP_Server.new()
|
|
|
|
_server.listen(1234)
|
|
|
|
|
|
|
|
func _process(_delta):
|
|
|
|
if _server.is_connection_available():
|
|
|
|
_client_connection = _server.take_connection()
|
2020-10-26 21:29:11 +01:00
|
|
|
var length = _client_connection.get_u32()
|
2020-09-21 15:36:09 +02:00
|
|
|
var filename = _client_connection.get_string(length)
|
2020-10-26 21:29:11 +01:00
|
|
|
|
|
|
|
length = _client_connection.get_u32()
|
|
|
|
var content = _client_connection.get_string(length)
|
|
|
|
|
|
|
|
open(content)
|
2020-10-06 11:34:12 +02:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event.is_action_pressed("save"):
|
|
|
|
save()
|
2020-09-21 15:36:09 +02:00
|
|
|
|
2020-10-26 21:29:11 +01:00
|
|
|
func open(content):
|
2020-09-21 15:36:09 +02:00
|
|
|
text = content
|
|
|
|
show()
|
|
|
|
grab_focus()
|
|
|
|
|
|
|
|
func save():
|
2020-10-23 16:43:02 +02:00
|
|
|
if visible:
|
|
|
|
# Add a newline to the end of the file if there is none.
|
|
|
|
if text.length() > 0 and text.substr(text.length()-1, 1) != "\n":
|
|
|
|
text += "\n"
|
|
|
|
|
2020-10-26 21:29:11 +01:00
|
|
|
_client_connection.put_string(text)
|
|
|
|
|
2020-10-23 16:43:02 +02:00
|
|
|
close()
|
2020-10-26 16:36:38 +01:00
|
|
|
emit_signal("saved")
|
2020-09-22 15:55:01 +02:00
|
|
|
|
|
|
|
func close():
|
2020-10-22 16:19:22 +02:00
|
|
|
if _client_connection and _client_connection.is_connected_to_host():
|
2020-09-22 15:55:01 +02:00
|
|
|
_client_connection.disconnect_from_host()
|
2020-09-21 15:36:09 +02:00
|
|
|
text = ""
|
|
|
|
hide()
|