This commit is contained in:
TheBrokenRail 2022-03-10 22:37:39 -05:00
parent 6cf0447c3b
commit dc72103c6a
6 changed files with 86 additions and 107 deletions

View File

@ -55,8 +55,8 @@ main (gint argc, gchar **argv) {
zenity_tree (results->data, results->tree_data); zenity_tree (results->data, results->tree_data);
break; break;
case MODE_LAST: case MODE_LAST:
g_printerr ("You must specify a dialog type. See 'zenity " g_printerr ("You must specify a dialog type. See 'zenity "
"--help' for details\n"); "--help' for details\n");
zenity_option_free (); zenity_option_free ();
exit (-1); exit (-1);
default: default:

View File

@ -67,72 +67,72 @@ static GOptionEntry general_options[] = {{"title",
0, 0,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_general_dialog_title, &zenity_general_dialog_title,
"Set the dialog title", "Set the dialog title",
"TITLE"}, "TITLE"},
{"window-icon", {"window-icon",
'\0', '\0',
0, 0,
G_OPTION_ARG_FILENAME, G_OPTION_ARG_FILENAME,
&zenity_general_window_icon, &zenity_general_window_icon,
"Set the window icon", "Set the window icon",
"ICONPATH"}, "ICONPATH"},
{"width", {"width",
'\0', '\0',
0, 0,
G_OPTION_ARG_INT, G_OPTION_ARG_INT,
&zenity_general_width, &zenity_general_width,
"Set the width", "Set the width",
"WIDTH"}, "WIDTH"},
{"height", {"height",
'\0', '\0',
0, 0,
G_OPTION_ARG_INT, G_OPTION_ARG_INT,
&zenity_general_height, &zenity_general_height,
"Set the height", "Set the height",
"HEIGHT"}, "HEIGHT"},
{"timeout", {"timeout",
'\0', '\0',
0, 0,
G_OPTION_ARG_INT, G_OPTION_ARG_INT,
&zenity_general_timeout_delay, &zenity_general_timeout_delay,
"Set dialog timeout in seconds", "Set dialog timeout in seconds",
/* Timeout for closing the dialog */ /* Timeout for closing the dialog */
"TIMEOUT"}, "TIMEOUT"},
{"ok-label", {"ok-label",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_general_ok_button, &zenity_general_ok_button,
"Set the label of the OK button", "Set the label of the OK button",
"TEXT"}, "TEXT"},
{"cancel-label", {"cancel-label",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_general_cancel_button, &zenity_general_cancel_button,
"Set the label of the Cancel button", "Set the label of the Cancel button",
"TEXT"}, "TEXT"},
{"extra-button", {"extra-button",
'\0', '\0',
0, 0,
G_OPTION_ARG_STRING_ARRAY, G_OPTION_ARG_STRING_ARRAY,
&zenity_general_extra_buttons, &zenity_general_extra_buttons,
"Add an extra button", "Add an extra button",
"TEXT"}, "TEXT"},
{"modal", {"modal",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_general_modal, &zenity_general_modal,
"Set the modal hint", "Set the modal hint",
NULL}, NULL},
{"attach", {"attach",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_INT, G_OPTION_ARG_INT,
&zenity_general_attach, &zenity_general_attach,
"Set the parent window to attach to", "Set the parent window to attach to",
"WINDOW"}, "WINDOW"},
{NULL}}; {NULL}};
static GOptionEntry entry_options[] = {{"entry", static GOptionEntry entry_options[] = {{"entry",
@ -140,28 +140,28 @@ static GOptionEntry entry_options[] = {{"entry",
G_OPTION_FLAG_IN_MAIN, G_OPTION_FLAG_IN_MAIN,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_entry_active, &zenity_entry_active,
"Display text entry dialog", "Display text entry dialog",
NULL}, NULL},
{"text", {"text",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_general_dialog_text, &zenity_general_dialog_text,
"Set the dialog text", "Set the dialog text",
"TEXT"}, "TEXT"},
{"entry-text", {"entry-text",
'\0', '\0',
0, 0,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_entry_entry_text, &zenity_entry_entry_text,
"Set the entry text", "Set the entry text",
"TEXT"}, "TEXT"},
{"hide-text", {"hide-text",
'\0', '\0',
0, 0,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_entry_hide_text, &zenity_entry_hide_text,
"Hide the entry text", "Hide the entry text",
NULL}, NULL},
{NULL}}; {NULL}};
@ -170,94 +170,94 @@ static GOptionEntry list_options[] = {{"list",
G_OPTION_FLAG_IN_MAIN, G_OPTION_FLAG_IN_MAIN,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_list_active, &zenity_list_active,
"Display list dialog", "Display list dialog",
NULL}, NULL},
{"text", {"text",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_general_dialog_text, &zenity_general_dialog_text,
"Set the dialog text", "Set the dialog text",
"TEXT"}, "TEXT"},
{"column", {"column",
'\0', '\0',
0, 0,
G_OPTION_ARG_STRING_ARRAY, G_OPTION_ARG_STRING_ARRAY,
&zenity_list_columns, &zenity_list_columns,
"Set the column header", "Set the column header",
"COLUMN"}, "COLUMN"},
{"checklist", {"checklist",
'\0', '\0',
0, 0,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_list_checklist, &zenity_list_checklist,
"Use check boxes for the first column", "Use check boxes for the first column",
NULL}, NULL},
{"radiolist", {"radiolist",
'\0', '\0',
0, 0,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_list_radiolist, &zenity_list_radiolist,
"Use radio buttons for the first column", "Use radio buttons for the first column",
NULL}, NULL},
{"imagelist", {"imagelist",
'\0', '\0',
0, 0,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_list_imagelist, &zenity_list_imagelist,
"Use an image for the first column", "Use an image for the first column",
NULL}, NULL},
{"separator", {"separator",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_general_separator, &zenity_general_separator,
"Set output separator character", "Set output separator character",
"SEPARATOR"}, "SEPARATOR"},
{"multiple", {"multiple",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_general_multiple, &zenity_general_multiple,
"Allow multiple rows to be selected", "Allow multiple rows to be selected",
NULL}, NULL},
{"editable", {"editable",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_general_editable, &zenity_general_editable,
"Allow changes to text", "Allow changes to text",
NULL}, NULL},
{"print-column", {"print-column",
'\0', '\0',
0, 0,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_list_print_column, &zenity_list_print_column,
"Print a specific column (Default is 1. 'ALL' can be used to print " "Print a specific column (Default is 1. 'ALL' can be used to print "
"all columns)", "all columns)",
/* Column index number to print out on a list dialog */ /* Column index number to print out on a list dialog */
"NUMBER"}, "NUMBER"},
{"hide-column", {"hide-column",
'\0', '\0',
0, 0,
G_OPTION_ARG_STRING, G_OPTION_ARG_STRING,
&zenity_list_hide_column, &zenity_list_hide_column,
"Hide a specific column", "Hide a specific column",
"NUMBER"}, "NUMBER"},
{"hide-header", {"hide-header",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_list_hide_header, &zenity_list_hide_header,
"Hide the column headers", "Hide the column headers",
NULL}, NULL},
{"mid-search", {"mid-search",
'\0', '\0',
G_OPTION_FLAG_NOALIAS, G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_NONE, G_OPTION_ARG_NONE,
&zenity_list_mid_search, &zenity_list_mid_search,
"Change list default search function searching for text in the " "Change list default search function searching for text in the "
"middle, not on the beginning", "middle, not on the beginning",
NULL}, NULL},
{NULL}}; {NULL}};
@ -271,9 +271,9 @@ zenity_option_init (void) {
/* Initialize the various dialog structures */ /* Initialize the various dialog structures */
results->mode = MODE_LAST; results->mode = MODE_LAST;
results->data = g_new0 (ZenityData, 1); results->data = g_new0 (ZenityData, 1);
results->entry_data = g_new0 (ZenityEntryData, 1); results->entry_data = g_new0 (ZenityEntryData, 1);
results->tree_data = g_new0 (ZenityTreeData, 1); results->tree_data = g_new0 (ZenityTreeData, 1);
} }
void void
@ -295,14 +295,14 @@ zenity_option_free (void) {
g_strfreev (zenity_general_extra_buttons); g_strfreev (zenity_general_extra_buttons);
if (zenity_entry_entry_text) if (zenity_entry_entry_text)
g_free (zenity_entry_entry_text); g_free (zenity_entry_entry_text);
if (zenity_list_columns) if (zenity_list_columns)
g_strfreev (zenity_list_columns); g_strfreev (zenity_list_columns);
if (zenity_list_print_column) if (zenity_list_print_column)
g_free (zenity_list_print_column); g_free (zenity_list_print_column);
if (zenity_list_hide_column) if (zenity_list_hide_column)
g_free (zenity_list_hide_column); g_free (zenity_list_hide_column);
g_option_context_free (ctx); g_option_context_free (ctx);
} }
@ -513,40 +513,34 @@ zenity_create_context (void) {
tmp_ctx = g_option_context_new (NULL); tmp_ctx = g_option_context_new (NULL);
/* Adds general option entries */ /* Adds general option entries */
a_group = g_option_group_new ("general", a_group = g_option_group_new (
"General options", "general", "General options", "Show general options", NULL, NULL);
"Show general options",
NULL,
NULL);
g_option_group_add_entries (a_group, general_options); g_option_group_add_entries (a_group, general_options);
g_option_group_set_parse_hooks ( g_option_group_set_parse_hooks (
a_group, zenity_general_pre_callback, zenity_general_post_callback); a_group, zenity_general_pre_callback, zenity_general_post_callback);
g_option_group_set_error_hook (a_group, zenity_option_error_callback); g_option_group_set_error_hook (a_group, zenity_option_error_callback);
g_option_context_add_group (tmp_ctx, a_group); g_option_context_add_group (tmp_ctx, a_group);
/* Adds entry option entries */ /* Adds entry option entries */
a_group = g_option_group_new ("entry", a_group = g_option_group_new (
"Text entry options", "entry", "Text entry options", "Show text entry options", NULL, NULL);
"Show text entry options",
NULL,
NULL);
g_option_group_add_entries (a_group, entry_options); g_option_group_add_entries (a_group, entry_options);
g_option_group_set_parse_hooks ( g_option_group_set_parse_hooks (
a_group, zenity_entry_pre_callback, zenity_entry_post_callback); a_group, zenity_entry_pre_callback, zenity_entry_post_callback);
g_option_group_set_error_hook (a_group, zenity_option_error_callback); g_option_group_set_error_hook (a_group, zenity_option_error_callback);
g_option_context_add_group (tmp_ctx, a_group); g_option_context_add_group (tmp_ctx, a_group);
/* Adds list option entries */ /* Adds list option entries */
a_group = g_option_group_new ( a_group = g_option_group_new (
"list", "List options", "Show list options", NULL, NULL); "list", "List options", "Show list options", NULL, NULL);
g_option_group_add_entries (a_group, list_options); g_option_group_add_entries (a_group, list_options);
g_option_group_set_parse_hooks ( g_option_group_set_parse_hooks (
a_group, zenity_list_pre_callback, zenity_list_post_callback); a_group, zenity_list_pre_callback, zenity_list_post_callback);
g_option_group_set_error_hook (a_group, zenity_option_error_callback); g_option_group_set_error_hook (a_group, zenity_option_error_callback);
g_option_context_add_group (tmp_ctx, a_group); g_option_context_add_group (tmp_ctx, a_group);
/* Adds gtk option entries */ /* Adds gtk option entries */
a_group = gtk_get_option_group (TRUE); a_group = gtk_get_option_group (TRUE);
g_option_context_add_group (tmp_ctx, a_group); g_option_context_add_group (tmp_ctx, a_group);
/* Enable help options */ /* Enable help options */
@ -560,16 +554,16 @@ void
zenity_option_error (gchar *string, ZenityError error) { zenity_option_error (gchar *string, ZenityError error) {
switch (error) { switch (error) {
case ERROR_SYNTAX: case ERROR_SYNTAX:
g_printerr ("This option is not available. Please see --help " g_printerr ("This option is not available. Please see --help "
"for all possible usages.\n"); "for all possible usages.\n");
zenity_option_free (); zenity_option_free ();
exit (-1); exit (-1);
case ERROR_SUPPORT: case ERROR_SUPPORT:
g_printerr ("--%s is not supported for this dialog\n", string); g_printerr ("--%s is not supported for this dialog\n", string);
zenity_option_free (); zenity_option_free ();
exit (-1); exit (-1);
case ERROR_DIALOG: case ERROR_DIALOG:
g_printerr ("Two or more dialog options specified\n"); g_printerr ("Two or more dialog options specified\n");
zenity_option_free (); zenity_option_free ();
exit (-1); exit (-1);
default: default:
@ -591,19 +585,19 @@ zenity_option_parse (gint argc, gchar **argv) {
have their post condition tested. This test is done here. */ have their post condition tested. This test is done here. */
if (strcmp (zenity_general_separator, "|") != 0) if (strcmp (zenity_general_separator, "|") != 0)
if (results->mode != MODE_LIST) if (results->mode != MODE_LIST)
zenity_option_error (zenity_option_get_name ( zenity_option_error (zenity_option_get_name (
list_options, &zenity_general_separator), list_options, &zenity_general_separator),
ERROR_SUPPORT); ERROR_SUPPORT);
if (zenity_general_multiple) if (zenity_general_multiple)
if (results->mode != MODE_LIST) if (results->mode != MODE_LIST)
zenity_option_error ( zenity_option_error (
zenity_option_get_name (list_options, &zenity_general_multiple), zenity_option_get_name (list_options, &zenity_general_multiple),
ERROR_SUPPORT); ERROR_SUPPORT);
if (zenity_general_editable) if (zenity_general_editable)
if (results->mode != MODE_LIST) if (results->mode != MODE_LIST)
zenity_option_error ( zenity_option_error (
zenity_option_get_name (list_options, &zenity_general_editable), zenity_option_get_name (list_options, &zenity_general_editable),
ERROR_SUPPORT); ERROR_SUPPORT);

View File

@ -30,11 +30,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
typedef enum { typedef enum { MODE_ENTRY, MODE_LIST, MODE_LAST } ZenityDialogMode;
MODE_ENTRY,
MODE_LIST,
MODE_LAST
} ZenityDialogMode;
typedef enum { typedef enum {
ERROR_SYNTAX, ERROR_SYNTAX,
@ -47,8 +43,8 @@ typedef struct {
ZenityDialogMode mode; ZenityDialogMode mode;
ZenityData *data; ZenityData *data;
ZenityEntryData *entry_data; ZenityEntryData *entry_data;
ZenityTreeData *tree_data; ZenityTreeData *tree_data;
} ZenityParsingOptions; } ZenityParsingOptions;
void zenity_option_error (gchar *string, ZenityError error); void zenity_option_error (gchar *string, ZenityError error);

View File

@ -61,11 +61,8 @@ zenity_tree_dialog_untoggle (
} }
static void static void
check_or_radio_label_activated_cb (GtkTreeView *tree_view, check_or_radio_label_activated_cb (GtkTreeView *tree_view, GtkTreePath *path,
GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) {
GtkTreeViewColumn *column,
gpointer user_data)
{
GtkTreeModel *model = gtk_tree_view_get_model (tree_view); GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
GtkTreeIter iter; GtkTreeIter iter;
gboolean value; gboolean value;
@ -384,13 +381,13 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
tree_data->hide_column, n_columns); tree_data->hide_column, n_columns);
if (n_columns == 0) { if (n_columns == 0) {
g_printerr ("No column titles specified for List dialog.\n"); g_printerr ("No column titles specified for List dialog.\n");
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return; return;
} }
if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) { if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) {
g_printerr ("You should use only one List dialog type.\n"); g_printerr ("You should use only one List dialog type.\n");
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return; return;
} }
@ -444,18 +441,15 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
tree_view = gtk_builder_get_object (builder, "zenity_tree_view"); tree_view = gtk_builder_get_object (builder, "zenity_tree_view");
if (tree_data->radiobox || tree_data->checkbox) if (tree_data->radiobox || tree_data->checkbox) {
{ gtk_tree_view_set_activate_on_single_click (
gtk_tree_view_set_activate_on_single_click (GTK_TREE_VIEW(tree_view), GTK_TREE_VIEW (tree_view), TRUE);
TRUE);
g_signal_connect (tree_view, g_signal_connect (tree_view,
"row-activated", "row-activated",
G_CALLBACK (check_or_radio_label_activated_cb), G_CALLBACK (check_or_radio_label_activated_cb),
data); data);
} } else {
else
{
g_signal_connect (tree_view, g_signal_connect (tree_view,
"row-activated", "row-activated",
G_CALLBACK (zenity_tree_row_activated), G_CALLBACK (zenity_tree_row_activated),
@ -489,14 +483,11 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model)); gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (model));
if (tree_data->radiobox || tree_data->checkbox) if (tree_data->radiobox || tree_data->checkbox) {
{
gtk_tree_selection_set_mode ( gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
GTK_SELECTION_SINGLE); GTK_SELECTION_SINGLE);
} } else {
else
{
if (tree_data->multi) if (tree_data->multi)
gtk_tree_selection_set_mode ( gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
@ -641,8 +632,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
* despite it not containing any user readable text. * despite it not containing any user readable text.
* Set it to second column instead if it exists. */ * Set it to second column instead if it exists. */
if (tree_data->imagebox && n_columns > 1) { if (tree_data->imagebox && n_columns > 1) {
gtk_tree_view_set_search_column (GTK_TREE_VIEW (tree_view), gtk_tree_view_set_search_column (GTK_TREE_VIEW (tree_view), 1);
1);
} }
zenity_util_show_dialog (dialog, data->attach); zenity_util_show_dialog (dialog, data->attach);
@ -769,7 +759,7 @@ zenity_tree_dialog_output (void) {
g_free (print_columns); g_free (print_columns);
g_free (hide_columns); g_free (hide_columns);
g_free (separator); g_free (separator);
g_slist_foreach (selected, (GFunc) (void *) g_free, NULL); g_slist_foreach (selected, (GFunc) (void *) g_free, NULL);
selected = NULL; selected = NULL;
} }

View File

@ -75,14 +75,13 @@ zenity_util_load_ui_file (const gchar *root_widget, ...) {
g_ptr_array_add (ptrarray, NULL); g_ptr_array_add (ptrarray, NULL);
objects = (gchar **) g_ptr_array_free (ptrarray, FALSE); objects = (gchar **) g_ptr_array_free (ptrarray, FALSE);
result = gtk_builder_add_objects_from_resource ( result = gtk_builder_add_objects_from_resource (
builder, "/zenity.ui", objects, &error); builder, "/zenity.ui", objects, &error);
g_strfreev (objects); g_strfreev (objects);
if (result == 0) { if (result == 0) {
g_warning ("Could not load ui data: %s", g_warning ("Could not load ui data: %s", error->message);
error->message);
g_error_free (error); g_error_free (error);
g_object_unref (builder); g_object_unref (builder);
return NULL; return NULL;

0
utils/format.sh Normal file → Executable file
View File