Consider focus when toggling clear button
Fixes: https://bugs.launchpad.net/midori/+bug/934083
This commit is contained in:
parent
d2fe0791e1
commit
bbbfa0d677
3 changed files with 49 additions and 8 deletions
|
@ -27,9 +27,9 @@ sokoke_on_entry_focus_in_event (GtkEntry* entry,
|
||||||
g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
|
g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
|
||||||
if (has_default)
|
if (has_default)
|
||||||
{
|
{
|
||||||
gtk_entry_set_text (entry, "");
|
|
||||||
g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
|
g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
|
||||||
GINT_TO_POINTER (0));
|
GINT_TO_POINTER (0));
|
||||||
|
gtk_entry_set_text (entry, "");
|
||||||
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
|
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
|
||||||
PANGO_STYLE_NORMAL);
|
PANGO_STYLE_NORMAL);
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ sokoke_on_entry_focus_out_event (GtkEntry* entry,
|
||||||
{
|
{
|
||||||
const gchar* default_text = (const gchar*)g_object_get_data (
|
const gchar* default_text = (const gchar*)g_object_get_data (
|
||||||
G_OBJECT (entry), "sokoke_default_text");
|
G_OBJECT (entry), "sokoke_default_text");
|
||||||
gtk_entry_set_text (entry, default_text);
|
|
||||||
g_object_set_data (G_OBJECT (entry),
|
g_object_set_data (G_OBJECT (entry),
|
||||||
"sokoke_has_default", GINT_TO_POINTER (1));
|
"sokoke_has_default", GINT_TO_POINTER (1));
|
||||||
|
gtk_entry_set_text (entry, default_text);
|
||||||
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
|
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
|
||||||
PANGO_STYLE_ITALIC);
|
PANGO_STYLE_ITALIC);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,9 @@ gtk_entry_set_placeholder_text (GtkEntry* entry,
|
||||||
/* Note: The default text initially overwrites any previous text */
|
/* Note: The default text initially overwrites any previous text */
|
||||||
gchar* old_value = g_object_get_data (G_OBJECT (entry),
|
gchar* old_value = g_object_get_data (G_OBJECT (entry),
|
||||||
"sokoke_default_text");
|
"sokoke_default_text");
|
||||||
|
g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
|
||||||
|
(gpointer)default_text);
|
||||||
|
|
||||||
if (!old_value)
|
if (!old_value)
|
||||||
{
|
{
|
||||||
g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
|
g_object_set_data (G_OBJECT (entry), "sokoke_has_default",
|
||||||
|
@ -98,8 +101,12 @@ gtk_entry_set_placeholder_text (GtkEntry* entry,
|
||||||
PANGO_STYLE_ITALIC);
|
PANGO_STYLE_ITALIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
|
}
|
||||||
(gpointer)default_text);
|
|
||||||
|
const gchar*
|
||||||
|
gtk_entry_get_placeholder_text (GtkEntry* entry)
|
||||||
|
{
|
||||||
|
return g_object_get_data (G_OBJECT (entry), "sokoke_default_text");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -89,8 +89,10 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
#if !GTK_CHECK_VERSION (3, 2, 0) && defined (HAVE_HILDON_2_2)
|
#if !GTK_CHECK_VERSION (3, 2, 0) && defined (HAVE_HILDON_2_2)
|
||||||
#define gtk_entry_set_placeholder_text hildon_gtk_entry_set_placeholder_text
|
#define gtk_entry_set_placeholder_text hildon_gtk_entry_set_placeholder_text
|
||||||
|
#define gtk_entry_get_placeholder_text hildon_gtk_entry_get_placeholder_text
|
||||||
#elif !GTK_CHECK_VERSION (3, 2, 0)
|
#elif !GTK_CHECK_VERSION (3, 2, 0)
|
||||||
#define gtk_entry_set_placeholder_text sokoke_entry_set_default_text
|
void gtk_entry_set_placeholder_text (GtkEntry* entry, const gchar* text);
|
||||||
|
const gchar* gtk_entry_get_placeholder_text (GtkEntry* entry);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !GTK_CHECK_VERSION(2, 12, 0)
|
#if !GTK_CHECK_VERSION(2, 12, 0)
|
||||||
|
|
|
@ -1731,18 +1731,40 @@ midori_download_prepare_tooltip_text (WebKitDownload* download)
|
||||||
return g_string_free (tooltip, FALSE);
|
return g_string_free (tooltip, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sokoke_entry_has_placeholder_text (GtkEntry* entry)
|
||||||
|
{
|
||||||
|
const gchar* text = gtk_entry_get_text (entry);
|
||||||
|
const gchar* hint = gtk_entry_get_placeholder_text (entry);
|
||||||
|
if (!gtk_widget_has_focus (GTK_WIDGET (entry))
|
||||||
|
&& hint != NULL
|
||||||
|
&& (text == NULL || !strcmp (text, hint)))
|
||||||
|
return TRUE;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sokoke_entry_changed_cb (GtkEditable* editable,
|
sokoke_entry_changed_cb (GtkEditable* editable,
|
||||||
GtkEntry* entry)
|
GtkEntry* entry)
|
||||||
{
|
{
|
||||||
const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
|
const gchar* text = gtk_entry_get_text (entry);
|
||||||
gboolean visible = text && *text;
|
gboolean visible = text && *text
|
||||||
|
&& ! sokoke_entry_has_placeholder_text (entry);
|
||||||
gtk_icon_entry_set_icon_from_stock (
|
gtk_icon_entry_set_icon_from_stock (
|
||||||
GTK_ICON_ENTRY (entry),
|
GTK_ICON_ENTRY (entry),
|
||||||
GTK_ICON_ENTRY_SECONDARY,
|
GTK_ICON_ENTRY_SECONDARY,
|
||||||
visible ? GTK_STOCK_CLEAR : NULL);
|
visible ? GTK_STOCK_CLEAR : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sokoke_entry_focus_out_event_cb (GtkEditable* editable,
|
||||||
|
GdkEventFocus* event,
|
||||||
|
GtkEntry* entry)
|
||||||
|
{
|
||||||
|
sokoke_entry_changed_cb (editable, entry);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sokoke_entry_icon_released_cb (GtkEntry* entry,
|
sokoke_entry_icon_released_cb (GtkEntry* entry,
|
||||||
GtkIconEntryPosition icon_pos,
|
GtkIconEntryPosition icon_pos,
|
||||||
|
@ -1769,17 +1791,27 @@ sokoke_entry_set_clear_button_visible (GtkEntry* entry,
|
||||||
g_object_connect (entry,
|
g_object_connect (entry,
|
||||||
"signal::icon-release",
|
"signal::icon-release",
|
||||||
G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
|
G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
|
||||||
|
"signal::focus-in-event",
|
||||||
|
G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
|
||||||
|
"signal::focus-out-event",
|
||||||
|
G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
|
||||||
"signal::changed",
|
"signal::changed",
|
||||||
G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
|
G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
|
||||||
g_signal_emit_by_name (G_OBJECT (entry), "changed");
|
sokoke_entry_changed_cb ((GtkEditable*)entry, entry);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_object_disconnect (entry,
|
g_object_disconnect (entry,
|
||||||
"any_signal::icon-release",
|
"any_signal::icon-release",
|
||||||
G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
|
G_CALLBACK (sokoke_entry_icon_released_cb), NULL,
|
||||||
|
"any_signal::focus-in-event",
|
||||||
|
G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
|
||||||
|
"any_signal::focus-out-event",
|
||||||
|
G_CALLBACK (sokoke_entry_focus_out_event_cb), entry,
|
||||||
"any_signal::changed",
|
"any_signal::changed",
|
||||||
G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
|
G_CALLBACK (sokoke_entry_changed_cb), entry, NULL);
|
||||||
|
gtk_icon_entry_set_icon_from_stock (
|
||||||
|
GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_SECONDARY, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue