Add _xed_document_needs_saving

Based on acbf4d4f0c
This commit is contained in:
JosephMcc 2017-01-29 03:28:52 -08:00
parent 511fc3dfec
commit 5071bfe065
4 changed files with 140 additions and 147 deletions

View File

@ -806,24 +806,6 @@ _xed_cmd_file_save_as (GtkAction *action,
file_save_as (tab, window);
}
static gboolean
document_needs_saving (XedDocument *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 (xed_document_is_local (doc) && xed_document_get_deleted (doc))
{
return TRUE;
}
return FALSE;
}
/*
* The docs in the list must belong to the same XedWindow.
*/
@ -863,7 +845,7 @@ _xed_cmd_file_save_documents_list (XedWindow *window,
user is running xed - Paolo (Dec. 8, 2005) */
if (xed_document_is_untitled (doc) || xed_document_get_readonly (doc))
{
if (document_needs_saving (doc))
if (_xed_document_needs_saving (doc))
{
tabs_to_save_as = g_slist_prepend (tabs_to_save_as, t);
}
@ -1214,7 +1196,7 @@ tab_state_changed_while_saving (XedTab *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 (_xed_document_needs_saving (doc))
{
return;
}
@ -1327,7 +1309,7 @@ save_and_close_all_documents (const GList *docs,
(state != XED_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 (_xed_document_needs_saving (doc));
/* FIXME: manage the case of local readonly files owned by the
user is running xed - Paolo (Dec. 8, 2005) */

View File

@ -1674,6 +1674,37 @@ xed_document_get_deleted (XedDocument *doc)
return doc->priv->deleted;
}
/*
* Deletion and external modification is only checked for local files.
*/
gboolean
_xed_document_needs_saving (XedDocument *doc)
{
g_return_val_if_fail (XED_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 (xed_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.

View File

@ -41,9 +41,6 @@
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define XED_TYPE_DOCUMENT (xed_document_get_type())
#define XED_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_DOCUMENT, XedDocument))
#define XED_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_DOCUMENT, XedDocumentClass))
@ -78,13 +75,9 @@ typedef enum
XED_DOCUMENT_SAVE_IGNORE_INVALID_CHARS = 1 << 3
} XedDocumentSaveFlags;
/* Private structure type */
typedef struct _XedDocumentPrivate XedDocumentPrivate;
/*
* Main object structure
*/
typedef struct _XedDocument XedDocument;
typedef struct _XedDocumentPrivate XedDocumentPrivate;
typedef struct _XedDocumentClass XedDocumentClass;
struct _XedDocument
{
@ -94,11 +87,6 @@ struct _XedDocument
XedDocumentPrivate *priv;
};
/*
* Class definition
*/
typedef struct _XedDocumentClass XedDocumentClass;
struct _XedDocumentClass
{
GtkSourceBufferClass parent_class;
@ -159,20 +147,16 @@ GFile *xed_document_get_location (XedDocument *doc);
void xed_document_set_location (XedDocument *doc,
GFile *location);
gchar *xed_document_get_uri_for_display
(XedDocument *doc);
gchar *xed_document_get_short_name_for_display
(XedDocument *doc);
gchar *xed_document_get_uri_for_display (XedDocument *doc);
void xed_document_set_short_name_for_display
(XedDocument *doc,
gchar *xed_document_get_short_name_for_display (XedDocument *doc);
void xed_document_set_short_name_for_display (XedDocument *doc,
const gchar *name);
gchar *xed_document_get_content_type
(XedDocument *doc);
gchar *xed_document_get_content_type (XedDocument *doc);
void xed_document_set_content_type
(XedDocument *doc,
void xed_document_set_content_type (XedDocument *doc,
const gchar *content_type);
gchar *xed_document_get_mime_type (XedDocument *doc);
@ -211,17 +195,14 @@ gboolean xed_document_goto_line_offset(XedDocument *doc,
void xed_document_set_language (XedDocument *doc,
GtkSourceLanguage *lang);
GtkSourceLanguage
*xed_document_get_language (XedDocument *doc);
GtkSourceLanguage *xed_document_get_language (XedDocument *doc);
const XedEncoding
*xed_document_get_encoding (XedDocument *doc);
const XedEncoding *xed_document_get_encoding (XedDocument *doc);
void xed_document_set_newline_type (XedDocument *doc,
XedDocumentNewlineType newline_type);
XedDocumentNewlineType
xed_document_get_newline_type (XedDocument *doc);
XedDocumentNewlineType xed_document_get_newline_type (XedDocument *doc);
gchar *xed_document_get_metadata (XedDocument *doc,
const gchar *key);
@ -236,8 +217,7 @@ void xed_document_set_metadata (XedDocument *doc,
void _xed_document_set_readonly (XedDocument *doc,
gboolean readonly);
glong _xed_document_get_seconds_since_last_save_or_load
(XedDocument *doc);
glong _xed_document_get_seconds_since_last_save_or_load (XedDocument *doc);
void _xed_document_apply_error_style (XedDocument *doc,
GtkTextIter *start,
@ -248,19 +228,17 @@ void _xed_document_apply_error_style (XedDocument *doc,
GtkTextIter *end);
/* Note: this is a sync stat: use only on local files */
gboolean _xed_document_check_externally_modified
(XedDocument *doc);
gboolean _xed_document_check_externally_modified (XedDocument *doc);
gboolean _xed_document_needs_saving (XedDocument *doc);
typedef GMountOperation *(*XedMountOperationFactory)(XedDocument *doc,
gpointer userdata);
void _xed_document_set_mount_operation_factory
(XedDocument *doc,
void _xed_document_set_mount_operation_factory (XedDocument *doc,
XedMountOperationFactory callback,
gpointer userdata);
GMountOperation
*_xed_document_create_mount_operation
(XedDocument *doc);
GMountOperation *_xed_document_create_mount_operation (XedDocument *doc);
void _xed_document_set_search_context (XedDocument *doc,
GtkSourceSearchContext *search_context);

View File

@ -2501,10 +2501,12 @@ _xed_tab_can_close (XedTab *tab)
doc = xed_tab_get_document (tab);
/* TODO: we need to save the file also if it has been externally
modified - Paolo (Oct 10, 2005) */
if (_xed_document_needs_saving (doc))
{
return FALSE;
}
return (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)) && !xed_document_get_deleted (doc));
return TRUE;
}
/**