Skip to content

Commit

Permalink
now search or type @ for crash type and filter rows
Browse files Browse the repository at this point in the history
problem row color code changed in ui
  • Loading branch information
sshil authored and msrb committed Oct 23, 2024
1 parent 2465db7 commit 8b5ea5f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
7 changes: 2 additions & 5 deletions data/css/oops.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ GtkListBoxRow, row {
}

GtkListBoxRow:selected, row:selected {
background-color: #e0e0e0;
}

.header-bar {
background-color: #e0e0e0;
background-color: #007bff; /* Custom blue color */
color: #ffffff; /* White text color for better contrast */
}

.app-menu-button {
Expand Down
2 changes: 1 addition & 1 deletion data/ui/oops-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<object class="GtkSearchEntry" id="search_entry">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="placeholder-text" translatable="yes">Search Crashes</property>
<property name="placeholder-text" translatable="yes">Search or type @ for crash types</property>
<signal name="search-changed" handler="on_se_problems_search_changed"/>
<style>
<class name="search-crash"/>
Expand Down
69 changes: 67 additions & 2 deletions src/gnome_abrt/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,30 @@ def set_pattern(self, pattern):
self._list_box_selection.unselect_all()

def match(self, list_box_row):
# None nevere matches the patter
# None matches the pattern
if list_box_row is None:
return False

# taking problem type so that we can search by "@"
problem_type = list_box_row.problem_type

# handling special case for filtering by problem_type using "@" symbol
if self._pattern.startswith("@"):
search_type = self._pattern[1:].strip().lower()

# Empty string mathces everything
if search_type == "":
return True

if search_type == "misbehavior":
return problem_type == "misbehavior"
elif search_type == "system":
return problem_type in ["system failure", "system crash"]
elif search_type == "application":
return problem_type == "application crash"
else:
return False

# Empty string matches everything
if not self._pattern:
return True

Expand Down Expand Up @@ -206,6 +225,8 @@ def __init__(self, problem_values):
super().__init__()

self._problem = problem_values[4]
# Store the problem type as a property (this is what we will filter by)
self.problem_type = problem_values[2].lower() # Store as lowercase for easier comparison


#applying margins directly on the ListBoxRow
Expand Down Expand Up @@ -419,6 +440,8 @@ def __init__(self, application, sources, controller):
self.style_manager.connect("notify::color-scheme", self.on_theme_changed)

self.search_entry.hide() # Ensure the search entry is hidden on load
#function to set up the auto-completion for the search entry
self.setup_search_completion()

# Ensure buttons are packed only once
if self.btn_delete.get_parent() is None:
Expand Down Expand Up @@ -462,6 +485,48 @@ def on_window_map(self, widget):
#move it back to the original position after a slight delay
GLib.idle_add(self.restore_paned_position, current_position)

def setup_search_completion(self):
"""Manually set up a popover to show suggestions for the search entry"""
#created a Gtk.ListBox to show suggestions
self.completion_list = Gtk.ListBox()
self.completion_list.set_selection_mode(Gtk.SelectionMode.SINGLE)

#suggestions to the list
suggestions = ["@Misbehavior", "@System", "@Application"]
for suggestion in suggestions:
row = Gtk.ListBoxRow()
label = Gtk.Label(label=suggestion)
row.set_child(label)
self.completion_list.append(row)

#created a popover to hold the list of suggestions
self.completion_popover = Gtk.Popover()
self.completion_popover.set_child(self.completion_list)
self.completion_popover.set_parent(self.search_entry)
self.completion_list.connect("row-activated", self.on_suggestion_selected)
self.search_entry.connect("changed", self.on_search_entry_changed)

def on_search_entry_changed(self, entry):
"""Show suggestions when the user types '@'"""
text = entry.get_text()
if text.startswith("@"):
#after typing '@' the popover will be shown to the search entry
self.completion_popover.popup()
else:
#hide the popover if the user types something else
self.completion_popover.popdown()

def on_suggestion_selected(self, listbox, row):
"""Handle suggestion selection from the list."""
suggestion = row.get_child().get_text()

#set the suggestion as the text in the search entry
self.search_entry.set_text(suggestion)
self.search_entry.set_position(-1) #moves the cursor to the last position
self.completion_popover.popdown()
#apply the filter based on the selected suggestion
self._filter.set_pattern(suggestion)

def restore_paned_position(self, original_position):
"""Optional: restoring the original paned position after the adjustment - might delete later"""
self.gr_main_layout.set_position(original_position)
Expand Down

0 comments on commit 8b5ea5f

Please sign in to comment.