[Goodies-commits] r5869 - in xfce4-dict/trunk: . lib
Enrico Troeger
enrico at xfce.org
Wed Oct 29 23:39:36 CET 2008
Author: enrico
Date: 2008-10-29 22:39:36 +0000 (Wed, 29 Oct 2008)
New Revision: 5869
Added:
xfce4-dict/trunk/lib/searchentry.c
xfce4-dict/trunk/lib/searchentry.h
Modified:
xfce4-dict/trunk/ChangeLog
xfce4-dict/trunk/lib/Makefile.am
xfce4-dict/trunk/lib/common.c
xfce4-dict/trunk/lib/common.h
xfce4-dict/trunk/lib/gui.c
Log:
Add searchentry.[c|h], a subclass of GtkComboBox to embed a SexyIconEntry.
Add a combo box around the search field in the main window to provide a history of previously searched words.
Modified: xfce4-dict/trunk/ChangeLog
===================================================================
--- xfce4-dict/trunk/ChangeLog 2008-10-29 22:39:32 UTC (rev 5868)
+++ xfce4-dict/trunk/ChangeLog 2008-10-29 22:39:36 UTC (rev 5869)
@@ -1,3 +1,11 @@
+2008-10-29 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+
+ * Always clear the spell check dictionary list in the prefs dialog,
+ even if an empty or invalid spell check command was given.
+ * Add a combo box around the search field in the main window
+ to provide a history of previously searched words.
+
+
2008-10-28 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Guess the default spell check dictionary based on the user's
Modified: xfce4-dict/trunk/lib/Makefile.am
===================================================================
--- xfce4-dict/trunk/lib/Makefile.am 2008-10-29 22:39:32 UTC (rev 5868)
+++ xfce4-dict/trunk/lib/Makefile.am 2008-10-29 22:39:36 UTC (rev 5869)
@@ -15,6 +15,8 @@
prefs.h \
sexy-icon-entry.c \
sexy-icon-entry.h \
+ searchentry.c \
+ searchentry.h \
spell.c \
spell.h \
wraplabel.c \
Modified: xfce4-dict/trunk/lib/common.c
===================================================================
--- xfce4-dict/trunk/lib/common.c 2008-10-29 22:39:32 UTC (rev 5868)
+++ xfce4-dict/trunk/lib/common.c 2008-10-29 22:39:36 UTC (rev 5869)
@@ -41,6 +41,7 @@
#include "spell.h"
#include "dictd.h"
#include "gui.h"
+#include "searchentry.h"
@@ -222,6 +223,7 @@
}
/* remove leading and trailing spaces */
g_strstrip(dd->searched_word);
+ xfd_search_entry_prepend_text(XFD_SEARCH_ENTRY(dd->main_combo), dd->searched_word);
dict_gui_clear_text_buffer(dd);
Modified: xfce4-dict/trunk/lib/common.h
===================================================================
--- xfce4-dict/trunk/lib/common.h 2008-10-29 22:39:32 UTC (rev 5868)
+++ xfce4-dict/trunk/lib/common.h 2008-10-29 22:39:36 UTC (rev 5869)
@@ -91,6 +91,7 @@
GtkWidget *close_button;
GtkWidget *close_menu_item;
GtkWidget *pref_menu_item;
+ GtkWidget *main_combo;
GtkWidget *main_entry;
GtkWidget *panel_entry;
GtkWidget *main_textview;
Modified: xfce4-dict/trunk/lib/gui.c
===================================================================
--- xfce4-dict/trunk/lib/gui.c 2008-10-29 22:39:32 UTC (rev 5868)
+++ xfce4-dict/trunk/lib/gui.c 2008-10-29 22:39:36 UTC (rev 5869)
@@ -33,6 +33,7 @@
#include "common.h"
#include "gui.h"
#include "sexy-icon-entry.h"
+#include "searchentry.h"
#include "inline-icon.h"
@@ -268,6 +269,16 @@
}
+static void combo_changed_cb(GtkComboBox *combo, DictData *dd)
+{
+ gchar *text = gtk_combo_box_get_active_text(combo);
+
+ dict_search_word(dd, text);
+
+ g_free(text);
+}
+
+
static void entry_changed_cb(GtkEditable *editable, DictData *dd)
{
entry_is_dirty = TRUE;
@@ -477,14 +488,16 @@
gtk_widget_show(label_box);
gtk_box_pack_start(GTK_BOX(entry_box), label_box, TRUE, TRUE, 0);
- dd->main_entry = sexy_icon_entry_new_full("gtk-find", "gtk-clear");
- gtk_entry_set_text(GTK_ENTRY(dd->main_entry), _("Search term"));
- gtk_widget_show(dd->main_entry);
- 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);
+ dd->main_combo = xfd_search_entry_new(_("Search term"));
+ gtk_widget_show(dd->main_combo);
+ gtk_box_pack_start(GTK_BOX(label_box), dd->main_combo, TRUE, TRUE, 0);
+ g_signal_connect(dd->main_combo, "active-changed", G_CALLBACK(combo_changed_cb), dd);
+
+ dd->main_entry = gtk_bin_get_child(GTK_BIN(dd->main_combo));
+ g_signal_connect(dd->main_entry, "changed", G_CALLBACK(entry_changed_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);
+ g_signal_connect(dd->main_entry, "button-press-event", G_CALLBACK(entry_button_press_cb), dd);
update_search_button(dd, entry_box);
Added: xfce4-dict/trunk/lib/searchentry.c
===================================================================
--- xfce4-dict/trunk/lib/searchentry.c (rev 0)
+++ xfce4-dict/trunk/lib/searchentry.c 2008-10-29 22:39:36 UTC (rev 5869)
@@ -0,0 +1,174 @@
+/* $Id$
+ *
+ * Copyright 2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+ *
+ * This program 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.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+/* Subclass of a GtkComboBoxEntry which embeds a SexyIconEntry instead of
+ * a plain GtkEntry. */
+
+
+#include <gtk/gtk.h>
+#include <string.h>
+#include "searchentry.h"
+#include "sexy-icon-entry.h"
+
+
+static void xfd_search_entry_class_init (XfdSearchEntryClass *klass);
+static void xfd_search_entry_init (XfdSearchEntry *self);
+
+
+enum
+{
+ ACTIVE_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+
+GType xfd_search_entry_get_type(void)
+{
+ static GType self_type = 0;
+ if (! self_type)
+ {
+ static const GTypeInfo self_info =
+ {
+ sizeof(XfdSearchEntryClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc)xfd_search_entry_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof(XfdSearchEntry),
+ 0,
+ (GInstanceInitFunc)xfd_search_entry_init,
+ NULL /* value_table */
+ };
+
+ self_type = g_type_register_static(GTK_TYPE_COMBO_BOX_ENTRY, "XfdSearchEntry", &self_info, 0);
+ }
+
+ return self_type;
+}
+
+
+static void xfd_search_entry_class_init(XfdSearchEntryClass *klass)
+{
+ signals[ACTIVE_CHANGED] = g_signal_new("active-changed",
+ G_TYPE_FROM_CLASS (klass),
+ (GSignalFlags) (G_SIGNAL_RUN_LAST),
+ 0,
+ 0,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+
+static void combo_changed_cb(GtkComboBox *combo_box, gpointer data)
+{
+ GtkTreeIter iter;
+
+ if (gtk_combo_box_get_active_iter(combo_box, &iter))
+ {
+ g_signal_emit(XFD_SEARCH_ENTRY(combo_box), signals[ACTIVE_CHANGED], 0);
+ }
+}
+
+
+static void xfd_search_entry_init(XfdSearchEntry *self)
+{
+ GtkWidget *entry;
+ GtkCellRenderer *text_renderer;
+
+ /* we want the widget to have appears-as-list applied
+ * (code and idea stolen from Midori, thanks Christian) */
+ gtk_rc_parse_string("style \"xfd-search-entry-style\" {\n"
+ " GtkComboBox::appears-as-list = 1\n }\n"
+ "widget_class \"*XfdSearchEntry\" "
+ "style \"xfd-search-entry-style\"\n");
+
+ entry = sexy_icon_entry_new_full("gtk-find", "gtk-clear");
+
+ gtk_widget_show(entry);
+ gtk_container_add(GTK_CONTAINER(self), entry);
+
+ text_renderer = gtk_cell_renderer_text_new();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(self), text_renderer, TRUE);
+
+ gtk_combo_box_set_active(GTK_COMBO_BOX(self), -1);
+
+ g_signal_connect(self, "changed", G_CALLBACK(combo_changed_cb), NULL);
+}
+
+
+GtkWidget *xfd_search_entry_new(const gchar *text)
+{
+ GtkWidget *widget;
+ GtkListStore *store;
+
+ store = gtk_list_store_new(1, G_TYPE_STRING);
+
+ widget = g_object_new(XFD_SEARCH_ENTRY_TYPE, "model", store, "text-column", 0, NULL);
+
+ gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(widget))), text);
+
+ g_object_unref(store);
+
+ return widget;
+}
+
+
+void xfd_search_entry_prepend_text(XfdSearchEntry *search_entry, const gchar *text)
+{
+ GtkTreeIter iter;
+ GtkListStore *store;
+ GtkTreeModel *model;
+ gint i, len;
+ gchar *str;
+
+ g_return_if_fail(GTK_IS_COMBO_BOX(search_entry));
+ g_return_if_fail(text != NULL);
+
+ model = gtk_combo_box_get_model(GTK_COMBO_BOX(search_entry));
+ store = GTK_LIST_STORE(model);
+
+ /* check whether 'text' is already in the model */
+ len = gtk_tree_model_iter_n_children(model, NULL);
+ for (i = 0; i < len; i++)
+ {
+ if (gtk_tree_model_iter_nth_child(model, &iter, NULL, i))
+ {
+ gtk_tree_model_get(model, &iter, 0, &str, -1);
+ if (str != NULL && strcmp(str, text) == 0)
+ {
+ /* if we found 'text' in the model, move it to the top of the list and return */
+ gtk_list_store_move_after(store, &iter, NULL);
+
+ g_free(str);
+ return;
+ }
+ g_free(str);
+ }
+ }
+
+ /* add 'text' to the model/store */
+ gtk_list_store_prepend(store, &iter);
+ gtk_list_store_set(store, &iter, 0, text, -1);
+}
+
Added: xfce4-dict/trunk/lib/searchentry.h
===================================================================
--- xfce4-dict/trunk/lib/searchentry.h (rev 0)
+++ xfce4-dict/trunk/lib/searchentry.h 2008-10-29 22:39:36 UTC (rev 5869)
@@ -0,0 +1,56 @@
+/* $Id$
+ *
+ * Copyright 2006-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+ *
+ * This program 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.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+
+#ifndef __SEARCHENTRY_H__
+#define __SEARCHENTRY_H__
+
+G_BEGIN_DECLS
+
+#define XFD_SEARCH_ENTRY_TYPE (xfd_search_entry_get_type())
+#define XFD_SEARCH_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
+ XFD_SEARCH_ENTRY_TYPE, XfdSearchEntry))
+#define XFD_SEARCH_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),\
+ XFD_SEARCH_ENTRY_TYPE, XfdSearchEntryClass))
+#define IS_XFD_SEARCH_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),\
+ XFD_SEARCH_ENTRY_TYPE))
+#define IS_XFD_SEARCH_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),\
+ XFD_SEARCH_ENTRY_TYPE))
+
+typedef struct _XfdSearchEntry XfdSearchEntry;
+typedef struct _XfdSearchEntryClass XfdSearchEntryClass;
+
+struct _XfdSearchEntry
+{
+ GtkComboBoxEntry parent;
+};
+
+struct _XfdSearchEntryClass
+{
+ GtkComboBoxEntryClass parent_class;
+};
+
+GType xfd_search_entry_get_type (void);
+GtkWidget* xfd_search_entry_new (const gchar *text);
+void xfd_search_entry_prepend_text (XfdSearchEntry *search_entry, const gchar *text);
+
+G_END_DECLS
+
+#endif /* __SEARCHENTRY_H__ */
More information about the Goodies-commits
mailing list