From e2ef69d67fc4fdf2673179c43e74e4642c033fe4 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sun, 12 Feb 2023 17:53:17 +0000 Subject: [PATCH 1/6] Add new file templates to Config Files menu Move config_files_menu to ui_widgets. --- src/templates.c | 33 ++++++++++++++++++++++++++++++--- src/ui_utils.c | 7 +++---- src/ui_utils.h | 1 + src/utils.c | 1 + 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/templates.c b/src/templates.c index ebf4c89e0c..d5bb409a2a 100644 --- a/src/templates.c +++ b/src/templates.c @@ -271,9 +271,11 @@ static void populate_file_template_menu(GtkWidget *menu) } -static void create_file_template_menu(void) +static void create_file_template_menus(void) { - GtkWidget *item; + GtkWidget *item, *menu; + GSList *list, *node; + const gchar *subdir; new_with_template_menu = gtk_menu_new(); item = ui_lookup_widget(main_widgets.window, "menu_new_with_template1"); @@ -283,6 +285,31 @@ static void create_file_template_menu(void) g_object_ref(new_with_template_toolbar_menu); geany_menu_button_action_set_menu(GEANY_MENU_BUTTON_ACTION(toolbar_get_action_by_name("New")), new_with_template_toolbar_menu); + + // create config files menu + item = gtk_menu_item_new_with_mnemonic(_("Templates")); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(ui_widgets.config_files_menu), item); + menu = gtk_menu_new(); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + + item = gtk_menu_item_new_with_mnemonic(_("Files")); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(menu), item); + menu = gtk_menu_new(); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + + subdir = GEANY_TEMPLATES_SUBDIR G_DIR_SEPARATOR_S "files"; + list = utils_get_config_files(subdir); + foreach_slist(node, list) + { + gchar *fname = node->data; + + SETPTR(fname, g_build_filename(app->configdir, subdir, fname, NULL)); + ui_add_config_file_menu_item(fname, NULL, GTK_CONTAINER(menu)); + g_free(fname); + } + g_slist_free(list); } @@ -313,7 +340,7 @@ void templates_init(void) if (!init_done) { - create_file_template_menu(); + create_file_template_menus(); g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL); init_done = TRUE; } diff --git a/src/ui_utils.c b/src/ui_utils.c index 8ba90ef481..d53c72eea9 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -93,7 +93,6 @@ static struct GtkWidget *redo_items[3]; GtkWidget *undo_items[3]; GtkWidget *save_buttons[4]; - GtkWidget *config_files_menu; } widgets; @@ -2161,7 +2160,7 @@ void ui_add_config_file_menu_item(const gchar *real_path, const gchar *label, Gt GtkWidget *item; if (!parent) - parent = GTK_CONTAINER(widgets.config_files_menu); + parent = GTK_CONTAINER(ui_widgets.config_files_menu); if (!label) { @@ -2192,7 +2191,7 @@ static void create_config_files_menu(void) { GtkWidget *menu, *item; - widgets.config_files_menu = menu = gtk_menu_new(); + ui_widgets.config_files_menu = menu = gtk_menu_new(); item = ui_lookup_widget(main_widgets.window, "configuration_files1"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); @@ -2204,7 +2203,7 @@ static void create_config_files_menu(void) gtk_widget_show(item); /* sort menu after all items added */ - g_idle_add(sort_menu, widgets.config_files_menu); + g_idle_add(sort_menu, ui_widgets.config_files_menu); } diff --git a/src/ui_utils.h b/src/ui_utils.h index 6ac5534deb..2a6cd0c67b 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -195,6 +195,7 @@ typedef struct UIWidgets GtkWidget *print_page_setup; GtkWidget *recent_projects_menuitem; GtkWidget *recent_projects_menu_menubar; + GtkWidget *config_files_menu; GtkWidget *config_files_filetype_menu; /* dialogs */ diff --git a/src/utils.c b/src/utils.c index 2a8cccddb5..6c5a7c3113 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1889,6 +1889,7 @@ GSList *utils_get_config_files(const gchar *subdir) if (!list) { + // create user config subdirectory utils_mkdir(path, FALSE); } SETPTR(path, g_build_path(G_DIR_SEPARATOR_S, app->datadir, subdir, NULL)); From 52fce9de756954c8a1e3bf33f7b298220481b2ab Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 13 Feb 2023 11:28:21 +0000 Subject: [PATCH 2/6] List general templates too --- src/templates.c | 11 +++++++++++ src/utils.c | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/templates.c b/src/templates.c index d5bb409a2a..0d059480a9 100644 --- a/src/templates.c +++ b/src/templates.c @@ -292,6 +292,17 @@ static void create_file_template_menus(void) gtk_container_add(GTK_CONTAINER(ui_widgets.config_files_menu), item); menu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + list = utils_get_config_files(GEANY_TEMPLATES_SUBDIR); + foreach_slist(node, list) + { + gchar *fname = node->data; + + SETPTR(fname, g_build_filename(app->configdir, GEANY_TEMPLATES_SUBDIR, fname, NULL)); + if (!g_file_test(fname, G_FILE_TEST_IS_DIR)) + ui_add_config_file_menu_item(fname, NULL, GTK_CONTAINER(menu)); + g_free(fname); + } + g_slist_free(list); item = gtk_menu_item_new_with_mnemonic(_("Files")); gtk_widget_show(item); diff --git a/src/utils.c b/src/utils.c index 6c5a7c3113..dd464feda5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1880,7 +1880,8 @@ gchar *utils_str_remove_chars(gchar *string, const gchar *chars) } -/* Gets list of sorted filenames with no path and no duplicates from user and system config */ +/* Gets list of sorted filenames with no path and no duplicates from user and system config. + * Filenames are in locale encoding. */ GSList *utils_get_config_files(const gchar *subdir) { gchar *path = g_build_path(G_DIR_SEPARATOR_S, app->configdir, subdir, NULL); From 937485a7181156fab959ed79304a2442aca2e10c Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 13 Feb 2023 12:15:22 +0000 Subject: [PATCH 3/6] Put items with submenus at the top of the menu --- src/ui_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui_utils.c b/src/ui_utils.c index d53c72eea9..f558e19e3f 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -2874,11 +2874,11 @@ static gint compare_menu_item_labels(gconstpointer a, gconstpointer b) gchar *sa, *sb; gint result; - /* put entries with submenus at the end of the menu */ + /* put entries with submenus at the start of the menu */ if (gtk_menu_item_get_submenu(item_a) && !gtk_menu_item_get_submenu(item_b)) - return 1; - else if (!gtk_menu_item_get_submenu(item_a) && gtk_menu_item_get_submenu(item_b)) return -1; + else if (!gtk_menu_item_get_submenu(item_a) && gtk_menu_item_get_submenu(item_b)) + return 1; sa = ui_menu_item_get_text(item_a); sb = ui_menu_item_get_text(item_b); From 558c70ac81f439bbd91b952dd256b4b5ccf8ebed Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 15 Feb 2023 11:58:16 +0000 Subject: [PATCH 4/6] Update docs --- doc/geany.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/geany.txt b/doc/geany.txt index 5612b9558a..91da951b8a 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -3973,8 +3973,8 @@ On Windows 7 and above you most likely will find it at: ``C:\users\UserName\Roaming\geany`` -Tools menu items ----------------- +Configuration files menu +------------------------ There's a *Configuration files* submenu in the *Tools* menu that contains items for some of the available user configuration files. Clicking on one opens it in the editor for you to update. Geany will @@ -4958,17 +4958,17 @@ clicked. Customizing templates ^^^^^^^^^^^^^^^^^^^^^ -Each template can be customized to your needs. The templates are -stored in the ``~/.config/geany/templates/`` directory (see the section called -`Command line options`_ for further information about the configuration -directory). Just open the desired template with an editor (ideally, -Geany ;-) ) and edit the template to your needs. There are some -wildcards which will be automatically replaced by Geany at startup. +Each template can be customized to your needs. User templates are +stored in the ``templates`` subdirectory of your configuration directory +(see `Configuration file paths`_). +These can be handily opened for editing using the +*Tools->Configuration Files->Templates* submenu. See also: `Configuration files menu`_. Template wildcards `````````````````` +There are some wildcards which will be automatically replaced by Geany on inserting a template. All wildcards must be enclosed by "{" and "}", e.g. {date}. **Wildcards for character escaping** From 4da55f97cfb662a21953d8f38513e6982ce08855 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 15 Feb 2023 13:35:44 +0000 Subject: [PATCH 5/6] Tweak template wildcards formatting --- doc/geany.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/geany.txt b/doc/geany.txt index 91da951b8a..0d6a3cb5ce 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -4968,8 +4968,9 @@ These can be handily opened for editing using the Template wildcards `````````````````` -There are some wildcards which will be automatically replaced by Geany on inserting a template. -All wildcards must be enclosed by "{" and "}", e.g. {date}. +There are some wildcards which will be automatically replaced by Geany on inserting a template +or completing a snippet (see `User-definable snippets`_). +All wildcards must be enclosed by "{" and "}", e.g. ``{date}``. **Wildcards for character escaping** From abfaf3b282ccaf46c9cdb2ecb25dd3205caacf9a Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 6 Oct 2023 16:14:08 +0100 Subject: [PATCH 6/6] Move Files submenu to top --- src/templates.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/templates.c b/src/templates.c index 0d059480a9..704e81d8a9 100644 --- a/src/templates.c +++ b/src/templates.c @@ -307,6 +307,8 @@ static void create_file_template_menus(void) item = gtk_menu_item_new_with_mnemonic(_("Files")); gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item); + gtk_menu_reorder_child(GTK_MENU(menu), item, 0); + menu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);