[nautilus/wip/antoniof/use-cached-templates-menu-model: 1/2] files-view: Only refresh templates menu if needed
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/use-cached-templates-menu-model: 1/2] files-view: Only refresh templates menu if needed
- Date: Tue, 26 Oct 2021 11:28:11 +0000 (UTC)
commit b2458ecd3854baf35361fedaf58cd24658eddd6b
Author: António Fernandes <antoniof gnome org>
Date: Mon Dec 21 23:29:30 2020 +0000
files-view: Only refresh templates menu if needed
Menus are updates very frequently. Each time, we read the Templates
directory tree and recreate a menu model from it.
This is wasteful and may cause noticeable UI lag if the Templates
directory has got a lot of files and subdirectories.
We already have a file monitor in place which notifies us when the
content of the Templates directory actually changes, so we can rely
on it to know when we need to read the directory again instead;
otherwise, we can use the cached menu model.
Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/1069
Relates to https://gitlab.gnome.org/GNOME/nautilus/-/issues/1705
src/nautilus-files-view.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 4e57ae61e..c2b320dc7 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_refresh;
gboolean scripts_present;
gboolean in_destruction;
@@ -3049,6 +3050,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_refresh = TRUE;
if (priv->active)
{
schedule_update_context_menus (view);
@@ -5918,12 +5920,6 @@ update_templates_menu (NautilusFilesView *view,
directory = nautilus_directory_get_by_uri (templates_directory_uri);
submenu = update_directory_in_templates_menu (view, directory);
- if (submenu != NULL)
- {
- GObject *object;
- object = gtk_builder_get_object (builder, "templates-submenu");
- nautilus_gmenu_set_from_model (G_MENU (object), submenu);
- }
nautilus_view_set_templates_menu (NAUTILUS_VIEW (view), submenu);
@@ -8313,11 +8309,27 @@ static void
update_background_menu (NautilusFilesView *view,
GtkBuilder *builder)
{
+ NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view);
+ g_autoptr (GMenuModel) submenu = NULL;
+ GObject *object;
+
if (nautilus_files_view_supports_creating_files (view) &&
!showing_recent_directory (view) &&
!showing_starred_directory (view))
{
- update_templates_menu (view, builder);
+ if (priv->templates_menu_needs_refresh)
+ {
+ update_templates_menu (view, builder);
+ priv->templates_menu_needs_refresh = FALSE;
+ }
+
+ if (priv->templates_present)
+ {
+ submenu = nautilus_view_get_templates_menu (NAUTILUS_VIEW (view));
+ object = gtk_builder_get_object (builder, "templates-submenu");
+
+ nautilus_gmenu_set_from_model (G_MENU (object), submenu);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]