summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Engber <engber@src.gnome.org>2001-03-29 19:28:11 +0000
committerMike Engber <engber@src.gnome.org>2001-03-29 19:28:11 +0000
commit037d8d5898908effb54897a5a26b78d1c0f4baa4 (patch)
tree2ac9bc169a845d835862a1c10d63c62ed1d51dd5
parent295499e7d67b731d66d4ccc06990202802aac066 (diff)
downloadnautilus-037d8d5898908effb54897a5a26b78d1c0f4baa4.tar.gz
reviewed by: Darin Adler <darin@eazel.com>
reviewed by: Darin Adler <darin@eazel.com> * components/notes/nautilus-notes.c: (schedule_save_callback), (cancel_pending_save), (schedule_save), (set_note_text_from_metadata), (done_with_file), (notes_save_metainfo), (on_changed), (make_notes_view): Notes now saves changes after a timeout instead of waiting until focus change - bug 6884.
-rw-r--r--ChangeLog12
-rw-r--r--components/notes/nautilus-notes.c52
2 files changed, 64 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 09681b4e1..b1ff120c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2001-03-29 Michael Engber <engber@eazel.com>
+
+ reviewed by: Darin Adler <darin@eazel.com>
+
+ * components/notes/nautilus-notes.c: (schedule_save_callback),
+ (cancel_pending_save), (schedule_save),
+ (set_note_text_from_metadata), (done_with_file),
+ (notes_save_metainfo), (on_changed), (make_notes_view):
+ Notes now saves changes after a timeout instead of waiting
+ until focus change - bug 6884.
+
2001-03-29 John Sullivan <sullivan@eazel.com>
reviewed by: Darin Adler <darin@eazel.com>
@@ -16,6 +27,7 @@
2001-03-29 John Sullivan <sullivan@eazel.com>
+>>>>>>> 1.4304
reviewed by: Ramiro Estrugo <ramiro@eazel.com>
Fixed bug 3328 (Need a preference to specify upper bounds for
diff --git a/components/notes/nautilus-notes.c b/components/notes/nautilus-notes.c
index 336ddcda2..81a1541c1 100644
--- a/components/notes/nautilus-notes.c
+++ b/components/notes/nautilus-notes.c
@@ -59,10 +59,48 @@ typedef struct {
GtkWidget *note_text_field;
char *uri;
NautilusFile *file;
+ guint save_timeout_id;
} Notes;
+static void notes_save_metainfo (Notes *notes);
+
static int notes_object_count = 0;
+#define SAVE_TIMEOUT (3 * 1000)
+
+static gboolean
+schedule_save_callback (gpointer data)
+{
+ Notes *notes;
+
+ notes = data;
+
+ /* Zero out save_timeout_id so no one will try to cancel our in-progress timeout callback.
+ */
+ notes->save_timeout_id = 0;
+
+ notes_save_metainfo (notes);
+
+ return FALSE;
+}
+
+static void
+cancel_pending_save (Notes *notes)
+{
+ if (notes->save_timeout_id != 0) {
+ gtk_timeout_remove (notes->save_timeout_id);
+ notes->save_timeout_id = 0;
+ }
+}
+
+static void
+schedule_save (Notes *notes)
+{
+ cancel_pending_save (notes);
+
+ notes->save_timeout_id = gtk_timeout_add (SAVE_TIMEOUT, schedule_save_callback, notes);
+}
+
static void
set_note_text_from_metadata (NautilusFile *file,
Notes *notes)
@@ -81,6 +119,8 @@ set_note_text_from_metadata (NautilusFile *file,
* metadata has actually changed.
*/
if (strcmp (saved_text, current_text) != 0) {
+ cancel_pending_save (notes);
+
gtk_editable_delete_text (GTK_EDITABLE (notes->note_text_field), 0, -1);
position = 0;
@@ -104,6 +144,8 @@ set_note_text_from_metadata (NautilusFile *file,
static void
done_with_file (Notes *notes)
{
+ cancel_pending_save (notes);
+
if (notes->file != NULL) {
nautilus_file_monitor_remove (notes->file, notes);
gtk_signal_disconnect_by_func (GTK_OBJECT (notes->file),
@@ -153,6 +195,8 @@ notes_save_metainfo (Notes *notes)
return;
}
+ cancel_pending_save (notes);
+
/* Block the handler, so we don't respond to our own change.
*/
gtk_signal_handler_block_by_func (GTK_OBJECT (notes->file),
@@ -198,6 +242,11 @@ on_text_field_focus_out_event (GtkWidget *widget,
return FALSE;
}
+static void
+on_changed (GtkEditable *editable, Notes *notes)
+{
+ schedule_save (notes);
+}
static void
do_destroy (GtkObject *obj, Notes *notes)
@@ -253,6 +302,9 @@ make_notes_view (BonoboGenericFactory *Factory, const char *goad_id, gpointer cl
gtk_signal_connect (GTK_OBJECT (notes->note_text_field), "focus_out_event",
GTK_SIGNAL_FUNC (on_text_field_focus_out_event),
notes);
+ gtk_signal_connect (GTK_OBJECT (notes->note_text_field), "changed",
+ GTK_SIGNAL_FUNC (on_changed),
+ notes);
gtk_widget_show_all (vbox);