Remember last opened file and open it on start, implements #33

This commit is contained in:
ChaoticByte 2025-01-07 22:46:13 +01:00
parent ec7544cb3b
commit 974c40fcb4
No known key found for this signature in database
2 changed files with 19 additions and 0 deletions

View file

@ -65,11 +65,25 @@ func load_shader(path: String):
if "/" in path: # update current working directory if "/" in path: # update current working directory
self.cwd = path.substr(0, path.rfind("/")) self.cwd = path.substr(0, path.rfind("/"))
self.last_shader_savepath = path self.last_shader_savepath = path
store_last_opened_file()
func save_shader(path: String): func save_shader(path: String):
print("Save ", path) print("Save ", path)
var file = FileAccess.open(path, FileAccess.WRITE) var file = FileAccess.open(path, FileAccess.WRITE)
file.store_string(self.shader_code) file.store_string(self.shader_code)
file.flush()
if "/" in path: # update current working directory if "/" in path: # update current working directory
self.cwd = path.substr(0, path.rfind("/")) self.cwd = path.substr(0, path.rfind("/"))
self.last_shader_savepath = path self.last_shader_savepath = path
store_last_opened_file()
func store_last_opened_file():
var f = FileAccess.open("user://last_opened", FileAccess.WRITE)
if f != null:
f.store_pascal_string(last_shader_savepath)
f.flush()
func remember_last_opened_file():
var f = FileAccess.open("user://last_opened", FileAccess.READ)
if f != null:
last_shader_savepath = f.get_pascal_string()

View file

@ -1,6 +1,7 @@
extends Node extends Node
@onready var editor_window = %EditorWindow @onready var editor_window = %EditorWindow
@onready var ui_container = %UserInterfaceContainer
@onready var app_name = ProjectSettings.get_setting("application/config/name") @onready var app_name = ProjectSettings.get_setting("application/config/name")
func _ready(): func _ready():
@ -11,6 +12,10 @@ func _ready():
editor_window.position.y) editor_window.position.y)
get_window().min_size = Vector2i(400, 400) get_window().min_size = Vector2i(400, 400)
editor_window.min_size = Vector2i(560, 400) editor_window.min_size = Vector2i(560, 400)
# Load last opened file
Filesystem.remember_last_opened_file()
if Filesystem.last_shader_savepath != "":
ui_container.get_node("Editor")._on_open_shader_dialog_file_selected(Filesystem.last_shader_savepath)
func update_title(current_file: String = ""): func update_title(current_file: String = ""):
if current_file == "": if current_file == "":