[gtksourceview/wip/loader-saver: 2/3] Remove the GtkSourceFileLoader:location property



commit e424fefcab2440b1d3f74ac65a1c31b85ccda9ee
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 7 21:12:59 2014 +0200

    Remove the GtkSourceFileLoader:location property

 docs/reference/gtksourceview-3.0-sections.txt |    1 -
 gtksourceview/gtksourcefileloader.c           |   87 ++++++-------------------
 gtksourceview/gtksourcefileloader.h           |    5 +-
 tests/test-file-loader.c                      |    3 +-
 4 files changed, 24 insertions(+), 72 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index d188cd6..2c898c9 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -269,7 +269,6 @@ gtk_source_file_loader_new_from_stream
 gtk_source_file_loader_set_candidate_encodings
 gtk_source_file_loader_get_buffer
 gtk_source_file_loader_get_file
-gtk_source_file_loader_get_location
 gtk_source_file_loader_get_input_stream
 gtk_source_file_loader_load_async
 gtk_source_file_loader_load_finish
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 08bcbc1..aab03d5 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -51,7 +51,6 @@ enum
        PROP_0,
        PROP_BUFFER,
        PROP_FILE,
-       PROP_LOCATION,
        PROP_INPUT_STREAM
 };
 
@@ -156,11 +155,6 @@ gtk_source_file_loader_set_property (GObject      *object,
                                                   (gpointer *)&loader->priv->file);
                        break;
 
-               case PROP_LOCATION:
-                       g_assert (loader->priv->location == NULL);
-                       loader->priv->location = g_value_dup_object (value);
-                       break;
-
                case PROP_INPUT_STREAM:
                        g_assert (loader->priv->input_stream_property == NULL);
                        loader->priv->input_stream_property = g_value_dup_object (value);
@@ -190,10 +184,6 @@ gtk_source_file_loader_get_property (GObject    *object,
                        g_value_set_object (value, loader->priv->file);
                        break;
 
-               case PROP_LOCATION:
-                       g_value_set_object (value, loader->priv->location);
-                       break;
-
                case PROP_INPUT_STREAM:
                        g_value_set_object (value, loader->priv->input_stream_property);
                        break;
@@ -207,6 +197,7 @@ gtk_source_file_loader_get_property (GObject    *object,
 static void
 reset (GtkSourceFileLoader *loader)
 {
+       g_clear_object (&loader->priv->location);
        g_clear_object (&loader->priv->task);
        g_clear_object (&loader->priv->input_stream);
        g_clear_object (&loader->priv->output_stream);
@@ -245,7 +236,6 @@ gtk_source_file_loader_dispose (GObject *object)
                loader->priv->file = NULL;
        }
 
-       g_clear_object (&loader->priv->location);
        g_clear_object (&loader->priv->input_stream_property);
 
        g_slist_free (loader->priv->candidate_encodings);
@@ -317,26 +307,11 @@ gtk_source_file_loader_class_init (GtkSourceFileLoaderClass *klass)
                                                              G_PARAM_STATIC_STRINGS));
 
        /**
-        * GtkSourceFileLoader:location:
-        *
-        * The #GFile to load.
-        *
-        * Since: 3.14
-        */
-       g_object_class_install_property (object_class, PROP_LOCATION,
-                                        g_param_spec_object ("location",
-                                                             _("Location"),
-                                                             "",
-                                                             G_TYPE_FILE,
-                                                             G_PARAM_READWRITE |
-                                                             G_PARAM_CONSTRUCT_ONLY |
-                                                             G_PARAM_STATIC_STRINGS));
-
-       /**
         * GtkSourceFileLoader:input-stream:
         *
         * The #GInputStream to load. Useful for reading stdin. If this property
-        * is set, the #GtkSourceFileLoader:location property is ignored.
+        * is %NULL, the contents is read from the #GtkSourceFile's "location"
+        * property.
         *
         * Since: 3.14
         */
@@ -754,24 +729,23 @@ 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 #GtkSourceFileLoader object. The contents will be read from the
+ * @file's #GtkSourceFile:location property.
  *
  * 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 +755,9 @@ gtk_source_file_loader_new (GtkSourceBuffer *buffer,
  * @file: the #GtkSourceFile.
  * @stream: the #GInputStream to load, e.g. stdin.
  *
+ * Creates a #GtkSourceFileLoader object. The contents will be read from the
+ * @stream.
+ *
  * Returns: a new #GtkSourceFileLoader object.
  * Since: 3.14
  */
@@ -853,22 +830,6 @@ gtk_source_file_loader_get_file (GtkSourceFileLoader *loader)
 }
 
 /**
- * gtk_source_file_loader_get_location:
- * @loader: a #GtkSourceFileLoader.
- *
- * Returns: (transfer none): the #GFile to load, or %NULL if an input stream is
- *   used.
- * Since: 3.14
- */
-GFile *
-gtk_source_file_loader_get_location (GtkSourceFileLoader *loader)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
-
-       return loader->priv->location;
-}
-
-/**
  * gtk_source_file_loader_get_input_stream:
  * @loader: a #GtkSourceFileLoader.
  *
@@ -933,6 +894,17 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
 
        reset (loader);
 
+       if (loader->priv->input_stream_property == NULL)
+       {
+               loader->priv->location = gtk_source_file_get_location (loader->priv->file);
+               g_return_if_fail (loader->priv->location != NULL);
+               g_object_ref (loader->priv->location);
+       }
+       else
+       {
+               gtk_source_file_set_location (loader->priv->file, NULL);
+       }
+
        loader->priv->task = g_task_new (loader, cancellable, callback, user_data);
        g_task_set_priority (loader->priv->task, io_priority);
 
@@ -944,23 +916,6 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
               g_print ("Start loading\n");
        });
 
-       /* Update GtkSourceFile location directly. The other GtkSourceFile
-        * properties are updated when the operation is finished. But since the
-        * file is loaded, the previous contents is lost, so the previous
-        * location is anyway not needed. And for display purposes, the new
-        * location is directly needed (for example to display the filename in a
-        * tab or an info bar with the progress information).
-        */
-       if (loader->priv->input_stream_property != NULL)
-       {
-               gtk_source_file_set_location (loader->priv->file, NULL);
-       }
-       else
-       {
-               gtk_source_file_set_location (loader->priv->file,
-                                             loader->priv->location);
-       }
-
        implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(loader->priv->source_buffer);
 
        /* The BufferOutputStream has a strong reference to the buffer.
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index 2ca1167..8acf1ed 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,
@@ -93,8 +92,6 @@ GtkSourceBuffer               *gtk_source_file_loader_get_buffer      (GtkSourceFileLoader  
   *lo
 
 GtkSourceFile          *gtk_source_file_loader_get_file        (GtkSourceFileLoader     *loader);
 
-GFile                  *gtk_source_file_loader_get_location    (GtkSourceFileLoader     *loader);
-
 GInputStream           *gtk_source_file_loader_get_input_stream
                                                                (GtkSourceFileLoader     *loader);
 
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]