Kaydet (Commit) a20ee7d8 authored tarafından Enrico Tröger's avatar Enrico Tröger

Add a clear icon to the toolbar search and goto text fields (will be available with GTK >= 2.16).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3516 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst ee35d4b1
......@@ -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>
......
......@@ -26,6 +26,7 @@
#include "geany.h"
#include "support.h"
#include "ui_utils.h"
#include "geanyentryaction.h"
#include <ctype.h>
......@@ -88,7 +89,10 @@ static GtkWidget *geany_entry_action_create_tool_item(GtkAction *action)
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);
......
......@@ -1178,6 +1178,34 @@ ui_image_menu_item_new(const gchar *stock_id, const gchar *label)
}
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));
......
......@@ -185,6 +185,8 @@ GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name);
void ui_widget_set_sensitive(GtkWidget *widget, gboolean set);
void ui_entry_add_clear_icon(GtkWidget *entry);
/* End of 'generic' functions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment