[anjuta/git-shell] libanjuta: Don't depend on GtkEntryBuffer to catch AnjutaEntry changes.
- From: James Liggett <jrliggett src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/git-shell] libanjuta: Don't depend on GtkEntryBuffer to catch AnjutaEntry changes.
- Date: Sun, 24 Oct 2010 07:25:44 +0000 (UTC)
commit 87cdd1a0e01896e3e9f82ae0dcae3ddcb409b26f
Author: James Liggett <jrliggett cox net>
Date: Sun Oct 24 00:18:35 2010 -0700
libanjuta: Don't depend on GtkEntryBuffer to catch AnjutaEntry changes.
We can't be guaranteed that the buffer will stay the same throughout the life
of the entry, so we have to use a semi-override of gtk_entry_set_text instead.
This commit introduces a new method, anjuta_entry_set_text that will set the
help mode appropriately, instead of relying on the buffer to notify of changes.
libanjuta/anjuta-entry.c | 95 +++++++++-------------------------------------
libanjuta/anjuta-entry.h | 1 +
2 files changed, 19 insertions(+), 77 deletions(-)
---
diff --git a/libanjuta/anjuta-entry.c b/libanjuta/anjuta-entry.c
index 8b7ba43..9ee493d 100644
--- a/libanjuta/anjuta-entry.c
+++ b/libanjuta/anjuta-entry.c
@@ -53,9 +53,6 @@ struct _AnjutaEntryPriv
G_DEFINE_TYPE (AnjutaEntry, anjuta_entry, GTK_TYPE_ENTRY);
-/* The buffer inserted/deleted handlers must be blocked before calling
- * this function. Make the calling function do the blocking so we don't have
- * to block/unblock more than once. */
static void
anjuta_entry_set_mode (AnjutaEntry *self, AnjutaEntryMode mode)
{
@@ -92,52 +89,6 @@ anjuta_entry_set_mode (AnjutaEntry *self, AnjutaEntryMode mode)
break;
}
}
-
-static void
-on_buffer_inserted_text (GtkEntryBuffer *buffer, guint position, gchar *chars,
- guint n_chars, AnjutaEntry *self)
-{
- if (n_chars > 0)
- {
- if (self->priv->showing_help_text)
- anjuta_entry_set_mode (self, ANJUTA_ENTRY_NORMAL);
- }
-}
-
-static void
-on_buffer_deleted_text (GtkEntryBuffer *buffer, guint position, guint n_chars,
- AnjutaEntry *self)
-{
- const gchar *text;
-
- text = gtk_entry_get_text (GTK_ENTRY (self));
-
- if (text[0] == '\0')
- anjuta_entry_set_mode (self, ANJUTA_ENTRY_HELP);
-}
-
-
-static void
-anjuta_entry_block_change_handlers (AnjutaEntry *self)
-{
- GtkEntryBuffer *buffer;
-
- buffer = gtk_entry_get_buffer (GTK_ENTRY (self));
-
- g_signal_handlers_block_by_func (buffer, on_buffer_inserted_text, self);
- g_signal_handlers_block_by_func (buffer, on_buffer_deleted_text, self);
-}
-
-static void
-anjuta_entry_unbloock_change_handlers (AnjutaEntry *self)
-{
- GtkEntryBuffer *buffer;
-
- buffer = gtk_entry_get_buffer (GTK_ENTRY (self));
-
- g_signal_handlers_unblock_by_func (buffer, on_buffer_inserted_text, self);
- g_signal_handlers_unblock_by_func (buffer, on_buffer_deleted_text, self);
-}
/* It's probably terrible practice for a subclass to be listening to the
* parent' class's signals, but for some reason the icon release signal
@@ -151,34 +102,19 @@ anjuta_entry_icon_release (GtkEntry *entry, GtkEntryIconPosition icon_pos,
self = ANJUTA_ENTRY (entry);
if (icon_pos == GTK_ENTRY_ICON_SECONDARY)
- {
- anjuta_entry_block_change_handlers (self);
gtk_entry_set_text (entry, "");
- anjuta_entry_unbloock_change_handlers (self);
- }
}
static void
anjuta_entry_init (AnjutaEntry *self)
{
- GtkEntryBuffer *buffer;
-
self->priv = g_new0 (AnjutaEntryPriv, 1);
- buffer = gtk_entry_get_buffer (GTK_ENTRY (self));
gtk_entry_set_icon_from_stock (GTK_ENTRY (self), GTK_ENTRY_ICON_SECONDARY,
GTK_STOCK_CLEAR);
gtk_entry_set_icon_activatable (GTK_ENTRY (self), GTK_ENTRY_ICON_SECONDARY,
TRUE);
- g_signal_connect (G_OBJECT (buffer), "inserted-text",
- G_CALLBACK (on_buffer_inserted_text),
- self);
-
- g_signal_connect (G_OBJECT (buffer), "deleted-text",
- G_CALLBACK (on_buffer_deleted_text),
- self);
-
g_signal_connect (G_OBJECT (self), "icon-release",
G_CALLBACK (anjuta_entry_icon_release),
NULL);
@@ -221,12 +157,8 @@ anjuta_entry_set_property (GObject *object, guint prop_id, const GValue *value,
{
if (self->priv->help_text)
{
- anjuta_entry_block_change_handlers (self);
-
gtk_entry_set_text (GTK_ENTRY (self),
self->priv->help_text);
-
- anjuta_entry_unbloock_change_handlers (self);
}
}
break;
@@ -265,15 +197,8 @@ anjuta_entry_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
self = ANJUTA_ENTRY (widget);
if (self->priv->showing_help_text)
- {
- anjuta_entry_block_change_handlers (self);
anjuta_entry_set_mode (self, ANJUTA_ENTRY_NORMAL);
- /* Don't unblock the change handlers right away so the user can
- * enter something. Unblock the change handlers again when the
- * entry loses focus. */
- }
-
return GTK_WIDGET_CLASS (anjuta_entry_parent_class)->focus_in_event (widget, event);
}
@@ -289,8 +214,6 @@ anjuta_entry_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
if (text == NULL || text[0] == '\0')
anjuta_entry_set_mode (self, ANJUTA_ENTRY_HELP);
- anjuta_entry_unbloock_change_handlers (self);
-
return GTK_WIDGET_CLASS (anjuta_entry_parent_class)->focus_out_event (widget, event);
}
@@ -362,6 +285,24 @@ anjuta_entry_dup_text (AnjutaEntry *self)
}
/**
+ * anjuta_entry_set_text:
+ * @self: An AnjutaEntry
+ * @text: The new text
+ *
+ * Sets the text on the entry, showing the help text if the text is empty.
+ */
+void
+anjuta_entry_set_text (AnjutaEntry *self, const gchar *text)
+{
+ if (text != NULL && text[0] != '\0')
+ anjuta_entry_set_mode (self, ANJUTA_ENTRY_NORMAL);
+ else
+ anjuta_entry_set_mode (self, ANJUTA_ENTRY_HELP);
+
+ gtk_entry_set_text (GTK_ENTRY (self), text);
+}
+
+/**
* anjuta_entry_is_showing_help_text:
* @self: An AnjutaEntry
*
diff --git a/libanjuta/anjuta-entry.h b/libanjuta/anjuta-entry.h
index 61fed90..199fc30 100644
--- a/libanjuta/anjuta-entry.h
+++ b/libanjuta/anjuta-entry.h
@@ -53,6 +53,7 @@ GType anjuta_entry_get_type (void) G_GNUC_CONST;
GtkWidget *anjuta_entry_new (void);
const gchar *anjuta_entry_get_text (AnjutaEntry *self);
gchar *anjuta_entry_dup_text (AnjutaEntry *self);
+void anjuta_entry_set_text (AnjutaEntry *self, const gchar *text);
gboolean anjuta_entry_is_showing_help_text (AnjutaEntry *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]