[epiphany/gnome-3-32] history-dialog: Fix context menu popup



commit 7f0cdfb4203aec62673df4208a06bcc58a294ff0
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Mon Feb 25 22:05:16 2019 +0000

    history-dialog: Fix context menu popup
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/651
    
    
    (cherry picked from commit 876e07b6b14303f5baed1457ec142cff93b41d45)

 src/ephy-history-dialog.c           | 34 +++++++++-------
 src/resources/gtk/history-dialog.ui | 77 ++++++++++++-------------------------
 2 files changed, 45 insertions(+), 66 deletions(-)
---
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index c3d4e8b2a..69bde6272 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -50,7 +50,7 @@ struct _EphyHistoryDialog {
 
   GtkWidget *listbox;
   GtkWidget *forget_all_button;
-  GtkWidget *popover_menu;
+  GtkWidget *popup_menu;
 
   GActionGroup *action_group;
 
@@ -565,27 +565,31 @@ on_listbox_button_press_event (GtkWidget         *widget,
                                GdkEventButton    *event,
                                EphyHistoryDialog *self)
 {
-  if (event->button == 3) {
-    GList *rows = gtk_list_box_get_selected_rows ( GTK_LIST_BOX (self->listbox));
+  if (event->button == GDK_BUTTON_SECONDARY) {
+    GtkListBoxRow *row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (self->listbox), event->y);
+    GList *rows = NULL;
+    guint state = event->state & gtk_accelerator_get_default_mod_mask ();
     int n;
 
-    n = g_list_length (rows);
+    if (!row)
+      return GDK_EVENT_PROPAGATE;
 
-    if (n <= 0) {
-      g_list_free (rows);
+    if (state != GDK_CONTROL_MASK)
+      gtk_list_box_unselect_all (GTK_LIST_BOX (self->listbox));
 
-      return FALSE;
-    }
+    gtk_list_box_select_row (GTK_LIST_BOX (self->listbox), row);
+    rows = gtk_list_box_get_selected_rows (GTK_LIST_BOX (self->listbox));
+    n = g_list_length (rows);
+    g_list_free (rows);
 
-    update_popup_menu_actions (self->action_group, (n == 1));
+    update_popup_menu_actions (self->action_group, n == 1);
 
-    gtk_popover_set_relative_to (GTK_POPOVER (self->popover_menu), GTK_WIDGET (rows->data));
-    gtk_popover_popup (GTK_POPOVER (self->popover_menu));
+    gtk_menu_popup_at_pointer (GTK_MENU (self->popup_menu), (GdkEvent *)event);
 
-    return TRUE;
+    return GDK_EVENT_STOP;
   }
 
-  return FALSE;
+  return GDK_EVENT_PROPAGATE;
 }
 
 
@@ -740,7 +744,7 @@ ephy_history_dialog_class_init (EphyHistoryDialogClass *klass)
                                                "/org/gnome/epiphany/gtk/history-dialog.ui");
   gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, listbox);
   gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, forget_all_button);
-  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, popover_menu);
+  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, popup_menu);
 
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_selected);
@@ -799,6 +803,8 @@ ephy_history_dialog_init (EphyHistoryDialog *self)
   gtk_list_box_set_header_func (GTK_LIST_BOX (self->listbox), box_header_func, NULL, NULL);
   ephy_gui_ensure_window_group (GTK_WINDOW (self));
 
+  gtk_menu_attach_to_widget (GTK_MENU (self->popup_menu), GTK_WIDGET (self), NULL);
+
   self->action_group = create_action_group (self);
   gtk_widget_insert_action_group (GTK_WIDGET (self), "history", self->action_group);
 
diff --git a/src/resources/gtk/history-dialog.ui b/src/resources/gtk/history-dialog.ui
index 26f1cac25..3c48b001c 100644
--- a/src/resources/gtk/history-dialog.ui
+++ b/src/resources/gtk/history-dialog.ui
@@ -117,62 +117,35 @@
       </object>
     </child>
   </template>
-  <object class="GtkPopoverMenu" id="popover_menu">
+  <object class="GtkMenu" id="popup_menu">
+    <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="border_width">6</property>
     <child>
-      <object class="GtkBox">
+      <object class="GtkMenuItem">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">6</property>
-        <child>
-          <object class="GtkModelButton">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="action_name">history.open-selection</property>
-            <property name="text" translatable="yes">_Open</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkModelButton">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="action_name">history.copy-url</property>
-            <property name="text" translatable="yes">_Copy Location</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkModelButton">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="action_name">history.forget</property>
-            <property name="text" translatable="yes">_Delete</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
+        <property name="can_focus">True</property>
+        <property name="action_name">history.open-selection</property>
+        <property name="label" translatable="yes">_Open</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="action_name">history.copy-url</property>
+        <property name="label" translatable="yes">_Copy Location</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="action_name">history.forget</property>
+        <property name="label" translatable="yes">_Delete</property>
+        <property name="use_underline">True</property>
       </object>
-      <packing>
-        <property name="submenu">main</property>
-        <property name="position">1</property>
-      </packing>
     </child>
   </object>
 </interface>


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