Compare commits
2 Commits
9fae276011
...
eeb6744947
Author | SHA1 | Date | |
---|---|---|---|
|
eeb6744947 | ||
|
d3764d3c4a |
34
ServerUI.gd
34
ServerUI.gd
@ -7,6 +7,9 @@ const SERVER_STATUS_TEXT: Dictionary = {
|
|||||||
|
|
||||||
const ACCEPTED_FILE_FORMATS := ["md"] # server should ignore these file types when adding endpoints
|
const ACCEPTED_FILE_FORMATS := ["md"] # server should ignore these file types when adding endpoints
|
||||||
|
|
||||||
|
export(bool) var enable_file_autosave := true # if true, will save the active file's contents every save_file_timeout seconds.
|
||||||
|
export(float) var save_file_timeout := 4.0 # the time to save document content after the edited signal of TextEdit
|
||||||
|
|
||||||
enum ContextMenuOptions {
|
enum ContextMenuOptions {
|
||||||
MOVE_UP,
|
MOVE_UP,
|
||||||
MOVE_DOWN,
|
MOVE_DOWN,
|
||||||
@ -147,7 +150,7 @@ func set_server_running(running: bool) -> void:
|
|||||||
is_server_running = running # TODO: logic for disabling and enabling certain nodes
|
is_server_running = running # TODO: logic for disabling and enabling certain nodes
|
||||||
|
|
||||||
|
|
||||||
func _generate_filestxt() -> String:
|
func _generate_filestxt():
|
||||||
var files := ""
|
var files := ""
|
||||||
|
|
||||||
for file in working_files:
|
for file in working_files:
|
||||||
@ -155,7 +158,12 @@ func _generate_filestxt() -> String:
|
|||||||
if file.include_in_filestxt:
|
if file.include_in_filestxt:
|
||||||
files += "%s %s %s\n" % [file.file_path, file.date, file.title]
|
files += "%s %s %s\n" % [file.file_path, file.date, file.title]
|
||||||
|
|
||||||
return files
|
var f := File.new()
|
||||||
|
if f.open(server_dir.plus_file("files.txt"), File.WRITE) == OK:
|
||||||
|
f.store_string(files)
|
||||||
|
f.close()
|
||||||
|
else:
|
||||||
|
push_error("File.txt open for save error!")
|
||||||
|
|
||||||
|
|
||||||
func _is_file_in_filestxt(path: String) -> bool:
|
func _is_file_in_filestxt(path: String) -> bool:
|
||||||
@ -229,6 +237,26 @@ func _on_DocInputTextEdit_text_changed() -> void:
|
|||||||
current_file.content = new_text
|
current_file.content = new_text
|
||||||
current_file.dirty = true
|
current_file.dirty = true
|
||||||
|
|
||||||
|
if !current_file.timer:
|
||||||
|
var t := Timer.new()
|
||||||
|
t.wait_time = save_file_timeout
|
||||||
|
t.one_shot = true
|
||||||
|
current_file.timer = t
|
||||||
|
add_child(t)
|
||||||
|
t.connect("timeout", self, "_on_EditedTimeout_timeout", [t, current_file])
|
||||||
|
else:
|
||||||
|
current_file.timer.stop()
|
||||||
|
current_file.timer.start()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_EditedTimeout_timeout(timer: Timer, file: FileDef) -> void:
|
||||||
|
file.timer = null
|
||||||
|
timer.queue_free()
|
||||||
|
|
||||||
|
var f := File.new()
|
||||||
|
if f.open(server_dir.plus_file(file.file_path), File.WRITE) == OK:
|
||||||
|
f.store_string(file.content)
|
||||||
|
|
||||||
|
|
||||||
func FileDef(
|
func FileDef(
|
||||||
file_path: String,
|
file_path: String,
|
||||||
@ -252,3 +280,5 @@ class FileDef:
|
|||||||
var dirty: bool = false
|
var dirty: bool = false
|
||||||
|
|
||||||
var content: String
|
var content: String
|
||||||
|
|
||||||
|
var timer: Timer
|
||||||
|
Loading…
Reference in New Issue
Block a user