Prune whitespace from the end of the selection before inserting it into

the lookuplet text widget.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@94 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-03-10 20:30:58 +00:00
parent ea9f65f24f
commit d7ad411c11
+23 -4
View File
@@ -1,10 +1,12 @@
/** /**
* $Id: querybox.c,v 1.3 2001/02/24 02:48:22 mdb Exp $ * $Id: querybox.c,v 1.4 2001/03/10 20:30:58 mdb Exp $
*/ */
#include <config.h> #include <config.h>
#include <glib.h> #include <glib.h>
#include <gnome.h> #include <gnome.h>
#include <ctype.h>
#include <string.h>
#include "binding.h" #include "binding.h"
#include "launcher.h" #include "launcher.h"
@@ -18,11 +20,28 @@ static void
selection_received (GtkWidget* widget, GtkSelectionData* selection_data, selection_received (GtkWidget* widget, GtkSelectionData* selection_data,
gpointer data) gpointer data)
{ {
int length = selection_data->length;
/* make sure some selection was provided */ /* make sure some selection was provided */
if (selection_data->length > 0) { if (length > 0) {
gchar* start, *end;
gchar* search_text =
gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
/* prune spaces from the end of the text */
for (start = search_text; isspace(*start); start++);
for (end = search_text + length - 1; isspace(*end); end--);
end++; *end = '\0';
/* only set the new text if we changed anything */
if (length != strlen(start)) {
length = strlen(start);
gtk_entry_set_text(GTK_ENTRY(widget), start);
}
g_free(search_text);
/* select the text in the entry so that it can be easily replaced */ /* select the text in the entry so that it can be easily replaced */
gtk_editable_select_region(GTK_EDITABLE(_query), 0, gtk_editable_select_region(GTK_EDITABLE(_query), 0, length);
selection_data->length);
} }
} }