[frogr] Fixed bug in tags autocompletion when special characters are present
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Fixed bug in tags autocompletion when special characters are present
- Date: Sat, 22 Jan 2011 11:21:12 +0000 (UTC)
commit 6c3719cc2bf5754bd423d405813512bdac6c7d13
Author: Mario Sanchez Prada <msanchez igalia com>
Date: Sat Jan 22 12:20:03 2011 +0100
Fixed bug in tags autocompletion when special characters are present
src/frogr-add-tags-dialog.c | 19 +++++++++++--------
src/frogr-details-dialog.c | 19 +++++++++++--------
2 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/src/frogr-add-tags-dialog.c b/src/frogr-add-tags-dialog.c
index f04d9a6..b4b4fb6 100644
--- a/src/frogr-add-tags-dialog.c
+++ b/src/frogr-add-tags-dialog.c
@@ -95,7 +95,8 @@ _tag_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
{
FrogrAddTagsDialog *self = NULL;
FrogrAddTagsDialogPrivate *priv = NULL;
- gchar *stripped_key = NULL;
+ const gchar *entry_text = NULL;
+ gchar *stripped_entry_text = NULL;
gchar *basetext = NULL;
gchar *tag = NULL;
gchar *lc_basetext = NULL;
@@ -113,16 +114,18 @@ _tag_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
/* Do nothing if the cursor is not in the last position */
cursor_pos = gtk_editable_get_position (GTK_EDITABLE (priv->entry));
- if (cursor_pos < g_utf8_strlen (key, -1))
+ if (cursor_pos < gtk_entry_get_text_length (GTK_ENTRY (priv->entry)))
return FALSE;
/* Look for the last token in 'key' */
- stripped_key = g_strstrip (g_strndup (key, cursor_pos));
- basetext = g_strrstr (stripped_key, " ");
+ entry_text = gtk_entry_get_text (GTK_ENTRY (priv->entry));
+ stripped_entry_text = gtk_editable_get_chars (GTK_EDITABLE (priv->entry), 0, cursor_pos);
+ stripped_entry_text = g_strstrip (stripped_entry_text);
+ basetext = g_strrstr (stripped_entry_text, " ");
if (basetext)
basetext++;
else
- basetext = stripped_key;
+ basetext = stripped_entry_text;
/* Downcase everything and compare */
lc_basetext = g_utf8_strdown (basetext, -1);
@@ -130,7 +133,7 @@ _tag_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
if (g_str_has_prefix (lc_tag, lc_basetext))
matches = TRUE;
- g_free (stripped_key);
+ g_free (stripped_entry_text);
g_free (tag);
g_free (lc_basetext);
g_free (lc_tag);
@@ -163,10 +166,10 @@ _completion_match_selected_cb (GtkEntryCompletion *widget, GtkTreeModel *model,
else
matching_text = entry_text;
- entry_text_len = g_utf8_strlen (entry_text, -1);
+ entry_text_len = gtk_entry_get_text_length (GTK_ENTRY (priv->entry));
matching_text_len = g_utf8_strlen (matching_text, -1);
- base_text = g_strndup (entry_text, entry_text_len - matching_text_len);
+ base_text = gtk_editable_get_chars (GTK_EDITABLE (priv->entry), 0, entry_text_len - matching_text_len);
new_text = g_strdup_printf ("%s%s ", base_text, tag);
gtk_entry_set_text (GTK_ENTRY (priv->entry), new_text);
diff --git a/src/frogr-details-dialog.c b/src/frogr-details-dialog.c
index 180e5d8..e833a2b 100644
--- a/src/frogr-details-dialog.c
+++ b/src/frogr-details-dialog.c
@@ -402,7 +402,8 @@ _tag_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
{
FrogrDetailsDialog *self = NULL;
FrogrDetailsDialogPrivate *priv = NULL;
- gchar *stripped_key = NULL;
+ const gchar *entry_text = NULL;
+ gchar *stripped_entry_text = NULL;
gchar *basetext = NULL;
gchar *tag = NULL;
gchar *lc_basetext = NULL;
@@ -420,16 +421,18 @@ _tag_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
/* Do nothing if the cursor is not in the last position */
cursor_pos = gtk_editable_get_position (GTK_EDITABLE (priv->tags_entry));
- if (cursor_pos < g_utf8_strlen (key, -1))
+ if (cursor_pos < gtk_entry_get_text_length (GTK_ENTRY (priv->tags_entry)))
return FALSE;
/* Look for the last token in 'key' */
- stripped_key = g_strstrip (g_strndup (key, cursor_pos));
- basetext = g_strrstr (stripped_key, " ");
+ entry_text = gtk_entry_get_text (GTK_ENTRY (priv->tags_entry));
+ stripped_entry_text = gtk_editable_get_chars (GTK_EDITABLE (priv->tags_entry), 0, cursor_pos);
+ stripped_entry_text = g_strstrip (stripped_entry_text);
+ basetext = g_strrstr (stripped_entry_text, " ");
if (basetext)
basetext++;
else
- basetext = stripped_key;
+ basetext = stripped_entry_text;
/* Downcase everything and compare */
lc_basetext = g_utf8_strdown (basetext, -1);
@@ -437,7 +440,7 @@ _tag_list_completion_func (GtkEntryCompletion *completion, const gchar *key,
if (g_str_has_prefix (lc_tag, lc_basetext))
matches = TRUE;
- g_free (stripped_key);
+ g_free (stripped_entry_text);
g_free (tag);
g_free (lc_basetext);
g_free (lc_tag);
@@ -470,10 +473,10 @@ _completion_match_selected_cb (GtkEntryCompletion *widget, GtkTreeModel *model,
else
matching_text = entry_text;
- entry_text_len = g_utf8_strlen (entry_text, -1);
+ entry_text_len = gtk_entry_get_text_length (GTK_ENTRY (priv->tags_entry));
matching_text_len = g_utf8_strlen (matching_text, -1);
- base_text = g_strndup (entry_text, entry_text_len - matching_text_len);
+ base_text = gtk_editable_get_chars (GTK_EDITABLE (priv->tags_entry), 0, entry_text_len - matching_text_len);
new_text = g_strdup_printf ("%s%s ", base_text, tag);
gtk_entry_set_text (GTK_ENTRY (priv->tags_entry), new_text);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]