[gedit] Add _gedit_document_needs_saving
- From: Volker Sobek <vsobek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Add _gedit_document_needs_saving
- Date: Sat, 23 Nov 2013 14:01:21 +0000 (UTC)
commit acbf4d4f0cea28744147eafff96ed601db43c86a
Author: Volker Sobek <reklov live com>
Date: Fri Nov 22 01:05:38 2013 +0100
Add _gedit_document_needs_saving
Use the new function in place of the previously used helper function
document_needs_saving in gedit/gedit-commands-file.c and similar code
in gedit/gedit-tab.c.
Notice: document_needs_saving didn't check if the doc had been
externally modified, which _gedit_document_needs_saving now does.
_gedit_document_needs_saving does not check remote files for external
modification or deletion. The code it replaces didn't do that either.
https://bugzilla.gnome.org/show_bug.cgi?id=379778
gedit/gedit-commands-file.c | 20 +++-----------------
gedit/gedit-document.c | 33 +++++++++++++++++++++++++++++++++
gedit/gedit-document.h | 2 ++
gedit/gedit-tab.c | 9 +--------
4 files changed, 39 insertions(+), 25 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index fdf4654..66a9b69 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -990,20 +990,6 @@ _gedit_cmd_file_save_as (GtkAction *action,
_gedit_cmd_file_save_as_tab (tab, window);
}
-static gboolean
-document_needs_saving (GeditDocument *doc)
-{
- if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
- return TRUE;
-
- /* we check if it was deleted only for local files
- * since for remote files it may hang */
- if (gedit_document_is_local (doc) && gedit_document_get_deleted (doc))
- return TRUE;
-
- return FALSE;
-}
-
/*
* The docs in the list must belong to the same GeditWindow.
*/
@@ -1045,7 +1031,7 @@ _gedit_cmd_file_save_documents_list (GeditWindow *window,
if (gedit_document_is_untitled (doc) ||
gedit_document_get_readonly (doc))
{
- if (document_needs_saving (doc))
+ if (_gedit_document_needs_saving (doc))
{
tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
t);
@@ -1420,7 +1406,7 @@ tab_state_changed_while_saving (GeditTab *tab,
/* If the saving operation failed or was interrupted, then the
document is still "modified" -> do not close the tab */
- if (document_needs_saving (doc))
+ if (_gedit_document_needs_saving (doc))
return;
/* Close the document only if it has been succesfully saved.
@@ -1542,7 +1528,7 @@ save_and_close_all_documents (const GList *docs,
(state != GEDIT_TAB_STATE_REVERTING)) /* CHECK: is this the right behavior with
REVERTING ?*/
{
/* The document must be saved before closing */
- g_return_if_fail (document_needs_saving (doc));
+ g_return_if_fail (_gedit_document_needs_saving (doc));
/* FIXME: manage the case of local readonly files owned by the
user is running gedit - Paolo (Dec. 8, 2005) */
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 40bce93..33b4bd5 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -2031,6 +2031,39 @@ gedit_document_get_deleted (GeditDocument *doc)
}
/*
+ * Deletion and external modification is only checked for local files.
+ */
+gboolean
+_gedit_document_needs_saving (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+
+ if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
+ {
+ return TRUE;
+ }
+
+ if (doc->priv->externally_modified ||
+ doc->priv->deleted)
+ {
+ return TRUE;
+ }
+
+ if (gedit_document_is_local (doc))
+ {
+ check_file_on_disk (doc);
+
+ if (doc->priv->externally_modified ||
+ doc->priv->deleted)
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+/*
* If @line is bigger than the lines of the document, the cursor is moved
* to the last line and FALSE is returned.
*/
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index 7ce4d3a..7696062 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -347,6 +347,8 @@ void _gedit_document_apply_error_style
gboolean _gedit_document_check_externally_modified
(GeditDocument *doc);
+gboolean _gedit_document_needs_saving (GeditDocument *doc);
+
/* Search macros */
#define GEDIT_SEARCH_IS_DONT_SET_FLAGS(sflags) ((sflags & GEDIT_SEARCH_DONT_SET_FLAGS) != 0)
#define GEDIT_SEARCH_SET_DONT_SET_FLAGS(sflags,state) ((state == TRUE) ? \
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index bf316fd..e950e55 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -2760,14 +2760,7 @@ _gedit_tab_get_can_close (GeditTab *tab)
doc = gedit_tab_get_document (tab);
- if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
- {
- return FALSE;
- }
-
- if (gedit_document_is_local (doc) &&
- (gedit_document_get_deleted (doc) ||
- _gedit_document_check_externally_modified (doc)))
+ if (_gedit_document_needs_saving (doc))
{
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]