From 974c40fcb4b75a2290cdac0f95a905621eaf5a1a Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Tue, 7 Jan 2025 22:46:13 +0100 Subject: [PATCH] Remember last opened file and open it on start, implements #33 --- src/Filesystem.gd | 14 ++++++++++++++ src/Main.gd | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/src/Filesystem.gd b/src/Filesystem.gd index 2ead478..760bc07 100644 --- a/src/Filesystem.gd +++ b/src/Filesystem.gd @@ -65,11 +65,25 @@ func load_shader(path: String): if "/" in path: # update current working directory self.cwd = path.substr(0, path.rfind("/")) self.last_shader_savepath = path + store_last_opened_file() func save_shader(path: String): print("Save ", path) var file = FileAccess.open(path, FileAccess.WRITE) file.store_string(self.shader_code) + file.flush() if "/" in path: # update current working directory self.cwd = path.substr(0, path.rfind("/")) 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() diff --git a/src/Main.gd b/src/Main.gd index 6c59d07..2acdbf4 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -1,6 +1,7 @@ extends Node @onready var editor_window = %EditorWindow +@onready var ui_container = %UserInterfaceContainer @onready var app_name = ProjectSettings.get_setting("application/config/name") func _ready(): @@ -11,6 +12,10 @@ func _ready(): editor_window.position.y) get_window().min_size = Vector2i(400, 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 = ""): if current_file == "":