[nautilus/antoniof/context-menu-simplification: 3/5] ui-utilities: Move menu pop up code to files-view
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/antoniof/context-menu-simplification: 3/5] ui-utilities: Move menu pop up code to files-view
- Date: Fri, 27 Jul 2018 15:03:27 +0000 (UTC)
commit 5e8e63eff9ee92c3b8660ad1ba89f2ee08307175
Author: António Fernandes <antoniof gnome org>
Date: Sat May 12 17:25:57 2018 +0100
ui-utilities: Move menu pop up code to files-view
In the past, nautilus_pop_up_context_menu_at_pointer() was the common
path for popping up context menus from the view and pathbar.
However, different paths were introduced in
commit 29cf64bd7632b25dd56a275078da6130b201edeb and
commit 489d4d091e7006f0ec68849e836a52119af88959, which
share some code but couldn't use this API.
Now that the pathbar context menus are gone, this is actually
causing more code duplication while making it harder to read.
Instead, handle everything in files-view.c.
src/nautilus-files-view.c | 27 ++++++++++-----------------
src/nautilus-ui-utilities.c | 24 ------------------------
src/nautilus-ui-utilities.h | 3 ---
3 files changed, 10 insertions(+), 44 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index f0e50cb7a..d5cdc838b 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8170,6 +8170,7 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
const GdkEvent *event)
{
NautilusFilesViewPrivate *priv;
+ g_autoptr (GtkWidget) gtk_menu = NULL;
g_assert (NAUTILUS_IS_FILES_VIEW (view));
@@ -8180,32 +8181,28 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
*/
update_context_menus_if_pending (view);
+ gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (priv->selection_menu));
+ gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), GTK_WIDGET (view), NULL);
if (event != NULL)
{
- nautilus_pop_up_context_menu_at_pointer (GTK_WIDGET (view),
- priv->selection_menu,
- event);
+ gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), event);
}
else
{
/* If triggered from the keyboard, popup at selection, not pointer */
g_autofree GdkRectangle *rectangle = NULL;
- g_autoptr (GtkWidget) gtk_menu = NULL;
rectangle = nautilus_files_view_reveal_for_selection_context_menu (view);
g_return_if_fail (rectangle != NULL);
- gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (priv->selection_menu));
- gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), GTK_WIDGET (view), NULL);
-
gtk_menu_popup_at_rect (GTK_MENU (gtk_menu),
gtk_widget_get_window (GTK_WIDGET (view)),
rectangle,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_NORTH_WEST,
NULL);
- g_object_ref_sink (gtk_menu);
}
+ g_object_ref_sink (gtk_menu);
}
/**
@@ -8220,6 +8217,7 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
const GdkEvent *event)
{
NautilusFilesViewPrivate *priv;
+ g_autoptr (GtkWidget) gtk_menu = NULL;
g_assert (NAUTILUS_IS_FILES_VIEW (view));
@@ -8230,28 +8228,23 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
*/
update_context_menus_if_pending (view);
+ gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (priv->background_menu));
+ gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), GTK_WIDGET (view), NULL);
if (event != NULL)
{
- nautilus_pop_up_context_menu_at_pointer (GTK_WIDGET (view),
- priv->background_menu,
- event);
+ gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), event);
}
else
{
/* It was triggered from the keyboard, so pop up from the center of view.
*/
- g_autoptr (GtkWidget) gtk_menu = NULL;
-
- gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (priv->background_menu));
- gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), GTK_WIDGET (view), NULL);
-
gtk_menu_popup_at_widget (GTK_MENU (gtk_menu),
GTK_WIDGET (view),
GDK_GRAVITY_CENTER,
GDK_GRAVITY_CENTER,
NULL);
- g_object_ref_sink (gtk_menu);
}
+ g_object_ref_sink (gtk_menu);
}
static gboolean
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index cc8d71ed3..1c84ee113 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -169,30 +169,6 @@ nautilus_gmenu_add_item_in_submodel (GMenu *menu,
g_object_unref (submodel);
}
-/**
- * nautilus_pop_up_context_menu_at_pointer:
- *
- * Pop up a context menu at the pointer's position. If @event_button is NULL,
- * the current even will be assumed by gtk_menu_popup_at_pointer().
- */
-void
-nautilus_pop_up_context_menu_at_pointer (GtkWidget *parent,
- GMenu *menu,
- const GdkEvent *event)
-{
- g_autoptr (GtkWidget) gtk_menu = NULL;
-
- g_return_if_fail (G_IS_MENU (menu));
- g_return_if_fail (GTK_IS_WIDGET (parent));
-
- gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));
- gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL);
-
- gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), event);
-
- g_object_ref_sink (gtk_menu);
-}
-
#define NAUTILUS_THUMBNAIL_FRAME_LEFT 3
#define NAUTILUS_THUMBNAIL_FRAME_TOP 3
#define NAUTILUS_THUMBNAIL_FRAME_RIGHT 3
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index 2aa78f432..6419f0d2f 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -33,9 +33,6 @@ void nautilus_gmenu_merge (GMenu *original
GMenu *gmenu_to_merge,
const gchar *submodel_name,
gboolean prepend);
-void nautilus_pop_up_context_menu_at_pointer (GtkWidget *parent,
- GMenu *menu,
- const GdkEvent *event);
void nautilus_ui_frame_image (GdkPixbuf **pixbuf);
void nautilus_ui_frame_video (GdkPixbuf **pixbuf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]