diff --git a/thunar/thunar-action-manager.c b/thunar/thunar-action-manager.c index d3da8b318de1b1be654f4ce6652f2e1e25fcd7c1..48e34b132bfe9c97ca50a69e638609ad292876bf 100644 --- a/thunar/thunar-action-manager.c +++ b/thunar/thunar-action-manager.c @@ -2884,9 +2884,12 @@ thunar_action_manager_create_document_submenu_new (ThunarActionManager *action_m gchar *label_text; GtkWidget *submenu; GtkWidget *item; + guint file_scan_limit; _thunar_return_val_if_fail (THUNAR_IS_ACTION_MANAGER (action_mgr), NULL); + g_object_get (G_OBJECT (action_mgr->preferences), "misc-max-number-of-templates", &file_scan_limit, NULL); + home_dir = thunar_g_file_new_for_home (); path = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES); @@ -2904,7 +2907,7 @@ thunar_action_manager_create_document_submenu_new (ThunarActionManager *action_m if (G_LIKELY (templates_dir != NULL)) { /* load the ThunarFiles */ - files = thunar_io_scan_directory (NULL, templates_dir, G_FILE_QUERY_INFO_NONE, TRUE, FALSE, TRUE, NULL); + files = thunar_io_scan_directory (NULL, templates_dir, G_FILE_QUERY_INFO_NONE, TRUE, FALSE, TRUE, &file_scan_limit, NULL); } submenu = gtk_menu_new(); @@ -2926,6 +2929,14 @@ thunar_action_manager_create_document_submenu_new (ThunarActionManager *action_m xfce_gtk_menu_append_separator (GTK_MENU_SHELL (submenu)); xfce_gtk_image_menu_item_new_from_icon_name (_("_Empty File"), NULL, NULL, G_CALLBACK (thunar_action_manager_action_create_document), G_OBJECT (action_mgr), "text-x-generic", GTK_MENU_SHELL (submenu)); + + if (file_scan_limit == 0) + { + xfce_gtk_menu_append_separator (GTK_MENU_SHELL (submenu)); + xfce_gtk_image_menu_item_new_from_icon_name (("The maximum number of templates was exceeded.\n" + "Adjust 'misc-max-number-of-templates' if required."), NULL, NULL, NULL, + G_OBJECT (action_mgr), "dialog-warning", GTK_MENU_SHELL (submenu)); + } g_object_unref (templates_dir); diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index bce145c1b5d996732f79c6fe5d85758f2edad64c..8e355c7a33eb9676347d4f80af5a73d9c586901e 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -63,7 +63,7 @@ _tij_collect_nofollow (ThunarJob *job, /* try to scan the directory */ child_file_list = thunar_io_scan_directory (job, lp->data, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - TRUE, unlinking, FALSE, &err); + TRUE, unlinking, FALSE, NULL, &err); /* prepend the new files to the existing list */ file_list = thunar_g_list_prepend_deep (file_list, lp->data); @@ -1295,7 +1295,7 @@ _thunar_io_jobs_ls (ThunarJob *job, /* collect directory contents (non-recursively) */ file_list = thunar_io_scan_directory (job, directory, G_FILE_QUERY_INFO_NONE, - FALSE, FALSE, TRUE, &err); + FALSE, FALSE, TRUE, NULL, &err); /* abort on errors or cancellation */ if (err != NULL) diff --git a/thunar/thunar-io-scan-directory.c b/thunar/thunar-io-scan-directory.c index 822a351bd4ed0fe83372bd16d850aabca293d1c8..daad82c7d23cae64550ac9f10612561c7689b0a4 100644 --- a/thunar/thunar-io-scan-directory.c +++ b/thunar/thunar-io-scan-directory.c @@ -32,7 +32,21 @@ #include <thunar/thunar-io-scan-directory.h> - +/** + * thunar_io_scan_directory: + * @job : a #ThunarJob instance + * @file : The folder to scan + * @flags : @GFileQueryInfoFlags to consider during scan + * @recursively : Wheather as well subfolders should be scanned + * @unlinking : ??? + * @return_thunar_files : TRUE in order to return the result as a list of #ThunarFile's, FALSE to return a list of #GFile's + * @n_files_max : Maximum number of files to scan, NULL for unlimited + * @error : Will be se on any error + * + * Scans the passed folder for files and returns them as a #GList + * + * Return value: (transfer full): the #GLIst of #GFiles or #ThunarFiles, to be released with e.g. 'g_list_free_full' + **/ GList * thunar_io_scan_directory (ThunarJob *job, GFile *file, @@ -40,6 +54,7 @@ thunar_io_scan_directory (ThunarJob *job, gboolean recursively, gboolean unlinking, gboolean return_thunar_files, + guint *n_files_max, GError **error) { GFileEnumerator *enumerator; @@ -116,6 +131,14 @@ thunar_io_scan_directory (ThunarJob *job, if (G_UNLIKELY (info == NULL && err == NULL)) break; + if (G_UNLIKELY (n_files_max != NULL)) + { + if (*n_files_max == 0) + break; + else + (*n_files_max)--; + } + is_mounted = TRUE; if (err != NULL) { @@ -188,7 +211,7 @@ thunar_io_scan_directory (ThunarJob *job, && g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { child_files = thunar_io_scan_directory (job, child_file, flags, recursively, - unlinking, return_thunar_files, &err); + unlinking, return_thunar_files, n_files_max, &err); /* prepend children to the file list to make sure they're * processed first (required for unlinking) */ diff --git a/thunar/thunar-io-scan-directory.h b/thunar/thunar-io-scan-directory.h index 8137d6a019d516dfc122e2ff73a3137551009aaf..06c89d2082c541134ebeae4d4470539617c351ed 100644 --- a/thunar/thunar-io-scan-directory.h +++ b/thunar/thunar-io-scan-directory.h @@ -34,6 +34,7 @@ GList *thunar_io_scan_directory (ThunarJob *job, gboolean recursively, gboolean unlinking, gboolean return_thunar_files, + guint *n_files_max, GError **error); G_END_DECLS diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 23c97d295a1e3eccb331a84ac8f50c2c5f9009f3..b10146c0c456c5898811ad8c509ade1b5300e574 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -128,6 +128,7 @@ enum PROP_MISC_HIGHLIGHTING_ENABLED, PROP_MISC_UNDO_REDO_HISTORY_SIZE, PROP_MISC_CONFIRM_MOVE_TO_TRASH, + PROP_MISC_MAX_NUMBER_OF_TEMPLATES, N_PROPERTIES, }; @@ -1201,7 +1202,21 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) NULL, FALSE, EXO_PARAM_READWRITE); - + + /** + * ThunarPreferences:misc-max-number-of-templates + * + * Maximum number of templates for which will be scanned in the 'templates' directory + * Required to prevent possible lag when thecontext menu is opened + **/ + preferences_props[PROP_MISC_MAX_NUMBER_OF_TEMPLATES] = + g_param_spec_uint ("misc-max-number-of-templates", + "MiscMaxNumberOfTemplates", + NULL, + 0, G_MAXUINT, + 100, + EXO_PARAM_READWRITE); + /* install all properties */ g_object_class_install_properties (gobject_class, N_PROPERTIES, preferences_props); } diff --git a/thunar/thunar-transfer-job.c b/thunar/thunar-transfer-job.c index 10365d1e4351a6a6cb9a842abd9c09f6a8f7ba06..19d4d77782e374149b288344e834b27bf8141e91 100644 --- a/thunar/thunar-transfer-job.c +++ b/thunar/thunar-transfer-job.c @@ -417,7 +417,7 @@ thunar_transfer_job_collect_node (ThunarTransferJob *job, /* scan the directory for immediate children */ file_list = thunar_io_scan_directory (THUNAR_JOB (job), node->source_file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - FALSE, FALSE, FALSE, &err); + FALSE, FALSE, FALSE, NULL, &err); /* add children to the transfer node */ for (lp = file_list; err == NULL && lp != NULL; lp = lp->next)