[gtksourceview/wip/chergert/gsv-gtk4: 18/175] file: modernize GtkSourceFileSaver
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 18/175] file: modernize GtkSourceFileSaver
- Date: Thu, 25 Jun 2020 19:44:44 +0000 (UTC)
commit d8aa40c1ff278e2c85150814289dda1ba2e3d26d
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 8 20:09:42 2020 -0800
file: modernize GtkSourceFileSaver
- Use G_DECLARE_ macros
- Use get_instance_private
- Fix spacing style for multi-line functions
gtksourceview/gtksourceautocleanups.h | 1 -
gtksourceview/gtksourcefilesaver.c | 290 +++++++++++++++++-----------------
gtksourceview/gtksourcefilesaver.h | 110 ++++---------
3 files changed, 180 insertions(+), 221 deletions(-)
---
diff --git a/gtksourceview/gtksourceautocleanups.h b/gtksourceview/gtksourceautocleanups.h
index 2ed4003b..4f3858c3 100644
--- a/gtksourceview/gtksourceautocleanups.h
+++ b/gtksourceview/gtksourceautocleanups.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
#ifndef __GI_SCANNER__
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceFileSaver, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceGutter, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceGutterRenderer, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceGutterRendererPixbuf, g_object_unref)
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 9c29aaec..a4f2e87d 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -80,8 +80,10 @@ enum
PROP_FLAGS
};
-struct _GtkSourceFileSaverPrivate
+struct _GtkSourceFileSaver
{
+ GObject parent_instance;
+
/* Weak ref to the GtkSourceBuffer. A strong ref could create a
* reference cycle in an application. For example a subclass of
* GtkSourceBuffer can have a strong ref to the FileSaver.
@@ -104,8 +106,7 @@ struct _GtkSourceFileSaverPrivate
GTask *task;
};
-typedef struct _TaskData TaskData;
-struct _TaskData
+typedef struct
{
/* The output_stream contains the required converter(s) for the encoding
* and the compression type.
@@ -135,12 +136,12 @@ struct _TaskData
gchar chunk_buffer[WRITE_CHUNK_SIZE];
guint tried_mount : 1;
-};
+} TaskData;
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFileSaver, gtk_source_file_saver, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GtkSourceFileSaver, gtk_source_file_saver, G_TYPE_OBJECT)
-static void read_file_chunk (GTask *task);
-static void write_file_chunk (GTask *task);
+static void read_file_chunk (GTask *task);
+static void write_file_chunk (GTask *task);
static void recover_not_mounted (GTask *task);
static TaskData *
@@ -174,31 +175,31 @@ task_data_free (gpointer data)
static void
gtk_source_file_saver_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
switch (prop_id)
{
case PROP_BUFFER:
- g_assert (saver->priv->source_buffer == NULL);
- saver->priv->source_buffer = g_value_get_object (value);
- g_object_add_weak_pointer (G_OBJECT (saver->priv->source_buffer),
- (gpointer *)&saver->priv->source_buffer);
+ g_assert (saver->source_buffer == NULL);
+ saver->source_buffer = g_value_get_object (value);
+ g_object_add_weak_pointer (G_OBJECT (saver->source_buffer),
+ (gpointer *)&saver->source_buffer);
break;
case PROP_FILE:
- g_assert (saver->priv->file == NULL);
- saver->priv->file = g_value_get_object (value);
- g_object_add_weak_pointer (G_OBJECT (saver->priv->file),
- (gpointer *)&saver->priv->file);
+ g_assert (saver->file == NULL);
+ saver->file = g_value_get_object (value);
+ g_object_add_weak_pointer (G_OBJECT (saver->file),
+ (gpointer *)&saver->file);
break;
case PROP_LOCATION:
- g_assert (saver->priv->location == NULL);
- saver->priv->location = g_value_dup_object (value);
+ g_assert (saver->location == NULL);
+ saver->location = g_value_dup_object (value);
break;
case PROP_ENCODING:
@@ -225,40 +226,40 @@ gtk_source_file_saver_set_property (GObject *object,
static void
gtk_source_file_saver_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
switch (prop_id)
{
case PROP_BUFFER:
- g_value_set_object (value, saver->priv->source_buffer);
+ g_value_set_object (value, saver->source_buffer);
break;
case PROP_FILE:
- g_value_set_object (value, saver->priv->file);
+ g_value_set_object (value, saver->file);
break;
case PROP_LOCATION:
- g_value_set_object (value, saver->priv->location);
+ g_value_set_object (value, saver->location);
break;
case PROP_ENCODING:
- g_value_set_boxed (value, saver->priv->encoding);
+ g_value_set_boxed (value, saver->encoding);
break;
case PROP_NEWLINE_TYPE:
- g_value_set_enum (value, saver->priv->newline_type);
+ g_value_set_enum (value, saver->newline_type);
break;
case PROP_COMPRESSION_TYPE:
- g_value_set_enum (value, saver->priv->compression_type);
+ g_value_set_enum (value, saver->compression_type);
break;
case PROP_FLAGS:
- g_value_set_flags (value, saver->priv->flags);
+ g_value_set_flags (value, saver->flags);
break;
default:
@@ -272,24 +273,24 @@ gtk_source_file_saver_dispose (GObject *object)
{
GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
- if (saver->priv->source_buffer != NULL)
+ if (saver->source_buffer != NULL)
{
- g_object_remove_weak_pointer (G_OBJECT (saver->priv->source_buffer),
- (gpointer *)&saver->priv->source_buffer);
+ g_object_remove_weak_pointer (G_OBJECT (saver->source_buffer),
+ (gpointer *)&saver->source_buffer);
- saver->priv->source_buffer = NULL;
+ saver->source_buffer = NULL;
}
- if (saver->priv->file != NULL)
+ if (saver->file != NULL)
{
- g_object_remove_weak_pointer (G_OBJECT (saver->priv->file),
- (gpointer *)&saver->priv->file);
+ g_object_remove_weak_pointer (G_OBJECT (saver->file),
+ (gpointer *)&saver->file);
- saver->priv->file = NULL;
+ saver->file = NULL;
}
- g_clear_object (&saver->priv->location);
- g_clear_object (&saver->priv->task);
+ g_clear_object (&saver->location);
+ g_clear_object (&saver->task);
G_OBJECT_CLASS (gtk_source_file_saver_parent_class)->dispose (object);
}
@@ -299,28 +300,28 @@ gtk_source_file_saver_constructed (GObject *object)
{
GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
- if (saver->priv->file != NULL)
+ if (saver->file != NULL)
{
const GtkSourceEncoding *encoding;
GtkSourceNewlineType newline_type;
GtkSourceCompressionType compression_type;
- encoding = gtk_source_file_get_encoding (saver->priv->file);
+ encoding = gtk_source_file_get_encoding (saver->file);
gtk_source_file_saver_set_encoding (saver, encoding);
- newline_type = gtk_source_file_get_newline_type (saver->priv->file);
+ newline_type = gtk_source_file_get_newline_type (saver->file);
gtk_source_file_saver_set_newline_type (saver, newline_type);
- compression_type = gtk_source_file_get_compression_type (saver->priv->file);
+ compression_type = gtk_source_file_get_compression_type (saver->file);
gtk_source_file_saver_set_compression_type (saver, compression_type);
- if (saver->priv->location == NULL)
+ if (saver->location == NULL)
{
- saver->priv->location = gtk_source_file_get_location (saver->priv->file);
+ saver->location = gtk_source_file_get_location (saver->file);
- if (saver->priv->location != NULL)
+ if (saver->location != NULL)
{
- g_object_ref (saver->priv->location);
+ g_object_ref (saver->location);
}
else
{
@@ -480,7 +481,6 @@ gtk_source_file_saver_class_init (GtkSourceFileSaverClass *klass)
static void
gtk_source_file_saver_init (GtkSourceFileSaver *saver)
{
- saver->priv = gtk_source_file_saver_get_instance_private (saver);
}
/* BEGIN NOTE:
@@ -506,8 +506,8 @@ gtk_source_file_saver_init (GtkSourceFileSaver *saver)
*/
static void
cancel_output_stream_ready_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GOutputStream *output_stream = G_OUTPUT_STREAM (source_object);
GTask *task = G_TASK (user_data);
@@ -559,8 +559,8 @@ cancel_output_stream (GTask *task)
static void
query_info_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GFile *location = G_FILE (source_object);
GTask *task = G_TASK (user_data);
@@ -591,8 +591,8 @@ query_info_cb (GObject *source_object,
static void
close_output_stream_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GOutputStream *output_stream = G_OUTPUT_STREAM (source_object);
GTask *task = G_TASK (user_data);
@@ -625,7 +625,7 @@ close_output_stream_cb (GObject *source_object,
g_print ("Query info on file\n");
});
- g_file_query_info_async (saver->priv->location,
+ g_file_query_info_async (saver->location,
QUERY_ATTRIBUTES,
G_FILE_QUERY_INFO_NONE,
g_task_get_priority (task),
@@ -675,8 +675,8 @@ write_complete (GTask *task)
static void
write_file_chunk_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GOutputStream *output_stream = G_OUTPUT_STREAM (source_object);
GTask *task = G_TASK (user_data);
@@ -794,8 +794,8 @@ read_file_chunk (GTask *task)
static void
replace_file_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GFile *location = G_FILE (source_object);
GTask *task = G_TASK (user_data);
@@ -831,7 +831,7 @@ replace_file_cb (GObject *source_object,
return;
}
- if (saver->priv->compression_type == GTK_SOURCE_COMPRESSION_TYPE_GZIP)
+ if (saver->compression_type == GTK_SOURCE_COMPRESSION_TYPE_GZIP)
{
GZlibCompressor *compressor;
@@ -856,14 +856,14 @@ replace_file_cb (GObject *source_object,
DEBUG ({
g_print ("Encoding charset: %s\n",
- gtk_source_encoding_get_charset (saver->priv->encoding));
+ gtk_source_encoding_get_charset (saver->encoding));
});
- if (saver->priv->encoding != gtk_source_encoding_get_utf8 ())
+ if (saver->encoding != gtk_source_encoding_get_utf8 ())
{
GCharsetConverter *converter;
- converter = g_charset_converter_new (gtk_source_encoding_get_charset (saver->priv->encoding),
+ converter = g_charset_converter_new (gtk_source_encoding_get_charset (saver->encoding),
"UTF-8",
NULL);
@@ -897,14 +897,14 @@ begin_write (GTask *task)
saver = g_task_get_source_object (task);
- create_backup = (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP) != 0;
+ create_backup = (saver->flags & GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP) != 0;
DEBUG ({
g_print ("Start replacing file contents\n");
g_print ("Make backup: %s\n", create_backup ? "yes" : "no");
});
- g_file_replace_async (saver->priv->location,
+ g_file_replace_async (saver->location,
NULL,
create_backup,
G_FILE_CREATE_NONE,
@@ -916,8 +916,8 @@ begin_write (GTask *task)
static void
check_externally_modified_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GFile *location = G_FILE (source_object);
GTask *task = G_TASK (user_data);
@@ -960,7 +960,7 @@ check_externally_modified_cb (GObject *source_object,
return;
}
- if (_gtk_source_file_get_modification_time (saver->priv->file, &old_mtime) &&
+ if (_gtk_source_file_get_modification_time (saver->file, &old_mtime) &&
info != NULL &&
g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
@@ -998,21 +998,21 @@ check_externally_modified (GTask *task)
saver = g_task_get_source_object (task);
- if (saver->priv->file != NULL)
+ if (saver->file != NULL)
{
GFile *prev_location;
- prev_location = gtk_source_file_get_location (saver->priv->file);
+ prev_location = gtk_source_file_get_location (saver->file);
/* Don't check for externally modified for a "save as" operation,
* because the user has normally accepted to overwrite the file if it
* already exists.
*/
save_as = (prev_location == NULL ||
- !g_file_equal (prev_location, saver->priv->location));
+ !g_file_equal (prev_location, saver->location));
}
- if (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME ||
+ if (saver->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME ||
save_as)
{
begin_write (task);
@@ -1023,7 +1023,7 @@ check_externally_modified (GTask *task)
g_print ("Check externally modified\n");
});
- g_file_query_info_async (saver->priv->location,
+ g_file_query_info_async (saver->location,
G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NONE,
g_task_get_priority (task),
@@ -1034,8 +1034,8 @@ check_externally_modified (GTask *task)
static void
mount_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+ GAsyncResult *result,
+ gpointer user_data)
{
GFile *location = G_FILE (source_object);
GTask *task = G_TASK (user_data);
@@ -1066,7 +1066,7 @@ recover_not_mounted (GTask *task)
saver = g_task_get_source_object (task);
task_data = g_task_get_task_data (task);
- mount_operation = _gtk_source_file_create_mount_operation (saver->priv->file);
+ mount_operation = _gtk_source_file_create_mount_operation (saver->file);
DEBUG ({
g_print ("%s\n", G_STRFUNC);
@@ -1074,7 +1074,7 @@ recover_not_mounted (GTask *task)
task_data->tried_mount = TRUE;
- g_file_mount_enclosing_volume (saver->priv->location,
+ g_file_mount_enclosing_volume (saver->location,
G_MOUNT_MOUNT_NONE,
mount_operation,
g_task_get_cancellable (task),
@@ -1113,7 +1113,7 @@ gtk_source_file_saver_error_quark (void)
*/
GtkSourceFileSaver *
gtk_source_file_saver_new (GtkSourceBuffer *buffer,
- GtkSourceFile *file)
+ GtkSourceFile *file)
{
g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
@@ -1143,8 +1143,8 @@ gtk_source_file_saver_new (GtkSourceBuffer *buffer,
*/
GtkSourceFileSaver *
gtk_source_file_saver_new_with_target (GtkSourceBuffer *buffer,
- GtkSourceFile *file,
- GFile *target_location)
+ GtkSourceFile *file,
+ GFile *target_location)
{
g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
@@ -1169,7 +1169,7 @@ gtk_source_file_saver_get_buffer (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
- return saver->priv->source_buffer;
+ return saver->source_buffer;
}
/**
@@ -1184,7 +1184,7 @@ gtk_source_file_saver_get_file (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
- return saver->priv->file;
+ return saver->file;
}
/**
@@ -1199,7 +1199,7 @@ gtk_source_file_saver_get_location (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
- return saver->priv->location;
+ return saver->location;
}
/**
@@ -1214,19 +1214,19 @@ gtk_source_file_saver_get_location (GtkSourceFileSaver *saver)
*/
void
gtk_source_file_saver_set_encoding (GtkSourceFileSaver *saver,
- const GtkSourceEncoding *encoding)
+ const GtkSourceEncoding *encoding)
{
g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (saver->task == NULL);
if (encoding == NULL)
{
encoding = gtk_source_encoding_get_utf8 ();
}
- if (saver->priv->encoding != encoding)
+ if (saver->encoding != encoding)
{
- saver->priv->encoding = encoding;
+ saver->encoding = encoding;
g_object_notify (G_OBJECT (saver), "encoding");
}
}
@@ -1243,7 +1243,7 @@ gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
- return saver->priv->encoding;
+ return saver->encoding;
}
/**
@@ -1258,14 +1258,14 @@ gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver)
*/
void
gtk_source_file_saver_set_newline_type (GtkSourceFileSaver *saver,
- GtkSourceNewlineType newline_type)
+ GtkSourceNewlineType newline_type)
{
g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (saver->task == NULL);
- if (saver->priv->newline_type != newline_type)
+ if (saver->newline_type != newline_type)
{
- saver->priv->newline_type = newline_type;
+ saver->newline_type = newline_type;
g_object_notify (G_OBJECT (saver), "newline-type");
}
}
@@ -1282,7 +1282,7 @@ gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
- return saver->priv->newline_type;
+ return saver->newline_type;
}
/**
@@ -1297,14 +1297,14 @@ gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver)
*/
void
gtk_source_file_saver_set_compression_type (GtkSourceFileSaver *saver,
- GtkSourceCompressionType compression_type)
+ GtkSourceCompressionType compression_type)
{
g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (saver->task == NULL);
- if (saver->priv->compression_type != compression_type)
+ if (saver->compression_type != compression_type)
{
- saver->priv->compression_type = compression_type;
+ saver->compression_type = compression_type;
g_object_notify (G_OBJECT (saver), "compression-type");
}
}
@@ -1321,7 +1321,7 @@ gtk_source_file_saver_get_compression_type (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_COMPRESSION_TYPE_NONE);
- return saver->priv->compression_type;
+ return saver->compression_type;
}
/**
@@ -1333,14 +1333,14 @@ gtk_source_file_saver_get_compression_type (GtkSourceFileSaver *saver)
*/
void
gtk_source_file_saver_set_flags (GtkSourceFileSaver *saver,
- GtkSourceFileSaverFlags flags)
+ GtkSourceFileSaverFlags flags)
{
g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (saver->task == NULL);
- if (saver->priv->flags != flags)
+ if (saver->flags != flags)
{
- saver->priv->flags = flags;
+ saver->flags = flags;
g_object_notify (G_OBJECT (saver), "flags");
}
}
@@ -1357,7 +1357,7 @@ gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_FILE_SAVER_FLAGS_NONE);
- return saver->priv->flags;
+ return saver->flags;
}
/**
@@ -1386,14 +1386,14 @@ gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver)
* https://bugzilla.gnome.org/show_bug.cgi?id=616044
*/
void
-gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
- gint io_priority,
- GCancellable *cancellable,
- GFileProgressCallback progress_callback,
- gpointer progress_callback_data,
- GDestroyNotify progress_callback_notify,
- GAsyncReadyCallback callback,
- gpointer user_data)
+gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
+ gint io_priority,
+ GCancellable *cancellable,
+ GFileProgressCallback progress_callback,
+ gpointer progress_callback_data,
+ GDestroyNotify progress_callback_notify,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
TaskData *task_data;
gboolean check_invalid_chars;
@@ -1401,31 +1401,31 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (saver->task == NULL);
- saver->priv->task = g_task_new (saver, cancellable, callback, user_data);
- g_task_set_priority (saver->priv->task, io_priority);
+ saver->task = g_task_new (saver, cancellable, callback, user_data);
+ g_task_set_priority (saver->task, io_priority);
task_data = task_data_new ();
- g_task_set_task_data (saver->priv->task, task_data, task_data_free);
+ g_task_set_task_data (saver->task, task_data, task_data_free);
task_data->progress_cb = progress_callback;
task_data->progress_cb_data = progress_callback_data;
task_data->progress_cb_notify = progress_callback_notify;
- if (saver->priv->source_buffer == NULL ||
- saver->priv->file == NULL ||
- saver->priv->location == NULL)
+ if (saver->source_buffer == NULL ||
+ saver->file == NULL ||
+ saver->location == NULL)
{
- g_task_return_boolean (saver->priv->task, FALSE);
+ g_task_return_boolean (saver->task, FALSE);
return;
}
- check_invalid_chars = (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS) == 0;
+ check_invalid_chars = (saver->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS) == 0;
- if (check_invalid_chars && _gtk_source_buffer_has_invalid_chars (saver->priv->source_buffer))
+ if (check_invalid_chars && _gtk_source_buffer_has_invalid_chars (saver->source_buffer))
{
- g_task_return_new_error (saver->priv->task,
+ g_task_return_new_error (saver->task,
GTK_SOURCE_FILE_SAVER_ERROR,
GTK_SOURCE_FILE_SAVER_ERROR_INVALID_CHARS,
_("The buffer contains invalid characters."));
@@ -1436,17 +1436,17 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
g_print ("Start saving\n");
});
- implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline
(saver->priv->source_buffer);
+ implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline (saver->source_buffer);
/* The BufferInputStream has a strong reference to the buffer.
* We create the BufferInputStream here so we are sure that the
* buffer will not be destroyed during the file saving.
*/
- task_data->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER
(saver->priv->source_buffer),
- saver->priv->newline_type,
+ task_data->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER (saver->source_buffer),
+ saver->newline_type,
implicit_trailing_newline);
- check_externally_modified (saver->priv->task);
+ check_externally_modified (saver->task);
}
/**
@@ -1469,8 +1469,8 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
*/
gboolean
gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
- GAsyncResult *result,
- GError **error)
+ GAsyncResult *result,
+ GError **error)
{
gboolean ok;
@@ -1480,25 +1480,25 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
ok = g_task_propagate_boolean (G_TASK (result), error);
- if (ok && saver->priv->file != NULL)
+ if (ok && saver->file != NULL)
{
TaskData *task_data;
- gtk_source_file_set_location (saver->priv->file,
- saver->priv->location);
+ gtk_source_file_set_location (saver->file,
+ saver->location);
- _gtk_source_file_set_encoding (saver->priv->file,
- saver->priv->encoding);
+ _gtk_source_file_set_encoding (saver->file,
+ saver->encoding);
- _gtk_source_file_set_newline_type (saver->priv->file,
- saver->priv->newline_type);
+ _gtk_source_file_set_newline_type (saver->file,
+ saver->newline_type);
- _gtk_source_file_set_compression_type (saver->priv->file,
- saver->priv->compression_type);
+ _gtk_source_file_set_compression_type (saver->file,
+ saver->compression_type);
- _gtk_source_file_set_externally_modified (saver->priv->file, FALSE);
- _gtk_source_file_set_deleted (saver->priv->file, FALSE);
- _gtk_source_file_set_readonly (saver->priv->file, FALSE);
+ _gtk_source_file_set_externally_modified (saver->file, FALSE);
+ _gtk_source_file_set_deleted (saver->file, FALSE);
+ _gtk_source_file_set_readonly (saver->file, FALSE);
task_data = g_task_get_task_data (G_TASK (result));
@@ -1507,17 +1507,17 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
GTimeVal modification_time;
g_file_info_get_modification_time (task_data->info, &modification_time);
- _gtk_source_file_set_modification_time (saver->priv->file, modification_time);
+ _gtk_source_file_set_modification_time (saver->file, modification_time);
}
}
- if (ok && saver->priv->source_buffer != NULL)
+ if (ok && saver->source_buffer != NULL)
{
- gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (saver->priv->source_buffer),
+ gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (saver->source_buffer),
FALSE);
}
- g_clear_object (&saver->priv->task);
+ g_clear_object (&saver->task);
return ok;
}
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index b835bea9..117a1579 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -33,17 +33,8 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_FILE_SAVER (gtk_source_file_saver_get_type())
-#define GTK_SOURCE_FILE_SAVER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),
GTK_SOURCE_TYPE_FILE_SAVER, GtkSourceFileSaver))
-#define GTK_SOURCE_FILE_SAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),
GTK_SOURCE_TYPE_FILE_SAVER, GtkSourceFileSaverClass))
-#define GTK_SOURCE_IS_FILE_SAVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),
GTK_SOURCE_TYPE_FILE_SAVER))
-#define GTK_SOURCE_IS_FILE_SAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_FILE_SAVER))
-#define GTK_SOURCE_FILE_SAVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),
GTK_SOURCE_TYPE_FILE_SAVER, GtkSourceFileSaverClass))
-
-typedef struct _GtkSourceFileSaverClass GtkSourceFileSaverClass;
-typedef struct _GtkSourceFileSaverPrivate GtkSourceFileSaverPrivate;
-
-#define GTK_SOURCE_FILE_SAVER_ERROR gtk_source_file_saver_error_quark ()
+#define GTK_SOURCE_TYPE_FILE_SAVER (gtk_source_file_saver_get_type())
+#define GTK_SOURCE_FILE_SAVER_ERROR (gtk_source_file_saver_error_quark())
/**
* GtkSourceFileSaverError:
@@ -79,87 +70,56 @@ typedef enum _GtkSourceFileSaverFlags
GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP = 1 << 2
} GtkSourceFileSaverFlags;
-struct _GtkSourceFileSaver
-{
- GObject object;
-
- GtkSourceFileSaverPrivate *priv;
-};
-
-struct _GtkSourceFileSaverClass
-{
- GObjectClass parent_class;
-
- gpointer padding[10];
-};
-
GTK_SOURCE_AVAILABLE_IN_3_14
-GType gtk_source_file_saver_get_type (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (GtkSourceFileSaver, gtk_source_file_saver, GTK_SOURCE, FILE_SAVER, GObject)
GTK_SOURCE_AVAILABLE_IN_3_14
-GQuark gtk_source_file_saver_error_quark (void);
-
+GQuark gtk_source_file_saver_error_quark (void);
GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileSaver *gtk_source_file_saver_new (GtkSourceBuffer *buffer,
- GtkSourceFile *file);
-
+GtkSourceFileSaver *gtk_source_file_saver_new (GtkSourceBuffer *buffer,
+ GtkSourceFile *file);
GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileSaver *gtk_source_file_saver_new_with_target (GtkSourceBuffer *buffer,
- GtkSourceFile *file,
- GFile *target_location);
-
+GtkSourceFileSaver *gtk_source_file_saver_new_with_target (GtkSourceBuffer *buffer,
+ GtkSourceFile *file,
+ GFile
*target_location);
GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceBuffer *gtk_source_file_saver_get_buffer (GtkSourceFileSaver *saver);
-
+GtkSourceBuffer *gtk_source_file_saver_get_buffer (GtkSourceFileSaver *saver);
GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFile *gtk_source_file_saver_get_file (GtkSourceFileSaver *saver);
-
+GtkSourceFile *gtk_source_file_saver_get_file (GtkSourceFileSaver *saver);
GTK_SOURCE_AVAILABLE_IN_3_14
-GFile *gtk_source_file_saver_get_location (GtkSourceFileSaver *saver);
-
+GFile *gtk_source_file_saver_get_location (GtkSourceFileSaver *saver);
GTK_SOURCE_AVAILABLE_IN_3_14
-void gtk_source_file_saver_set_encoding (GtkSourceFileSaver *saver,
- const GtkSourceEncoding *encoding);
-
+void gtk_source_file_saver_set_encoding (GtkSourceFileSaver *saver,
+ const GtkSourceEncoding *encoding);
GTK_SOURCE_AVAILABLE_IN_3_14
-const GtkSourceEncoding *gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver);
-
+const GtkSourceEncoding *gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver);
GTK_SOURCE_AVAILABLE_IN_3_14
-void gtk_source_file_saver_set_newline_type (GtkSourceFileSaver *saver,
- GtkSourceNewlineType newline_type);
-
+void gtk_source_file_saver_set_newline_type (GtkSourceFileSaver *saver,
+ GtkSourceNewlineType
newline_type);
GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceNewlineType gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver);
-
+GtkSourceNewlineType gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver);
GTK_SOURCE_AVAILABLE_IN_3_14
-void gtk_source_file_saver_set_compression_type
- (GtkSourceFileSaver *saver,
- GtkSourceCompressionType compression_type);
-
+void gtk_source_file_saver_set_compression_type (GtkSourceFileSaver *saver,
+ GtkSourceCompressionType
compression_type);
GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceCompressionType gtk_source_file_saver_get_compression_type
- (GtkSourceFileSaver *saver);
-
+GtkSourceCompressionType gtk_source_file_saver_get_compression_type (GtkSourceFileSaver *saver);
GTK_SOURCE_AVAILABLE_IN_3_14
-void gtk_source_file_saver_set_flags (GtkSourceFileSaver *saver,
- GtkSourceFileSaverFlags flags);
-
+void gtk_source_file_saver_set_flags (GtkSourceFileSaver *saver,
+ GtkSourceFileSaverFlags flags);
GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileSaverFlags gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver);
-
+GtkSourceFileSaverFlags gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver);
GTK_SOURCE_AVAILABLE_IN_3_14
-void gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
- gint io_priority,
- GCancellable *cancellable,
- GFileProgressCallback progress_callback,
- gpointer
progress_callback_data,
- GDestroyNotify
progress_callback_notify,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
+void gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
+ gint io_priority,
+ GCancellable *cancellable,
+ GFileProgressCallback
progress_callback,
+ gpointer
progress_callback_data,
+ GDestroyNotify
progress_callback_notify,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
GTK_SOURCE_AVAILABLE_IN_3_14
-gboolean gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
- GAsyncResult *result,
- GError **error);
+gboolean gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
+ GAsyncResult *result,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]