[gimp] Bug 794221 - Recently used colors on text don't get added to the color history
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 794221 - Recently used colors on text don't get added to the color history
- Date: Fri, 23 Mar 2018 13:24:12 +0000 (UTC)
commit 822a7228c4f522190d02395b4c2c76a6b13a498c
Author: Michael Natterer <mitch gimp org>
Date: Fri Mar 23 14:19:01 2018 +0100
Bug 794221 - Recently used colors on text don't get added to the color history
Add signal GimpTextBuffer::color-applied which is emitted when text is
inserted or when color is applied to a span of text.
In GimpTextTool, connect to the signal and update the global color
history.
Unrelated: rename gimp_text_tag_get_color() to get_fg_color() and add
boolean return values to get_fg_color() and get_fg_color() which
indicates if a color is set on the tag at all. This ended up unneeded
in the fix but is an improvement regardless.
app/tools/gimptexttool.c | 19 +++++++++++++++++++
app/widgets/gimptextbuffer.c | 37 ++++++++++++++++++++++++++++++++-----
app/widgets/gimptextbuffer.h | 3 +++
app/widgets/gimptextstyleeditor.c | 2 +-
app/widgets/gimptexttag.c | 24 +++++++++++++++++-------
app/widgets/gimptexttag.h | 18 +++++++++---------
6 files changed, 81 insertions(+), 22 deletions(-)
---
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index e3e579f..8ca768f 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -34,6 +34,7 @@
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
+#include "core/gimp-palettes.h"
#include "core/gimpimage-pick-item.h"
#include "core/gimpimage-undo.h"
#include "core/gimpimage-undo-push.h"
@@ -177,6 +178,11 @@ static void gimp_text_tool_buffer_begin_edit (GimpTextBuffer *buffer,
static void gimp_text_tool_buffer_end_edit (GimpTextBuffer *buffer,
GimpTextTool *text_tool);
+static void gimp_text_tool_buffer_color_applied
+ (GimpTextBuffer *buffer,
+ const GimpRGB *color,
+ GimpTextTool *text_tool);
+
G_DEFINE_TYPE (GimpTextTool, gimp_text_tool, GIMP_TYPE_DRAW_TOOL)
@@ -238,6 +244,9 @@ gimp_text_tool_init (GimpTextTool *text_tool)
g_signal_connect (text_tool->buffer, "end-user-action",
G_CALLBACK (gimp_text_tool_buffer_end_edit),
text_tool);
+ g_signal_connect (text_tool->buffer, "color-applied",
+ G_CALLBACK (gimp_text_tool_buffer_color_applied),
+ text_tool);
text_tool->handle_rectangle_change_complete = TRUE;
@@ -1330,6 +1339,7 @@ gimp_text_tool_text_notify (GimpText *text,
g_signal_handlers_block_by_func (text_tool->buffer,
gimp_text_tool_buffer_end_edit,
text_tool);
+
if (text->markup)
gimp_text_buffer_set_markup (text_tool->buffer, text->markup);
else
@@ -1790,6 +1800,15 @@ gimp_text_tool_buffer_end_edit (GimpTextBuffer *buffer,
}
}
+static void
+gimp_text_tool_buffer_color_applied (GimpTextBuffer *buffer,
+ const GimpRGB *color,
+ GimpTextTool *text_tool)
+{
+ gimp_palettes_add_color_history (GIMP_TOOL (text_tool)->tool_info->gimp,
+ color);
+}
+
/* public functions */
diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c
index a2052be..aef673e 100644
--- a/app/widgets/gimptextbuffer.c
+++ b/app/widgets/gimptextbuffer.c
@@ -38,6 +38,13 @@
#include "gimp-intl.h"
+enum
+{
+ COLOR_APPLIED,
+ LAST_SIGNAL
+};
+
+
/* local function prototypes */
static void gimp_text_buffer_constructed (GObject *object);
@@ -53,6 +60,8 @@ G_DEFINE_TYPE (GimpTextBuffer, gimp_text_buffer, GTK_TYPE_TEXT_BUFFER)
#define parent_class gimp_text_buffer_parent_class
+static guint buffer_signals[LAST_SIGNAL] = { 0, };
+
static void
gimp_text_buffer_class_init (GimpTextBufferClass *klass)
@@ -65,6 +74,16 @@ gimp_text_buffer_class_init (GimpTextBufferClass *klass)
object_class->finalize = gimp_text_buffer_finalize;
buffer_class->mark_set = gimp_text_buffer_mark_set;
+
+ buffer_signals[COLOR_APPLIED] =
+ g_signal_new ("color-applied",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpTextBufferClass, color_applied),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1,
+ GIMP_TYPE_RGB);
}
static void
@@ -928,7 +947,7 @@ gimp_text_buffer_get_iter_color (GimpTextBuffer *buffer,
if (gtk_text_iter_has_tag (iter, tag))
{
if (color)
- gimp_text_tag_get_color (tag, color);
+ gimp_text_tag_get_fg_color (tag, color);
return tag;
}
@@ -956,7 +975,7 @@ gimp_text_buffer_get_color_tag (GimpTextBuffer *buffer,
tag = list->data;
- gimp_text_tag_get_color (tag, &tag_color);
+ gimp_text_tag_get_fg_color (tag, &tag_color);
gimp_rgb_get_uchar (&tag_color, &tag_r, &tag_g, &tag_b);
@@ -1014,6 +1033,8 @@ gimp_text_buffer_set_color (GimpTextBuffer *buffer,
gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), tag,
start, end);
+
+ g_signal_emit (buffer, buffer_signals[COLOR_APPLIED], 0, color);
}
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
@@ -1038,7 +1059,7 @@ gimp_text_buffer_get_preedit_color_tag (GimpTextBuffer *buffer,
tag = list->data;
- gimp_text_tag_get_color (tag, &tag_color);
+ gimp_text_tag_get_fg_color (tag, &tag_color);
gimp_rgb_get_uchar (&tag_color, &tag_r, &tag_g, &tag_b);
@@ -1276,7 +1297,7 @@ gimp_text_buffer_tag_to_name (GimpTextBuffer *buffer,
GimpRGB color;
guchar r, g, b;
- gimp_text_tag_get_color (tag, &color);
+ gimp_text_tag_get_fg_color (tag, &color);
gimp_rgb_get_uchar (&color, &r, &g, &b);
*value = g_strdup_printf ("#%02x%02x%02x", r, g, b);
@@ -1297,7 +1318,7 @@ gimp_text_buffer_tag_to_name (GimpTextBuffer *buffer,
GimpRGB color;
guchar r, g, b;
- gimp_text_tag_get_color (tag, &color);
+ gimp_text_tag_get_fg_color (tag, &color);
gimp_rgb_get_uchar (&color, &r, &g, &b);
*value = g_strdup_printf ("#%02x%02x%02x", r, g, b);
@@ -1436,6 +1457,7 @@ gimp_text_buffer_insert (GimpTextBuffer *buffer,
GList *insert_tags;
GList *remove_tags;
GSList *tags_off = NULL;
+ GimpRGB color;
g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
@@ -1504,6 +1526,11 @@ gimp_text_buffer_insert (GimpTextBuffer *buffer,
g_list_free (remove_tags);
g_list_free (insert_tags);
+ if (gimp_text_buffer_get_iter_color (buffer, &start, &color))
+ {
+ g_signal_emit (buffer, buffer_signals[COLOR_APPLIED], 0, &color);
+ }
+
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
}
diff --git a/app/widgets/gimptextbuffer.h b/app/widgets/gimptextbuffer.h
index a155915..78d5788 100644
--- a/app/widgets/gimptextbuffer.h
+++ b/app/widgets/gimptextbuffer.h
@@ -60,6 +60,9 @@ struct _GimpTextBuffer
struct _GimpTextBufferClass
{
GtkTextBufferClass parent_class;
+
+ void (* color_applied) (GimpTextBuffer *buffer,
+ const GimpRGB *color);
};
diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c
index c37e3cf..afb320b 100644
--- a/app/widgets/gimptextstyleeditor.c
+++ b/app/widgets/gimptextstyleeditor.c
@@ -752,7 +752,7 @@ gimp_text_style_editor_set_color (GimpTextStyleEditor *editor,
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
if (color_tag)
- gimp_text_tag_get_color (color_tag, &color);
+ gimp_text_tag_get_fg_color (color_tag, &color);
g_signal_handlers_block_by_func (editor->color_button,
gimp_text_style_editor_color_changed,
diff --git a/app/widgets/gimptexttag.c b/app/widgets/gimptexttag.c
index 893fe71..60fc46c 100644
--- a/app/widgets/gimptexttag.c
+++ b/app/widgets/gimptexttag.c
@@ -81,32 +81,42 @@ gimp_text_tag_get_font (GtkTextTag *tag)
return font;
}
-void
-gimp_text_tag_get_color (GtkTextTag *tag,
- GimpRGB *color)
+gboolean
+gimp_text_tag_get_fg_color (GtkTextTag *tag,
+ GimpRGB *color)
{
GdkColor *gdk_color;
+ gboolean set;
g_object_get (tag,
- GIMP_TEXT_PROP_NAME_COLOR, &gdk_color,
+ "foreground-set", &set,
+ GIMP_TEXT_PROP_NAME_FG_COLOR, &gdk_color,
NULL);
- gimp_rgb_set_gdk_color (color, gdk_color);
+ if (set)
+ gimp_rgb_set_gdk_color (color, gdk_color);
gdk_color_free (gdk_color);
+
+ return set;
}
-void
+gboolean
gimp_text_tag_get_bg_color (GtkTextTag *tag,
GimpRGB *color)
{
GdkColor *gdk_color;
+ gboolean set;
g_object_get (tag,
+ "background-set", &set,
GIMP_TEXT_PROP_NAME_BG_COLOR, &gdk_color,
NULL);
- gimp_rgb_set_gdk_color (color, gdk_color);
+ if (set)
+ gimp_rgb_set_gdk_color (color, gdk_color);
gdk_color_free (gdk_color);
+
+ return set;
}
diff --git a/app/widgets/gimptexttag.h b/app/widgets/gimptexttag.h
index 183f4f0..7e0ebfc 100644
--- a/app/widgets/gimptexttag.h
+++ b/app/widgets/gimptexttag.h
@@ -28,18 +28,18 @@
#define GIMP_TEXT_PROP_NAME_BASELINE "rise"
#define GIMP_TEXT_PROP_NAME_KERNING "rise" /* FIXME */
#define GIMP_TEXT_PROP_NAME_FONT "font"
-#define GIMP_TEXT_PROP_NAME_COLOR "foreground-gdk"
+#define GIMP_TEXT_PROP_NAME_FG_COLOR "foreground-gdk"
#define GIMP_TEXT_PROP_NAME_BG_COLOR "background-gdk"
-gint gimp_text_tag_get_size (GtkTextTag *tag);
-gint gimp_text_tag_get_baseline (GtkTextTag *tag);
-gint gimp_text_tag_get_kerning (GtkTextTag *tag);
-gchar * gimp_text_tag_get_font (GtkTextTag *tag);
-void gimp_text_tag_get_color (GtkTextTag *tag,
- GimpRGB *color);
-void gimp_text_tag_get_bg_color (GtkTextTag *tag,
- GimpRGB *color);
+gint gimp_text_tag_get_size (GtkTextTag *tag);
+gint gimp_text_tag_get_baseline (GtkTextTag *tag);
+gint gimp_text_tag_get_kerning (GtkTextTag *tag);
+gchar * gimp_text_tag_get_font (GtkTextTag *tag);
+gboolean gimp_text_tag_get_fg_color (GtkTextTag *tag,
+ GimpRGB *color);
+gboolean gimp_text_tag_get_bg_color (GtkTextTag *tag,
+ GimpRGB *color);
#endif /* __GIMP_TEXT_TAG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]