Compare commits

..

4 Commits

4 changed files with 32 additions and 13 deletions

View File

@ -31,7 +31,7 @@
{ {
"type": "git", "type": "git",
"url": "https://git.bugsy.cz/beval/roster.git", "url": "https://git.bugsy.cz/beval/roster.git",
"tag": "v0.8.2" "tag": "v0.8.3"
} }
] ]
} }

View File

@ -1,5 +1,5 @@
project('roster', project('roster',
version: '0.8.2', version: '0.8.3',
meson_version: '>= 1.0.0', meson_version: '>= 1.0.0',
default_options: [ 'warning_level=2', 'werror=false', ], default_options: [ 'warning_level=2', 'werror=false', ],
) )

View File

@ -924,6 +924,9 @@ class RequestTabWidget(Gtk.Box):
language = self._get_language_from_content_type(content_type) language = self._get_language_from_content_type(content_type)
source_buffer.set_language(language) source_buffer.set_language(language)
# Switch to body tab
self.response_stack.set_visible_child_name("body")
def display_error(self, error: str) -> None: def display_error(self, error: str) -> None:
"""Display error in this tab's UI.""" """Display error in this tab's UI."""
self.status_label.set_text("Error") self.status_label.set_text("Error")
@ -1150,6 +1153,18 @@ class RequestTabWidget(Gtk.Box):
return "" return ""
def _is_json_content_type(self, content_type):
"""Check if the content type is JSON or a JSON-based format."""
return ('application/json' in content_type
or 'text/json' in content_type
or '+json' in content_type)
def _is_xml_content_type(self, content_type):
"""Check if the content type is XML or an XML-based format."""
return ('application/xml' in content_type
or 'text/xml' in content_type
or '+xml' in content_type)
def _get_language_from_content_type(self, content_type): def _get_language_from_content_type(self, content_type):
"""Get GtkSourceView language ID from content type.""" """Get GtkSourceView language ID from content type."""
if not content_type: if not content_type:
@ -1157,9 +1172,9 @@ class RequestTabWidget(Gtk.Box):
language_manager = GtkSource.LanguageManager.get_default() language_manager = GtkSource.LanguageManager.get_default()
if 'application/json' in content_type or 'text/json' in content_type: if self._is_json_content_type(content_type):
return language_manager.get_language('json') return language_manager.get_language('json')
elif 'application/xml' in content_type or 'text/xml' in content_type: elif self._is_xml_content_type(content_type):
return language_manager.get_language('xml') return language_manager.get_language('xml')
elif 'text/html' in content_type: elif 'text/html' in content_type:
return language_manager.get_language('html') return language_manager.get_language('html')
@ -1176,10 +1191,10 @@ class RequestTabWidget(Gtk.Box):
return body return body
try: try:
if 'application/json' in content_type or 'text/json' in content_type: if self._is_json_content_type(content_type):
parsed = json.loads(body) parsed = json.loads(body)
return json.dumps(parsed, indent=2, ensure_ascii=False) return json.dumps(parsed, indent=2, ensure_ascii=False)
elif 'application/xml' in content_type or 'text/xml' in content_type: elif self._is_xml_content_type(content_type):
dom = xml.dom.minidom.parseString(body) dom = xml.dom.minidom.parseString(body)
return dom.toprettyxml(indent=" ") return dom.toprettyxml(indent=" ")
except Exception as e: except Exception as e:

View File

@ -1183,9 +1183,8 @@ class RosterWindow(Adw.ApplicationWindow):
return return
# Apply variable substitution if environment is selected # Apply variable substitution if environment is selected
substituted_request = request def show_export(env):
if widget.selected_environment_id: substituted_request = request
env = widget.get_selected_environment()
if env: if env:
from .variable_substitution import VariableSubstitution from .variable_substitution import VariableSubstitution
substituted_request, undefined = VariableSubstitution.substitute_request(request, env) substituted_request, undefined = VariableSubstitution.substitute_request(request, env)
@ -1196,10 +1195,15 @@ class RosterWindow(Adw.ApplicationWindow):
# Show warning toast but continue with export # Show warning toast but continue with export
self._show_toast(f"Warning: {len(undefined)} undefined variable(s)") self._show_toast(f"Warning: {len(undefined)} undefined variable(s)")
# Show export dialog with substituted request # Show export dialog with substituted request
from .export_dialog import ExportDialog from .export_dialog import ExportDialog
dialog = ExportDialog(substituted_request) dialog = ExportDialog(substituted_request)
dialog.present(self) dialog.present(self)
if widget.selected_environment_id:
widget.get_selected_environment(show_export)
else:
show_export(None)
def _mark_tab_as_saved(self, saved_request_id, name, request, scripts=None): def _mark_tab_as_saved(self, saved_request_id, name, request, scripts=None):
"""Mark the current tab as saved (clear modified flag).""" """Mark the current tab as saved (clear modified flag)."""