Fix visual indicators: add tooltips to headers, colored background to body
This commit is contained in:
parent
50f5661843
commit
277a8dc13e
@ -294,6 +294,13 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
# Set up theme
|
# Set up theme
|
||||||
self._setup_request_body_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_scroll.set_child(self.body_sourceview)
|
||||||
body_box.append(body_scroll)
|
body_box.append(body_scroll)
|
||||||
|
|
||||||
@ -757,11 +764,13 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
def _update_header_indicators(self):
|
def _update_header_indicators(self):
|
||||||
"""Update warning indicators on header rows."""
|
"""Update warning indicators on header rows."""
|
||||||
from .variable_substitution import VariableSubstitution
|
from .variable_substitution import VariableSubstitution
|
||||||
|
from .widgets.header_row import HeaderRow
|
||||||
|
|
||||||
# Iterate through all header rows
|
# Iterate through all header rows
|
||||||
child = self.headers_listbox.get_first_child()
|
child = self.headers_listbox.get_first_child()
|
||||||
while 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
|
# Check key
|
||||||
key_text = child.key_entry.get_text()
|
key_text = child.key_entry.get_text()
|
||||||
key_vars = set(VariableSubstitution.find_variables(key_text))
|
key_vars = set(VariableSubstitution.find_variables(key_text))
|
||||||
@ -769,8 +778,11 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
|
|
||||||
if undefined_in_key:
|
if undefined_in_key:
|
||||||
child.key_entry.add_css_class("warning")
|
child.key_entry.add_css_class("warning")
|
||||||
|
tooltip = "Undefined: " + ", ".join(sorted(undefined_in_key))
|
||||||
|
child.key_entry.set_tooltip_text(tooltip)
|
||||||
else:
|
else:
|
||||||
child.key_entry.remove_css_class("warning")
|
child.key_entry.remove_css_class("warning")
|
||||||
|
child.key_entry.set_tooltip_text("")
|
||||||
|
|
||||||
# Check value
|
# Check value
|
||||||
value_text = child.value_entry.get_text()
|
value_text = child.value_entry.get_text()
|
||||||
@ -779,18 +791,48 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
|
|
||||||
if undefined_in_value:
|
if undefined_in_value:
|
||||||
child.value_entry.add_css_class("warning")
|
child.value_entry.add_css_class("warning")
|
||||||
|
tooltip = "Undefined: " + ", ".join(sorted(undefined_in_value))
|
||||||
|
child.value_entry.set_tooltip_text(tooltip)
|
||||||
else:
|
else:
|
||||||
child.value_entry.remove_css_class("warning")
|
child.value_entry.remove_css_class("warning")
|
||||||
|
child.value_entry.set_tooltip_text("")
|
||||||
|
|
||||||
child = child.get_next_sibling()
|
child = child.get_next_sibling()
|
||||||
|
|
||||||
def _update_body_indicators(self):
|
def _update_body_indicators(self):
|
||||||
"""Update warning indicators in body text."""
|
"""Update warning indicators in body text with colored background."""
|
||||||
# For body, we use a simpler approach: just set tooltip if there are undefined vars
|
import re
|
||||||
from .variable_substitution import VariableSubstitution
|
from .variable_substitution import VariableSubstitution
|
||||||
|
|
||||||
buffer = self.body_sourceview.get_buffer()
|
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))
|
body_vars = set(VariableSubstitution.find_variables(body_text))
|
||||||
undefined_in_body = body_vars & self.undefined_variables
|
undefined_in_body = body_vars & self.undefined_variables
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user