Commit b4797d25 authored by Daniel Brötzmann's avatar Daniel Brötzmann

XMLConsole: Add search functionality

parent 7931d111
Pipeline #4455 passed with stages
in 2 minutes and 45 seconds
......@@ -14,6 +14,25 @@
<property name="icon_name">utilities-terminal-symbolic</property>
</object>
</child>
<child>
<object class="GtkToggleButton" id="search_toggle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_left">6</property>
<signal name="toggled" handler="_on_search_toggled" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">system-search-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<object class="GtkPopover" id="popover">
<property name="can_focus">False</property>
......@@ -80,18 +99,103 @@
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="scrolled">
<property name="height_request">400</property>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkRevealer" id="search_revealer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">none</property>
<property name="transition_duration">100</property>
<child>
<object class="GtkToolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="show_arrow">False</property>
<property name="icon_size">2</property>
<child>
<object class="GtkToolItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">6</property>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="placeholder_text" translatable="yes">Start Search...</property>
<signal name="activate" handler="_on_search_activate" swapped="no"/>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="search_forward">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="icon_name">go-down-symbolic</property>
<signal name="clicked" handler="_on_search_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="search_backward">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="icon_name">go-up-symbolic</property>
<signal name="clicked" handler="_on_search_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTextView" id="textview">
<object class="GtkScrolledWindow" id="scrolled">
<property name="height_request">400</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="cursor_visible">False</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</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>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
......
......@@ -122,6 +122,13 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
if (event.get_state() & Gdk.ModifierType.CONTROL_MASK and
event.keyval == Gdk.KEY_Up):
self._on_paste_last()
if (event.get_state() & Gdk.ModifierType.CONTROL_MASK and
event.keyval == Gdk.KEY_f):
self._ui.search_toggle.set_active(
not self._ui.search_revealer.get_child_revealed())
if event.keyval == Gdk.KEY_F3:
search_str = self._ui.search_entry.get_text()
self._find(search_str, True)
def _on_row_activated(self, _listbox, row):
text = row.get_child().get_text()
......@@ -201,6 +208,51 @@ class XMLConsoleWindow(Gtk.ApplicationWindow):
self._combo.hide()
self._ui.menubutton.hide()
def _on_search_toggled(self, button):
self._ui.search_revealer.set_reveal_child(button.get_active())
self._ui.search_entry.grab_focus()
def _on_search_activate(self, _widget):
search_str = self._ui.search_entry.get_text()
self._find(search_str, True)
def _on_search_clicked(self, button):
forward = bool(button is self._ui.search_forward)
search_str = self._ui.search_entry.get_text()
self._find(search_str, forward)
def _find(self, search_str, forward):
textbuffer = self._ui.textview.get_buffer()
cursor_mark = textbuffer.get_insert()
current_pos = textbuffer.get_iter_at_mark(cursor_mark)
if current_pos.get_offset() == textbuffer.get_char_count():
current_pos = textbuffer.get_start_iter()
last_pos_mark = textbuffer.get_mark('last_pos')
if last_pos_mark is not None:
current_pos = textbuffer.get_iter_at_mark(last_pos_mark)
if forward:
match = current_pos.forward_search(
search_str,
Gtk.TextSearchFlags.VISIBLE_ONLY |
Gtk.TextSearchFlags.CASE_INSENSITIVE,
None)
else:
current_pos.backward_cursor_position()
match = current_pos.backward_search(
search_str,
Gtk.TextSearchFlags.VISIBLE_ONLY |
Gtk.TextSearchFlags.CASE_INSENSITIVE,
None)
if match is not None:
match_start, match_end = match
textbuffer.select_range(match_start, match_end)
mark = textbuffer.create_mark('last_pos', match_end, True)
self._ui.textview.scroll_to_mark(mark, 0, True, 0.5, 0.5)
@staticmethod
def _get_accounts():
accounts = app.get_accounts_sorted()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment