[nautilus/wip/antoniof/meets-valgrind: 12/12] templastes_WIP
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/meets-valgrind: 12/12] templastes_WIP
- Date: Tue, 22 Dec 2020 15:33:31 +0000 (UTC)
commit 6be4b60c91d7c4c166e77069a333fc833988293d
Author: António Fernandes <antoniof gnome org>
Date: Mon Dec 21 23:29:30 2020 +0000
templastes_WIP
src/nautilus-files-view.c | 17 ++++++++++++----
src/nautilus-pathbar.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 1e5d0fd2d..cb212ed06 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -221,6 +221,7 @@ typedef struct
*/
gboolean loading;
gboolean templates_present;
+ gboolean templates_menu_needs_update;
gboolean scripts_present;
gboolean in_destruction;
@@ -3002,6 +3003,7 @@ templates_added_or_changed_callback (NautilusDirectory *directory,
view = NAUTILUS_FILES_VIEW (callback_data);
priv = nautilus_files_view_get_instance_private (view);
+ priv->templates_menu_needs_update = TRUE;
if (priv->active)
{
schedule_update_context_menus (view);
@@ -5877,6 +5879,7 @@ update_templates_menu (NautilusFilesView *view,
return;
}
+ priv->templates_menu_needs_update = FALSE;
sorted_copy = nautilus_directory_list_sort_by_uri
(nautilus_directory_list_copy (priv->templates_directory_list));
@@ -8160,7 +8163,10 @@ static void
update_background_menu (NautilusFilesView *view,
GtkBuilder *builder)
{
- if (nautilus_files_view_supports_creating_files (view) &&
+ NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view);
+
+ if (priv->templates_menu_needs_update &&
+ nautilus_files_view_supports_creating_files (view) &&
!showing_recent_directory (view) &&
!showing_starred_directory (view))
{
@@ -8178,11 +8184,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_model);
g_clear_object (&priv->selection_menu_model);
- object = gtk_builder_get_object (builder, "background-menu");
- priv->background_menu_model = g_object_ref (G_MENU (object));
+ if (priv->background_menu_model == NULL ||
+ priv->templates_menu_needs_update)
+ {
+ object = gtk_builder_get_object (builder, "background-menu");
+ g_set_object (&priv->background_menu_model, G_MENU (object));
+ }
object = gtk_builder_get_object (builder, "selection-menu");
priv->selection_menu_model = g_object_ref (G_MENU (object));
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index edc0fff56..f22382ed8 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -940,13 +940,62 @@ nautilus_path_bar_set_extensions_background_menu (NautilusPathBar *self,
nautilus_gmenu_set_from_model (self->extensions_section, menu);
}
+static void
+remove_all_recursively (GMenu *menu)
+{
+ gint n_items;
+
+ n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu));
+ for (gint i = 0; i < n_items; i++)
+ {
+ GMenuModel *submenu;
+
+ submenu = g_menu_model_get_item_link (G_MENU_MODEL (menu), i, G_MENU_LINK_SUBMENU);
+
+ if (submenu != NULL)
+ {
+ remove_all_recursively (G_MENU (submenu));
+ }
+ }
+
+ g_menu_remove_all (menu);
+}
+
+
void
nautilus_path_bar_set_templates_menu (NautilusPathBar *self,
GMenuModel *menu)
{
+ GMenu *cvm = self->current_view_menu;
+ int n_items, i;
+ g_autoptr (GMenuItem) item = NULL;
+
g_return_if_fail (NAUTILUS_IS_PATH_BAR (self));
- nautilus_gmenu_set_from_model (self->templates_submenu, menu);
+ n_items = g_menu_model_get_n_items (G_MENU_MODEL (cvm));
+ for (i = 0; i < n_items; i++)
+ {
+ g_autofree gchar *action = NULL;
+
+ g_menu_model_get_item_attribute (G_MENU_MODEL (cvm), i, "action", "s", &action);
+
+ if (g_strcmp0 (action, "view.new-document") == 0)
+ {
+ item = g_menu_item_new_from_model (G_MENU_MODEL (cvm), i);
+ break;
+ }
+ }
+ g_assert (item != NULL);
+ g_menu_item_set_submenu (item, menu);
+
+ if (self->templates_submenu != NULL)
+ {
+ remove_all_recursively (self->templates_submenu);
+ }
+
+ g_menu_remove (cvm, i);
+ g_menu_insert_item (cvm, i, item);
+ g_set_object (&self->templates_submenu, G_MENU (menu));
}
/* Changes the icons wherever it is needed */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]