diff --git a/src/request_tab_widget.py b/src/request_tab_widget.py index f3dd9b5..996e500 100644 --- a/src/request_tab_widget.py +++ b/src/request_tab_widget.py @@ -37,6 +37,7 @@ class RequestTabWidget(Gtk.Box): self.response = response self.modified = False self.original_request = None + self.original_scripts = None self.project_id = project_id self.selected_environment_id = selected_environment_id self.scripts = scripts @@ -652,6 +653,10 @@ class RequestTabWidget(Gtk.Box): body_buffer = self.body_sourceview.get_buffer() body_buffer.connect("changed", self._on_request_changed) + # Setup script change tracking + postprocessing_buffer = self.postprocessing_sourceview.get_buffer() + postprocessing_buffer.connect("changed", self._on_request_changed) + # Setup variable indicator updates (debounced) if self.project_id: self.url_entry.connect("changed", lambda w: self._schedule_indicator_update()) @@ -680,7 +685,8 @@ class RequestTabWidget(Gtk.Box): if not self.original_request: return False - return ( + # Check if request changed + request_changed = ( request.method != self.original_request.method or request.url != self.original_request.url or request.body != self.original_request.body or @@ -688,6 +694,23 @@ class RequestTabWidget(Gtk.Box): request.syntax != self.original_request.syntax ) + # Check if scripts changed + current_scripts = self.get_scripts() + scripts_changed = False + + if self.original_scripts is None and current_scripts: + # Had no scripts, now has scripts + scripts_changed = (current_scripts.preprocessing.strip() != "" or + current_scripts.postprocessing.strip() != "") + elif self.original_scripts and current_scripts: + # Compare scripts + scripts_changed = ( + current_scripts.preprocessing != self.original_scripts.preprocessing or + current_scripts.postprocessing != self.original_scripts.postprocessing + ) + + return request_changed or scripts_changed + def _load_request(self, request): """Load a request into this tab's UI.""" # Set method diff --git a/src/window.py b/src/window.py index 64dd2f9..061ca12 100644 --- a/src/window.py +++ b/src/window.py @@ -315,6 +315,14 @@ class RosterWindow(Adw.ApplicationWindow): widget.original_request = tab.original_request widget.project_manager = self.project_manager # Inject project manager + # Set original scripts for change tracking (if this is a saved request) + if saved_request_id and scripts: + from .models import Scripts + widget.original_scripts = Scripts( + preprocessing=scripts.preprocessing, + postprocessing=scripts.postprocessing + ) + # Populate environment dropdown if project_id is set if project_id and hasattr(widget, '_populate_environment_dropdown'): widget._populate_environment_dropdown() @@ -788,12 +796,12 @@ class RosterWindow(Adw.ApplicationWindow): self._show_toast(f"Saved as '{name}'") # Clear modified flag on current tab - self._mark_tab_as_saved(saved_request.id, name, request) + self._mark_tab_as_saved(saved_request.id, name, request, scripts) dialog.connect("response", on_response) dialog.present(self) - def _mark_tab_as_saved(self, saved_request_id, name, request): + def _mark_tab_as_saved(self, saved_request_id, name, request, scripts=None): """Mark the current tab as saved (clear modified flag).""" page = self.tab_view.get_selected_page() if not page: @@ -807,6 +815,7 @@ class RosterWindow(Adw.ApplicationWindow): tab.saved_request_id = saved_request_id tab.name = name tab.modified = False + tab.scripts = scripts # Update original_request to match saved state original = HttpRequest( @@ -818,6 +827,17 @@ class RosterWindow(Adw.ApplicationWindow): ) tab.original_request = original + # Update original_scripts to match saved state + if scripts: + from .models import Scripts + original_scripts = Scripts( + preprocessing=scripts.preprocessing, + postprocessing=scripts.postprocessing + ) + widget.original_scripts = original_scripts + else: + widget.original_scripts = None + # Update widget state widget.original_request = original widget.modified = False @@ -845,7 +865,7 @@ class RosterWindow(Adw.ApplicationWindow): self._show_toast(f"Updated '{name}'") # Clear modified flag on current tab - self._mark_tab_as_saved(existing_request_id, name, request) + self._mark_tab_as_saved(existing_request_id, name, request, scripts) dialog.connect("response", on_overwrite_response) dialog.present(self) @@ -951,6 +971,14 @@ class RosterWindow(Adw.ApplicationWindow): # Load scripts into widget if scripts: widget.load_scripts(scripts) + # Set original scripts for change tracking + from .models import Scripts + widget.original_scripts = Scripts( + preprocessing=scripts.preprocessing, + postprocessing=scripts.postprocessing + ) + else: + widget.original_scripts = None if is_copy: # This is a copy - mark as unsaved