[anjuta] sourceview: keep a separate reference to AnjutaShell in SourceviewIO



commit 678a2f8bcad5530e7ad91d01402e2575313c02e1
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Thu Feb 21 22:08:43 2013 +0100

    sourceview: keep a separate reference to AnjutaShell in SourceviewIO
    
    So that we can reference it even though the parent Sourceview may have been
    destroyed. This is/will be used when saving the file as a result of closing it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692451

 plugins/sourceview/sourceview-io.c |   24 +++++++++++++++++++-----
 plugins/sourceview/sourceview-io.h |    4 +++-
 2 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/plugins/sourceview/sourceview-io.c b/plugins/sourceview/sourceview-io.c
index 19e10b3..4cba471 100644
--- a/plugins/sourceview/sourceview-io.c
+++ b/plugins/sourceview/sourceview-io.c
@@ -244,7 +244,7 @@ static void
 on_save_finished (GObject* file, GAsyncResult* result, gpointer data)
 {
        SourceviewIO* sio = SOURCEVIEW_IO(data);
-       AnjutaShell* shell = ANJUTA_PLUGIN (sio->sv->priv->plugin)->shell;
+       
        GError* err = NULL;
        gchar* etag;
 
@@ -270,8 +270,11 @@ on_save_finished (GObject* file, GAsyncResult* result, gpointer data)
 
                g_signal_emit_by_name (sio, "save-finished");
        }
+
+       if (sio->shell)
+               anjuta_shell_saving_pop (sio->shell);
+
        g_object_unref (sio);
-       anjuta_shell_saving_pop (shell);
 }
 
 void
@@ -292,7 +295,6 @@ sourceview_io_save (SourceviewIO* sio)
 void
 sourceview_io_save_as (SourceviewIO* sio, GFile* file)
 {
-       AnjutaShell* shell = ANJUTA_PLUGIN (sio->sv->priv->plugin)->shell;
        gboolean backup = TRUE;
        gsize len;
 
@@ -342,7 +344,7 @@ sourceview_io_save_as (SourceviewIO* sio, GFile* file)
                                       sio->cancel,
                                       on_save_finished,
                                       sio);
-       anjuta_shell_saving_push (shell);
+       anjuta_shell_saving_push (sio->shell);
 
        g_object_ref (sio);
 }
@@ -588,7 +590,19 @@ sourceview_io_get_read_only (SourceviewIO* sio)
 SourceviewIO*
 sourceview_io_new (Sourceview* sv)
 {
-       SourceviewIO* sio = SOURCEVIEW_IO(g_object_new (SOURCEVIEW_TYPE_IO, NULL));
+       SourceviewIO* sio;
+
+       g_return_val_if_fail (ANJUTA_IS_SOURCEVIEW(sv), NULL);
+
+       sio = SOURCEVIEW_IO(g_object_new (SOURCEVIEW_TYPE_IO, NULL));
+
        sio->sv = sv;
+       g_object_add_weak_pointer (G_OBJECT (sv), (gpointer*)&sio->sv);
+
+       /* Store a separate pointer to the shell since we want to have access
+        * to it even though the parent Sourceview has been destroyed .*/
+       sio->shell = ANJUTA_PLUGIN (sv->priv->plugin)->shell;
+       g_object_add_weak_pointer (G_OBJECT (sio->shell), (gpointer*)&sio->shell);
+
        return sio;
 }
diff --git a/plugins/sourceview/sourceview-io.h b/plugins/sourceview/sourceview-io.h
index 3b8206a..f1c85fa 100644
--- a/plugins/sourceview/sourceview-io.h
+++ b/plugins/sourceview/sourceview-io.h
@@ -54,10 +54,12 @@ struct _SourceviewIO
 {
        GObject parent_instance;
 
+       Sourceview* sv;
+       AnjutaShell* shell;
+
        GFile* file;
        gchar* etag;
        gchar* filename;
-       Sourceview* sv;
        gchar* write_buffer;
        gchar* read_buffer;
        GCancellable* cancel;


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