[eog] Revert "Merge branch 'eog-popover-sidebar'"



commit 901f9ad62a25cff22350cfeb18f568ff42190cb9
Author: Felix Riemann <friemann gnome org>
Date:   Wed Jul 6 19:51:02 2022 +0000

    Revert "Merge branch 'eog-popover-sidebar'"
    
    This reverts merge request !125

 src/eog-sidebar.c | 166 +++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 128 insertions(+), 38 deletions(-)
---
diff --git a/src/eog-sidebar.c b/src/eog-sidebar.c
index 8ddcc61e..1e2489ca 100644
--- a/src/eog-sidebar.c
+++ b/src/eog-sidebar.c
@@ -27,6 +27,10 @@
 #include "config.h"
 #endif
 
+#include <string.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
 
 #include "eog-sidebar.h"
@@ -54,8 +58,8 @@ static gint signals[SIGNAL_LAST];
 
 struct _EogSidebarPrivate {
        GtkWidget *notebook;
-       GtkWidget *list_box;
-       GtkWidget *popover;
+       GtkWidget *select_button;
+       GtkWidget *menu;
        GtkWidget *hbox;
        GtkWidget *label;
        GtkWidget *arrow;
@@ -70,6 +74,11 @@ eog_sidebar_destroy (GtkWidget *object)
 {
        EogSidebar *eog_sidebar = EOG_SIDEBAR (object);
 
+       if (eog_sidebar->priv->menu) {
+               gtk_menu_detach (GTK_MENU (eog_sidebar->priv->menu));
+               eog_sidebar->priv->menu = NULL;
+       }
+
        if (eog_sidebar->priv->page_model) {
                g_object_unref (eog_sidebar->priv->page_model);
                eog_sidebar->priv->page_model = NULL;
@@ -228,6 +237,64 @@ eog_sidebar_class_init (EogSidebarClass *eog_sidebar_class)
                              GTK_TYPE_WIDGET);
 }
 
+static gboolean
+eog_sidebar_select_button_press_cb (GtkWidget      *widget,
+                                   GdkEventButton *event,
+                                   gpointer        user_data)
+{
+       EogSidebar *eog_sidebar = EOG_SIDEBAR (user_data);
+
+       if (event->button == 1) {
+               GtkRequisition requisition;
+               GtkAllocation allocation;
+
+               gtk_widget_get_allocation (widget, &allocation);
+
+               gtk_widget_set_size_request (eog_sidebar->priv->menu, -1, -1);
+               gtk_widget_get_preferred_size (eog_sidebar->priv->menu, &requisition, NULL);
+               gtk_widget_set_size_request (eog_sidebar->priv->menu,
+                                            MAX (allocation.width,
+                                                 requisition.width), -1);
+
+               gtk_widget_grab_focus (widget);
+
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+
+               gtk_menu_popup_at_widget (GTK_MENU (eog_sidebar->priv->menu),
+                                         widget, GDK_GRAVITY_SOUTH_WEST,
+                                         GDK_GRAVITY_NORTH_WEST,
+                                         (const GdkEvent*) event);
+
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+static gboolean
+eog_sidebar_select_button_key_press_cb (GtkWidget   *widget,
+                                       GdkEventKey *event,
+                                       gpointer     user_data)
+{
+       EogSidebar *eog_sidebar = EOG_SIDEBAR (user_data);
+
+       if (event->keyval == GDK_KEY_space ||
+           event->keyval == GDK_KEY_KP_Space ||
+           event->keyval == GDK_KEY_Return ||
+           event->keyval == GDK_KEY_KP_Enter) {
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+
+               gtk_menu_popup_at_widget (GTK_MENU (eog_sidebar->priv->menu),
+                                         widget, GDK_GRAVITY_SOUTH_WEST,
+                                         GDK_GRAVITY_NORTH_WEST,
+                                         (const GdkEvent*) event);
+
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
 static void
 eog_sidebar_close_clicked_cb (GtkWidget *widget,
                              gpointer   user_data)
@@ -238,15 +305,35 @@ eog_sidebar_close_clicked_cb (GtkWidget *widget,
 }
 
 static void
-eog_sidebar_menu_item_activate_cb (GtkListBox    *list_box,
-                                   GtkListBoxRow *row,
-                                  gpointer       user_data)
+eog_sidebar_menu_deactivate_cb (GtkWidget *widget,
+                              gpointer   user_data)
+{
+       GtkWidget *menu_button;
+
+       menu_button = GTK_WIDGET (user_data);
+
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu_button), FALSE);
+}
+
+static void
+eog_sidebar_menu_detach_cb (GtkWidget *widget,
+                          GtkMenu   *menu)
+{
+       EogSidebar *eog_sidebar = EOG_SIDEBAR (widget);
+
+       eog_sidebar->priv->menu = NULL;
+}
+
+static void
+eog_sidebar_menu_item_activate_cb (GtkWidget *widget,
+                                  gpointer   user_data)
 {
        EogSidebar *eog_sidebar = EOG_SIDEBAR (user_data);
        GtkTreeIter iter;
-       GtkWidget *item;
+       GtkWidget *menu_item, *item;
        gboolean valid;
 
+       menu_item = gtk_menu_get_active (GTK_MENU (eog_sidebar->priv->menu));
        valid = gtk_tree_model_get_iter_first (eog_sidebar->priv->page_model, &iter);
 
        while (valid) {
@@ -254,7 +341,7 @@ eog_sidebar_menu_item_activate_cb (GtkListBox    *list_box,
                                    PAGE_COLUMN_MENU_ITEM, &item,
                                    -1);
 
-               if (item == GTK_WIDGET (row)) {
+               if (item == menu_item) {
                        eog_sidebar_select_page (eog_sidebar, &iter);
                        valid = FALSE;
                } else {
@@ -264,8 +351,6 @@ eog_sidebar_menu_item_activate_cb (GtkListBox    *list_box,
                g_object_unref (item);
        }
 
-       gtk_popover_popdown (GTK_POPOVER (eog_sidebar->priv->popover));
-
        g_object_notify (G_OBJECT (eog_sidebar), "current-page");
 }
 
@@ -285,7 +370,6 @@ eog_sidebar_init (EogSidebar *eog_sidebar)
        GtkWidget *hbox;
        GtkWidget *close_button;
        GtkWidget *select_hbox;
-       GtkWidget *select_button;
        GtkWidget *arrow;
        GtkWidget *image;
 
@@ -310,11 +394,18 @@ eog_sidebar_init (EogSidebar *eog_sidebar)
        gtk_box_pack_start (GTK_BOX (eog_sidebar), hbox, FALSE, FALSE, 0);
        gtk_widget_show (hbox);
 
-       select_button = gtk_menu_button_new ();
-       gtk_widget_set_focus_on_click (select_button, TRUE);
-       gtk_button_set_relief (GTK_BUTTON (select_button),
+       eog_sidebar->priv->select_button = gtk_toggle_button_new ();
+       gtk_button_set_relief (GTK_BUTTON (eog_sidebar->priv->select_button),
                               GTK_RELIEF_NONE);
 
+       g_signal_connect (eog_sidebar->priv->select_button, "button_press_event",
+                         G_CALLBACK (eog_sidebar_select_button_press_cb),
+                         eog_sidebar);
+
+       g_signal_connect (eog_sidebar->priv->select_button, "key_press_event",
+                         G_CALLBACK (eog_sidebar_select_button_key_press_cb),
+                         eog_sidebar);
+
        select_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
        eog_sidebar->priv->label = gtk_label_new ("");
@@ -331,11 +422,11 @@ eog_sidebar_init (EogSidebar *eog_sidebar)
        eog_sidebar->priv->arrow = arrow;
        gtk_widget_set_visible (arrow, FALSE);
 
-       gtk_container_add (GTK_CONTAINER (select_button), select_hbox);
+       gtk_container_add (GTK_CONTAINER (eog_sidebar->priv->select_button), select_hbox);
        gtk_widget_show (select_hbox);
 
-       gtk_box_set_center_widget (GTK_BOX (hbox), select_button);
-       gtk_widget_show (select_button);
+       gtk_box_set_center_widget (GTK_BOX (hbox), eog_sidebar->priv->select_button);
+       gtk_widget_show (eog_sidebar->priv->select_button);
 
        close_button = gtk_button_new ();
 
@@ -354,20 +445,17 @@ eog_sidebar_init (EogSidebar *eog_sidebar)
        gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
        gtk_widget_show (close_button);
 
-       eog_sidebar->priv->list_box = gtk_list_box_new ();
-       gtk_widget_show (eog_sidebar->priv->list_box);
-       g_signal_connect (eog_sidebar->priv->list_box, "row-selected",
-                          G_CALLBACK (eog_sidebar_menu_item_activate_cb),
-                          eog_sidebar);
+       eog_sidebar->priv->menu = gtk_menu_new ();
 
-       eog_sidebar->priv->popover = gtk_popover_new (select_button);
-       g_object_set (eog_sidebar->priv->list_box, "margin", 6, NULL);
+       g_signal_connect (eog_sidebar->priv->menu, "deactivate",
+                         G_CALLBACK (eog_sidebar_menu_deactivate_cb),
+                         eog_sidebar->priv->select_button);
 
-       gtk_container_add (GTK_CONTAINER (eog_sidebar->priv->popover),
-                           eog_sidebar->priv->list_box);
+       gtk_menu_attach_to_widget (GTK_MENU (eog_sidebar->priv->menu),
+                                  GTK_WIDGET (eog_sidebar),
+                                  eog_sidebar_menu_detach_cb);
 
-       gtk_menu_button_set_popover (GTK_MENU_BUTTON (select_button),
-                                     eog_sidebar->priv->popover);
+       gtk_widget_show (eog_sidebar->priv->menu);
 
        eog_sidebar->priv->notebook = gtk_notebook_new ();
 
@@ -398,8 +486,7 @@ eog_sidebar_add_page (EogSidebar   *eog_sidebar,
                      GtkWidget    *main_widget)
 {
        GtkTreeIter iter;
-       GtkWidget *label;
-       GtkWidget *row;
+       GtkWidget *menu_item;
        gchar *label_title;
        gint index;
 
@@ -409,21 +496,22 @@ eog_sidebar_add_page (EogSidebar   *eog_sidebar,
        index = gtk_notebook_append_page (GTK_NOTEBOOK (eog_sidebar->priv->notebook),
                                          main_widget, NULL);
 
-       label = gtk_label_new (title);
-       gtk_widget_show (label);
+       menu_item = gtk_menu_item_new_with_label (title);
 
-       row = gtk_list_box_row_new ();
-       gtk_widget_show (row);
+       g_signal_connect (menu_item, "activate",
+                         G_CALLBACK (eog_sidebar_menu_item_activate_cb),
+                         eog_sidebar);
 
-       gtk_container_add (GTK_CONTAINER (row), label);
-       gtk_container_add (GTK_CONTAINER (eog_sidebar->priv->list_box),
-                           row);
+       gtk_widget_show (menu_item);
+
+       gtk_menu_shell_append (GTK_MENU_SHELL (eog_sidebar->priv->menu),
+                              menu_item);
 
        /* Insert and move to end */
        gtk_list_store_insert_with_values (GTK_LIST_STORE (eog_sidebar->priv->page_model),
                                           &iter, 0,
                                           PAGE_COLUMN_TITLE, title,
-                                          PAGE_COLUMN_MENU_ITEM, row,
+                                          PAGE_COLUMN_MENU_ITEM, menu_item,
                                           PAGE_COLUMN_MAIN_WIDGET, main_widget,
                                           PAGE_COLUMN_NOTEBOOK_INDEX, index,
                                           -1);
@@ -440,6 +528,8 @@ eog_sidebar_add_page (EogSidebar   *eog_sidebar,
                            PAGE_COLUMN_NOTEBOOK_INDEX, &index,
                            -1);
 
+       gtk_menu_set_active (GTK_MENU (eog_sidebar->priv->menu), index);
+
        gtk_label_set_text (GTK_LABEL (eog_sidebar->priv->label), label_title);
 
        gtk_notebook_set_current_page (GTK_NOTEBOOK (eog_sidebar->priv->notebook),
@@ -488,7 +578,7 @@ eog_sidebar_remove_page (EogSidebar *eog_sidebar, GtkWidget *main_widget)
                gtk_notebook_remove_page (GTK_NOTEBOOK (eog_sidebar->priv->notebook),
                                          index);
 
-               gtk_container_remove (GTK_CONTAINER (eog_sidebar->priv->list_box), menu_item);
+               gtk_container_remove (GTK_CONTAINER (eog_sidebar->priv->menu), menu_item);
 
                gtk_list_store_remove (GTK_LIST_STORE (eog_sidebar->priv->page_model),
                                       &iter);


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