[gnome-builder] gui: cleanup session code
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] gui: cleanup session code
- Date: Thu, 8 Jul 2021 20:03:54 +0000 (UTC)
commit e73f44a34c0af310575fce92ea26e310fa640788
Author: Christian Hergert <chergert redhat com>
Date: Thu Jul 8 13:03:49 2021 -0700
gui: cleanup session code
src/libide/gui/ide-session.c | 66 +++++++++++++++++++++++++-------------------
1 file changed, 37 insertions(+), 29 deletions(-)
---
diff --git a/src/libide/gui/ide-session.c b/src/libide/gui/ide-session.c
index f5ee00d0a..8181ee982 100644
--- a/src/libide/gui/ide-session.c
+++ b/src/libide/gui/ide-session.c
@@ -662,39 +662,44 @@ save_state_to_disk (IdeSession *self,
g_autoptr(GVariant) state = NULL;
g_autoptr(GBytes) bytes = NULL;
g_autoptr(GFile) file = NULL;
+ GCancellable *cancellable;
IdeContext *context;
GVariantDict final_dict;
- /* It seems that because g_steal_pointer is an inline function it'll return "task" and set it
- * to NULL _then_ try to get the cancellable from it when using this getter inline in the
- * function call below. This looks like a bug from GCC/whatever, as they don't evaluate
- * expressions in the right order…
- */
- GCancellable *cancellable = ide_task_get_cancellable (task);
IDE_ENTRY;
+ g_assert (IDE_IS_SESSION (self));
+ g_assert (IDE_IS_TASK (task));
+ g_assert (pages_state != NULL);
+
+ cancellable = ide_task_get_cancellable (task);
+
g_variant_dict_init (&final_dict, NULL);
g_variant_dict_insert (&final_dict, "version", "u", (guint32) 1);
g_variant_dict_insert_value (&final_dict, "data", g_variant_builder_end (pages_state));
state = g_variant_ref_sink (g_variant_dict_end (&final_dict));
- g_debug ("Saving session state for all pages with %s", g_variant_print (state, TRUE));
bytes = g_variant_get_data_as_bytes (state);
+#if IDE_ENABLE_TRACE
+ {
+ g_autofree char *str = g_variant_print (state, TRUE);
+ IDE_TRACE_MSG ("Saving session state to %s", str);
+ }
+#endif
+
context = ide_object_get_context (IDE_OBJECT (self));
file = ide_context_cache_file (context, "session.gvariant", NULL);
- if (ide_task_return_error_if_cancelled (task))
- IDE_EXIT;
-
- g_file_replace_contents_bytes_async (file,
- bytes,
- NULL,
- FALSE,
- G_FILE_CREATE_NONE,
- cancellable,
- on_state_saved_to_cache_file_cb,
- g_object_ref (task));
+ if (!ide_task_return_error_if_cancelled (task))
+ g_file_replace_contents_bytes_async (file,
+ bytes,
+ NULL,
+ FALSE,
+ G_FILE_CREATE_NONE,
+ cancellable,
+ on_state_saved_to_cache_file_cb,
+ g_object_ref (task));
IDE_EXIT;
}
@@ -754,9 +759,7 @@ on_session_addin_page_saved_cb (GObject *object,
s->active--;
if (s->active == 0)
- {
- save_state_to_disk (self, task, &s->pages_state);
- }
+ save_state_to_disk (self, task, &s->pages_state);
IDE_EXIT;
}
@@ -780,13 +783,21 @@ foreach_page_in_grid_save_cb (GtkWidget *widget,
{
IdePage *page = IDE_PAGE (widget);
IdeTask *task = user_data;
- Save *s = ide_task_get_task_data (task);
- IdeSessionAddin *addin = find_suitable_addin_for_page (page, s->addins);
+ IdeSessionAddin *addin;
SavePage *save_page = NULL;
+ Save *s;
+
+ g_assert (IDE_IS_PAGE (page));
+ g_assert (IDE_IS_TASK (task));
+
+ s = ide_task_get_task_data (task);
- /* It's not a saveable page. */
- if (addin == NULL)
+ g_assert (s != NULL);
+ g_assert (s->addins != NULL);
+
+ if (!(addin = find_suitable_addin_for_page (page, s->addins)))
{
+ /* It's not a saveable page. */
s->active--;
return;
}
@@ -854,10 +865,7 @@ ide_session_save_async (IdeSession *self,
* pages to save.
*/
if (s->active == 0)
- {
- save_state_to_disk (self, task, &s->pages_state);
- IDE_EXIT;
- }
+ save_state_to_disk (self, task, &s->pages_state);
IDE_EXIT;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]