improve file reading in ServerUI, remove dirty flag from FileDef
This commit is contained in:
parent
6dd063382c
commit
12090f7930
24
ServerUI.gd
24
ServerUI.gd
@ -75,6 +75,7 @@ func set_server_dir(dir: String) -> void:
|
|||||||
if !directory.current_is_dir() && (file_name.get_extension() in ACCEPTED_FILE_FORMATS):
|
if !directory.current_is_dir() && (file_name.get_extension() in ACCEPTED_FILE_FORMATS):
|
||||||
var fd = FileDef(file_name, false)
|
var fd = FileDef(file_name, false)
|
||||||
working_files.append(fd)
|
working_files.append(fd)
|
||||||
|
fd.content = _get_file_content(file_name)
|
||||||
|
|
||||||
var in_filestxt := _is_file_in_filestxt(file_name)
|
var in_filestxt := _is_file_in_filestxt(file_name)
|
||||||
fd.include_in_filestxt = in_filestxt
|
fd.include_in_filestxt = in_filestxt
|
||||||
@ -82,7 +83,6 @@ func set_server_dir(dir: String) -> void:
|
|||||||
var file_metadata := _get_file_metadata(file_name)
|
var file_metadata := _get_file_metadata(file_name)
|
||||||
fd.title = file_metadata["title"]
|
fd.title = file_metadata["title"]
|
||||||
fd.date = file_metadata["date"]
|
fd.date = file_metadata["date"]
|
||||||
fd.content = file_metadata["content"]
|
|
||||||
|
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
@ -120,12 +120,6 @@ func _on_FileTree_item_selected() -> void:
|
|||||||
current_tree_selection = item
|
current_tree_selection = item
|
||||||
current_file = item.get_metadata(0)["file_def"] as FileDef
|
current_file = item.get_metadata(0)["file_def"] as FileDef
|
||||||
|
|
||||||
if !current_file.dirty:
|
|
||||||
var file_metadata := _get_file_metadata(current_file.file_path)
|
|
||||||
current_file.title = file_metadata["title"]
|
|
||||||
current_file.date = file_metadata["date"]
|
|
||||||
current_file.content = file_metadata["content"]
|
|
||||||
|
|
||||||
document_input_textedit.text = current_file.content
|
document_input_textedit.text = current_file.content
|
||||||
document_date_lineedit.text = current_file.date
|
document_date_lineedit.text = current_file.date
|
||||||
document_title_lineedit.text = current_file.title
|
document_title_lineedit.text = current_file.title
|
||||||
@ -227,12 +221,20 @@ func _get_file_metadata(path: String) -> Dictionary:
|
|||||||
res["title"] = def[2] if def.size() > 2 else ""
|
res["title"] = def[2] if def.size() > 2 else ""
|
||||||
break
|
break
|
||||||
|
|
||||||
if f.open(server_dir.plus_file(path), File.READ) == OK:
|
res["content"] = _get_file_content(path)
|
||||||
res["content"] = f.get_as_text()
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
func _get_file_content(path: String) -> String:
|
||||||
|
var content: String = ""
|
||||||
|
var f := File.new()
|
||||||
|
if f.open(server_dir.plus_file(path), File.READ) == OK:
|
||||||
|
content = f.get_as_text()
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
func _on_FileTreeContextMenu_id_pressed(id: int) -> void:
|
func _on_FileTreeContextMenu_id_pressed(id: int) -> void:
|
||||||
var idx = current_tree_selection.get_metadata(0)["id"] as int
|
var idx = current_tree_selection.get_metadata(0)["id"] as int
|
||||||
var fd = working_files[idx] as FileDef
|
var fd = working_files[idx] as FileDef
|
||||||
@ -250,20 +252,17 @@ func _on_FileTreeContextMenu_id_pressed(id: int) -> void:
|
|||||||
func _on_DocTitleLineEdit_text_changed(new_text: String) -> void:
|
func _on_DocTitleLineEdit_text_changed(new_text: String) -> void:
|
||||||
if current_file:
|
if current_file:
|
||||||
current_file.title = new_text
|
current_file.title = new_text
|
||||||
current_file.dirty = true
|
|
||||||
|
|
||||||
|
|
||||||
func _on_DocDateLineEdit_text_changed(new_text: String) -> void:
|
func _on_DocDateLineEdit_text_changed(new_text: String) -> void:
|
||||||
if current_file:
|
if current_file:
|
||||||
current_file.date = new_text
|
current_file.date = new_text
|
||||||
current_file.dirty = true
|
|
||||||
|
|
||||||
|
|
||||||
func _on_DocInputTextEdit_text_changed() -> void:
|
func _on_DocInputTextEdit_text_changed() -> void:
|
||||||
if current_file:
|
if current_file:
|
||||||
var new_text: String = document_input_textedit.text
|
var new_text: String = document_input_textedit.text
|
||||||
current_file.content = new_text
|
current_file.content = new_text
|
||||||
current_file.dirty = true
|
|
||||||
|
|
||||||
if !current_file.timer:
|
if !current_file.timer:
|
||||||
var t := Timer.new()
|
var t := Timer.new()
|
||||||
@ -305,7 +304,6 @@ class FileDef:
|
|||||||
var include_in_filestxt: bool = true
|
var include_in_filestxt: bool = true
|
||||||
var title: String # optional
|
var title: String # optional
|
||||||
var date: String # optional, YYYY-MM-DD
|
var date: String # optional, YYYY-MM-DD
|
||||||
var dirty: bool = false
|
|
||||||
|
|
||||||
var content: String
|
var content: String
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user