diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c index e73cccb..ab8658b 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -2426,7 +2426,7 @@ mousepad_window_menu_templates (GtkWidget *item, { GtkWidget *submenu; const gchar *homedir; - gchar *templates_path; + const gchar *templates_path; g_return_if_fail (MOUSEPAD_IS_WINDOW (window)); g_return_if_fail (GTK_IS_MENU_ITEM (item)); @@ -2434,13 +2434,19 @@ mousepad_window_menu_templates (GtkWidget *item, /* schedule the idle build of the recent menu */ mousepad_window_recent_menu (window); - /* get the home directory */ - homedir = g_getenv ("HOME"); - if (G_UNLIKELY (homedir == NULL)) - homedir = g_get_home_dir (); - /* get the templates path */ - templates_path = g_build_filename (homedir, "Templates", NULL); + templates_path = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES); + + /* check if the the template directory is valid */ + if (G_UNLIKELY (templates_path == NULL)) + { + /* if not, fallback to "~/Templates" */ + homedir = g_getenv ("HOME"); + if (G_UNLIKELY (homedir == NULL)) + homedir = g_get_home_dir (); + + templates_path = g_build_filename (homedir, "Templates", NULL); + } /* check if the directory exists */ if (g_file_test (templates_path, G_FILE_TEST_IS_DIR)) @@ -2464,9 +2470,6 @@ mousepad_window_menu_templates (GtkWidget *item, /* hide the templates menu item */ gtk_widget_hide (item); } - - /* cleanup */ - g_free (templates_path); }