From 37c6fbc6b23613384627f6618c0016e99e2a7d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 6 Nov 2019 10:06:11 +0100 Subject: [PATCH] extensions-tool: Prepare for alternative templates The template used when creating a new extension is intentionally minimal, as the sample code in the old extensions-tool proved to be annoying more often than not. However as we support per-command options, we don't have to limit ourselves to a single template, and can offer alternatives for common use cases. To prepare for that, namespace the existing template by moving it into a subfolder. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/812 --- .../extensions-tool/src/command-create.c | 21 ++++++++++++++----- .../src/gnome-extensions-tool.gresource.xml | 4 ++-- .../plain}/extension.js | 0 .../plain}/stylesheet.css | 0 4 files changed, 18 insertions(+), 7 deletions(-) rename subprojects/extensions-tool/src/{template => templates/plain}/extension.js (100%) rename subprojects/extensions-tool/src/{template => templates/plain}/stylesheet.css (100%) diff --git a/subprojects/extensions-tool/src/command-create.c b/subprojects/extensions-tool/src/command-create.c index 25fcc5ba0..000cf94d2 100644 --- a/subprojects/extensions-tool/src/command-create.c +++ b/subprojects/extensions-tool/src/command-create.c @@ -26,6 +26,8 @@ #include "common.h" #include "config.h" +#define TEMPLATES_PATH "/org/gnome/extensions-tool/templates" + static char * get_shell_version (GError **error) { @@ -85,21 +87,30 @@ create_metadata (GFile *target_dir, } -#define TEMPLATE_PATH "/org/gnome/extensions-tool/template" static gboolean -copy_extension_template (GFile *target_dir, GError **error) +copy_extension_template (const char *template, GFile *target_dir, GError **error) { g_auto (GStrv) templates = NULL; + g_autofree char *path = NULL; char **s; - templates = g_resources_enumerate_children (TEMPLATE_PATH, 0, NULL); + path = g_strdup_printf (TEMPLATES_PATH "/%s", template); + templates = g_resources_enumerate_children (path, 0, NULL); + + if (templates == NULL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + "No template %s", template); + return FALSE; + } + for (s = templates; *s; s++) { g_autoptr (GFile) target = NULL; g_autoptr (GFile) source = NULL; g_autofree char *uri = NULL; - uri = g_strdup_printf ("resource://%s/%s", TEMPLATE_PATH, *s); + uri = g_strdup_printf ("resource://%s/%s", path, *s); source = g_file_new_for_uri (uri); target = g_file_get_child (target_dir, *s); @@ -157,7 +168,7 @@ create_extension (const char *uuid, const char *name, const char *description) return FALSE; } - if (!copy_extension_template (dir, &error)) + if (!copy_extension_template ("plain", dir, &error)) { g_printerr ("%s\n", error->message); return FALSE; diff --git a/subprojects/extensions-tool/src/gnome-extensions-tool.gresource.xml b/subprojects/extensions-tool/src/gnome-extensions-tool.gresource.xml index 2aad7b1ce..dce8d5c66 100644 --- a/subprojects/extensions-tool/src/gnome-extensions-tool.gresource.xml +++ b/subprojects/extensions-tool/src/gnome-extensions-tool.gresource.xml @@ -1,7 +1,7 @@ - template/extension.js - template/stylesheet.css + templates/plain/extension.js + templates/plain/stylesheet.css diff --git a/subprojects/extensions-tool/src/template/extension.js b/subprojects/extensions-tool/src/templates/plain/extension.js similarity index 100% rename from subprojects/extensions-tool/src/template/extension.js rename to subprojects/extensions-tool/src/templates/plain/extension.js diff --git a/subprojects/extensions-tool/src/template/stylesheet.css b/subprojects/extensions-tool/src/templates/plain/stylesheet.css similarity index 100% rename from subprojects/extensions-tool/src/template/stylesheet.css rename to subprojects/extensions-tool/src/templates/plain/stylesheet.css