[dia/dia-next: 59/59] Sheet chooser remembers the last sheet



commit d21e36a0c79a1237a99e78b74ca194b1793a986a
Author: Zander Brown <zbrown gnome org>
Date:   Wed Jan 9 15:40:24 2019 +0000

    Sheet chooser remembers the last sheet

 app/commands.c                  |  2 +-
 app/display.c                   |  2 +-
 app/interface.c                 |  1 +
 app/toolbox.c                   | 30 +++++++++++++--------------
 app/widgets/dia-sheet-chooser.c | 46 +++++++++++++++++++++++++++++++++++++----
 app/widgets/dia-sheet-chooser.h | 22 +++++---------------
 6 files changed, 65 insertions(+), 38 deletions(-)
---
diff --git a/app/commands.c b/app/commands.c
index 7007d607..0c7ca5aa 100644
--- a/app/commands.c
+++ b/app/commands.c
@@ -294,7 +294,7 @@ received_clipboard_image_handler (GtkClipboard *clipboard,
       diagram_select(dia, obj);
       object_add_updates(obj, dia);
 
-      dia_display_do_update_menu_sensitivity (disp);
+      dia_display_do_update_menu_sensitivity (ddisp);
       diagram_flush(dia);
     } else {
       message_warning (_("No selected object can take an image."));
diff --git a/app/display.c b/app/display.c
index 030dfa00..e3797720 100644
--- a/app/display.c
+++ b/app/display.c
@@ -1288,7 +1288,7 @@ dia_display_set_title (DiaDisplay *ddisp, char *title)
     for (num = 0 ; num < num_pages ; num++) {
       page = gtk_notebook_get_nth_page (notebook, num);
       if (g_object_get_data (G_OBJECT (page), DIA_DISPLAY_DATA_HACK) == ddisp) {
-        GtkWidget *label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook), page);
+        GtkWidget *label = g_object_get_data (page, "tab-label");
         /* not using the passed in title here, because it may be too long */
         gchar *name = diagram_get_name (ddisp->diagram);
         gtk_label_set_label (GTK_LABEL (label), name);
diff --git a/app/interface.c b/app/interface.c
index 1a2a4262..c7252894 100644
--- a/app/interface.c
+++ b/app/interface.c
@@ -435,6 +435,7 @@ use_integrated_ui_for_display_shell(DiaDisplay *ddisp, char *title)
                                                   tab_label_container);
 
   g_object_set_data (G_OBJECT (ddisp->container), DIA_DISPLAY_DATA_HACK, ddisp);
+  g_object_set_data (G_OBJECT (ddisp->container), "tab-label", label);
 
   /*  the table containing all widgets  */
   table = gtk_grid_new ();
diff --git a/app/toolbox.c b/app/toolbox.c
index a986e1c8..cc764282 100644
--- a/app/toolbox.c
+++ b/app/toolbox.c
@@ -356,6 +356,8 @@ create_sheet_dropdown_menu (DiaToolbox *self)
   GSList *l;
   GtkWidget *button;
   DiaSheet *tmp;
+  gchar *sheetname;
+  DiaSheet *sheet;
 
   self->sheets = g_list_store_new (DIA_TYPE_SHEET);
 
@@ -382,7 +384,13 @@ create_sheet_dropdown_menu (DiaToolbox *self)
   button = dia_sheet_chooser_new ();
   g_signal_connect (G_OBJECT (button), "sheet-selected",
                     G_CALLBACK (sheet_selected), self);
-  dia_sheet_chooser_set_model (DIA_SHEET_CHOOSER (button), G_LIST_MODEL (self->sheets));
+
+  sheetname = persistence_register_string ("last-sheet-selected", _("Flowchart"));
+  sheet = get_sheet_by_name (sheetname);
+  fill_sheet_wbox (self, sheet);
+  g_free (sheetname);
+
+  dia_sheet_chooser_set_model (DIA_SHEET_CHOOSER (button), G_LIST_MODEL (self->sheets), sheet);
   gtk_box_pack_start (GTK_BOX (self), button, FALSE, FALSE, 0);
   gtk_widget_show (button);
 }
@@ -391,9 +399,13 @@ static void
 create_sheets (DiaToolbox *self)
 {
   GtkWidget *swin;
-  gchar *sheetname;
-  DiaSheet *sheet;
   
+  self->items = g_object_new (GTK_TYPE_GRID,
+                              "column-homogeneous", TRUE,
+                              "column-spacing", 4,
+                              "row-spacing", 4,
+                              NULL);
+
   create_sheet_dropdown_menu (self);
 
   swin = gtk_scrolled_window_new (NULL, NULL);
@@ -404,20 +416,8 @@ create_sheets (DiaToolbox *self)
   gtk_box_pack_start (GTK_BOX (self), swin, FALSE, FALSE, 0);
   gtk_widget_show (swin);
 
-  self->items = g_object_new (GTK_TYPE_GRID,
-                              "column-homogeneous", TRUE,
-                              "column-spacing", 4,
-                              "row-spacing", 4,
-                              NULL);
   gtk_container_add (GTK_CONTAINER (swin), self->items);
   gtk_widget_show (self->items);
-
-  sheetname = persistence_register_string ("last-sheet-selected", _("Flowchart"));
-  sheet = get_sheet_by_name (sheetname);
-  if (sheet != NULL) {
-    fill_sheet_wbox (self, sheet);
-  }
-  g_free (sheetname);
 }
 
 static void
