xed-document-output-stream: Clean up code style

This commit is contained in:
JosephMcc 2017-01-19 01:38:13 -08:00
parent dfa7714cc5
commit 28ef771d15
1 changed files with 241 additions and 247 deletions

View File

@ -138,10 +138,8 @@ xed_document_output_stream_constructed (GObject *object)
/* Init the undoable action */
gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc));
/* clear the buffer */
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->priv->doc),
"", 0);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc),
FALSE);
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->priv->doc), "", 0);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), FALSE);
gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc));
}
@ -218,8 +216,7 @@ get_newline_type (GtkTextIter *end)
GOutputStream *
xed_document_output_stream_new (XedDocument *doc)
{
return G_OUTPUT_STREAM (g_object_new (XED_TYPE_DOCUMENT_OUTPUT_STREAM,
"document", doc, NULL));
return G_OUTPUT_STREAM (g_object_new (XED_TYPE_DOCUMENT_OUTPUT_STREAM, "document", doc, NULL));
}
XedDocumentNewlineType
@ -228,13 +225,11 @@ xed_document_output_stream_detect_newline_type (XedDocumentOutputStream *stream)
XedDocumentNewlineType type;
GtkTextIter iter;
g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream),
XED_DOCUMENT_NEWLINE_TYPE_DEFAULT);
g_return_val_if_fail (XED_IS_DOCUMENT_OUTPUT_STREAM (stream), XED_DOCUMENT_NEWLINE_TYPE_DEFAULT);
type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT;
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->doc),
&iter);
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->doc), &iter);
if (gtk_text_iter_ends_line (&iter) || gtk_text_iter_forward_to_line_end (&iter))
{
@ -257,8 +252,7 @@ remove_ending_newline (XedDocumentOutputStream *stream)
gtk_text_iter_set_line_offset (&start, 0);
if (gtk_text_iter_ends_line (&start) &&
gtk_text_iter_backward_line (&start))
if (gtk_text_iter_ends_line (&start) && gtk_text_iter_backward_line (&start))
{
if (!gtk_text_iter_ends_line (&start))
{
@ -266,9 +260,7 @@ remove_ending_newline (XedDocumentOutputStream *stream)
}
/* Delete the empty line which is from 'start' to 'end' */
gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->priv->doc),
&start,
&end);
gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->priv->doc), &start, &end);
}
}
@ -277,8 +269,7 @@ end_append_text_to_document (XedDocumentOutputStream *stream)
{
remove_ending_newline (stream);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc),
FALSE);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), FALSE);
gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc));
}
@ -298,7 +289,9 @@ xed_document_output_stream_write (GOutputStream *stream,
gboolean valid;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
{
return -1;
}
ostream = XED_DOCUMENT_OUTPUT_STREAM (stream);
@ -307,8 +300,7 @@ xed_document_output_stream_write (GOutputStream *stream,
/* Init the undoable action */
gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (ostream->priv->doc));
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->priv->doc),
&ostream->priv->pos);
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->priv->doc), &ostream->priv->pos);
ostream->priv->is_initialized = TRUE;
}
@ -359,21 +351,23 @@ xed_document_output_stream_write (GOutputStream *stream,
/* TODO: we could escape invalid text and tag it in red
* and make the doc readonly.
*/
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
_("Invalid UTF-8 sequence in input"));
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Invalid UTF-8 sequence in input"));
if (freetext)
{
g_free (text);
}
return -1;
}
}
gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->doc),
&ostream->priv->pos, text, len);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->doc), &ostream->priv->pos, text, len);
if (freetext)
{
g_free (text);
}
return count;
}
@ -388,9 +382,10 @@ xed_document_output_stream_flush (GOutputStream *stream,
/* Flush deferred data if some. */
if (!ostream->priv->is_closed && ostream->priv->is_initialized &&
ostream->priv->buflen > 0 &&
xed_document_output_stream_write (stream, "", 0, cancellable,
error) == -1)
xed_document_output_stream_write (stream, "", 0, cancellable, error) == -1)
{
return FALSE;
}
return TRUE;
}
@ -410,8 +405,7 @@ xed_document_output_stream_close (GOutputStream *stream,
if (ostream->priv->buflen > 0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
_("Incomplete UTF-8 sequence in input"));
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Incomplete UTF-8 sequence in input"));
return FALSE;
}