[gnome-builder] gui: Restore currently visible pages on top of all the others



commit 1aca2d88b7ee2cb842c23ed6a144a03c3cb1e372
Author: vanadiae <vanadiae35 gmail com>
Date:   Fri Jul 9 15:09:00 2021 +0200

    gui: Restore currently visible pages on top of all the others
    
    Currently if pages A, B, C were opened in that order, and that page B is the
    currently visible one for this frame, it won't be the one which will be visible
    when re-opening the project. This is because the internal order stays in the
    order that the pages were opened, it doesn't change when a different page is
    shown, unlike the MRU order.
    
    So this commit now detects when a page is the currently shown one, and in that
    case saves it with the highest depth so that it is restored on top of all others.

 src/libide/gui/ide-session.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/gui/ide-session.c b/src/libide/gui/ide-session.c
index 6267f3f0b..398ecbd6b 100644
--- a/src/libide/gui/ide-session.c
+++ b/src/libide/gui/ide-session.c
@@ -633,10 +633,22 @@ get_page_position (IdePage *page,
   grid_column = gtk_widget_get_ancestor (GTK_WIDGET (frame), IDE_TYPE_GRID_COLUMN);
   grid = gtk_widget_get_ancestor (GTK_WIDGET (grid_column), IDE_TYPE_GRID);
 
-  gtk_container_child_get (GTK_CONTAINER (frame_pages_stack), GTK_WIDGET (page),
-                           "position", out_depth,
-                           NULL);
-  *out_depth = MAX (*out_depth, 0);
+  /* When this page is the currently visible one for this frame, we want to keep it on top when
+   * restoring so that there's no need to switch back to the pages we were working on. We need to
+   * do this because the stack's "position" child property only refers to the order in which the
+   * pages were initially opened, not the most-recently-used order.
+   */
+  if (ide_frame_get_visible_child (IDE_FRAME (frame)) == page)
+    {
+      *out_depth = g_list_model_get_n_items (G_LIST_MODEL (frame));
+    }
+  else
+    {
+      gtk_container_child_get (GTK_CONTAINER (frame_pages_stack), GTK_WIDGET (page),
+                               "position", out_depth,
+                               NULL);
+      *out_depth = MAX (*out_depth, 0);
+    }
 
   gtk_container_child_get (GTK_CONTAINER (grid_column), GTK_WIDGET (frame),
                            "index", out_row,


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