Fix visual indicators: add tooltips to headers, colored background to body

This commit is contained in:
vesp 2025-12-30 14:07:13 +01:00
parent 50f5661843
commit 277a8dc13e

View File

@ -294,6 +294,13 @@ class RequestTabWidget(Gtk.Box):
# Set up theme
self._setup_request_body_theme()
# Set up text tag for undefined variable highlighting
buffer = self.body_sourceview.get_buffer()
self.undefined_var_tag = buffer.create_tag(
"undefined-variable",
background="#ffc27d30" # Semi-transparent warning color
)
body_scroll.set_child(self.body_sourceview)
body_box.append(body_scroll)
@ -757,11 +764,13 @@ class RequestTabWidget(Gtk.Box):
def _update_header_indicators(self):
"""Update warning indicators on header rows."""
from .variable_substitution import VariableSubstitution
from .widgets.header_row import HeaderRow
# Iterate through all header rows
child = self.headers_listbox.get_first_child()
while child:
if hasattr(child, 'key_entry') and hasattr(child, 'value_entry'):
# Check if this is a HeaderRow widget
if isinstance(child, HeaderRow):
# Check key
key_text = child.key_entry.get_text()
key_vars = set(VariableSubstitution.find_variables(key_text))
@ -769,8 +778,11 @@ class RequestTabWidget(Gtk.Box):
if undefined_in_key:
child.key_entry.add_css_class("warning")
tooltip = "Undefined: " + ", ".join(sorted(undefined_in_key))
child.key_entry.set_tooltip_text(tooltip)
else:
child.key_entry.remove_css_class("warning")
child.key_entry.set_tooltip_text("")
# Check value
value_text = child.value_entry.get_text()
@ -779,18 +791,48 @@ class RequestTabWidget(Gtk.Box):
if undefined_in_value:
child.value_entry.add_css_class("warning")
tooltip = "Undefined: " + ", ".join(sorted(undefined_in_value))
child.value_entry.set_tooltip_text(tooltip)
else:
child.value_entry.remove_css_class("warning")
child.value_entry.set_tooltip_text("")
child = child.get_next_sibling()
def _update_body_indicators(self):
"""Update warning indicators in body text."""
# For body, we use a simpler approach: just set tooltip if there are undefined vars
"""Update warning indicators in body text with colored background."""
import re
from .variable_substitution import VariableSubstitution
buffer = self.body_sourceview.get_buffer()
body_text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), False)
# Get body text
start_iter = buffer.get_start_iter()
end_iter = buffer.get_end_iter()
body_text = buffer.get_text(start_iter, end_iter, False)
# Remove all existing undefined-variable tags
buffer.remove_tag(self.undefined_var_tag, start_iter, end_iter)
# Find all {{variable}} patterns and highlight undefined ones
pattern = VariableSubstitution.VARIABLE_PATTERN
for match in pattern.finditer(body_text):
var_name = match.group(1)
# Check if this variable is undefined
if var_name in self.undefined_variables:
# Get start and end positions
match_start = match.start()
match_end = match.end()
# Create text iters at these positions
start_tag_iter = buffer.get_iter_at_offset(match_start)
end_tag_iter = buffer.get_iter_at_offset(match_end)
# Apply the tag
buffer.apply_tag(self.undefined_var_tag, start_tag_iter, end_tag_iter)
# Also set tooltip for overall info
body_vars = set(VariableSubstitution.find_variables(body_text))
undefined_in_body = body_vars & self.undefined_variables