SF.net SVN: geany:[3516] trunk
eht16 at users.sourceforge.net
eht16 at xxxxx
Tue Jan 27 19:31:45 UTC 2009
Revision: 3516
http://geany.svn.sourceforge.net/geany/?rev=3516&view=rev
Author: eht16
Date: 2009-01-27 19:31:45 +0000 (Tue, 27 Jan 2009)
Log Message:
-----------
Add a clear icon to the toolbar search and goto text fields (will be available with GTK >= 2.16).
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/geanyentryaction.c
trunk/src/ui_utils.c
trunk/src/ui_utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/ChangeLog 2009-01-27 19:31:45 UTC (rev 3516)
@@ -2,6 +2,9 @@
* src/document.c:
Fix legacy file monitoring since I broke once more.
+ * src/geanyentryaction.c, src/ui_utils.c, src/ui_utils.h:
+ Add a clear icon to the toolbar search and goto text fields
+ (will be available with GTK >= 2.16).
2009-01-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/geanyentryaction.c
===================================================================
--- trunk/src/geanyentryaction.c 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/src/geanyentryaction.c 2009-01-27 19:31:45 UTC (rev 3516)
@@ -26,6 +26,7 @@
#include "geany.h"
#include "support.h"
+#include "ui_utils.h"
#include "geanyentryaction.h"
#include <ctype.h>
@@ -88,7 +89,10 @@
priv->entry = gtk_entry_new();
if (priv->numeric)
- gtk_entry_set_width_chars(GTK_ENTRY(priv->entry), 8);
+ gtk_entry_set_width_chars(GTK_ENTRY(priv->entry), 9);
+
+ ui_entry_add_clear_icon(priv->entry);
+
gtk_widget_show(priv->entry);
toolitem = g_object_new(GTK_TYPE_TOOL_ITEM, NULL);
Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/src/ui_utils.c 2009-01-27 19:31:45 UTC (rev 3516)
@@ -1178,6 +1178,34 @@
}
+static void entry_clear_icon_press_cb(GtkEntry *entry, gint icon_pos, GdkEvent *event, gpointer data)
+{
+ if (event->button.button == 1 && icon_pos == 1)
+ {
+ gtk_entry_set_text(entry, "");
+ }
+}
+
+
+/** Convenience function to add a small clear icon to the right end of the passed @a entry.
+ * A callback to clear the contents of the GtkEntry is automatically added.
+ *
+ * This feature is only available with GTK 2.16 but implemented as a runtime check,
+ * so it is safe to just use this function, if the code is ran with older versions,
+ * nothing happens. If ran with GTK 2.16 or newer, the icon is displayed.
+ *
+ * @param entry The GtkEntry object to which the icon should be attached.
+ */
+void ui_entry_add_clear_icon(GtkWidget *entry)
+{
+ if (gtk_check_version(2, 15, 2) == NULL)
+ {
+ g_object_set(entry, "secondary-icon-stock", "gtk-clear", NULL);
+ g_signal_connect(entry, "icon-press", G_CALLBACK(entry_clear_icon_press_cb), NULL);
+ }
+}
+
+
static void add_to_size_group(GtkWidget *widget, gpointer size_group)
{
g_return_if_fail(GTK_IS_SIZE_GROUP(size_group));
Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h 2009-01-27 19:10:12 UTC (rev 3515)
+++ trunk/src/ui_utils.h 2009-01-27 19:31:45 UTC (rev 3516)
@@ -185,6 +185,8 @@
void ui_widget_set_sensitive(GtkWidget *widget, gboolean set);
+void ui_entry_add_clear_icon(GtkWidget *entry);
+
/* End of 'generic' functions */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list