[gnome-terminal/search] [search] Make Find button insensitive if regex is invalid
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/search] [search] Make Find button insensitive if regex is invalid
- Date: Sun, 2 May 2010 07:22:15 +0000 (UTC)
commit 89e2381f0a825263f2b756dae572efdcc4036d89
Author: Behdad Esfahbod <behdad behdad org>
Date: Sun May 2 03:20:54 2010 -0400
[search] Make Find button insensitive if regex is invalid
src/terminal-search-dialog.c | 35 +++++++++++++++++++++--------------
src/terminal-window.c | 3 +--
2 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/src/terminal-search-dialog.c b/src/terminal-search-dialog.c
index addca2d..6991dad 100644
--- a/src/terminal-search-dialog.c
+++ b/src/terminal-search-dialog.c
@@ -43,6 +43,8 @@ get_quark (void)
#define TERMINAL_SEARCH_DIALOG_GET_PRIVATE(object) \
((TerminalSearchDialogPrivate *) g_object_get_qdata (G_OBJECT (object), get_quark ()))
+#define GET_FLAG(widget) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->widget))
+
typedef struct _TerminalSearchDialogPrivate
{
GtkWidget *search_label;
@@ -63,8 +65,8 @@ typedef struct _TerminalSearchDialogPrivate
} TerminalSearchDialogPrivate;
-static void search_text_entry_changed (GtkEditable *editable,
- GtkWidget *dialog);
+static void update_sensitivity (void *unused,
+ GtkWidget *dialog);
static void response_handler (GtkWidget *dialog,
gint response_id,
gpointer data);
@@ -121,7 +123,8 @@ terminal_search_dialog_new (GtkWindow *parent)
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);
gtk_entry_set_activates_default (GTK_ENTRY (priv->search_text_entry), TRUE);
- g_signal_connect (priv->search_text_entry, "changed", G_CALLBACK (search_text_entry_changed), dialog);
+ g_signal_connect (priv->search_text_entry, "changed", G_CALLBACK (update_sensitivity), dialog);
+ g_signal_connect (priv->regex_checkbutton, "toggled", G_CALLBACK (update_sensitivity), dialog);
g_signal_connect (dialog, "response", G_CALLBACK (response_handler), NULL);
@@ -160,23 +163,29 @@ terminal_search_dialog_private_destroy (TerminalSearchDialogPrivate *priv)
static void
-search_text_entry_changed (GtkEditable *editable,
- GtkWidget *dialog)
+update_sensitivity (void *unused, GtkWidget *dialog)
{
TerminalSearchDialogPrivate *priv = TERMINAL_SEARCH_DIALOG_GET_PRIVATE (dialog);
const gchar *search_string;
-
- search_string = gtk_entry_get_text (GTK_ENTRY (editable));
- g_return_if_fail (search_string != NULL);
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GTK_RESPONSE_ACCEPT,
- *search_string != '\0');
+ gboolean valid;
if (priv->regex) {
g_regex_unref (priv->regex);
priv->regex = NULL;
}
+
+ search_string = gtk_entry_get_text (GTK_ENTRY (priv->search_text_entry));
+ g_return_if_fail (search_string != NULL);
+
+ valid = *search_string != '\0';
+
+ if (valid && GET_FLAG (regex_checkbutton)) {
+ /* Check that the regex is valid */
+ valid = NULL != terminal_search_dialog_get_regex (dialog);
+ /* TODO show the error message somewhere */
+ }
+
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, valid);
}
static gboolean
@@ -301,8 +310,6 @@ terminal_search_dialog_get_search_text (GtkWidget *dialog)
return gtk_entry_get_text (GTK_ENTRY (priv->search_text_entry));
}
-#define GET_FLAG(widget) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->widget))
-
TerminalSearchFlags
terminal_search_dialog_get_search_flags (GtkWidget *dialog)
{
diff --git a/src/terminal-window.c b/src/terminal-window.c
index b8f06d9..80ea9e1 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -3528,8 +3528,7 @@ search_find_response_callback (GtkWidget *dialog,
return;
regex = terminal_search_dialog_get_regex (dialog);
- if (G_UNLIKELY (!regex))
- return; /* TODO error handling? */
+ g_return_if_fail (regex != NULL);
flags = terminal_search_dialog_get_search_flags (dialog);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]