[gtksourceview/wip/loader-saver: 22/31] Make gtk_source_file_set_location() public
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver: 22/31] Make gtk_source_file_set_location() public
- Date: Sun, 6 Jul 2014 13:23:09 +0000 (UTC)
commit 9e7c0b92a4d3404157ed5425f0a4452c8783c538
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jun 13 16:36:11 2014 +0200
Make gtk_source_file_set_location() public
It will be used by gedit_document_set_location(), which is used by the
file browser plugin when a file is renamed.
docs/reference/gtksourceview-3.0-sections.txt | 1 +
gtksourceview/gtksourcefile.c | 44 +++++++++++++++++++-----
gtksourceview/gtksourcefile.h | 7 ++--
gtksourceview/gtksourcefileloader.c | 6 ++--
gtksourceview/gtksourcefilesaver.c | 4 +-
5 files changed, 44 insertions(+), 18 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 0a00f9d..16bde97 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -240,6 +240,7 @@ GtkSourceMountOperationFactory
gtk_source_file_new
gtk_source_file_get_buffer
gtk_source_file_get_location
+gtk_source_file_set_location
gtk_source_file_get_encoding
gtk_source_file_get_newline_type
gtk_source_file_get_compression_type
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 8cd0155..3cde450 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -34,10 +34,10 @@
* A #GtkSourceFile object is the on-disk representation of a #GtkSourceBuffer.
* With a #GtkSourceFile, you can create and configure a #GtkSourceFileLoader
* and #GtkSourceFileSaver which take by default the values of the
- * #GtkSourceFile properties (except for the file loader which always
- * auto-detect some properties). On a successful load or save operation, the
- * #GtkSourceFile properties are updated. But an application cannot modify
- * directly the #GtkSourceFile properties.
+ * #GtkSourceFile properties (except for the file loader which auto-detect some
+ * properties). On a successful load or save operation, the #GtkSourceFile
+ * properties are updated. If an operation fails, the #GtkSourceFile properties
+ * have still the previous valid values.
*/
enum
@@ -138,6 +138,10 @@ gtk_source_file_set_property (GObject *object,
(gpointer *) &file->priv->buffer);
break;
+ case PROP_LOCATION:
+ gtk_source_file_set_location (file, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -208,7 +212,7 @@ gtk_source_file_class_init (GtkSourceFileClass *klass)
_("Location"),
"",
G_TYPE_FILE,
- G_PARAM_READABLE |
+ G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
@@ -302,17 +306,39 @@ gtk_source_file_get_buffer (GtkSourceFile *file)
return file->priv->buffer;
}
+/**
+ * gtk_source_file_set_location:
+ * @file: a #GtkSourceFile.
+ * @location: (nullable): the new #GFile, or %NULL.
+ *
+ * Sets the location. Most of the time it is better to change the location with a
+ * #GtkSourceFileLoader or #GtkSourceFileSaver. By doing so, the location of
+ * #GtkSourceFile is updated only when the file loading or saving have
+ * succeeded.
+ *
+ * One use case of this function is when your application renames the file (with
+ * g_file_move() for instance). In this case you don't want to reload the file
+ * from the new location.
+ *
+ * Since: 3.14
+ */
void
-_gtk_source_file_set_location (GtkSourceFile *file,
- GFile *location)
+gtk_source_file_set_location (GtkSourceFile *file,
+ GFile *location)
{
g_return_if_fail (GTK_SOURCE_IS_FILE (file));
- g_return_if_fail (G_IS_FILE (location));
+ g_return_if_fail (location == NULL || G_IS_FILE (location));
if (file->priv->location != location)
{
g_clear_object (&file->priv->location);
- file->priv->location = g_object_ref (location);
+ file->priv->location = location;
+
+ if (location != NULL)
+ {
+ g_object_ref (location);
+ }
+
g_object_notify (G_OBJECT (file), "location");
/* The modification_time is for the old location. */
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index fcae301..2fb1ff3 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -70,6 +70,9 @@ GtkSourceBuffer *gtk_source_file_get_buffer (GtkSourceFile *file);
GFile *gtk_source_file_get_location (GtkSourceFile *file);
+void gtk_source_file_set_location (GtkSourceFile *file,
+ GFile *location);
+
const GtkSourceEncoding *
gtk_source_file_get_encoding (GtkSourceFile *file);
@@ -85,10 +88,6 @@ void gtk_source_file_set_mount_operation_factory (GtkSourceFile
GDestroyNotify notify);
G_GNUC_INTERNAL
-void _gtk_source_file_set_location (GtkSourceFile *file,
- GFile *location);
-
-G_GNUC_INTERNAL
void _gtk_source_file_set_encoding (GtkSourceFile *file,
const GtkSourceEncoding *encoding);
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 8759283..7f9dc06 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -959,12 +959,12 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader *loader,
{
if (loader->priv->input_stream_property != NULL)
{
- _gtk_source_file_set_location (loader->priv->file, NULL);
+ gtk_source_file_set_location (loader->priv->file, NULL);
}
else
{
- _gtk_source_file_set_location (loader->priv->file,
- loader->priv->location);
+ gtk_source_file_set_location (loader->priv->file,
+ loader->priv->location);
}
_gtk_source_file_set_encoding (loader->priv->file,
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 6e1e5ab..d14ef80 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -1258,8 +1258,8 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
if (ok && saver->priv->file != NULL)
{
- _gtk_source_file_set_location (saver->priv->file,
- saver->priv->location);
+ gtk_source_file_set_location (saver->priv->file,
+ saver->priv->location);
_gtk_source_file_set_encoding (saver->priv->file,
saver->priv->encoding);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]