[gtksourceview/wip/loader-saver] FileLoader: remove location param from constructor
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver] FileLoader: remove location param from constructor
- Date: Tue, 8 Jul 2014 19:24:39 +0000 (UTC)
commit 2f655b78edf8da4408510c3068046f6be1735587
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Jul 8 21:19:39 2014 +0200
FileLoader: remove location param from constructor
gtksourceview/gtksourcefileloader.c | 40 ++++++++++++++++++++++++++++------
gtksourceview/gtksourcefileloader.h | 3 +-
gtksourceview/gtksourcefilesaver.c | 2 +-
tests/test-file-loader.c | 3 +-
4 files changed, 37 insertions(+), 11 deletions(-)
---
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 08bcbc1..0537985 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -267,6 +267,22 @@ gtk_source_file_loader_constructed (GObject *object)
g_slist_free (loader->priv->candidate_encodings);
loader->priv->candidate_encodings = g_slist_prepend (NULL, (gpointer) encoding);
+
+ if (loader->priv->location == NULL &&
+ loader->priv->input_stream_property == NULL)
+ {
+ loader->priv->location = gtk_source_file_get_location (loader->priv->file);
+
+ if (loader->priv->location != NULL)
+ {
+ g_object_ref (loader->priv->location);
+ }
+ else
+ {
+ g_warning ("GtkSourceFileLoader: the GtkSourceFile's location is NULL. "
+ "Call gtk_source_file_set_location() or read from a
GInputStream.");
+ }
+ }
}
G_OBJECT_CLASS (gtk_source_file_loader_parent_class)->dispose (object);
@@ -319,7 +335,9 @@ gtk_source_file_loader_class_init (GtkSourceFileLoaderClass *klass)
/**
* GtkSourceFileLoader:location:
*
- * The #GFile to load.
+ * The #GFile to load. If set to %NULL and if the
+ * #GtkSourceFileLoader:input-stream is %NULL too, the #GtkSourceFile's
+ * #GtkSourceFile:location is taken at construction time.
*
* Since: 3.14
*/
@@ -754,24 +772,29 @@ gtk_source_file_loader_error_quark (void)
* gtk_source_file_loader_new:
* @buffer: the #GtkSourceBuffer to load the contents into.
* @file: the #GtkSourceFile.
- * @location: the #GFile to load.
+ *
+ * Creates a new #GtkSourceFileLoader object. The contents is read from the
+ * @file's #GtkSourceFile:location. If not already done, set the @file's
+ * location with gtk_source_file_set_location() before calling this constructor.
+ * The previous location is anyway not needed, because as soon as the file
+ * loading begins, the @buffer is emptied.
+ *
+ * The file loader's #GtkSourceFileLoader:location is set at construction time
+ * with the @file's #GtkSourceFile:location value.
*
* Returns: a new #GtkSourceFileLoader object.
* Since: 3.14
*/
GtkSourceFileLoader *
gtk_source_file_loader_new (GtkSourceBuffer *buffer,
- GtkSourceFile *file,
- GFile *location)
+ GtkSourceFile *file)
{
g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
- g_return_val_if_fail (G_IS_FILE (location), NULL);
return g_object_new (GTK_SOURCE_TYPE_FILE_LOADER,
"buffer", buffer,
"file", file,
- "location", location,
NULL);
}
@@ -781,6 +804,8 @@ gtk_source_file_loader_new (GtkSourceBuffer *buffer,
* @file: the #GtkSourceFile.
* @stream: the #GInputStream to load, e.g. stdin.
*
+ * Creates a new #GtkSourceFileLoader object. The contents is read from @stream.
+ *
* Returns: a new #GtkSourceFileLoader object.
* Since: 3.14
*/
@@ -926,7 +951,8 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader *loader,
g_return_if_fail (loader->priv->task == NULL);
if (loader->priv->source_buffer == NULL ||
- loader->priv->file == NULL)
+ loader->priv->file == NULL ||
+ (loader->priv->location == NULL && loader->priv->input_stream_property == NULL))
{
return;
}
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index 2ca1167..59d67b6 100644
--- a/gtksourceview/gtksourcefileloader.h
+++ b/gtksourceview/gtksourcefileloader.h
@@ -78,8 +78,7 @@ GType gtk_source_file_loader_get_type (void) G_GNUC_CONST;
GQuark gtk_source_file_loader_error_quark (void);
GtkSourceFileLoader *gtk_source_file_loader_new (GtkSourceBuffer *buffer,
- GtkSourceFile *file,
- GFile *location);
+ GtkSourceFile *file);
GtkSourceFileLoader *gtk_source_file_loader_new_from_stream (GtkSourceBuffer *buffer,
GtkSourceFile *file,
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 539eef5..222bde5 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -300,7 +300,7 @@ gtk_source_file_saver_constructed (GObject *object)
}
else
{
- g_warning ("GtkSourceFileSaver: GtkSourceFile's location is NULL. "
+ g_warning ("GtkSourceFileSaver: the GtkSourceFile's location is NULL. "
"Use gtk_source_file_saver_new_with_target().");
}
}
diff --git a/tests/test-file-loader.c b/tests/test-file-loader.c
index fe9cfa8..9d5d621 100644
--- a/tests/test-file-loader.c
+++ b/tests/test-file-loader.c
@@ -99,7 +99,8 @@ test_loader (const gchar *filename,
location = g_file_new_for_path (filename);
buffer = gtk_source_buffer_new (NULL);
file = gtk_source_file_new ();
- loader = gtk_source_file_loader_new (buffer, file, location);
+ gtk_source_file_set_location (file, location);
+ loader = gtk_source_file_loader_new (buffer, file);
candidate_encodings = g_slist_prepend (NULL, (gpointer) gtk_source_encoding_get_utf8 ());
gtk_source_file_loader_set_candidate_encodings (loader, candidate_encodings);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]