diff --git a/app/widgets/dia-sheet-chooser.c b/app/widgets/dia-sheet-chooser.c
index d28739b9..70dc1df4 100644
--- a/app/widgets/dia-sheet-chooser.c
+++ b/app/widgets/dia-sheet-chooser.c
@@ -3,6 +3,13 @@
 #include "dia-sheet-chooser.h"
 #include "dia_dirs.h"
 
+struct _DiaSheetChooserPopover {
+  GtkPopover parent;
+
+  GtkWidget  *filter;
+  GtkWidget  *list;
+};
+
 G_DEFINE_TYPE (DiaSheetChooserPopover, dia_sheet_chooser_popover, GTK_TYPE_POPOVER)
 
 enum {
@@ -52,7 +59,7 @@ render_row (gpointer item, gpointer user_data)
 
   row = gtk_list_box_row_new ();
   /* TODO: Let's avoid the trap of set_data */
-  g_object_set_data (G_OBJECT (row), "dia-sheet", item);
+  g_object_set_data_full (G_OBJECT (row), "dia-sheet", item, g_object_unref);
   g_object_set_data (G_OBJECT (row),
                      "dia-list-top",
                      g_object_get_data (G_OBJECT (item), "dia-list-top"));
@@ -144,13 +151,35 @@ dia_sheet_chooser_popover_init (DiaSheetChooserPopover *self)
                     G_CALLBACK (sheet_activated), self);
 }
 
+struct find_data {
+  GtkWidget *list;
+  DiaSheet  *current;
+};
+
+static void
+find_current (GtkWidget *row, struct find_data *current)
+{
+  g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
+
+  if (g_strcmp0 (DIA_SHEET (g_object_get_data (row, "dia-sheet"))->name, current->current->name) == 0) {
+    gtk_list_box_select_row (current->list, GTK_LIST_BOX_ROW (row));
+  }
+}
+
 void
 dia_sheet_chooser_popover_set_model (DiaSheetChooserPopover *self,
-                                     GListModel             *model)
+                                     GListModel             *model,
+                                     DiaSheet               *current)
 {
+  struct find_data find = { self->list, current };
+
   gtk_list_box_bind_model (GTK_LIST_BOX (self->list),
                            G_LIST_MODEL (model),
                            render_row, NULL, NULL);
+
+  gtk_container_foreach (GTK_CONTAINER (self->list),
+                         (GtkCallback) find_current,
+                         &find);
 }
 
 GtkWidget *
@@ -159,6 +188,13 @@ dia_sheet_chooser_popover_new ()
   return g_object_new (DIA_TYPE_SHEET_CHOOSER_POPOVER, NULL);
 }
 
+struct _DiaSheetChooser {
+  GtkMenuButton parent;
+
+  GtkWidget *label;
+  GtkWidget *popover;
+};
+
 G_DEFINE_TYPE (DiaSheetChooser, dia_sheet_chooser, GTK_TYPE_MENU_BUTTON)
 
 static void
@@ -213,10 +249,12 @@ dia_sheet_chooser_init (DiaSheetChooser *self)
 
 void
 dia_sheet_chooser_set_model (DiaSheetChooser *self,
-                             GListModel      *model)
+                             GListModel      *model,
+                             DiaSheet        *current)
 {
   dia_sheet_chooser_popover_set_model (DIA_SHEET_CHOOSER_POPOVER (self->popover),
-                                       model);
+                                       model,
+                                       current);
 }
 
 GtkWidget *
diff --git a/app/widgets/dia-sheet-chooser.h b/app/widgets/dia-sheet-chooser.h
index a37c0116..3fb3c216 100644
--- a/app/widgets/dia-sheet-chooser.h
+++ b/app/widgets/dia-sheet-chooser.h
@@ -7,29 +7,17 @@ G_BEGIN_DECLS
 #define DIA_TYPE_SHEET_CHOOSER_POPOVER (dia_sheet_chooser_popover_get_type ())
 G_DECLARE_FINAL_TYPE (DiaSheetChooserPopover, dia_sheet_chooser_popover, DIA, SHEET_CHOOSER_POPOVER, 
GtkPopover)
 
-struct _DiaSheetChooserPopover {
-  GtkPopover parent;
-
-  GtkWidget  *filter;
-  GtkWidget  *list;
-};
-
 void       dia_sheet_chooser_popover_set_model (DiaSheetChooserPopover *self,
-                                                GListModel             *model);
+                                                GListModel             *model,
+                                                DiaSheet               *current);
 
 
 #define DIA_TYPE_SHEET_CHOOSER (dia_sheet_chooser_get_type ())
 G_DECLARE_FINAL_TYPE (DiaSheetChooser, dia_sheet_chooser, DIA, SHEET_CHOOSER, GtkMenuButton)
 
-struct _DiaSheetChooser {
-  GtkMenuButton parent;
-
-  GtkWidget *label;
-  GtkWidget *popover;
-};
-
 GtkWidget *dia_sheet_chooser_new               ();
 void       dia_sheet_chooser_set_model         (DiaSheetChooser *self,
-                                                GListModel      *model);
+                                                GListModel      *model,
+                                                DiaSheet        *current);
 
-G_END_DECLS
\ No newline at end of file
+G_END_DECLS


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