[nautilus/wip/antoniof/preserve_popover_menu_model: 111/111] view: Cast exported menus as models
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/preserve_popover_menu_model: 111/111] view: Cast exported menus as models
- Date: Fri, 24 Jan 2020 00:46:14 +0000 (UTC)
commit 8ee25cd32e8af4a21b0a5ed37ba91ce431d22156
Author: António Fernandes <antoniof gnome org>
Date: Sun Jun 23 15:24:33 2019 +0100
view: Cast exported menus as models
The view exports the background extensions and templates menu models for
consumption by the pathbar. They are exported as GMenu.
However, the consumer is not supposed to modify the menu, which is what
the GMenu API is for. Also, it needs to cast to GMenuModel everytime.
To make this clearer and cleaner, cast to GMenuModel at the point when
the GMenu API is not going to be used anymore.
src/nautilus-files-view.c | 66 +++++++++++++++++++++-------------------------
src/nautilus-pathbar.c | 10 +++----
src/nautilus-pathbar.h | 4 +--
src/nautilus-view.c | 12 ++++-----
src/nautilus-view.h | 16 +++++------
src/nautilus-window-slot.c | 36 ++++++++++++-------------
src/nautilus-window-slot.h | 4 +--
7 files changed, 70 insertions(+), 78 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 5dd2a9a69..cca403843 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -268,8 +268,8 @@ typedef struct
GtkWidget *zoom_level_label;
/* Exposed menus, for the path bar etc. */
- GMenu *extensions_background_menu;
- GMenu *templates_menu;
+ GMenuModel *extensions_background_menu;
+ GMenuModel *templates_menu;
gulong stop_signal_handler;
gulong reload_signal_handler;
@@ -708,27 +708,27 @@ nautilus_files_view_get_toolbar_menu_sections (NautilusView *view)
return priv->toolbar_menu_sections;
}
-static GMenu*
+static GMenuModel*
nautilus_files_view_get_templates_menu (NautilusView *self)
{
- GMenu *menu;
+ GMenuModel *menu;
g_object_get (self, "templates-menu", &menu, NULL);
return menu;
}
-static GMenu*
+static GMenuModel*
nautilus_files_view_get_extensions_background_menu (NautilusView *self)
{
- GMenu *menu;
+ GMenuModel *menu;
g_object_get (self, "extensions-background-menu", &menu, NULL);
return menu;
}
-static GMenu*
+static GMenuModel*
real_get_extensions_background_menu (NautilusView *view)
{
NautilusFilesViewPrivate *priv;
@@ -740,7 +740,7 @@ real_get_extensions_background_menu (NautilusView *view)
return priv->extensions_background_menu;
}
-static GMenu*
+static GMenuModel*
real_get_templates_menu (NautilusView *view)
{
NautilusFilesViewPrivate *priv;
@@ -754,21 +754,21 @@ real_get_templates_menu (NautilusView *view)
static void
nautilus_files_view_set_templates_menu (NautilusView *self,
- GMenu *menu)
+ GMenuModel *menu)
{
g_object_set (self, "templates-menu", menu, NULL);
}
static void
nautilus_files_view_set_extensions_background_menu (NautilusView *self,
- GMenu *menu)
+ GMenuModel *menu)
{
g_object_set (self, "extensions-background-menu", menu, NULL);
}
static void
real_set_extensions_background_menu (NautilusView *view,
- GMenu *menu)
+ GMenuModel *menu)
{
NautilusFilesViewPrivate *priv;
@@ -776,13 +776,12 @@ real_set_extensions_background_menu (NautilusView *view,
priv = nautilus_files_view_get_instance_private (NAUTILUS_FILES_VIEW (view));
- g_clear_object (&priv->extensions_background_menu);
- priv->extensions_background_menu = menu;
+ g_set_object (&priv->extensions_background_menu, menu);
}
static void
real_set_templates_menu (NautilusView *view,
- GMenu *menu)
+ GMenuModel *menu)
{
NautilusFilesViewPrivate *priv;
@@ -790,8 +789,7 @@ real_set_templates_menu (NautilusView *view,
priv = nautilus_files_view_get_instance_private (NAUTILUS_FILES_VIEW (view));
- g_clear_object (&priv->templates_menu);
- priv->templates_menu = menu;
+ g_set_object (&priv->templates_menu, menu);
}
static gboolean
@@ -4996,7 +4994,7 @@ add_extension_action (NautilusFilesView *view,
g_object_unref (action);
}
-static GMenu *
+static GMenuModel *
build_menu_for_extension_menu_items (NautilusFilesView *view,
const gchar *extension_prefix,
GList *menu_items)
@@ -5035,14 +5033,13 @@ build_menu_for_extension_menu_items (NautilusFilesView *view,
if (menu != NULL)
{
GList *children;
- GMenu *children_menu;
+ g_autoptr (GMenuModel) children_menu = NULL;
children = nautilus_menu_get_items (menu);
children_menu = build_menu_for_extension_menu_items (view, extension_id, children);
- g_menu_item_set_submenu (menu_item, G_MENU_MODEL (children_menu));
+ g_menu_item_set_submenu (menu_item, children_menu);
nautilus_menu_item_list_free (children);
- g_object_unref (children_menu);
}
g_menu_append_item (gmenu, menu_item);
@@ -5055,7 +5052,7 @@ build_menu_for_extension_menu_items (NautilusFilesView *view,
g_object_unref (menu_item);
}
- return gmenu;
+ return G_MENU_MODEL (gmenu);
}
static void
@@ -5064,8 +5061,8 @@ update_extensions_menus (NautilusFilesView *view,
{
GList *selection_items, *background_items;
GObject *object;
- g_autoptr (GMenu) background_menu = NULL;
- g_autoptr (GMenu) selection_menu = NULL;
+ g_autoptr (GMenuModel) background_menu = NULL;
+ g_autoptr (GMenuModel) selection_menu = NULL;
selection_items = get_extension_selection_menu_items (view);
if (selection_items != NULL)
@@ -5074,8 +5071,7 @@ update_extensions_menus (NautilusFilesView *view,
selection_items);
object = gtk_builder_get_object (builder, "selection-extensions-section");
- nautilus_gmenu_set_from_model (G_MENU (object),
- G_MENU_MODEL (selection_menu));
+ nautilus_gmenu_set_from_model (G_MENU (object), selection_menu);
nautilus_menu_item_list_free (selection_items);
}
@@ -5087,8 +5083,7 @@ update_extensions_menus (NautilusFilesView *view,
background_items);
object = gtk_builder_get_object (builder, "background-extensions-section");
- nautilus_gmenu_set_from_model (G_MENU (object),
- G_MENU_MODEL (background_menu));
+ nautilus_gmenu_set_from_model (G_MENU (object), background_menu);
nautilus_menu_item_list_free (background_items);
}
@@ -5722,12 +5717,12 @@ directory_belongs_in_templates_menu (const char *templates_directory_uri,
return TRUE;
}
-static GMenu *
+static GMenuModel *
update_directory_in_templates_menu (NautilusFilesView *view,
NautilusDirectory *directory)
{
GList *file_list, *filtered, *node;
- GMenu *menu, *children_menu;
+ GMenu *menu;
GMenuItem *menu_item;
gboolean any_templates;
NautilusFile *file;
@@ -5757,6 +5752,8 @@ update_directory_in_templates_menu (NautilusFilesView *view,
uri = nautilus_file_get_uri (file);
if (directory_belongs_in_templates_menu (templates_directory_uri, uri))
{
+ g_autoptr (GMenuModel) children_menu = NULL;
+
dir = nautilus_directory_get_by_uri (uri);
add_directory_to_templates_directory_list (view, dir);
@@ -5769,12 +5766,10 @@ update_directory_in_templates_menu (NautilusFilesView *view,
display_name = nautilus_file_get_display_name (file);
label = eel_str_double_underscores (display_name);
- menu_item = g_menu_item_new_submenu (label,
- G_MENU_MODEL (children_menu));
+ menu_item = g_menu_item_new_submenu (label, children_menu);
g_menu_append_item (menu, menu_item);
any_templates = TRUE;
g_object_unref (menu_item);
- g_object_unref (children_menu);
}
nautilus_directory_unref (dir);
@@ -5797,7 +5792,7 @@ update_directory_in_templates_menu (NautilusFilesView *view,
menu = NULL;
}
- return menu;
+ return G_MENU_MODEL (menu);
}
@@ -5809,7 +5804,7 @@ update_templates_menu (NautilusFilesView *view,
NautilusFilesViewPrivate *priv;
GList *sorted_copy, *node;
NautilusDirectory *directory;
- g_autoptr (GMenu) submenu = NULL;
+ g_autoptr (GMenuModel) submenu = NULL;
char *uri;
char *templates_directory_uri;
@@ -5848,8 +5843,7 @@ update_templates_menu (NautilusFilesView *view,
{
GObject *object;
object = gtk_builder_get_object (builder, "templates-submenu");
- nautilus_gmenu_set_from_model (G_MENU (object),
- G_MENU_MODEL (submenu));
+ nautilus_gmenu_set_from_model (G_MENU (object), submenu);
}
nautilus_view_set_templates_menu (NAUTILUS_VIEW (view), submenu);
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 820a562b9..5e1fa3021 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -918,22 +918,20 @@ nautilus_path_bar_class_init (NautilusPathBarClass *path_bar_class)
void
nautilus_path_bar_set_extensions_background_menu (NautilusPathBar *self,
- GMenu *menu)
+ GMenuModel *menu)
{
g_return_if_fail (NAUTILUS_IS_PATH_BAR (self));
- nautilus_gmenu_set_from_model (self->extensions_section,
- G_MENU_MODEL (menu));
+ nautilus_gmenu_set_from_model (self->extensions_section, menu);
}
void
nautilus_path_bar_set_templates_menu (NautilusPathBar *self,
- GMenu *menu)
+ GMenuModel *menu)
{
g_return_if_fail (NAUTILUS_IS_PATH_BAR (self));
- nautilus_gmenu_set_from_model (self->templates_submenu,
- G_MENU_MODEL (menu));
+ nautilus_gmenu_set_from_model (self->templates_submenu, menu);
}
/* Changes the icons wherever it is needed */
diff --git a/src/nautilus-pathbar.h b/src/nautilus-pathbar.h
index 617df825e..2e91e2922 100644
--- a/src/nautilus-pathbar.h
+++ b/src/nautilus-pathbar.h
@@ -28,6 +28,6 @@ void nautilus_path_bar_set_path (NautilusPathBar *path
GFile *file);
void nautilus_path_bar_set_extensions_background_menu (NautilusPathBar *path_bar,
- GMenu *menu);
+ GMenuModel *menu);
void nautilus_path_bar_set_templates_menu (NautilusPathBar *path_bar,
- GMenu *menu);
+ GMenuModel *menu);
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index e9213e769..b4c6bc347 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -93,7 +93,7 @@ nautilus_view_default_init (NautilusViewInterface *iface)
g_param_spec_object ("extensions-background-menu",
"Menu for the background click of extensions",
"Menu for the background click of extensions",
- G_TYPE_MENU,
+ G_TYPE_MENU_MODEL,
G_PARAM_READWRITE));
/**
* NautilusView::templates-menu:
@@ -104,7 +104,7 @@ nautilus_view_default_init (NautilusViewInterface *iface)
g_param_spec_object ("templates-menu",
"Menu of templates",
"Menu of templates",
- G_TYPE_MENU,
+ G_TYPE_MENU_MODEL,
G_PARAM_READWRITE));
}
@@ -171,7 +171,7 @@ nautilus_view_get_toolbar_menu_sections (NautilusView *view)
return NAUTILUS_VIEW_GET_IFACE (view)->get_toolbar_menu_sections (view);
}
-GMenu *
+GMenuModel *
nautilus_view_get_extensions_background_menu (NautilusView *view)
{
g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_extensions_background_menu, NULL);
@@ -182,14 +182,14 @@ nautilus_view_get_extensions_background_menu (NautilusView *view)
/* Protected */
void
nautilus_view_set_extensions_background_menu (NautilusView *view,
- GMenu *menu)
+ GMenuModel *menu)
{
g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_extensions_background_menu);
NAUTILUS_VIEW_GET_IFACE (view)->set_extensions_background_menu (view, menu);
}
-GMenu *
+GMenuModel *
nautilus_view_get_templates_menu (NautilusView *view)
{
g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_templates_menu, NULL);
@@ -200,7 +200,7 @@ nautilus_view_get_templates_menu (NautilusView *view)
/* Protected */
void
nautilus_view_set_templates_menu (NautilusView *view,
- GMenu *menu)
+ GMenuModel *menu)
{
g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_templates_menu);
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index 16bd471d2..b54889e68 100644
--- a/src/nautilus-view.h
+++ b/src/nautilus-view.h
@@ -53,17 +53,17 @@ struct _NautilusViewInterface
/*
* Returns the menu for the background click of extensions.
*/
- GMenu * (*get_extensions_background_menu) (NautilusView *view);
+ GMenuModel * (*get_extensions_background_menu) (NautilusView *view);
void (*set_extensions_background_menu) (NautilusView *view,
- GMenu *menu);
+ GMenuModel *menu);
/*
* Returns the menu for templates.
*/
- GMenu * (*get_templates_menu) (NautilusView *view);
+ GMenuModel * (*get_templates_menu) (NautilusView *view);
void (*set_templates_menu) (NautilusView *view,
- GMenu *menu);
+ GMenuModel *menu);
/* Current location of the view */
GFile* (*get_location) (NautilusView *view);
void (*set_location) (NautilusView *view,
@@ -112,10 +112,10 @@ gboolean nautilus_view_is_loading (Nautilus
gboolean nautilus_view_is_searching (NautilusView *view);
void nautilus_view_set_templates_menu (NautilusView *view,
- GMenu *menu);
-GMenu* nautilus_view_get_templates_menu (NautilusView *view);
+ GMenuModel *menu);
+GMenuModel * nautilus_view_get_templates_menu (NautilusView *view);
void nautilus_view_set_extensions_background_menu (NautilusView *view,
- GMenu *menu);
-GMenu* nautilus_view_get_extensions_background_menu (NautilusView *view);
+ GMenuModel *menu);
+GMenuModel * nautilus_view_get_extensions_background_menu (NautilusView *view);
G_END_DECLS
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index ee15f4c68..eedac736a 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -128,8 +128,8 @@ typedef struct
gint view_mode_before_search;
/* Menus */
- GMenu *extensions_background_menu;
- GMenu *templates_menu;
+ GMenuModel *extensions_background_menu;
+ GMenuModel *templates_menu;
/* View bindings */
GBinding *searching_binding;
@@ -169,11 +169,11 @@ static void trash_state_changed_cb (NautilusTrashMonitor *monitor,
gpointer user_data);
static void update_search_information (NautilusWindowSlot *self);
static void real_set_extensions_background_menu (NautilusWindowSlot *self,
- GMenu *menu);
-static GMenu* real_get_extensions_background_menu (NautilusWindowSlot *self);
+ GMenuModel *menu);
+static GMenuModel* real_get_extensions_background_menu (NautilusWindowSlot *self);
static void real_set_templates_menu (NautilusWindowSlot *self,
- GMenu *menu);
-static GMenu* real_get_templates_menu (NautilusWindowSlot *self);
+ GMenuModel *menu);
+static GMenuModel* real_get_templates_menu (NautilusWindowSlot *self);
static void nautilus_window_slot_setup_extra_location_widgets (NautilusWindowSlot *self);
void
@@ -764,22 +764,22 @@ nautilus_window_slot_set_selection (NautilusWindowSlot *self,
static void
real_set_extensions_background_menu (NautilusWindowSlot *self,
- GMenu *menu)
+ GMenuModel *menu)
{
NautilusWindowSlotPrivate *priv;
priv = nautilus_window_slot_get_instance_private (self);
- priv->extensions_background_menu = menu != NULL ? g_object_ref (menu) : NULL;
+ g_set_object (&priv->extensions_background_menu, menu);
}
static void
real_set_templates_menu (NautilusWindowSlot *self,
- GMenu *menu)
+ GMenuModel *menu)
{
NautilusWindowSlotPrivate *priv;
priv = nautilus_window_slot_get_instance_private (self);
- priv->templates_menu = menu != NULL ? g_object_ref (menu) : NULL;
+ g_set_object (&priv->templates_menu, menu);;
}
static void
@@ -842,7 +842,7 @@ nautilus_window_slot_set_property (GObject *object,
}
}
-static GMenu*
+static GMenuModel*
real_get_extensions_background_menu (NautilusWindowSlot *self)
{
NautilusWindowSlotPrivate *priv;
@@ -851,17 +851,17 @@ real_get_extensions_background_menu (NautilusWindowSlot *self)
return priv->extensions_background_menu;
}
-GMenu*
+GMenuModel*
nautilus_window_slot_get_extensions_background_menu (NautilusWindowSlot *self)
{
- GMenu *menu = NULL;
+ GMenuModel *menu = NULL;
g_object_get (self, "extensions-background-menu", &menu, NULL);
return menu;
}
-static GMenu*
+static GMenuModel*
real_get_templates_menu (NautilusWindowSlot *self)
{
NautilusWindowSlotPrivate *priv;
@@ -870,10 +870,10 @@ real_get_templates_menu (NautilusWindowSlot *self)
return priv->templates_menu;
}
-GMenu*
+GMenuModel*
nautilus_window_slot_get_templates_menu (NautilusWindowSlot *self)
{
- GMenu *menu = NULL;
+ GMenuModel *menu = NULL;
g_object_get (self, "templates-menu", &menu, NULL);
@@ -3250,14 +3250,14 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
g_param_spec_object ("extensions-background-menu",
"Background menu of extensions",
"Proxy property from the view for the background menu for extensions",
- G_TYPE_MENU,
+ G_TYPE_MENU_MODEL,
G_PARAM_READWRITE);
properties[PROP_TEMPLATES_MENU] =
g_param_spec_object ("templates-menu",
"Templates menu",
"Proxy property from the view for the templates menu",
- G_TYPE_MENU,
+ G_TYPE_MENU_MODEL,
G_PARAM_READWRITE);
properties[PROP_LOCATION] =
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index b4f15b04a..04f7e5439 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -101,9 +101,9 @@ GIcon* nautilus_window_slot_get_icon (NautilusWindowSlot *
NautilusToolbarMenuSections * nautilus_window_slot_get_toolbar_menu_sections (NautilusWindowSlot *slot);
-GMenu* nautilus_window_slot_get_templates_menu (NautilusWindowSlot *self);
+GMenuModel* nautilus_window_slot_get_templates_menu (NautilusWindowSlot *self);
-GMenu* nautilus_window_slot_get_extensions_background_menu (NautilusWindowSlot *self);
+GMenuModel* nautilus_window_slot_get_extensions_background_menu (NautilusWindowSlot *self);
gboolean nautilus_window_slot_get_active (NautilusWindowSlot *slot);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]