Commit 5fabbccf authored by Paolo Maggi's avatar Paolo Maggi Committed by Paolo Maggi

Re-added autosave feature. Based on a patch by Sergio Villar Senin

2006-01-19  Paolo Maggi  <paolo@gnome.org>

	Re-added autosave feature.
	Based on a patch by Sergio Villar Senin <svillar@igalia.com>

	* gedit/gedit-debug.[ch]: s/GEDIT_DEBUG_FILE/GEDIT_DEBUG_TAB

	* gedit/gedit-document.c (gedit_document_finalize)
	(gedit_document_init) (set_readonly) (gedit_document_get_encoding):
	remove autosave related functions (moved to gedit-tab.c)

	* gedit/gedit-document.h: remove autosave related functions (moved to
	gedit-tab.h)

	* gedit/gedit-prefs-manager-app.c
	(gedit_prefs_manager_auto_save_changed): use new functions for autosave

	* gedit/gedit-tab.c (install_auto_save_timeout)
	(install_auto_save_timeout_if_needed) (remove_auto_save_timeout)
	(gedit_tab_get_property) (gedit_tab_set_property)
	(gedit_tab_finalize) (gedit_tab_class_init)
	(document_uri_notify_handler)
	(recoverable_loading_error_message_area_response)
	(unrecoverable_reverting_error_message_area_response)
	(show_loading_message_area) (show_saving_message_area)
	(message_area_set_progress) (document_loading) (document_loaded)
	(document_saving) (end_saving)
	(unrecoverable_saving_error_message_area_response)
	(no_backup_error_message_area_response)
	(externally_modified_error_message_area_response)
	(recoverable_saving_error_message_area_response) (document_saved)
	(gedit_tab_init) (_gedit_tab_load) (_gedit_tab_revert)
	(_gedit_tab_save) (gedit_tab_auto_save) (_gedit_tab_save_as)
	(gedit_tab_get_auto_save_enabled) (gedit_tab_set_auto_save_enabled)
	(gedit_tab_get_auto_save_interval)
	(gedit_tab_set_auto_save_interval): implemented autosave feature.
	It works in the following way:
	- the auto_save_timeout timeout is used to call gedit_document_auto_save
	  every X minutes
	- when a file is loaded or saved the timeout is removed (to avoid the
	  case in which autosave is called while loading/saving)
	- when a file has been loaded/saved, if needed, the timeout is
	  re-created and so gedit_document_auto_save will be called after X
	  minutes again

	* gedit/gedit-tab.h: new functions related to autosave

	* bindings/python/gedit.defs: updated

2006-01-19  Paolo Borelli  <pborelli@katamail.com>

	* gedit/gedit-panel.c: fix warning.
	* gedit-ui.h: make view bottom pane action sensitive.
	* gedit/gedit-window.c: handle view bottom pane sensitivity according
	to the presence of items in the bottom pane.
