Commit 9a9d7489 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: make undo compression in the text tool work again

- in GimpText, make "text" and "markup" mutually exclusive, so that
  whenever one is set to non-NULL, the other is cleared automatically.
- add gimp_text_buffer_has_markup() which returns TRUE if any char
  in the buffer is tagged.
- in the text tool, only set "markup" on the text proxy if there is
  actually markup in the buffer, and set "text" otherwise.

This way we don't push "text" *and* "markup" undos on each keystroke,
and undo compression works the way it did before.
parent e9abde75
......@@ -399,10 +399,22 @@ gimp_text_set_property (GObject *object,
case PROP_TEXT:
g_free (text->text);
text->text = g_value_dup_string (value);
if (text->text && text->markup)
{
g_free (text->markup);
text->markup = NULL;
g_object_notify (object, "markup");
}
break;
case PROP_MARKUP:
g_free (text->markup);
text->markup = g_value_dup_string (value);
if (text->markup && text->text)
{
g_free (text->text);
text->text = NULL;
g_object_notify (object, "text");
}
break;
case PROP_FONT:
{
......
......@@ -164,7 +164,7 @@ static gboolean gimp_text_tool_set_drawable (GimpTextTool *text_tool,
GimpDrawable *drawable,
gboolean confirm);
static void gimp_text_tool_buffer_edited (GtkTextBuffer *buffer,
static void gimp_text_tool_buffer_edited (GimpTextBuffer *buffer,
GimpTextTool *text_tool);
......@@ -1272,17 +1272,28 @@ gimp_text_tool_create_layer (GimpTextTool *text_tool,
}
else
{
gchar *string = gimp_text_buffer_get_text (text_tool->buffer);
gchar *markup = gimp_text_buffer_get_markup (text_tool->buffer);
gchar *string;
g_object_set (text_tool->proxy,
"text", string,
"markup", markup,
"box-mode", GIMP_TEXT_BOX_DYNAMIC,
NULL);
if (gimp_text_buffer_has_markup (text_tool->buffer))
{
string = gimp_text_buffer_get_markup (text_tool->buffer);
g_object_set (text_tool->proxy,
"markup", string,
"box-mode", GIMP_TEXT_BOX_DYNAMIC,
NULL);
}
else
{
string = gimp_text_buffer_get_text (text_tool->buffer);
g_object_set (text_tool->proxy,
"text", string,
"box-mode", GIMP_TEXT_BOX_DYNAMIC,
NULL);
}
g_free (string);
g_free (markup);
text = gimp_config_duplicate (GIMP_CONFIG (text_tool->proxy));
}
......@@ -1577,23 +1588,31 @@ gimp_text_tool_set_drawable (GimpTextTool *text_tool,
}
static void
gimp_text_tool_buffer_edited (GtkTextBuffer *buffer,
GimpTextTool *text_tool)
gimp_text_tool_buffer_edited (GimpTextBuffer *buffer,
GimpTextTool *text_tool)
{
if (text_tool->text)
{
gchar *text = gimp_text_buffer_get_text (GIMP_TEXT_BUFFER (buffer));
gchar *markup = gimp_text_buffer_get_markup (GIMP_TEXT_BUFFER (buffer));
gchar *string;
g_object_set (text_tool->proxy,
"text", text,
"markup", markup,
NULL);
if (gimp_text_buffer_has_markup (buffer))
{
string = gimp_text_buffer_get_markup (buffer);
g_object_set (text_tool->proxy,
"markup", string,
NULL);
}
else
{
string = gimp_text_buffer_get_text (buffer);
/* g_printerr ("markup: %s\n", markup); */
g_object_set (text_tool->proxy,
"text", string,
NULL);
}
g_free (text);
g_free (markup);
g_free (string);
}
else
{
......
......@@ -303,6 +303,30 @@ gimp_text_buffer_get_markup (GimpTextBuffer *buffer)
return markup;
}
gboolean
gimp_text_buffer_has_markup (GimpTextBuffer *buffer)
{
GtkTextIter iter;
g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), FALSE);
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
do
{
GSList *tags = gtk_text_iter_get_tags (&iter);
if (tags)
{
g_slist_free (tags);
return TRUE;
}
}
while (gtk_text_iter_forward_char (&iter));
return FALSE;
}
GtkTextTag *
gimp_text_buffer_get_iter_baseline (GimpTextBuffer *buffer,
const GtkTextIter *iter,
......
......@@ -69,6 +69,8 @@ void gimp_text_buffer_set_markup (GimpTextBuffer *buffer,
const gchar *markup);
gchar * gimp_text_buffer_get_markup (GimpTextBuffer *buffer);
gboolean gimp_text_buffer_has_markup (GimpTextBuffer *buffer);
GtkTextTag * gimp_text_buffer_get_iter_baseline (GimpTextBuffer *buffer,
const GtkTextIter *iter,
gint *baseline);
......
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