From ef133baafd74adfc70ebcc94a506f84d2520d458 Mon Sep 17 00:00:00 2001 From: worron Date: Thu, 8 Feb 2024 05:52:22 +0300 Subject: [PATCH] Auto save main windows geometry on close (#162) --- addons/panku_console/common/panku_module.gd | 16 ++++++++++++++-- .../modules/expression_monitor/module.gd | 1 + .../modules/history_manager/module.gd | 1 + .../modules/interactive_shell/module.gd | 1 + .../modules/keyboard_shortcuts/module.gd | 1 + .../modules/native_logger/module.gd | 3 ++- 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/addons/panku_console/common/panku_module.gd b/addons/panku_console/common/panku_module.gd index c4a4c39..4ef3188 100644 --- a/addons/panku_console/common/panku_module.gd +++ b/addons/panku_console/common/panku_module.gd @@ -59,9 +59,21 @@ func load_window_data(window:PankuLynxWindow): window.set_window_visibility(load_module_data("window_visibility", false)) func save_window_data(window:PankuLynxWindow): + _save_window_geometry(window) + save_module_data("window_visibility", window.visible) + + +func _save_window_geometry(window:PankuLynxWindow): save_module_data("window_position", window.position) save_module_data("window_size", window.get_normal_window_size()) - save_module_data("window_visibility", window.visible) + + +# Add hook to window to auto save its geometry on close. +func add_auto_save_hook(window: PankuLynxWindow) -> void: + # Here some global settings check can be implemented, + # if we decide to make "save on close" feature optional + window.window_closed.connect(_save_window_geometry.bind(window)) + func get_module_env() -> RefCounted: return _env @@ -73,7 +85,7 @@ func _init_module(): var module_script_dir:String = get_script().resource_path.get_base_dir() var env_script_path = module_script_dir + "/env.gd" var opt_script_path = module_script_dir + "/opt.gd" - + if FileAccess.file_exists(env_script_path): _env = load(env_script_path).new() _env._module = self diff --git a/addons/panku_console/modules/expression_monitor/module.gd b/addons/panku_console/modules/expression_monitor/module.gd index 7b1c78e..7c5a827 100644 --- a/addons/panku_console/modules/expression_monitor/module.gd +++ b/addons/panku_console/modules/expression_monitor/module.gd @@ -21,6 +21,7 @@ func init_monitor_window(): monitor._module = self # monitor.set_data(load_module_data("exprs", [])) monitor_window = core.windows_manager.create_window(monitor) + add_auto_save_hook(monitor_window) monitor_window.queue_free_on_close = false monitor_window.set_window_title_text("Expression Monitor") diff --git a/addons/panku_console/modules/history_manager/module.gd b/addons/panku_console/modules/history_manager/module.gd index b8741d0..24a7607 100644 --- a/addons/panku_console/modules/history_manager/module.gd +++ b/addons/panku_console/modules/history_manager/module.gd @@ -13,6 +13,7 @@ func init_module(): # bind window window = core.windows_manager.create_window(ui) + add_auto_save_hook(window) window.queue_free_on_close = false window.set_window_title_text("History Manager") load_window_data(window) diff --git a/addons/panku_console/modules/interactive_shell/module.gd b/addons/panku_console/modules/interactive_shell/module.gd index 441b5a3..ebfbc55 100644 --- a/addons/panku_console/modules/interactive_shell/module.gd +++ b/addons/panku_console/modules/interactive_shell/module.gd @@ -28,6 +28,7 @@ func get_intro() -> String: func init_module(): interactive_shell = preload("./console_ui/panku_console_ui.tscn").instantiate() window = core.windows_manager.create_window(interactive_shell) + add_auto_save_hook(window) interactive_shell._repl._module = self window.queue_free_on_close = false window.set_window_title_text("Interative Shell V2") diff --git a/addons/panku_console/modules/keyboard_shortcuts/module.gd b/addons/panku_console/modules/keyboard_shortcuts/module.gd index 4cc8eab..db00dd2 100644 --- a/addons/panku_console/modules/keyboard_shortcuts/module.gd +++ b/addons/panku_console/modules/keyboard_shortcuts/module.gd @@ -10,6 +10,7 @@ func init_module(): # bind window window = core.windows_manager.create_window(key_mapper) + add_auto_save_hook(window) window.queue_free_on_close = false window.set_window_title_text("Keyboard Shortcuts") diff --git a/addons/panku_console/modules/native_logger/module.gd b/addons/panku_console/modules/native_logger/module.gd index a1bb080..cd4e055 100644 --- a/addons/panku_console/modules/native_logger/module.gd +++ b/addons/panku_console/modules/native_logger/module.gd @@ -28,6 +28,7 @@ func init_module(): logger_ui.console = core window = core.windows_manager.create_window(logger_ui) + add_auto_save_hook(window) window.queue_free_on_close = false window.set_window_title_text("Native Logger") @@ -47,7 +48,7 @@ func init_module(): func(bbcode:String): output_overlay.text = bbcode ) - + core.interactive_shell_visibility_changed.connect( func(v:bool): if output_overlay_display_mode == ScreenOverlayDisplayMode.ShowIfShellVisible: