[ghex/expand-search-options: 4/12] findrep: Implement GUI for expanded Find options
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/expand-search-options: 4/12] findrep: Implement GUI for expanded Find options
- Date: Mon, 25 Apr 2022 21:46:14 +0000 (UTC)
commit d452338241dd5a3710525e2aaac36aa7abba4ce4
Author: Logan Rathbone <poprocks gmail com>
Date: Tue Apr 12 14:57:15 2022 -0400
findrep: Implement GUI for expanded Find options
src/find-options.ui | 55 ++++++++++++++++++++++++++++++++++++
src/findreplace.c | 71 +++++++++++++++++++++++++++++++++++------------
src/ghex.gresource.xml.in | 1 +
3 files changed, 110 insertions(+), 17 deletions(-)
---
diff --git a/src/find-options.ui b/src/find-options.ui
new file mode 100644
index 0000000..8b29621
--- /dev/null
+++ b/src/find-options.ui
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- vim: ts=2 sw=2
+-->
+<!--
+ Copyright © 2022 Logan Rathbone <poprocks gmail com>
+
+ GHex is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ GHex is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GHex; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Original GHex Author: Jaka Mocnik <jaka gnu org>
+-->
+
+<interface>
+ <object class="GtkPopover" id="find_options_popover">
+ <child>
+ <object class="GtkGrid" id="find_options_grid">
+ <property name="column-spacing">6</property>
+ <property name="row-spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="find_options_regex">
+ <property name="use-underline">true</property>
+ <property name="label">_Regular expressions</property>
+ <layout>
+ <property name="column">0</property>
+ <property name="row">0</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="find_options_ignore_case">
+ <property name="use-underline">true</property>
+ <property name="label">_Ignore case</property>
+ <layout>
+ <property name="column">1</property>
+ <property name="row">0</property>
+ </layout>
+ </object>
+ </child>
+ </object> <!-- grid -->
+ </child>
+ </object>
+</interface>
diff --git a/src/findreplace.c b/src/findreplace.c
index 7422ace..b8f2f4a 100644
--- a/src/findreplace.c
+++ b/src/findreplace.c
@@ -69,6 +69,10 @@ typedef struct {
GtkWidget *hbox;
GtkWidget *f_next, *f_prev, *f_clear;
GtkWidget *close;
+ GtkWidget *options_btn;
+ GtkWidget *options_popover;
+ GtkWidget *options_regex;
+ GtkWidget *options_ignore_case;
gboolean found;
GCancellable *cancellable;
@@ -279,6 +283,8 @@ find_common (FindDialog *self, enum FindDirection direction,
gint64 str_len;
gint64 offset;
char *str;
+ HexDocumentFindData *find_data;
+ HexSearchFlags flags;
g_return_if_fail (FIND_IS_DIALOG(self));
@@ -299,32 +305,35 @@ find_common (FindDialog *self, enum FindDirection direction,
return;
}
+ flags = HEX_SEARCH_NONE;
+ if (gtk_check_button_get_active (GTK_CHECK_BUTTON(f_priv->options_regex)))
+ flags |= HEX_SEARCH_REGEX;
+ if (gtk_check_button_get_active (GTK_CHECK_BUTTON(f_priv->options_ignore_case)))
+ flags |= HEX_SEARCH_IGNORE_CASE;
+
/* Search for requested string */
if (direction == FIND_FORWARD)
{
- g_cancellable_reset (f_priv->cancellable);
- hex_document_find_forward_async (doc,
- f_priv->found == FALSE ? cursor_pos : cursor_pos + 1,
- str,
- str_len,
- &offset,
- found_msg,
- not_found_msg,
+ find_data->start = f_priv->found == FALSE ?
+ cursor_pos :
+ cursor_pos + f_priv->last_found_len;
+
+ hex_document_find_forward_full_async (doc,
+ find_data,
+ flags,
f_priv->cancellable,
find_ready_cb,
self);
}
else /* FIND_BACKWARD */
{
- hex_document_find_backward_async (doc,
- cursor_pos,
- str,
- str_len,
- &offset,
- found_msg,
- not_found_msg,
- NULL,
+ find_data->start = cursor_pos;
+
+ hex_document_find_backward_full_async (doc,
+ find_data,
+ flags,
+ f_priv->cancellable,
find_ready_cb,
self);
}
@@ -781,6 +790,7 @@ static void
find_dialog_init (FindDialog *self)
{
FindDialogPrivate *f_priv = find_dialog_get_instance_private (self);
+ GtkBuilder *builder;
f_priv->cancellable = g_cancellable_new ();
@@ -829,9 +839,36 @@ find_dialog_init (FindDialog *self)
_("Clears the data you are searching for"),
-1);
+ builder = gtk_builder_new_from_resource (RESOURCE_BASE_PATH "/find-options.ui");
+ f_priv->options_popover = GTK_WIDGET(
+ gtk_builder_get_object (builder, "find_options_popover"));
+ f_priv->options_regex = GTK_WIDGET(
+ gtk_builder_get_object (builder, "find_options_regex"));
+ f_priv->options_ignore_case = GTK_WIDGET(
+ gtk_builder_get_object (builder, "find_options_ignore_case"));
+
+ f_priv->options_btn = gtk_menu_button_new ();
+ gtk_menu_button_set_icon_name (GTK_MENU_BUTTON(f_priv->options_btn),
+ "emblem-system-symbolic");
+ gtk_menu_button_set_popover (GTK_MENU_BUTTON(f_priv->options_btn),
+ f_priv->options_popover);
+ gtk_widget_set_hexpand (f_priv->options_btn, TRUE);
+ gtk_widget_set_halign (f_priv->options_btn, GTK_ALIGN_END);
+ gtk_box_append (GTK_BOX(f_priv->hbox), f_priv->options_btn);
+ gtk_accessible_update_property (GTK_ACCESSIBLE(f_priv->options_btn),
+ GTK_ACCESSIBLE_PROPERTY_LABEL,
+ _("Find options"),
+ -1);
+ gtk_accessible_update_property (GTK_ACCESSIBLE(f_priv->options_btn),
+ GTK_ACCESSIBLE_PROPERTY_DESCRIPTION,
+ _("View options of the find pane"),
+ -1);
+
+ g_object_unref (builder);
+
f_priv->close = gtk_button_new_from_icon_name ("window-close-symbolic");
gtk_button_set_has_frame (GTK_BUTTON(f_priv->close), FALSE);
- gtk_widget_set_hexpand (f_priv->close, TRUE);
+ gtk_widget_set_hexpand (f_priv->close, FALSE);
gtk_widget_set_halign (f_priv->close, GTK_ALIGN_END);
g_signal_connect (G_OBJECT (f_priv->close), "clicked",
G_CALLBACK(common_cancel_cb), self);
diff --git a/src/ghex.gresource.xml.in b/src/ghex.gresource.xml.in
index 232a4f0..e952606 100644
--- a/src/ghex.gresource.xml.in
+++ b/src/ghex.gresource.xml.in
@@ -29,6 +29,7 @@
<file preprocess="xml-stripblanks" compressed="true">context-menu.ui</file>
<file preprocess="xml-stripblanks" compressed="true">preferences.ui</file>
<file preprocess="xml-stripblanks" compressed="true">paste-special.ui</file>
+ <file preprocess="xml-stripblanks" compressed="true">find-options.ui</file>
</gresource>
<gresource prefix="@resource_base_path@/css">
<file>ghex.css</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]