[nautilus/wip/ernestask/men-use: 5/5] files-view: Keep track of menu widgets
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/ernestask/men-use: 5/5] files-view: Keep track of menu widgets
- Date: Mon, 17 Dec 2018 17:22:44 +0000 (UTC)
commit fdb08b5acaa32dfd18b60f098169181b4f1ed0b6
Author: Ernestas Kulik <ekulik redhat com>
Date: Sun Dec 16 11:41:47 2018 +0100
files-view: Keep track of menu widgets
So that we can clean them up.
Fixes https://gitlab.gnome.org/GNOME/nautilus/issues/791
src/nautilus-files-view.c | 107 +++++++++++++++++++++++++++++++++++-----------
1 file changed, 81 insertions(+), 26 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 1031e87c6..beed025d2 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -234,8 +234,11 @@ typedef struct
GList *subdirectory_list;
- GMenu *selection_menu;
- GMenu *background_menu;
+ GMenu *selection_menu_model;
+ GMenu *background_menu_model;
+
+ GtkWidget *selection_menu;
+ GtkWidget *background_menu;
GActionGroup *view_action_group;
@@ -3208,6 +3211,21 @@ nautilus_files_view_destroy (GtkWidget *object)
GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->destroy (object);
}
+static void
+nautilus_files_view_unrealize (GtkWidget *widget)
+{
+ NautilusFilesView *view;
+ NautilusFilesViewPrivate *priv;
+
+ view = NAUTILUS_FILES_VIEW (widget);
+ priv = nautilus_files_view_get_instance_private (view);
+
+ g_clear_pointer (&priv->selection_menu, gtk_widget_destroy);
+ g_clear_pointer (&priv->background_menu, gtk_widget_destroy);
+
+ GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->unrealize (widget);
+}
+
static void
nautilus_files_view_finalize (GObject *object)
{
@@ -3218,8 +3236,8 @@ nautilus_files_view_finalize (GObject *object)
priv = nautilus_files_view_get_instance_private (view);
g_clear_object (&priv->view_action_group);
- g_clear_object (&priv->background_menu);
- g_clear_object (&priv->selection_menu);
+ g_clear_object (&priv->background_menu_model);
+ g_clear_object (&priv->selection_menu_model);
g_clear_object (&priv->toolbar_menu_sections->zoom_section);
g_clear_object (&priv->toolbar_menu_sections->extended_section);
g_clear_object (&priv->extensions_background_menu);
@@ -4984,7 +5002,7 @@ update_extensions_menus (NautilusFilesView *view)
selection_menu = build_menu_for_extension_menu_items (view, "extensions",
selection_items);
- nautilus_gmenu_merge (priv->selection_menu,
+ nautilus_gmenu_merge (priv->selection_menu_model,
selection_menu,
"extensions",
FALSE);
@@ -4997,7 +5015,7 @@ update_extensions_menus (NautilusFilesView *view)
background_menu = build_menu_for_extension_menu_items (view, "extensions",
background_items);
- nautilus_gmenu_merge (priv->background_menu,
+ nautilus_gmenu_merge (priv->background_menu_model,
background_menu,
"extensions",
FALSE);
@@ -5491,7 +5509,7 @@ update_scripts_menu (NautilusFilesView *view)
submenu = update_directory_in_scripts_menu (view, directory);
if (submenu != NULL)
{
- nautilus_gmenu_merge (priv->selection_menu,
+ nautilus_gmenu_merge (priv->selection_menu_model,
submenu,
"scripts-submenu",
TRUE);
@@ -5745,7 +5763,7 @@ update_templates_menu (NautilusFilesView *view)
submenu = update_directory_in_templates_menu (view, directory);
if (submenu != NULL)
{
- nautilus_gmenu_merge (priv->background_menu,
+ nautilus_gmenu_merge (priv->background_menu_model,
submenu,
"templates-submenu",
FALSE);
@@ -7731,7 +7749,7 @@ update_selection_menu (NautilusFilesView *view)
selection_count);
menu_item = g_menu_item_new (item_label, "view.new-folder-with-selection");
g_menu_item_set_attribute (menu_item, "hidden-when", "s", "action-disabled");
- nautilus_gmenu_add_item_in_submodel (priv->selection_menu,
+ nautilus_gmenu_add_item_in_submodel (priv->selection_menu_model,
menu_item,
"new-folder-with-selection-section",
FALSE);
@@ -7816,7 +7834,7 @@ update_selection_menu (NautilusFilesView *view)
g_menu_item_set_icon (menu_item, app_icon);
}
- nautilus_gmenu_add_item_in_submodel (priv->selection_menu,
+ nautilus_gmenu_add_item_in_submodel (priv->selection_menu_model,
menu_item,
"open-with-default-application-section",
FALSE);
@@ -7889,7 +7907,7 @@ update_selection_menu (NautilusFilesView *view)
}
menu_item = g_menu_item_new (item_label, "view.start-volume");
- nautilus_gmenu_add_item_in_submodel (priv->selection_menu,
+ nautilus_gmenu_add_item_in_submodel (priv->selection_menu_model,
menu_item,
"drive-section",
FALSE);
@@ -7933,7 +7951,7 @@ update_selection_menu (NautilusFilesView *view)
}
menu_item = g_menu_item_new (item_label, "view.stop-volume");
- nautilus_gmenu_add_item_in_submodel (priv->selection_menu,
+ nautilus_gmenu_add_item_in_submodel (priv->selection_menu_model,
menu_item,
"drive-section",
FALSE);
@@ -7964,14 +7982,14 @@ real_update_context_menus (NautilusFilesView *view)
priv = nautilus_files_view_get_instance_private (view);
builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-files-view-context-menus.ui");
- g_clear_object (&priv->background_menu);
- g_clear_object (&priv->selection_menu);
+ g_clear_object (&priv->background_menu_model);
+ g_clear_object (&priv->selection_menu_model);
object = gtk_builder_get_object (builder, "background-menu");
- priv->background_menu = g_object_ref (G_MENU (object));
+ priv->background_menu_model = g_object_ref (G_MENU (object));
object = gtk_builder_get_object (builder, "selection-menu");
- priv->selection_menu = g_object_ref (G_MENU (object));
+ priv->selection_menu_model = g_object_ref (G_MENU (object));
update_selection_menu (view);
update_background_menu (view);
@@ -8064,6 +8082,19 @@ nautilus_files_view_reveal_for_selection_context_menu (NautilusFilesView *view)
return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->reveal_for_selection_context_menu (view);
}
+static void
+nautilus_files_view_detach_selection_menu (GtkWidget *attach_widget,
+ GtkMenu *menu)
+{
+ NautilusFilesView *self;
+ NautilusFilesViewPrivate *priv;
+
+ self = NAUTILUS_FILES_VIEW (attach_widget);
+ priv = nautilus_files_view_get_instance_private (self);
+
+ priv->selection_menu = NULL;
+}
+
/**
* nautilus_files_view_pop_up_selection_context_menu
*
@@ -8077,7 +8108,6 @@ 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));
@@ -8088,11 +8118,17 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
*/
update_context_menus_if_pending (view);
- gtk_menu = g_object_ref_sink (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 (priv->selection_menu != NULL)
+ {
+ gtk_widget_destroy (priv->selection_menu);
+ }
+ priv->selection_menu = gtk_menu_new_from_model (G_MENU_MODEL (priv->selection_menu_model));
+
+ gtk_menu_attach_to_widget (GTK_MENU (priv->selection_menu), GTK_WIDGET (view),
+ nautilus_files_view_detach_selection_menu);
if (event != NULL)
{
- gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), event);
+ gtk_menu_popup_at_pointer (GTK_MENU (priv->selection_menu), event);
}
else
{
@@ -8102,7 +8138,7 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
rectangle = nautilus_files_view_reveal_for_selection_context_menu (view);
g_return_if_fail (rectangle != NULL);
- gtk_menu_popup_at_rect (GTK_MENU (gtk_menu),
+ gtk_menu_popup_at_rect (GTK_MENU (priv->selection_menu),
gtk_widget_get_window (GTK_WIDGET (view)),
rectangle,
GDK_GRAVITY_SOUTH_WEST,
@@ -8111,6 +8147,19 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
}
}
+static void
+nautilus_files_view_detach_background_menu (GtkWidget *attach_widget,
+ GtkMenu *menu)
+{
+ NautilusFilesView *self;
+ NautilusFilesViewPrivate *priv;
+
+ self = NAUTILUS_FILES_VIEW (attach_widget);
+ priv = nautilus_files_view_get_instance_private (self);
+
+ priv->background_menu = NULL;
+}
+
/**
* nautilus_files_view_pop_up_background_context_menu
*
@@ -8123,7 +8172,6 @@ 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));
@@ -8134,17 +8182,23 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
*/
update_context_menus_if_pending (view);
- gtk_menu = g_object_ref_sink (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 (priv->background_menu != NULL)
+ {
+ gtk_widget_destroy (priv->background_menu);
+ }
+ priv->background_menu = gtk_menu_new_from_model (G_MENU_MODEL (priv->background_menu_model));
+
+ gtk_menu_attach_to_widget (GTK_MENU (priv->background_menu), GTK_WIDGET (view),
+ nautilus_files_view_detach_background_menu);
if (event != NULL)
{
- gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), event);
+ gtk_menu_popup_at_pointer (GTK_MENU (priv->background_menu), event);
}
else
{
/* It was triggered from the keyboard, so pop up from the center of view.
*/
- gtk_menu_popup_at_widget (GTK_MENU (gtk_menu),
+ gtk_menu_popup_at_widget (GTK_MENU (priv->background_menu),
GTK_WIDGET (view),
GDK_GRAVITY_CENTER,
GDK_GRAVITY_CENTER,
@@ -9342,6 +9396,7 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
oclass->set_property = nautilus_files_view_set_property;
widget_class->destroy = nautilus_files_view_destroy;
+ widget_class->unrealize = nautilus_files_view_unrealize;
widget_class->event = nautilus_files_view_event;
widget_class->parent_set = nautilus_files_view_parent_set;
widget_class->grab_focus = nautilus_files_view_grab_focus;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]