[gtksourceview: 2/2] file: make check_file_on_disk() public
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview: 2/2] file: make check_file_on_disk() public
- Date: Sat, 13 Jun 2015 14:36:18 +0000 (UTC)
commit 61fbda026d78f26ac4a23072c29b9fb0ae528ba5
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Jun 11 20:06:13 2015 +0200
file: make check_file_on_disk() public
is_readonly() must not call check_file_on_disk(), because most of the
code using it will call is_readonly() just after receiving a notify
signal for the property.
So check_file_on_disk() needs to be public.
Since check_file_on_disk() is public, and for consistency, adapt
is_externally_modified() and is_deleted() to not call
check_file_on_disk(). This is better so only one call to
check_file_on_disk() is needed to retrieve all the properties.
docs/reference/gtksourceview-3.0-sections.txt | 1 +
gtksourceview/gtksourcefile.c | 50 +++++++++++++++----------
gtksourceview/gtksourcefile.h | 2 +
3 files changed, 33 insertions(+), 20 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 41970d5..5a1f093 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -250,6 +250,7 @@ gtk_source_file_set_location
gtk_source_file_get_encoding
gtk_source_file_get_newline_type
gtk_source_file_get_compression_type
+gtk_source_file_check_file_on_disk
gtk_source_file_is_externally_modified
gtk_source_file_is_deleted
gtk_source_file_is_readonly
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 5335a45..cdd22d8 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -479,8 +479,21 @@ _gtk_source_file_set_modification_time (GtkSourceFile *file,
}
}
-static void
-check_file_on_disk (GtkSourceFile *file)
+/**
+ * gtk_source_file_check_file_on_disk:
+ * @file: a #GtkSourceFile.
+ *
+ * Checks synchronously the file on disk, to know whether the file is externally
+ * modified, or has been deleted, and whether the file is read-only.
+ *
+ * #GtkSourceFile doesn't create a #GFileMonitor to track those properties, so
+ * this function needs to be called instead. Creating lots of #GFileMonitor's
+ * would take lots of resources.
+ *
+ * Since: 3.18
+ */
+void
+gtk_source_file_check_file_on_disk (GtkSourceFile *file)
{
GFileInfo *info;
@@ -544,8 +557,11 @@ _gtk_source_file_set_externally_modified (GtkSourceFile *file,
* gtk_source_file_is_externally_modified:
* @file: a #GtkSourceFile.
*
- * Checks synchronously whether the file is externally modified. If the
- * #GtkSourceFile:location is %NULL, returns FALSE.
+ * Returns whether the file is externally modified. If the
+ * #GtkSourceFile:location is %NULL, returns %FALSE.
+ *
+ * To have an up-to-date value, you must first call
+ * gtk_source_file_check_file_on_disk().
*
* Returns: whether the file is externally modified.
* Since: 3.18
@@ -555,11 +571,6 @@ gtk_source_file_is_externally_modified (GtkSourceFile *file)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
- if (!file->priv->externally_modified)
- {
- check_file_on_disk (file);
- }
-
return file->priv->externally_modified;
}
@@ -576,8 +587,11 @@ _gtk_source_file_set_deleted (GtkSourceFile *file,
* gtk_source_file_is_deleted:
* @file: a #GtkSourceFile.
*
- * Checks synchronously whether the file has been deleted. If the
- * #GtkSourceFile:location is %NULL, returns FALSE.
+ * Returns whether the file has been deleted. If the
+ * #GtkSourceFile:location is %NULL, returns %FALSE.
+ *
+ * To have an up-to-date value, you must first call
+ * gtk_source_file_check_file_on_disk().
*
* Returns: whether the file has been deleted.
* Since: 3.18
@@ -587,11 +601,6 @@ gtk_source_file_is_deleted (GtkSourceFile *file)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
- if (!file->priv->deleted)
- {
- check_file_on_disk (file);
- }
-
return file->priv->deleted;
}
@@ -614,8 +623,11 @@ _gtk_source_file_set_readonly (GtkSourceFile *file,
* gtk_source_file_is_readonly:
* @file: a #GtkSourceFile.
*
- * Checks synchronously whether the file is read-only. If the
- * #GtkSourceFile:location is %NULL, returns FALSE.
+ * Returns whether the file is read-only. If the
+ * #GtkSourceFile:location is %NULL, returns %FALSE.
+ *
+ * To have an up-to-date value, you must first call
+ * gtk_source_file_check_file_on_disk().
*
* Returns: whether the file is read-only.
* Since: 3.18
@@ -625,7 +637,5 @@ gtk_source_file_is_readonly (GtkSourceFile *file)
{
g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
- check_file_on_disk (file);
-
return file->priv->readonly;
}
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index 6bc956c..3ddc8df 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -87,6 +87,8 @@ void gtk_source_file_set_mount_operation_factory (GtkSourceFile
gpointer user_data,
GDestroyNotify notify);
+void gtk_source_file_check_file_on_disk (GtkSourceFile *file);
+
gboolean gtk_source_file_is_externally_modified (GtkSourceFile *file);
gboolean gtk_source_file_is_deleted (GtkSourceFile *file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]