[gimp] app: fix UI tag matching to always work case-insensitively
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: fix UI tag matching to always work case-insensitively
- Date: Sat, 5 May 2012 16:59:54 +0000 (UTC)
commit 30b4fe85105d80bfc67901711a6c54a0561d4a5d
Author: Michael Natterer <mitch gimp org>
Date: Sat May 5 18:58:04 2012 +0200
app: fix UI tag matching to always work case-insensitively
Add gimp_tag_has_prefix() and use it in GimpTagEntry when completing
patrially entered tag names, and fix two uses of strcmp() in
GimpTagPopup to use gimp_tag_compare_with_string().
app/core/gimptag.c | 38 +++++++++++++++++++++++++++++++++++++-
app/core/gimptag.h | 2 ++
app/widgets/gimptagentry.c | 18 ++++++++----------
app/widgets/gimptagpopup.c | 23 +++++++++--------------
4 files changed, 56 insertions(+), 25 deletions(-)
---
diff --git a/app/core/gimptag.c b/app/core/gimptag.c
index 8d0639a..2682169 100644
--- a/app/core/gimptag.c
+++ b/app/core/gimptag.c
@@ -246,7 +246,7 @@ gimp_tag_compare_func (const void *p1,
/**
* gimp_tag_compare_with_string:
* @tag: a #GimpTag object.
- * @tag_string: pointer to right-hand #GimpTag object.
+ * @tag_string: the string to compare to.
*
* Compares tag and a string according to tag comparison rules. Similar to
* gimp_tag_compare_func(), but can be used without creating temporary tag
@@ -277,6 +277,42 @@ gimp_tag_compare_with_string (GimpTag *tag,
}
/**
+ * gimp_tag_has_prefix:
+ * @tag: a #GimpTag object.
+ * @prefix_string: the prefix to compare to.
+ *
+ * Compares tag and a prefix according to tag comparison rules. Similar to
+ * gimp_tag_compare_with_string(), but does not work on the collate key
+ * because that can't be matched partially.
+ *
+ * Return value: wheher #tag starts with @prefix_string.
+ **/
+gboolean
+gimp_tag_has_prefix (GimpTag *tag,
+ const gchar *prefix_string)
+{
+ gchar *case_folded1;
+ gchar *case_folded2;
+ gboolean has_prefix;
+
+ g_return_val_if_fail (GIMP_IS_TAG (tag), FALSE);
+ g_return_val_if_fail (prefix_string != NULL, FALSE);
+
+ case_folded1 = g_utf8_casefold (g_quark_to_string (tag->tag), -1);
+ case_folded2 = g_utf8_casefold (prefix_string, -1);
+
+ has_prefix = g_str_has_prefix (case_folded1, case_folded2);
+
+ g_free (case_folded1);
+ g_free (case_folded2);
+
+ g_printerr ("'%s' has prefix '%s': %d\n",
+ g_quark_to_string (tag->tag), prefix_string, has_prefix);
+
+ return has_prefix;
+}
+
+/**
* gimp_tag_string_make_valid:
* @tag_string: a text string.
*
diff --git a/app/core/gimptag.h b/app/core/gimptag.h
index fc168f1..af56482 100644
--- a/app/core/gimptag.h
+++ b/app/core/gimptag.h
@@ -68,6 +68,8 @@ gint gimp_tag_compare_func (const void *p1,
const void *p2);
gint gimp_tag_compare_with_string (GimpTag *tag,
const gchar *tag_string);
+gboolean gimp_tag_has_prefix (GimpTag *tag,
+ const gchar *prefix_string);
gchar * gimp_tag_string_make_valid (const gchar *tag_string);
gboolean gimp_tag_is_tag_separator (gunichar c);
diff --git a/app/widgets/gimptagentry.c b/app/widgets/gimptagentry.c
index 2e9bc5b..3e38447 100644
--- a/app/widgets/gimptagentry.c
+++ b/app/widgets/gimptagentry.c
@@ -1044,13 +1044,11 @@ gimp_tag_entry_get_completion_candidates (GimpTagEntry *tag_entry,
gchar **used_tags,
gchar *src_prefix)
{
- GList *candidates = NULL;
- GList *all_tags;
- GList *list;
- const gchar *tag_name;
- gint i;
- gint length;
- gchar *prefix;
+ GList *candidates = NULL;
+ GList *all_tags;
+ GList *list;
+ gint length;
+ gchar *prefix;
if (! src_prefix || strlen (src_prefix) < 1)
return NULL;
@@ -1066,10 +1064,10 @@ gimp_tag_entry_get_completion_candidates (GimpTagEntry *tag_entry,
{
GimpTag *tag = list->data;
- tag_name = gimp_tag_get_name (tag);
-
- if (g_str_has_prefix (tag_name, prefix))
+ if (gimp_tag_has_prefix (tag, prefix))
{
+ gint i;
+
/* check if tag is not already entered */
for (i = 0; i < length; i++)
{
diff --git a/app/widgets/gimptagpopup.c b/app/widgets/gimptagpopup.c
index a00789a..738e861 100644
--- a/app/widgets/gimptagpopup.c
+++ b/app/widgets/gimptagpopup.c
@@ -210,12 +210,10 @@ gimp_tag_popup_constructed (GObject *object)
GList *tag_list;
GList *tag_iterator;
gint i;
- gint j;
gint max_height;
gint screen_height;
gchar **current_tags;
gint current_count;
- const gchar *list_tag;
GdkRectangle popup_rects[2]; /* variants of popup placement */
GdkRectangle popup_rect; /* best popup rect in screen coordinates */
@@ -255,15 +253,14 @@ gimp_tag_popup_constructed (GObject *object)
i++, tag_iterator = g_list_next (tag_iterator))
{
PopupTagData *tag_data = &popup->tag_data[i];
+ gint j;
tag_data->tag = tag_iterator->data;
tag_data->state = GTK_STATE_NORMAL;
- list_tag = gimp_tag_get_name (tag_data->tag);
-
for (j = 0; j < current_count; j++)
{
- if (! strcmp (current_tags[j], list_tag))
+ if (! gimp_tag_compare_with_string (tag_data->tag, current_tags[j]))
{
tag_data->state = GTK_STATE_SELECTED;
break;
@@ -966,12 +963,11 @@ static void
gimp_tag_popup_toggle_tag (GimpTagPopup *popup,
PopupTagData *tag_data)
{
- gchar **current_tags;
- GString *tag_str;
- const gchar *tag;
- gint length;
- gint i;
- gboolean tag_toggled_off = FALSE;
+ gchar **current_tags;
+ GString *tag_str;
+ gint length;
+ gint i;
+ gboolean tag_toggled_off = FALSE;
if (tag_data->state == GTK_STATE_NORMAL)
{
@@ -986,13 +982,12 @@ gimp_tag_popup_toggle_tag (GimpTagPopup *popup,
return;
}
- tag = gimp_tag_get_name (tag_data->tag);
current_tags = gimp_tag_entry_parse_tags (GIMP_TAG_ENTRY (popup->combo_entry));
tag_str = g_string_new ("");
length = g_strv_length (current_tags);
for (i = 0; i < length; i++)
{
- if (! strcmp (current_tags[i], tag))
+ if (! gimp_tag_compare_with_string (tag_data->tag, current_tags[i]))
{
tag_toggled_off = TRUE;
}
@@ -1018,7 +1013,7 @@ gimp_tag_popup_toggle_tag (GimpTagPopup *popup,
g_string_append_c (tag_str, ' ');
}
- g_string_append (tag_str, tag);
+ g_string_append (tag_str, gimp_tag_get_name (tag_data->tag));
}
gimp_tag_entry_set_tag_string (GIMP_TAG_ENTRY (popup->combo_entry),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]