From e33a6bc5d897738d29c8b0de93d3087b887fd5d4 Mon Sep 17 00:00:00 2001 From: Arda Aydin Date: Sat, 12 Sep 2026 13:58:55 +0300 Subject: [PATCH] Guard file open and device connect against conflicting state Opening a file while connected to a device prompts to disconnect first. Connecting to a device while a file is open prompts to save unsaved changes, then closes the file before showing the connect dialog. Co-Authored-By: Claude Opus 4.6 --- app_state.py | 2 +- main.py | 16 ++++++++++++++++ sax_file.py | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app_state.py b/app_state.py index 2f9aa77..f317a74 100644 --- a/app_state.py +++ b/app_state.py @@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it. import configparser import os -VERSION = "0.0.0.086" +VERSION = "0.0.0.087" PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties") DEFAULT_GRID_SIZE = 10 DEFAULT_ADD_TIMESTAMP = True diff --git a/main.py b/main.py index e4ea734..455b1a6 100644 --- a/main.py +++ b/main.py @@ -1927,6 +1927,22 @@ _cov_poll_id = None def do_device_connect(): """Opens the connect dialog and initiates a device connection.""" + if app_state.current_file_path and not app_state.live_mode: + if app_state.is_dirty: + answer = messagebox.askyesnocancel( + "Unsaved Changes", + "The current file has unsaved changes.\n\n" + "Save before connecting to a device?", + ) + if answer is None: + return + if answer: + sax_file.execute_direct_overwrite_save() + sax_file.reset_to_startup_state() + sax_file.refresh_treeview_from_dom(None) + wiresheet.render_components([]) + app_state.window.title(app_state.base_window_title()) + connect_dialog.ConnectDialog(app_state.window, _connect_to_device) diff --git a/sax_file.py b/sax_file.py index cd3cea1..c51ea2a 100644 --- a/sax_file.py +++ b/sax_file.py @@ -126,6 +126,19 @@ def open_file(): messagebox.showwarning("Action Blocked", "Cannot load SAX profiles because 'Sedona home folder' configuration is missing or empty.") return + if app_state.live_mode: + answer = messagebox.askyesnocancel( + "Device Connected", + "A live device connection is active.\n\n" + "Disconnect from the device and open a file?\n\n" + "Choose Yes to disconnect and open, No to cancel.", + ) + if not answer: + return + # Import here to avoid circular import at module level + from main import do_device_disconnect + do_device_disconnect() + file_path = filedialog.askopenfilename( title="Select SAX File", filetypes=[("SAX Files", "*.sax"), ("XML Files", "*.xml"), ("All Files", "*.*")],