make sure tree items can't be moved out of bounds

This commit is contained in:
Lera Elvoé 2022-06-23 19:09:00 +03:00
parent c3e0bd043f
commit 9fae276011

View File

@ -108,6 +108,7 @@ func _on_FileTree_item_edited() -> void:
func _on_FileTree_item_selected() -> void:
var item: TreeItem = file_tree.get_selected()
current_tree_selection = item
current_file = item.get_metadata(0)["file_def"] as FileDef
if !current_file.dirty:
@ -124,6 +125,17 @@ func _on_FileTree_item_selected() -> void:
func _on_FileTree_item_rmb_selected(position: Vector2) -> void:
current_tree_selection = file_tree.get_selected()
file_tree_context_menu.rect_position = position + file_tree.rect_global_position
if (current_tree_selection.get_metadata(0)["id"] as int) == 0:
file_tree_context_menu.set_item_disabled(ContextMenuOptions.MOVE_UP, true)
else:
file_tree_context_menu.set_item_disabled(ContextMenuOptions.MOVE_UP, false)
if (current_tree_selection.get_metadata(0)["id"] as int) == working_files.size() - 1:
file_tree_context_menu.set_item_disabled(ContextMenuOptions.MOVE_DOWN, true)
else:
file_tree_context_menu.set_item_disabled(ContextMenuOptions.MOVE_DOWN, false)
file_tree_context_menu.popup()
@ -158,7 +170,12 @@ func _is_file_in_filestxt(path: String) -> bool:
func _get_file_metadata(path: String) -> Dictionary:
var f := File.new()
var res = {}
var res = {
"file_path": path,
"date": "",
"title": "",
"content": "",
}
if f.open(server_dir.plus_file("files.txt"), File.READ) == OK:
var text := f.get_as_text()
@ -166,10 +183,10 @@ func _get_file_metadata(path: String) -> Dictionary:
for line in lines:
line = line as String
if line.empty():
res = {}
continue
var def = line.split(" ", true, 2)
if def[0] == path:
res["file_path"] = def[0]
# res["file_path"] = def[0]
res["date"] = def[1] if def.size() > 1 else ""
res["title"] = def[2] if def.size() > 2 else ""
break