From 9f80d93895c869f3a767611833bafe94a74ee29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=83=C2=B6ger?= <enrico@xfce.org> Date: Fri, 24 Oct 2008 17:30:22 +0000 Subject: [PATCH] Fix auto clearing issues introduced in last commit. (Old svn revision: 5792) --- lib/gui.c | 14 +++++-- panel-plugin/xfce4-dict-plugin.c | 67 +++++++++++++++++--------------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/lib/gui.c b/lib/gui.c index 9edafd9..a3a20ed 100644 --- a/lib/gui.c +++ b/lib/gui.c @@ -40,6 +40,7 @@ static gboolean hovering_over_link = FALSE; static GdkCursor *hand_cursor = NULL; static GdkCursor *regular_cursor = NULL; +static gboolean entry_is_dirty = FALSE; /* all textview_* functions are from the gtk-demo app to get links in the textview working */ @@ -252,6 +253,12 @@ static void entry_icon_pressed_cb(SexyIconEntry *entry, gint icon_pos, gint butt } +static void entry_changed_cb(GtkEditable *editable, DictData *dd) +{ + entry_is_dirty = TRUE; +} + + static void entry_button_clicked_cb(GtkButton *button, DictData *dd) { entry_activate_cb(NULL, dd); @@ -261,11 +268,9 @@ static void entry_button_clicked_cb(GtkButton *button, DictData *dd) static gboolean entry_button_press_cb(GtkWidget *widget, GdkEventButton *event, DictData *dd) { - static gboolean ran = FALSE; - - if (! ran) + if (! entry_is_dirty) { - ran = TRUE; + entry_is_dirty = TRUE; if (event->button == 1) gtk_entry_set_text(GTK_ENTRY(widget), ""); } @@ -463,6 +468,7 @@ void dict_gui_create_main_window(DictData *dd) gtk_box_pack_start(GTK_BOX(label_box), dd->main_entry, TRUE, TRUE, 0); g_signal_connect(dd->main_entry, "button-press-event", G_CALLBACK(entry_button_press_cb), dd); g_signal_connect(dd->main_entry, "activate", G_CALLBACK(entry_activate_cb), dd); + g_signal_connect(dd->main_entry, "changed", G_CALLBACK(entry_changed_cb), dd); g_signal_connect(dd->main_entry, "icon_released", G_CALLBACK(entry_icon_pressed_cb), dd); update_search_button(dd, entry_box); diff --git a/panel-plugin/xfce4-dict-plugin.c b/panel-plugin/xfce4-dict-plugin.c index e4d7433..4daebfd 100644 --- a/panel-plugin/xfce4-dict-plugin.c +++ b/panel-plugin/xfce4-dict-plugin.c @@ -54,6 +54,8 @@ typedef struct } DictPanelData; +static gboolean entry_is_dirty = FALSE; + static GdkPixbuf *dict_plugin_load_and_scale(const guint8 *data, gint dstw, gint dsth) { GdkPixbuf *pb, *pb_scaled; @@ -262,29 +264,6 @@ static void dict_plugin_style_set(XfcePanelPlugin *plugin, gpointer unused, Dict } -static gboolean dict_plugin_panel_entry_buttonpress_cb(GtkWidget *entry, GdkEventButton *event, DictPanelData *dpd) -{ - GtkWidget *toplevel; - static gboolean ran = FALSE; - - if (! ran) - { - ran = TRUE; - if (event->button == 1) - gtk_entry_set_text(GTK_ENTRY(entry), ""); - } - - /* Determine toplevel parent widget */ - toplevel = gtk_widget_get_toplevel(entry); - - /* Grab entry focus if possible */ - if (event->button != 3 && toplevel && toplevel->window) - xfce_panel_plugin_focus_widget(dpd->plugin, entry); - - return FALSE; -} - - static void dict_plugin_write_rc_file(XfcePanelPlugin *plugin, DictPanelData *dpd) { dict_write_rc_file(dpd->dd); @@ -333,7 +312,7 @@ static void dict_plugin_properties_dialog(XfcePanelPlugin *plugin, DictPanelData } -static void dict_plugin_panel_entry_activate_cb(GtkEntry *entry, DictPanelData *dpd) +static void entry_activate_cb(GtkEntry *entry, DictPanelData *dpd) { const gchar *entered_text = gtk_entry_get_text(GTK_ENTRY(dpd->dd->panel_entry)); @@ -350,7 +329,7 @@ static void entry_icon_pressed_cb(SexyIconEntry *entry, gint pos, gint button, D if (pos == SEXY_ICON_ENTRY_PRIMARY) { - dict_plugin_panel_entry_activate_cb(NULL, dpd); + entry_activate_cb(NULL, dpd); gtk_widget_grab_focus(dpd->dd->main_entry); } else if (pos == SEXY_ICON_ENTRY_SECONDARY) @@ -363,6 +342,34 @@ static void entry_icon_pressed_cb(SexyIconEntry *entry, gint pos, gint button, D } +static gboolean entry_buttonpress_cb(GtkWidget *entry, GdkEventButton *event, DictPanelData *dpd) +{ + GtkWidget *toplevel; + + if (! entry_is_dirty) + { + entry_is_dirty = TRUE; + if (event->button == 1) + gtk_entry_set_text(GTK_ENTRY(entry), ""); + } + + /* Determine toplevel parent widget */ + toplevel = gtk_widget_get_toplevel(entry); + + /* Grab entry focus if possible */ + if (event->button != 3 && toplevel && toplevel->window) + xfce_panel_plugin_focus_widget(dpd->plugin, entry); + + return FALSE; +} + + +static void entry_changed_cb(GtkEditable *editable, DictData *dd) +{ + entry_is_dirty = TRUE; +} + + static void dict_plugin_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint info, guint ltime, DictPanelData *dpd) { @@ -428,12 +435,10 @@ static void dict_plugin_construct(XfcePanelPlugin *plugin) dpd->dd->panel_entry = sexy_icon_entry_new_full(NULL, "gtk-clear"); gtk_entry_set_width_chars(GTK_ENTRY(dpd->dd->panel_entry), 25); gtk_entry_set_text(GTK_ENTRY(dpd->dd->panel_entry), _("Search term")); - g_signal_connect(dpd->dd->panel_entry, "icon_released", - G_CALLBACK(entry_icon_pressed_cb), dpd); - g_signal_connect(dpd->dd->panel_entry, "activate", - G_CALLBACK(dict_plugin_panel_entry_activate_cb), dpd); - g_signal_connect(dpd->dd->panel_entry, "button-press-event", - G_CALLBACK(dict_plugin_panel_entry_buttonpress_cb), dpd); + g_signal_connect(dpd->dd->panel_entry, "icon_released", G_CALLBACK(entry_icon_pressed_cb), dpd); + g_signal_connect(dpd->dd->panel_entry, "activate", G_CALLBACK(entry_activate_cb), dpd); + g_signal_connect(dpd->dd->panel_entry, "button-press-event", G_CALLBACK(entry_buttonpress_cb), dpd); + g_signal_connect(dpd->dd->panel_entry, "changed", G_CALLBACK(entry_changed_cb), dpd); if (dpd->dd->show_panel_entry && xfce_panel_plugin_get_orientation(dpd->plugin) == GTK_ORIENTATION_HORIZONTAL) -- GitLab