[gedit/wip/gedit-document-stuff] GeditDocument: use new API of GtkSourceFile to check file on disk
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/gedit-document-stuff] GeditDocument: use new API of GtkSourceFile to check file on disk
- Date: Thu, 11 Jun 2015 12:17:51 +0000 (UTC)
commit d08808dd709bbc04bbd2b341b055d193787679dc
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Jun 11 14:14:19 2015 +0200
GeditDocument: use new API of GtkSourceFile to check file on disk
gedit/gedit-document.c | 66 +++++++++++-------------------------------------
1 files changed, 15 insertions(+), 51 deletions(-)
---
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 9aa67c2..4ec22ca 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -71,8 +71,6 @@ typedef struct
guint user_action;
guint readonly : 1;
- guint externally_modified : 1;
- guint deleted : 1;
guint language_set_by_user : 1;
guint mtime_set : 1;
guint use_gvfs_metadata : 1;
@@ -1282,8 +1280,6 @@ gedit_document_loaded_real (GeditDocument *doc)
}
priv->mtime_set = FALSE;
- priv->externally_modified = FALSE;
- priv->deleted = FALSE;
g_get_current_time (&priv->time_of_last_save_or_load);
@@ -1357,8 +1353,6 @@ saved_query_info_cb (GFile *location,
g_get_current_time (&priv->time_of_last_save_or_load);
- priv->externally_modified = FALSE;
- priv->deleted = FALSE;
priv->create = FALSE;
set_readonly (doc, FALSE);
@@ -1441,6 +1435,7 @@ gedit_document_is_local (GeditDocument *doc)
return g_file_has_uri_scheme (location, "file");
}
+/* TODO rename this function to check_can_write_file(). */
static void
check_file_on_disk (GeditDocument *doc)
{
@@ -1458,45 +1453,21 @@ check_file_on_disk (GeditDocument *doc)
}
info = g_file_query_info (location,
- G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
- if (info != NULL)
+ if (info != NULL &&
+ g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
{
- /* While at it also check if permissions changed */
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
- {
- gboolean read_only;
-
- read_only = !g_file_info_get_attribute_boolean (info,
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
-
- set_readonly (doc, read_only);
- }
-
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) && priv->mtime_set)
- {
- GTimeVal timeval;
+ gboolean read_only;
- g_file_info_get_modification_time (info, &timeval);
-
- /* Note that mtime can even go backwards if the
- * user is copying over a file with an old mtime
- */
- if (timeval.tv_sec != priv->mtime.tv_sec ||
- timeval.tv_usec != priv->mtime.tv_usec)
- {
- priv->externally_modified = TRUE;
- }
- }
+ read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
- g_object_unref (info);
- }
- else
- {
- priv->deleted = TRUE;
+ set_readonly (doc, read_only);
}
+
+ g_clear_object (&info);
}
gboolean
@@ -1508,12 +1479,7 @@ _gedit_document_check_externally_modified (GeditDocument *doc)
priv = gedit_document_get_instance_private (doc);
- if (!priv->externally_modified)
- {
- check_file_on_disk (doc);
- }
-
- return priv->externally_modified;
+ return gtk_source_file_is_externally_modified (priv->file);
}
/**
@@ -1533,12 +1499,7 @@ gedit_document_get_deleted (GeditDocument *doc)
priv = gedit_document_get_instance_private (doc);
- if (!priv->deleted)
- {
- check_file_on_disk (doc);
- }
-
- return priv->deleted;
+ return gtk_source_file_is_deleted (priv->file);
}
/*
@@ -1548,6 +1509,8 @@ gboolean
_gedit_document_needs_saving (GeditDocument *doc)
{
GeditDocumentPrivate *priv;
+ gboolean externally_modified = FALSE;
+ gboolean deleted = FALSE;
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
@@ -1560,10 +1523,11 @@ _gedit_document_needs_saving (GeditDocument *doc)
if (gedit_document_is_local (doc))
{
- check_file_on_disk (doc);
+ externally_modified = gtk_source_file_is_externally_modified (priv->file);
+ deleted = gtk_source_file_is_deleted (priv->file);
}
- return (priv->externally_modified || priv->deleted) && !priv->create;
+ return (externally_modified || deleted) && !priv->create;
}
/* If @line is bigger than the lines of the document, the cursor is moved
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]