[gedit/wip/reusable-code] Make the DocumentSaver independent of Document



commit 03184cb59118f950c71f8d677cd747d666e3412b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Sep 17 22:13:16 2013 +0200

    Make the DocumentSaver independent of Document
    
    The last dependency was _gedit_document_create_mount_operation().
    The mount operation is set to the DocumentSaver, with
    gedit_document_saver_set_mount_operation_factory().
    
    So the mount operation comes from GeditViewFrame (to have the parent
    window), it is set to GeditDocument with
    _gedit_document_set_mount_operation_factory(). Then it is set to
    GeditDocumentSaver with a similar function.

 gedit/gedit-document-saver.c |   34 +++++++++++++++++++++++++++++-----
 gedit/gedit-document-saver.h |    5 +++++
 gedit/gedit-document.c       |    7 +++++--
 gedit/gedit-document.h       |    3 +--
 gedit/gedit-view-frame.c     |    3 +--
 5 files changed, 41 insertions(+), 11 deletions(-)
---
diff --git a/gedit/gedit-document-saver.c b/gedit/gedit-document-saver.c
index c493828..d3e1c9e 100644
--- a/gedit/gedit-document-saver.c
+++ b/gedit/gedit-document-saver.c
@@ -28,6 +28,7 @@
 #include <string.h>
 
 #include "gedit-document-saver.h"
+#include "gedit-document.h"
 #include "gedit/gedit-document-input-stream.h"
 #include "gedit-marshal.h"
 #include "gedit/gedit-utils.h"
@@ -102,6 +103,9 @@ struct _GeditDocumentSaverPrivate
 
        GError                   *error;
 
+       GeditMountOperationFactory mount_operation_factory;
+       gpointer                   mount_operation_userdata;
+
        guint                     used : 1;
        guint                     ensure_trailing_newline : 1;
 };
@@ -879,19 +883,28 @@ mount_ready_callback (GFile        *file,
        }
 }
 
+static GMountOperation *
+create_mount_operation (GeditDocumentSaver *saver)
+{
+       if (saver->priv->mount_operation_factory == NULL)
+       {
+               return g_mount_operation_new ();
+       }
+       else
+       {
+               return saver->priv->mount_operation_factory (saver->priv->mount_operation_userdata);
+       }
+}
+
 static void
 recover_not_mounted (AsyncData *async)
 {
-       GeditDocument *doc;
-       GMountOperation *mount_operation;
+       GMountOperation *mount_operation = create_mount_operation (async->saver);
 
        DEBUG ({
               g_print ("%s\n", G_STRFUNC);
        });
 
-       doc = gedit_document_saver_get_document (async->saver);
-       mount_operation = _gedit_document_create_mount_operation (doc);
-
        async->tried_mount = TRUE;
        g_file_mount_enclosing_volume (async->saver->priv->location,
                                       G_MOUNT_MOUNT_NONE,
@@ -1124,4 +1137,15 @@ gedit_document_saver_get_info (GeditDocumentSaver *saver)
        return saver->priv->info;
 }
 
+void
+gedit_document_saver_set_mount_operation_factory (GeditDocumentSaver         *saver,
+                                                 GeditMountOperationFactory  callback,
+                                                 gpointer                    user_data)
+{
+       g_return_if_fail (GEDIT_IS_DOCUMENT_SAVER (saver));
+
+       saver->priv->mount_operation_factory = callback;
+       saver->priv->mount_operation_userdata = user_data;
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gedit/gedit-document-saver.h b/gedit/gedit-document-saver.h
index 8b559af..a929ef5 100644
--- a/gedit/gedit-document-saver.h
+++ b/gedit/gedit-document-saver.h
@@ -90,6 +90,11 @@ goffset                       gedit_document_saver_get_bytes_written (GeditDocumentSaver  
*saver);
 
 GFileInfo              *gedit_document_saver_get_info          (GeditDocumentSaver  *saver);
 
+void                    gedit_document_saver_set_mount_operation_factory
+                                                               (GeditDocumentSaver         *saver,
+                                                                GeditMountOperationFactory  callback,
+                                                                gpointer                    user_data);
+
 G_END_DECLS
 
 #endif  /* __GEDIT_DOCUMENT_SAVER_H__  */
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 1226974..d4b1483 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1838,6 +1838,10 @@ gedit_document_save_real (GeditDocument                *doc,
                                                             flags,
                                                             ensure_trailing_newline);
 
+               gedit_document_saver_set_mount_operation_factory (doc->priv->saver,
+                                                                 doc->priv->mount_operation_factory,
+                                                                 doc->priv->mount_operation_userdata);
+
                g_signal_connect (doc->priv->saver,
                                  "saving",
                                  G_CALLBACK (document_saver_saving),
@@ -2823,8 +2827,7 @@ _gedit_document_create_mount_operation (GeditDocument *doc)
        }
        else
        {
-               return doc->priv->mount_operation_factory (doc,
-                                                          doc->priv->mount_operation_userdata);
+               return doc->priv->mount_operation_factory (doc->priv->mount_operation_userdata);
        }
 }
 
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index 5a843d4..71415b1 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -299,8 +299,7 @@ gboolean    _gedit_document_check_externally_modified
  * @doc:
  * @userdata:
  */
-typedef GMountOperation *(*GeditMountOperationFactory)(GeditDocument *doc,
-                                                      gpointer       userdata);
+typedef GMountOperation *(*GeditMountOperationFactory)(gpointer userdata);
 
 void                    _gedit_document_set_mount_operation_factory    (GeditDocument              *doc,
                                                                         GeditMountOperationFactory  callback,
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index 0480163..8e61f3a 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -1367,8 +1367,7 @@ gedit_view_frame_class_init (GeditViewFrameClass *klass)
 }
 
 static GMountOperation *
-view_frame_mount_operation_factory (GeditDocument *doc,
-                                   gpointer       user_data)
+view_frame_mount_operation_factory (gpointer user_data)
 {
        GtkWidget *frame = user_data;
        GtkWidget *window = gtk_widget_get_toplevel (frame);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]