[anjuta] sourceview: only cancel open operations when closing editor
- From: Carl-Anton Ingmarsson <carlantoni src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] sourceview: only cancel open operations when closing editor
- Date: Mon, 25 Feb 2013 09:10:32 +0000 (UTC)
commit a715f1a1251a7fc47aadacf686931227ca49dea3
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date: Thu Feb 21 22:11:55 2013 +0100
sourceview: only cancel open operations when closing editor
We want an ongoing save operation to finish even though the sourceview
has been finalized.
Also rework the code so that SourceviewIO cancels the open operations
by itself when the Sourceview is finalized instead of having the
Sourceview be responsible for it.
https://bugzilla.gnome.org/show_bug.cgi?id=692451
plugins/sourceview/sourceview-io.c | 36 +++++++++++++++++++++---------------
plugins/sourceview/sourceview-io.h | 3 +--
plugins/sourceview/sourceview.c | 3 +--
3 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/plugins/sourceview/sourceview-io.c b/plugins/sourceview/sourceview-io.c
index 4cba471..cbf3987 100644
--- a/plugins/sourceview/sourceview-io.c
+++ b/plugins/sourceview/sourceview-io.c
@@ -47,13 +47,23 @@ static guint io_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (SourceviewIO, sourceview_io, G_TYPE_OBJECT);
static void
+on_sourceview_finalized (gpointer data, GObject* where_the_object_was)
+{
+ SourceviewIO* sio = SOURCEVIEW_IO (data);
+
+ sio->sv = NULL;
+ /* Cancel all open operations */
+ g_cancellable_cancel (sio->open_cancel);
+}
+
+static void
sourceview_io_init (SourceviewIO *object)
{
object->file = NULL;
object->filename = NULL;
object->read_buffer = NULL;
object->write_buffer = NULL;
- object->cancel = g_cancellable_new();
+ object->open_cancel = g_cancellable_new();
object->monitor = NULL;
object->last_encoding = NULL;
object->bytes_read = 0;
@@ -63,13 +73,17 @@ static void
sourceview_io_finalize (GObject *object)
{
SourceviewIO* sio = SOURCEVIEW_IO(object);
+
+ if (sio->sv)
+ g_object_weak_unref (G_OBJECT (sio->sv), on_sourceview_finalized, sio);
+
if (sio->file)
g_object_unref (sio->file);
g_free (sio->etag);
g_free(sio->filename);
g_free(sio->read_buffer);
g_free(sio->write_buffer);
- g_object_unref (sio->cancel);
+ g_object_unref (sio->open_cancel);
if (sio->monitor)
g_object_unref (sio->monitor);
@@ -334,14 +348,13 @@ sourceview_io_save_as (SourceviewIO* sio, GFile* file)
return;
}
}
- g_cancellable_reset (sio->cancel);
g_file_replace_contents_async (file,
sio->write_buffer,
len,
NULL,
backup,
G_FILE_CREATE_NONE,
- sio->cancel,
+ NULL,
on_save_finished,
sio);
anjuta_shell_saving_push (sio->shell);
@@ -403,7 +416,6 @@ append_buffer (SourceviewIO* sio, gsize size)
g_signal_emit_by_name (sio, "open-failed", conv_error);
g_error_free (conv_error);
- g_cancellable_cancel (sio->cancel);
return FALSE;
}
sio->last_encoding = enc;
@@ -421,7 +433,7 @@ on_read_finished (GObject* input, GAsyncResult* result, gpointer data)
gsize current_bytes = 0;
GError* err = NULL;
- if (!g_cancellable_set_error_if_cancelled (sio->cancel, &err))
+ if (!g_cancellable_set_error_if_cancelled (sio->open_cancel, &err))
current_bytes = g_input_stream_read_finish (input_stream, result, &err);
if (err)
{
@@ -438,7 +450,7 @@ on_read_finished (GObject* input, GAsyncResult* result, gpointer data)
sio->read_buffer + sio->bytes_read,
READ_SIZE,
IO_PRIORITY,
- sio->cancel,
+ sio->open_cancel,
on_read_finished,
sio);
return;
@@ -503,7 +515,7 @@ sourceview_io_open (SourceviewIO* sio, GFile* file)
sio->read_buffer,
READ_SIZE,
IO_PRIORITY,
- sio->cancel,
+ sio->open_cancel,
on_read_finished,
g_object_ref (sio));
}
@@ -516,12 +528,6 @@ sourceview_io_get_file (SourceviewIO* sio)
return sio->file;
}
-void
-sourceview_io_cancel (SourceviewIO* sio)
-{
- g_cancellable_cancel (sio->cancel);
-}
-
const gchar*
sourceview_io_get_filename (SourceviewIO* sio)
{
@@ -597,7 +603,7 @@ sourceview_io_new (Sourceview* sv)
sio = SOURCEVIEW_IO(g_object_new (SOURCEVIEW_TYPE_IO, NULL));
sio->sv = sv;
- g_object_add_weak_pointer (G_OBJECT (sv), (gpointer*)&sio->sv);
+ g_object_weak_ref (G_OBJECT (sv), on_sourceview_finalized, sio);
/* Store a separate pointer to the shell since we want to have access
* to it even though the parent Sourceview has been destroyed .*/
diff --git a/plugins/sourceview/sourceview-io.h b/plugins/sourceview/sourceview-io.h
index f1c85fa..365cfe0 100644
--- a/plugins/sourceview/sourceview-io.h
+++ b/plugins/sourceview/sourceview-io.h
@@ -62,7 +62,7 @@ struct _SourceviewIO
gchar* filename;
gchar* write_buffer;
gchar* read_buffer;
- GCancellable* cancel;
+ GCancellable* open_cancel;
GFileMonitor* monitor;
gssize bytes_read;
@@ -73,7 +73,6 @@ GType sourceview_io_get_type (void) G_GNUC_CONST;
void sourceview_io_save (SourceviewIO* sio);
void sourceview_io_save_as (SourceviewIO* sio, GFile* file);
void sourceview_io_open (SourceviewIO* sio, GFile* file);
-void sourceview_io_cancel (SourceviewIO* sio);
GFile* sourceview_io_get_file (SourceviewIO* sio);
const gchar* sourceview_io_get_filename (SourceviewIO* sio);
void sourceview_io_set_filename (SourceviewIO* sio, const gchar* filename);
diff --git a/plugins/sourceview/sourceview.c b/plugins/sourceview/sourceview.c
index 420562f..ba8690e 100644
--- a/plugins/sourceview/sourceview.c
+++ b/plugins/sourceview/sourceview.c
@@ -978,8 +978,7 @@ sourceview_dispose(GObject *object)
g_signal_handlers_disconnect_by_func (cobj->priv->io, on_open_failed, cobj);
g_signal_handlers_disconnect_by_func (cobj->priv->io, on_save_finish, cobj);
g_signal_handlers_disconnect_by_func (cobj->priv->io, on_save_failed, cobj);
-
- sourceview_io_cancel (cobj->priv->io);
+
g_clear_object (&cobj->priv->io);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]