parent d9dadd3a
2006-01-19 Paolo Maggi <paolo@gnome.org>
Re-added autosave feature.
Based on a patch by Sergio Villar Senin <svillar@igalia.com>
* gedit/gedit-debug.[ch]: s/GEDIT_DEBUG_FILE/GEDIT_DEBUG_TAB
* gedit/gedit-document.c (gedit_document_finalize)
(gedit_document_init) (set_readonly) (gedit_document_get_encoding):
remove autosave related functions (moved to gedit-tab.c)
* gedit/gedit-document.h: remove autosave related functions (moved to
gedit-tab.h)
* gedit/gedit-prefs-manager-app.c
(gedit_prefs_manager_auto_save_changed): use new functions for autosave
* gedit/gedit-tab.c (install_auto_save_timeout)
(install_auto_save_timeout_if_needed) (remove_auto_save_timeout)
(gedit_tab_get_property) (gedit_tab_set_property)
(gedit_tab_finalize) (gedit_tab_class_init)
(document_uri_notify_handler)
(recoverable_loading_error_message_area_response)
(unrecoverable_reverting_error_message_area_response)
(show_loading_message_area) (show_saving_message_area)
(message_area_set_progress) (document_loading) (document_loaded)
(document_saving) (end_saving)
(unrecoverable_saving_error_message_area_response)
(no_backup_error_message_area_response)
(externally_modified_error_message_area_response)
(recoverable_saving_error_message_area_response) (document_saved)
(gedit_tab_init) (_gedit_tab_load) (_gedit_tab_revert)
(_gedit_tab_save) (gedit_tab_auto_save) (_gedit_tab_save_as)
(gedit_tab_get_auto_save_enabled) (gedit_tab_set_auto_save_enabled)
(gedit_tab_get_auto_save_interval)
(gedit_tab_set_auto_save_interval): implemented autosave feature.
It works in the following way:
- the auto_save_timeout timeout is used to call gedit_document_auto_save
every X minutes
- when a file is loaded or saved the timeout is removed (to avoid the
case in which autosave is called while loading/saving)
- when a file has been loaded/saved, if needed, the timeout is
re-created and so gedit_document_auto_save will be called after X
minutes again
* gedit/gedit-tab.h: new functions related to autosave
* bindings/python/gedit.defs: updated
2006-01-19 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-panel.c: fix warning.
......
......@@ -359,26 +359,6 @@
(return-type "const-GeditEncoding*")
)
(define-method set_auto_save_enabled
(of-object "GeditDocument")
(c-name "gedit_document_set_auto_save_enabled")
(return-type "none")
(parameters
'("gboolean" "enable")
)
)
(define-method set_auto_save_interval
(of-object "GeditDocument")
(c-name "gedit_document_set_auto_save_interval")
(return-type "none")
(parameters
'("gint" "interval")
)
)
;; From ../../gedit/gedit-encodings.h
(define-function gedit_encoding_get_type
......@@ -614,6 +594,36 @@
(return-type "GeditTabState")
)
(define-method set_auto_save_enabled
(of-object "GeditTab")
(c-name "gedit_tab_set_auto_save_enabled")
(return-type "none")
(parameters
'("gboolean" "enable")
)
)
(define-method get_auto_save_enabled
(of-object "GeditTab")
(c-name "gedit_tab_get_auto_save_enabled")
(return-type "gboolean")
)
(define-method set_auto_save_interval
(of-object "GeditTab")
(c-name "gedit_tab_set_auto_save_interval")
(return-type "none")
(parameters
'("gint" "interval")
)
)
(define-method get_auto_save_interval
(of-object "GeditTab")
(c-name "gedit_tab_get_auto_save_interval")
(return-type "gint")
)
;; From ../../gedit/gedit-view.h
(define-function gedit_view_get_type
......
......@@ -66,8 +66,8 @@ gedit_debug_init ()
debug = debug | GEDIT_DEBUG_PRINT;
if (g_getenv ("GEDIT_DEBUG_PLUGINS") != NULL)
debug = debug | GEDIT_DEBUG_PLUGINS;
if (g_getenv ("GEDIT_DEBUG_FILE") != NULL)
debug = debug | GEDIT_DEBUG_FILE;
if (g_getenv ("GEDIT_DEBUG_TAB") != NULL)
debug = debug | GEDIT_DEBUG_TAB;
if (g_getenv ("GEDIT_DEBUG_DOCUMENT") != NULL)
debug = debug | GEDIT_DEBUG_DOCUMENT;
if (g_getenv ("GEDIT_DEBUG_COMMANDS") != NULL)
......
......@@ -47,7 +47,7 @@ typedef enum {
GEDIT_DEBUG_PRINT = 1 << 2,
GEDIT_DEBUG_PREFS = 1 << 3,
GEDIT_DEBUG_PLUGINS = 1 << 4,
GEDIT_DEBUG_FILE = 1 << 5,
GEDIT_DEBUG_TAB = 1 << 5,
GEDIT_DEBUG_DOCUMENT = 1 << 6,
GEDIT_DEBUG_COMMANDS = 1 << 7,
GEDIT_DEBUG_APP = 1 << 8,
......@@ -55,6 +55,7 @@ typedef enum {
GEDIT_DEBUG_UTILS = 1 << 10,
GEDIT_DEBUG_METADATA = 1 << 11,
GEDIT_DEBUG_WINDOW = 1 << 12,
} GeditDebugSection;
......@@ -63,7 +64,7 @@ typedef enum {
#define DEBUG_PRINT GEDIT_DEBUG_PRINT, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_PREFS GEDIT_DEBUG_PREFS, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_PLUGINS GEDIT_DEBUG_PLUGINS, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_FILE GEDIT_DEBUG_FILE, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_TAB GEDIT_DEBUG_TAB, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_DOCUMENT GEDIT_DEBUG_DOCUMENT,__FILE__, __LINE__, G_STRFUNC
#define DEBUG_COMMANDS GEDIT_DEBUG_COMMANDS,__FILE__, __LINE__, G_STRFUNC
#define DEBUG_APP GEDIT_DEBUG_APP, __FILE__, __LINE__, G_STRFUNC
......
......@@ -76,7 +76,6 @@ PROFILE (static GTimer *timer = NULL);
static void gedit_document_set_readonly (GeditDocument *doc,
gboolean readonly);
static void to_search_region_range (GeditDocument *doc,
GtkTextIter *start,
GtkTextIter *end);
......@@ -91,7 +90,6 @@ static void delete_range_cb (GeditDocument *doc,
struct _GeditDocumentPrivate
{
gint auto_save : 1;
gint readonly : 1;
gint last_save_was_manually : 1;
gint language_set_by_user : 1;
......@@ -108,9 +106,6 @@ struct _GeditDocumentPrivate
gchar *mime_type;
gint auto_save_interval;
guint auto_save_timeout;
time_t mtime;
GTimeVal time_of_last_save_or_load;
......@@ -214,9 +209,6 @@ gedit_document_finalize (GObject *object)
gedit_debug (DEBUG_DOCUMENT);
if (doc->priv->auto_save_timeout > 0)
g_source_remove (doc->priv->auto_save_timeout);
if (doc->priv->untitled_number > 0)
{
g_return_if_fail (doc->priv->uri == NULL);
......@@ -639,13 +631,6 @@ gedit_document_init (GeditDocument *doc)
gtk_source_buffer_set_check_brackets (GTK_SOURCE_BUFFER (doc),
gedit_prefs_manager_get_bracket_matching ());
doc->priv->auto_save = gedit_prefs_manager_get_auto_save ();
doc->priv->auto_save = (doc->priv->auto_save != FALSE);
doc->priv->auto_save_interval = gedit_prefs_manager_get_auto_save_interval ();
if (doc->priv->auto_save_interval <= 0)
doc->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;
gedit_document_set_enable_search_highlighting (doc,
gedit_prefs_manager_get_enable_search_highlighting ());
......@@ -891,28 +876,6 @@ set_readonly (GeditDocument *doc,
readonly = (readonly != FALSE);
if (readonly)
{
if (doc->priv->auto_save_timeout > 0)
{
g_source_remove (doc->priv->auto_save_timeout);
doc->priv->auto_save_timeout = 0;
}
}
else
{
if (doc->priv->auto_save &&
(doc->priv->auto_save_timeout <= 0) &&
!gedit_document_is_untitled (doc))
{
/* doc->priv->auto_save_timeout = g_timeout_add
(doc->priv->auto_save_interval * 1000 * 60,
(GSourceFunc)gedit_document_auto_save,
doc);
*/
}
}
if (doc->priv->readonly == readonly)
return;
......@@ -1257,6 +1220,7 @@ gedit_document_is_untitled (GeditDocument *doc)
return (doc->priv->uri == NULL);
}
gboolean
gedit_document_get_deleted (GeditDocument *doc)
{
......@@ -1686,35 +1650,6 @@ gedit_document_get_encoding (GeditDocument *doc)
return doc->priv->encoding;
}
void
gedit_document_set_auto_save_enabled (GeditDocument *doc,
gboolean enable)
{
gedit_debug (DEBUG_DOCUMENT);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
enable = (enable != FALSE);
// TODO
return;
}
void
gedit_document_set_auto_save_interval (GeditDocument *doc,
gint interval)
{
gedit_debug (DEBUG_DOCUMENT);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
g_return_if_fail (interval > 0);
// TODO
return;
}
glong
_gedit_document_get_seconds_since_last_save_or_load (GeditDocument *doc)
{
......
......@@ -118,7 +118,10 @@ typedef enum
GEDIT_DOCUMENT_SAVE_IGNORE_MTIME = 1 << 0,
/* write the file directly without attempting to backup */
GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP = 1 << 1
GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP = 1 << 1,
/* preserve previous backup file, needed to support autosaving */
GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP = 1 << 2
} GeditDocumentSaveFlags;
......@@ -219,19 +222,13 @@ GtkSourceLanguage
const GeditEncoding
*gedit_document_get_encoding (GeditDocument *doc);
// CHECK: I think this can be private
void gedit_document_set_auto_save_enabled
(GeditDocument *doc,
gboolean enable);
void gedit_document_set_auto_save_interval
(GeditDocument *doc,
gint interval);
void gedit_document_set_enable_search_highlighting
(GeditDocument *doc,
gboolean enable);
gboolean gedit_document_get_enable_search_highlighting
(GeditDocument *doc);
/*
* Non exported functions
*/
......
......@@ -1110,8 +1110,9 @@ gedit_prefs_manager_auto_save_changed (GConfClient *client,
while (l != NULL)
{
GeditDocument *doc = GEDIT_DOCUMENT (l->data);
GeditTab *tab = gedit_tab_get_from_document (doc);
gedit_document_set_auto_save_enabled (doc, auto_save);
gedit_tab_set_auto_save_enabled (tab, auto_save);
l = l->next;
}
......@@ -1138,8 +1139,9 @@ gedit_prefs_manager_auto_save_changed (GConfClient *client,
while (l != NULL)
{
GeditDocument *doc = GEDIT_DOCUMENT (l->data);
GeditTab *tab = gedit_tab_get_from_document (doc);
gedit_document_set_auto_save_interval (doc, auto_save_interval);
gedit_tab_set_auto_save_interval (tab, auto_save_interval);
l = l->next;
}
......
This diff is collapsed.
......@@ -108,6 +108,20 @@ GeditTab *gedit_tab_get_from_document (GeditDocument *doc);
GeditTabState gedit_tab_get_state (GeditTab *tab);
gboolean gedit_tab_get_auto_save_enabled
(GeditTab *tab);
void gedit_tab_set_auto_save_enabled
(GeditTab *tab,
gboolean enable);
gint gedit_tab_get_auto_save_interval
(GeditTab *tab);
void gedit_tab_set_auto_save_interval
(GeditTab *tab,
gint interval);
/*
* Non exported methods
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment