summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-04-17 11:59:06 -0400
committerMatthias Clasen <mclasen@redhat.com>2022-04-17 12:57:46 -0400
commitc5e26dd591d558890cfa41392924078b0ac7e334 (patch)
tree85a2ec405cbc66d8fe4dbf0cdac9c1ea034a015c
parentb88ac0890eaeb4294d41ba409cbd8460d575fcad (diff)
downloadgtk+-c5e26dd591d558890cfa41392924078b0ac7e334.tar.gz
gtk-builder-tool: Reshuffle --help
Use GOptionContext better.
-rw-r--r--po/POTFILES.in3
-rw-r--r--tools/gtk-builder-tool-enumerate.c40
-rw-r--r--tools/gtk-builder-tool-preview.c12
-rw-r--r--tools/gtk-builder-tool-simplify.c24
-rw-r--r--tools/gtk-builder-tool-validate.c30
-rw-r--r--tools/gtk-builder-tool.c17
6 files changed, 96 insertions, 30 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0e56e619c6..99c2034b9a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -403,6 +403,9 @@ modules/printbackends/gtkprintbackendlpr.c
modules/printbackends/gtkprintercups.c
tools/encodesymbolic.c
tools/gtk-builder-tool.c
+tools/gtk-builder-tool-enumerate.c
+tools/gtk-builder-tool-preview.c
tools/gtk-builder-tool-simplify.c
+tools/gtk-builder-tool-validate.c
tools/gtk-launch.c
tools/updateiconcache.c
diff --git a/tools/gtk-builder-tool-enumerate.c b/tools/gtk-builder-tool-enumerate.c
index feb3758cc5..f0c6c8dc7e 100644
--- a/tools/gtk-builder-tool-enumerate.c
+++ b/tools/gtk-builder-tool-enumerate.c
@@ -17,6 +17,8 @@
* Author: Matthias Clasen
*/
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -46,12 +48,42 @@ do_enumerate (int *argc, const char ***argv)
GSList *list, *l;
GObject *object;
const char *name;
- const char *filename;
+ char **filenames = NULL;
+ GOptionContext *context;
+ const GOptionEntry entries[] = {
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE") },
+ { NULL, }
+ };
+
+ g_set_prgname ("gtk4-builder-tool enumerate");
+ context = g_option_context_new (NULL);
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_set_summary (context, _("List all named objects."));
+
+ if (!g_option_context_parse (context, argc, (char ***)argv, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ exit (1);
+ }
+
+ g_option_context_free (context);
- filename = (*argv)[1];
+ if (filenames == NULL)
+ {
+ g_printerr ("No .ui file specified\n");
+ exit (1);
+ }
+
+ if (g_strv_length (filenames) > 1)
+ {
+ g_printerr ("Can only enumerate a single .ui file\n");
+ exit (1);
+ }
builder = gtk_builder_new ();
- ret = gtk_builder_add_from_file (builder, filename, &error);
+ ret = gtk_builder_add_from_file (builder, filenames[0], &error);
if (ret == 0)
{
@@ -72,4 +104,6 @@ do_enumerate (int *argc, const char ***argv)
g_slist_free (list);
g_object_unref (builder);
+
+ g_strfreev (filenames);
}
diff --git a/tools/gtk-builder-tool-preview.c b/tools/gtk-builder-tool-preview.c
index df6e29976f..6c7473d80e 100644
--- a/tools/gtk-builder-tool-preview.c
+++ b/tools/gtk-builder-tool-preview.c
@@ -17,6 +17,8 @@
* Author: Matthias Clasen
*/
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -173,9 +175,9 @@ do_preview (int *argc,
char *css = NULL;
char **filenames = NULL;
const GOptionEntry entries[] = {
- { "id", 0, 0, G_OPTION_ARG_STRING, &id, NULL, NULL },
- { "css", 0, 0, G_OPTION_ARG_FILENAME, &css, NULL, NULL },
- { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, NULL },
+ { "id", 0, 0, G_OPTION_ARG_STRING, &id, N_("Preview only the named object"), N_("ID") },
+ { "css", 0, 0, G_OPTION_ARG_FILENAME, &css, N_("Use style from CSS file"), N_("FILE") },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE") },
{ NULL, }
};
GError *error = NULL;
@@ -186,9 +188,11 @@ do_preview (int *argc,
exit (1);
}
+ g_set_prgname ("gtk4-builder-tool preview");
context = g_option_context_new (NULL);
- g_option_context_set_help_enabled (context, FALSE);
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_set_summary (context, _("Preview the file."));
if (!g_option_context_parse (context, argc, (char ***)argv, &error))
{
diff --git a/tools/gtk-builder-tool-simplify.c b/tools/gtk-builder-tool-simplify.c
index fb3acdde40..21dcfa2dc6 100644
--- a/tools/gtk-builder-tool-simplify.c
+++ b/tools/gtk-builder-tool-simplify.c
@@ -17,6 +17,8 @@
* Author: Matthias Clasen
*/
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -2351,28 +2353,30 @@ do_simplify (int *argc,
gboolean replace = FALSE;
gboolean convert3to4 = FALSE;
char **filenames = NULL;
- GOptionContext *ctx;
+ GOptionContext *context;
const GOptionEntry entries[] = {
- { "replace", 0, 0, G_OPTION_ARG_NONE, &replace, NULL, NULL },
- { "3to4", 0, 0, G_OPTION_ARG_NONE, &convert3to4, NULL, NULL },
- { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, NULL },
+ { "replace", 0, 0, G_OPTION_ARG_NONE, &replace, N_("Replace the file"), NULL },
+ { "3to4", 0, 0, G_OPTION_ARG_NONE, &convert3to4, N_("Convert from GTK 3 to GTK 4"), NULL },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE") },
{ NULL, }
};
GError *error = NULL;
int i;
- ctx = g_option_context_new (NULL);
- g_option_context_set_help_enabled (ctx, FALSE);
- g_option_context_add_main_entries (ctx, entries, NULL);
+ g_set_prgname ("gtk4-builder-tool simplify");
+ context = g_option_context_new (NULL);
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_set_summary (context, _("Simplify the file."));
- if (!g_option_context_parse (ctx, argc, (char ***)argv, &error))
+ if (!g_option_context_parse (context, argc, (char ***)argv, &error))
{
g_printerr ("%s\n", error->message);
g_error_free (error);
exit (1);
}
- g_option_context_free (ctx);
+ g_option_context_free (context);
if (filenames == NULL)
{
@@ -2391,4 +2395,6 @@ do_simplify (int *argc,
if (!simplify_file (filenames[i], replace, convert3to4))
exit (1);
}
+
+ g_strfreev (filenames);
}
diff --git a/tools/gtk-builder-tool-validate.c b/tools/gtk-builder-tool-validate.c
index 8551231730..aa4069fd36 100644
--- a/tools/gtk-builder-tool-validate.c
+++ b/tools/gtk-builder-tool-validate.c
@@ -17,6 +17,8 @@
* Author: Matthias Clasen
*/
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -150,11 +152,35 @@ validate_file (const char *filename)
void
do_validate (int *argc, const char ***argv)
{
+ GError *error = NULL;
+ char **filenames = NULL;
+ GOptionContext *context;
+ const GOptionEntry entries[] = {
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE") },
+ { NULL, }
+ };
int i;
- for (i = 1; i < *argc; i++)
+ g_set_prgname ("gtk4-builder-tool validate");
+ context = g_option_context_new (NULL);
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_set_summary (context, _("Validate the file."));
+
+ if (!g_option_context_parse (context, argc, (char ***)argv, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ exit (1);
+ }
+
+ g_option_context_free (context);
+
+ for (i = 0; filenames[i]; i++)
{
- if (!validate_file ((*argv)[i]))
+ if (!validate_file (filenames[i]))
exit (1);
}
+
+ g_strfreev (filenames);
}
diff --git a/tools/gtk-builder-tool.c b/tools/gtk-builder-tool.c
index 7de50fc283..ff47e81bd3 100644
--- a/tools/gtk-builder-tool.c
+++ b/tools/gtk-builder-tool.c
@@ -34,21 +34,14 @@ usage (void)
g_print (_("Usage:\n"
" gtk-builder-tool [COMMAND] [OPTION…] FILE\n"
"\n"
+ "Perform various tasks on GtkBuilder .ui files.\n"
+ "\n"
"Commands:\n"
" validate Validate the file\n"
" simplify Simplify the file\n"
" enumerate List all named objects\n"
" preview Preview the file\n"
- "\n"
- "Simplify Options:\n"
- " --replace Replace the file\n"
- " --3to4 Convert from GTK 3 to GTK 4\n"
- "\n"
- "Preview Options:\n"
- " --id=ID Preview only the named object\n"
- " --css=FILE Use style from CSS file\n"
- "\n"
- "Perform various tasks on GtkBuilder .ui files.\n"));
+ "\n"));
exit (1);
}
@@ -117,10 +110,10 @@ main (int argc, const char *argv[])
gtk_test_register_all_types ();
- if (argc < 3)
+ if (argc < 2)
usage ();
- if (strcmp (argv[2], "--help") == 0)
+ if (strcmp (argv[1], "--help") == 0)
usage ();
argv++;