Fix history expander button functionality - set both min and max content heights
This commit is contained in:
parent
bfe3463b52
commit
0c139d2a3b
@ -8,7 +8,7 @@
|
||||
|
||||
<!-- Summary (always visible) -->
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="summary_box">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="spacing">12</property>
|
||||
<property name="margin-start">12</property>
|
||||
@ -61,6 +61,13 @@
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Click gesture for toggling expansion (only on summary) -->
|
||||
<child>
|
||||
<object class="GtkGestureClick" id="click_gesture">
|
||||
<signal name="released" handler="on_clicked" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
@ -104,15 +111,63 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Request Body (scrollable, initially collapsed) -->
|
||||
<child>
|
||||
<object class="GtkLabel" id="request_body_label">
|
||||
<property name="label">Body...</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="wrap">True</property>
|
||||
<object class="GtkScrolledWindow" id="request_body_scroll">
|
||||
<property name="margin-top">6</property>
|
||||
<property name="min-content-height">60</property>
|
||||
<property name="max-content-height">60</property>
|
||||
<property name="propagate-natural-height">True</property>
|
||||
<child>
|
||||
<object class="GtkTextView" id="request_body_text">
|
||||
<property name="editable">False</property>
|
||||
<property name="monospace">True</property>
|
||||
<property name="left-margin">6</property>
|
||||
<property name="right-margin">6</property>
|
||||
<property name="top-margin">6</property>
|
||||
<property name="bottom-margin">6</property>
|
||||
<property name="wrap-mode">word-char</property>
|
||||
<style>
|
||||
<class name="monospace"/>
|
||||
<class name="view"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Request Expander Separator -->
|
||||
<child>
|
||||
<object class="GtkButton" id="request_expander">
|
||||
<property name="halign">fill</property>
|
||||
<property name="margin-top">3</property>
|
||||
<signal name="clicked" handler="on_request_expander_clicked" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkSeparator">
|
||||
<property name="hexpand">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="request_expander_label">
|
||||
<property name="label">Show full request</property>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator">
|
||||
<property name="hexpand">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="flat"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
@ -143,15 +198,63 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Response Body (scrollable, initially collapsed) -->
|
||||
<child>
|
||||
<object class="GtkLabel" id="response_body_label">
|
||||
<property name="label">Body...</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="wrap">True</property>
|
||||
<object class="GtkScrolledWindow" id="response_body_scroll">
|
||||
<property name="margin-top">6</property>
|
||||
<property name="min-content-height">60</property>
|
||||
<property name="max-content-height">60</property>
|
||||
<property name="propagate-natural-height">True</property>
|
||||
<child>
|
||||
<object class="GtkTextView" id="response_body_text">
|
||||
<property name="editable">False</property>
|
||||
<property name="monospace">True</property>
|
||||
<property name="left-margin">6</property>
|
||||
<property name="right-margin">6</property>
|
||||
<property name="top-margin">6</property>
|
||||
<property name="bottom-margin">6</property>
|
||||
<property name="wrap-mode">word-char</property>
|
||||
<style>
|
||||
<class name="monospace"/>
|
||||
<class name="view"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Response Expander Separator -->
|
||||
<child>
|
||||
<object class="GtkButton" id="response_expander">
|
||||
<property name="halign">fill</property>
|
||||
<property name="margin-top">3</property>
|
||||
<signal name="clicked" handler="on_response_expander_clicked" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">horizontal</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="halign">center</property>
|
||||
<child>
|
||||
<object class="GtkSeparator">
|
||||
<property name="hexpand">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="response_expander_label">
|
||||
<property name="label">Show full response</property>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator">
|
||||
<property name="hexpand">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="flat"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
@ -172,12 +275,5 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Click gesture for toggling expansion -->
|
||||
<child>
|
||||
<object class="GtkGestureClick" id="click_gesture">
|
||||
<signal name="released" handler="on_clicked" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
|
||||
@ -34,9 +34,15 @@ class HistoryItem(Gtk.Box):
|
||||
timestamp_label = Gtk.Template.Child()
|
||||
status_label = Gtk.Template.Child()
|
||||
request_headers_label = Gtk.Template.Child()
|
||||
request_body_label = Gtk.Template.Child()
|
||||
request_body_scroll = Gtk.Template.Child()
|
||||
request_body_text = Gtk.Template.Child()
|
||||
request_expander = Gtk.Template.Child()
|
||||
request_expander_label = Gtk.Template.Child()
|
||||
response_headers_label = Gtk.Template.Child()
|
||||
response_body_label = Gtk.Template.Child()
|
||||
response_body_scroll = Gtk.Template.Child()
|
||||
response_body_text = Gtk.Template.Child()
|
||||
response_expander = Gtk.Template.Child()
|
||||
response_expander_label = Gtk.Template.Child()
|
||||
load_button = Gtk.Template.Child()
|
||||
|
||||
__gsignals__ = {
|
||||
@ -47,6 +53,8 @@ class HistoryItem(Gtk.Box):
|
||||
super().__init__()
|
||||
self.entry = entry
|
||||
self.expanded = False
|
||||
self.request_expanded = False
|
||||
self.response_expanded = False
|
||||
self._populate_ui()
|
||||
|
||||
def _populate_ui(self):
|
||||
@ -79,23 +87,34 @@ class HistoryItem(Gtk.Box):
|
||||
|
||||
# Details - Request body
|
||||
body_str = self.entry.request.body if self.entry.request.body else "(empty)"
|
||||
# Truncate long bodies
|
||||
if len(body_str) > 200:
|
||||
body_str = body_str[:200] + "..."
|
||||
self.request_body_label.set_text(body_str)
|
||||
self.request_body_text.get_buffer().set_text(body_str)
|
||||
|
||||
# Count lines to determine if we need the expander
|
||||
num_lines = body_str.count('\n') + 1
|
||||
# Show expander if content is longer than ~3 lines (60px)
|
||||
needs_expander = num_lines > 3 or len(body_str) > 150
|
||||
self.request_expander.set_visible(needs_expander)
|
||||
|
||||
# Details - Response
|
||||
if self.entry.response:
|
||||
self.response_headers_label.set_text(self.entry.response.headers)
|
||||
|
||||
response_body = self.entry.response.body if self.entry.response.body else "(empty)"
|
||||
# Truncate long bodies
|
||||
if len(response_body) > 200:
|
||||
response_body = response_body[:200] + "..."
|
||||
self.response_body_label.set_text(response_body)
|
||||
self.response_body_text.get_buffer().set_text(response_body)
|
||||
|
||||
# Count lines to determine if we need the expander
|
||||
num_lines = response_body.count('\n') + 1
|
||||
needs_expander = num_lines > 3 or len(response_body) > 150
|
||||
self.response_expander.set_visible(needs_expander)
|
||||
elif self.entry.error:
|
||||
self.response_headers_label.set_text("(error)")
|
||||
self.response_body_label.set_text(self.entry.error)
|
||||
error_text = self.entry.error
|
||||
self.response_body_text.get_buffer().set_text(error_text)
|
||||
|
||||
# Show expander for long errors
|
||||
num_lines = error_text.count('\n') + 1
|
||||
needs_expander = num_lines > 3 or len(error_text) > 150
|
||||
self.response_expander.set_visible(needs_expander)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_clicked(self, gesture, n_press, x, y):
|
||||
@ -107,6 +126,48 @@ class HistoryItem(Gtk.Box):
|
||||
"""Emit load signal when load button clicked."""
|
||||
self.emit('load-requested')
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_request_expander_clicked(self, button):
|
||||
"""Toggle request body expansion."""
|
||||
print(f"DEBUG: Request expander clicked! Current state: {self.request_expanded}")
|
||||
self.request_expanded = not self.request_expanded
|
||||
|
||||
if self.request_expanded:
|
||||
# Expand to show full scrollable content
|
||||
self.request_body_scroll.set_min_content_height(300)
|
||||
self.request_body_scroll.set_max_content_height(300)
|
||||
self.request_expander_label.set_text("Collapse request")
|
||||
print("DEBUG: Expanded request to 300px")
|
||||
else:
|
||||
# Collapse to show only few lines
|
||||
self.request_body_scroll.set_min_content_height(60)
|
||||
self.request_body_scroll.set_max_content_height(60)
|
||||
self.request_expander_label.set_text("Show full request")
|
||||
print("DEBUG: Collapsed request to 60px")
|
||||
|
||||
return True # Consume the event
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_response_expander_clicked(self, button):
|
||||
"""Toggle response body expansion."""
|
||||
print(f"DEBUG: Response expander clicked! Current state: {self.response_expanded}")
|
||||
self.response_expanded = not self.response_expanded
|
||||
|
||||
if self.response_expanded:
|
||||
# Expand to show full scrollable content
|
||||
self.response_body_scroll.set_min_content_height(300)
|
||||
self.response_body_scroll.set_max_content_height(300)
|
||||
self.response_expander_label.set_text("Collapse response")
|
||||
print("DEBUG: Expanded response to 300px")
|
||||
else:
|
||||
# Collapse to show only few lines
|
||||
self.response_body_scroll.set_min_content_height(60)
|
||||
self.response_body_scroll.set_max_content_height(60)
|
||||
self.response_expander_label.set_text("Show full response")
|
||||
print("DEBUG: Collapsed response to 60px")
|
||||
|
||||
return True # Consume the event
|
||||
|
||||
def toggle_expanded(self):
|
||||
"""Toggle between collapsed and expanded view."""
|
||||
self.expanded = not self.expanded
|
||||
|
||||
@ -417,6 +417,9 @@ class RosterWindow(Adw.ApplicationWindow):
|
||||
)
|
||||
self.history_manager.add_entry(entry)
|
||||
|
||||
# Refresh history panel to show new entry
|
||||
self._load_history()
|
||||
|
||||
self.http_client.execute_request_async(request, callback, None)
|
||||
|
||||
# History and Project Management
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user