parent
511fc3dfec
commit
5071bfe065
|
@ -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) */
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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))
|
||||
|
@ -57,9 +54,9 @@ G_BEGIN_DECLS
|
|||
|
||||
typedef enum
|
||||
{
|
||||
XED_DOCUMENT_NEWLINE_TYPE_LF,
|
||||
XED_DOCUMENT_NEWLINE_TYPE_CR,
|
||||
XED_DOCUMENT_NEWLINE_TYPE_CR_LF
|
||||
XED_DOCUMENT_NEWLINE_TYPE_LF,
|
||||
XED_DOCUMENT_NEWLINE_TYPE_CR,
|
||||
XED_DOCUMENT_NEWLINE_TYPE_CR_LF
|
||||
} XedDocumentNewlineType;
|
||||
|
||||
#define XED_DOCUMENT_NEWLINE_TYPE_DEFAULT XED_DOCUMENT_NEWLINE_TYPE_LF
|
||||
|
@ -72,67 +69,58 @@ typedef enum
|
|||
*/
|
||||
typedef enum
|
||||
{
|
||||
XED_DOCUMENT_SAVE_IGNORE_MTIME = 1 << 0,
|
||||
XED_DOCUMENT_SAVE_IGNORE_BACKUP = 1 << 1,
|
||||
XED_DOCUMENT_SAVE_PRESERVE_BACKUP = 1 << 2,
|
||||
XED_DOCUMENT_SAVE_IGNORE_MTIME = 1 << 0,
|
||||
XED_DOCUMENT_SAVE_IGNORE_BACKUP = 1 << 1,
|
||||
XED_DOCUMENT_SAVE_PRESERVE_BACKUP = 1 << 2,
|
||||
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 _XedDocument XedDocument;
|
||||
typedef struct _XedDocumentPrivate XedDocumentPrivate;
|
||||
typedef struct _XedDocumentClass XedDocumentClass;
|
||||
|
||||
struct _XedDocument
|
||||
{
|
||||
GtkSourceBuffer buffer;
|
||||
GtkSourceBuffer buffer;
|
||||
|
||||
/*< private > */
|
||||
XedDocumentPrivate *priv;
|
||||
/*< private > */
|
||||
XedDocumentPrivate *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* Class definition
|
||||
*/
|
||||
typedef struct _XedDocumentClass XedDocumentClass;
|
||||
|
||||
struct _XedDocumentClass
|
||||
{
|
||||
GtkSourceBufferClass parent_class;
|
||||
GtkSourceBufferClass parent_class;
|
||||
|
||||
/* Signals */ // CHECK: ancora da rivedere
|
||||
/* Signals */ // CHECK: ancora da rivedere
|
||||
|
||||
void (* cursor_moved) (XedDocument *document);
|
||||
void (* cursor_moved) (XedDocument *document);
|
||||
|
||||
/* Document load */
|
||||
void (* load) (XedDocument *document,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos,
|
||||
gboolean create);
|
||||
/* Document load */
|
||||
void (* load) (XedDocument *document,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos,
|
||||
gboolean create);
|
||||
|
||||
void (* loading) (XedDocument *document,
|
||||
goffset size,
|
||||
goffset total_size);
|
||||
void (* loading) (XedDocument *document,
|
||||
goffset size,
|
||||
goffset total_size);
|
||||
|
||||
void (* loaded) (XedDocument *document,
|
||||
const GError *error);
|
||||
void (* loaded) (XedDocument *document,
|
||||
const GError *error);
|
||||
|
||||
/* Document save */
|
||||
void (* save) (XedDocument *document,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
XedDocumentSaveFlags flags);
|
||||
/* Document save */
|
||||
void (* save) (XedDocument *document,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
XedDocumentSaveFlags flags);
|
||||
|
||||
void (* saving) (XedDocument *document,
|
||||
goffset size,
|
||||
goffset total_size);
|
||||
void (* saving) (XedDocument *document,
|
||||
goffset size,
|
||||
goffset total_size);
|
||||
|
||||
void (* saved) (XedDocument *document,
|
||||
const GError *error);
|
||||
void (* saved) (XedDocument *document,
|
||||
const GError *error);
|
||||
};
|
||||
|
||||
|
||||
|
@ -140,104 +128,96 @@ struct _XedDocumentClass
|
|||
|
||||
enum
|
||||
{
|
||||
XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED,
|
||||
XED_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
|
||||
XED_DOCUMENT_ERROR_TOO_BIG,
|
||||
XED_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED,
|
||||
XED_DOCUMENT_ERROR_CONVERSION_FALLBACK,
|
||||
XED_DOCUMENT_NUM_ERRORS
|
||||
XED_DOCUMENT_ERROR_EXTERNALLY_MODIFIED,
|
||||
XED_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
|
||||
XED_DOCUMENT_ERROR_TOO_BIG,
|
||||
XED_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED,
|
||||
XED_DOCUMENT_ERROR_CONVERSION_FALLBACK,
|
||||
XED_DOCUMENT_NUM_ERRORS
|
||||
};
|
||||
|
||||
GQuark xed_document_error_quark (void);
|
||||
GQuark xed_document_error_quark (void);
|
||||
|
||||
GType xed_document_get_type (void) G_GNUC_CONST;
|
||||
GType xed_document_get_type (void) G_GNUC_CONST;
|
||||
|
||||
XedDocument *xed_document_new (void);
|
||||
XedDocument *xed_document_new (void);
|
||||
|
||||
GFile *xed_document_get_location (XedDocument *doc);
|
||||
GFile *xed_document_get_location (XedDocument *doc);
|
||||
|
||||
void xed_document_set_location (XedDocument *doc,
|
||||
GFile *location);
|
||||
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,
|
||||
const gchar *name);
|
||||
gchar *xed_document_get_short_name_for_display (XedDocument *doc);
|
||||
|
||||
gchar *xed_document_get_content_type
|
||||
(XedDocument *doc);
|
||||
void xed_document_set_short_name_for_display (XedDocument *doc,
|
||||
const gchar *name);
|
||||
|
||||
void xed_document_set_content_type
|
||||
(XedDocument *doc,
|
||||
const gchar *content_type);
|
||||
gchar *xed_document_get_content_type (XedDocument *doc);
|
||||
|
||||
gchar *xed_document_get_mime_type (XedDocument *doc);
|
||||
void xed_document_set_content_type (XedDocument *doc,
|
||||
const gchar *content_type);
|
||||
|
||||
gboolean xed_document_get_readonly (XedDocument *doc);
|
||||
gchar *xed_document_get_mime_type (XedDocument *doc);
|
||||
|
||||
void xed_document_load (XedDocument *doc,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos,
|
||||
gboolean create);
|
||||
gboolean xed_document_get_readonly (XedDocument *doc);
|
||||
|
||||
gboolean xed_document_load_cancel (XedDocument *doc);
|
||||
void xed_document_load (XedDocument *doc,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos,
|
||||
gboolean create);
|
||||
|
||||
void xed_document_save (XedDocument *doc,
|
||||
XedDocumentSaveFlags flags);
|
||||
gboolean xed_document_load_cancel (XedDocument *doc);
|
||||
|
||||
void xed_document_save_as (XedDocument *doc,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
XedDocumentSaveFlags flags);
|
||||
void xed_document_save (XedDocument *doc,
|
||||
XedDocumentSaveFlags flags);
|
||||
|
||||
gboolean xed_document_is_untouched (XedDocument *doc);
|
||||
gboolean xed_document_is_untitled (XedDocument *doc);
|
||||
void xed_document_save_as (XedDocument *doc,
|
||||
GFile *location,
|
||||
const XedEncoding *encoding,
|
||||
XedDocumentSaveFlags flags);
|
||||
|
||||
gboolean xed_document_is_local (XedDocument *doc);
|
||||
gboolean xed_document_is_untouched (XedDocument *doc);
|
||||
gboolean xed_document_is_untitled (XedDocument *doc);
|
||||
|
||||
gboolean xed_document_get_deleted (XedDocument *doc);
|
||||
gboolean xed_document_is_local (XedDocument *doc);
|
||||
|
||||
gboolean xed_document_goto_line (XedDocument *doc,
|
||||
gint line);
|
||||
gboolean xed_document_get_deleted (XedDocument *doc);
|
||||
|
||||
gboolean xed_document_goto_line_offset(XedDocument *doc,
|
||||
gint line,
|
||||
gint line_offset);
|
||||
gboolean xed_document_goto_line (XedDocument *doc,
|
||||
gint line);
|
||||
|
||||
void xed_document_set_language (XedDocument *doc,
|
||||
GtkSourceLanguage *lang);
|
||||
GtkSourceLanguage
|
||||
*xed_document_get_language (XedDocument *doc);
|
||||
gboolean xed_document_goto_line_offset (XedDocument *doc,
|
||||
gint line,
|
||||
gint line_offset);
|
||||
|
||||
const XedEncoding
|
||||
*xed_document_get_encoding (XedDocument *doc);
|
||||
void xed_document_set_language (XedDocument *doc,
|
||||
GtkSourceLanguage *lang);
|
||||
GtkSourceLanguage *xed_document_get_language (XedDocument *doc);
|
||||
|
||||
void xed_document_set_newline_type (XedDocument *doc,
|
||||
XedDocumentNewlineType newline_type);
|
||||
const XedEncoding *xed_document_get_encoding (XedDocument *doc);
|
||||
|
||||
XedDocumentNewlineType
|
||||
xed_document_get_newline_type (XedDocument *doc);
|
||||
void xed_document_set_newline_type (XedDocument *doc,
|
||||
XedDocumentNewlineType newline_type);
|
||||
|
||||
gchar *xed_document_get_metadata (XedDocument *doc,
|
||||
const gchar *key);
|
||||
XedDocumentNewlineType xed_document_get_newline_type (XedDocument *doc);
|
||||
|
||||
void xed_document_set_metadata (XedDocument *doc,
|
||||
const gchar *first_key,
|
||||
...);
|
||||
gchar *xed_document_get_metadata (XedDocument *doc,
|
||||
const gchar *key);
|
||||
|
||||
void xed_document_set_metadata (XedDocument *doc,
|
||||
const gchar *first_key,
|
||||
...);
|
||||
|
||||
/*
|
||||
* Non exported functions
|
||||
*/
|
||||
void _xed_document_set_readonly (XedDocument *doc,
|
||||
gboolean readonly);
|
||||
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);
|
||||
gpointer userdata);
|
||||
|
||||
void _xed_document_set_mount_operation_factory
|
||||
(XedDocument *doc,
|
||||
XedMountOperationFactory callback,
|
||||
gpointer userdata);
|
||||
GMountOperation
|
||||
*_xed_document_create_mount_operation
|
||||
(XedDocument *doc);
|
||||
void _xed_document_set_mount_operation_factory (XedDocument *doc,
|
||||
XedMountOperationFactory callback,
|
||||
gpointer userdata);
|
||||
GMountOperation *_xed_document_create_mount_operation (XedDocument *doc);
|
||||
|
||||
void _xed_document_set_search_context (XedDocument *doc,
|
||||
GtkSourceSearchContext *search_context);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue