forked from AuroraMiddleware/gtk
gtk-builder-tool: Separate commands
Add separate commands for validation and simplification.
This commit is contained in:
parent
43cee06160
commit
d7523423d4
@ -30,17 +30,31 @@
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>gtk-builder-tool</command>
|
||||
<arg choice="opt"><replaceable>COMMAND</replaceable></arg>
|
||||
<arg choice="plain"><replaceable>FILE</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1><title>Description</title>
|
||||
<para>
|
||||
<command>gtk-builder-tool</command> validates and simplifies a GtkBuilder
|
||||
.ui file. Any validation errors are reported on stderr. If the file is
|
||||
valid, it is simplified by removing any properties that are set to their
|
||||
default value. The resulting xml is written to stdout.
|
||||
<command>gtk-builder-tool</command> can perform various operations
|
||||
on GtkBuilder .ui files.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1><title>Commands</title>
|
||||
<para>The following commands are understood:</para>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><option>validate</option></term>
|
||||
<listitem><para>Validate the .ui file and report errors to stderr.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>simplify</option></term>
|
||||
<listitem><para>Simplify the .ui file by removing properties that
|
||||
are set to their default values and write the resulting XML to stdout.</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
@ -362,7 +362,7 @@ GMarkupParser parser = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
do_simplify (const gchar *filename)
|
||||
{
|
||||
GMarkupParseContext *context;
|
||||
@ -373,7 +373,7 @@ do_simplify (const gchar *filename)
|
||||
if (!g_file_get_contents (filename, &buffer, NULL, &error))
|
||||
{
|
||||
g_printerr (_("Can't load file: %s\n"), error->message);
|
||||
return FALSE;
|
||||
exit (1);
|
||||
}
|
||||
|
||||
data.builder = gtk_builder_new ();
|
||||
@ -390,13 +390,11 @@ do_simplify (const gchar *filename)
|
||||
if (!g_markup_parse_context_parse (context, buffer, -1, &error))
|
||||
{
|
||||
g_printerr (_("Can't parse file: %s\n"), error->message);
|
||||
return FALSE;
|
||||
exit (1);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
do_validate (const gchar *filename)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
@ -410,16 +408,20 @@ do_validate (const gchar *filename)
|
||||
if (ret == 0)
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
return FALSE;
|
||||
exit (1);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
usage (void)
|
||||
{
|
||||
g_print (_("Usage: gtk-builder-tool FILE\n"
|
||||
g_print (_("Usage:\n"
|
||||
" gtk-builder-tool [COMMAND] FILE\n"
|
||||
"\n"
|
||||
"Commands:\n"
|
||||
" validate Validate the file\n"
|
||||
" simplify Simplify the file\n"
|
||||
"\n"
|
||||
"Validate and simplify GtkBuilder .ui files.\n"));
|
||||
exit (1);
|
||||
}
|
||||
@ -433,14 +435,15 @@ main (int argc, char *argv[])
|
||||
|
||||
gtk_test_register_all_types ();
|
||||
|
||||
if (argc < 2)
|
||||
if (argc < 3)
|
||||
usage ();
|
||||
|
||||
if (!do_validate (argv[1]))
|
||||
return 1;
|
||||
|
||||
if (!do_simplify (argv[1]))
|
||||
return 1;
|
||||
if (strcmp (argv[1], "validate") == 0)
|
||||
do_validate (argv[2]);
|
||||
else if (strcmp (argv[1], "simplify") == 0)
|
||||
do_simplify (argv[2]);
|
||||
else
|
||||
usage ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user