Bug 540169 - Zenity should offer color selection dialog
This commit is contained in:
parent
3c17a5a887
commit
4ccc7f6fac
@ -60,6 +60,8 @@ Display warning dialog
|
|||||||
.TP
|
.TP
|
||||||
.B \-\-scale
|
.B \-\-scale
|
||||||
Display scale dialog
|
Display scale dialog
|
||||||
|
.B \-\-color-selection
|
||||||
|
Display color selection dialog
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
General options
|
General options
|
||||||
@ -266,6 +268,16 @@ Print partial values
|
|||||||
.B \-\-hide\-value
|
.B \-\-hide\-value
|
||||||
Hide value
|
Hide value
|
||||||
|
|
||||||
|
.PP
|
||||||
|
Color selection options
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B \-\-color=VALUE
|
||||||
|
Set the initial color
|
||||||
|
.TP
|
||||||
|
.B \-\-show\-palette
|
||||||
|
Show the palette
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
Miscellaneous options
|
Miscellaneous options
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ zenity_SOURCES = \
|
|||||||
scale.c \
|
scale.c \
|
||||||
text.c \
|
text.c \
|
||||||
tree.c \
|
tree.c \
|
||||||
|
color.c \
|
||||||
util.c \
|
util.c \
|
||||||
util.h \
|
util.h \
|
||||||
zenity.h
|
zenity.h
|
||||||
|
97
src/color.c
Normal file
97
src/color.c
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* color.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Berislav Kovacki
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* Authors: Berislav Kovacki <pantokrator@pantokrator.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "zenity.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
static ZenityData *zen_data;
|
||||||
|
|
||||||
|
static void zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
|
void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
|
||||||
|
{
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GtkWidget *colorsel;
|
||||||
|
GdkColor color;
|
||||||
|
|
||||||
|
zen_data = data;
|
||||||
|
|
||||||
|
dialog = gtk_color_selection_dialog_new (NULL);
|
||||||
|
|
||||||
|
g_signal_connect (G_OBJECT (dialog), "response",
|
||||||
|
G_CALLBACK (zenity_colorselection_dialog_response),
|
||||||
|
color_data);
|
||||||
|
|
||||||
|
if (data->dialog_title)
|
||||||
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
|
colorsel = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog));
|
||||||
|
|
||||||
|
if (color_data->color) {
|
||||||
|
if (gdk_color_parse (color_data->color, &color))
|
||||||
|
gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (colorsel),
|
||||||
|
&color);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (colorsel),
|
||||||
|
color_data->show_palette);
|
||||||
|
|
||||||
|
zenity_util_show_dialog (dialog);
|
||||||
|
|
||||||
|
if (data->timeout_delay > 0) {
|
||||||
|
g_timeout_add (data->timeout_delay * 1000,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_main();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data)
|
||||||
|
{
|
||||||
|
GtkWidget *colorsel;
|
||||||
|
GdkColor color;
|
||||||
|
|
||||||
|
switch (response) {
|
||||||
|
case GTK_RESPONSE_OK:
|
||||||
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
|
colorsel = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (widget));
|
||||||
|
gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (colorsel), &color);
|
||||||
|
g_print ("%s\n", gdk_color_to_string (&color));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GTK_RESPONSE_CANCEL:
|
||||||
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_main_quit ();
|
||||||
|
}
|
@ -84,6 +84,9 @@ main (gint argc, gchar **argv) {
|
|||||||
case MODE_TEXTINFO:
|
case MODE_TEXTINFO:
|
||||||
zenity_text (results->data, results->text_data);
|
zenity_text (results->data, results->text_data);
|
||||||
break;
|
break;
|
||||||
|
case MODE_COLOR:
|
||||||
|
zenity_colorselection (results->data, results->color_data);
|
||||||
|
break;
|
||||||
case MODE_ABOUT:
|
case MODE_ABOUT:
|
||||||
zenity_about (results->data);
|
zenity_about (results->data);
|
||||||
break;
|
break;
|
||||||
|
90
src/option.c
90
src/option.c
@ -108,6 +108,11 @@ static gint zenity_scale_step;
|
|||||||
static gboolean zenity_scale_print_partial;
|
static gboolean zenity_scale_print_partial;
|
||||||
static gboolean zenity_scale_hide_value;
|
static gboolean zenity_scale_hide_value;
|
||||||
|
|
||||||
|
/* Color Selection Dialog Options */
|
||||||
|
static gboolean zenity_colorsel_active;
|
||||||
|
static gchar *zenity_colorsel_color;
|
||||||
|
static gboolean zenity_colorsel_show_palette;
|
||||||
|
|
||||||
/* Miscelaneus Options */
|
/* Miscelaneus Options */
|
||||||
static gboolean zenity_misc_about;
|
static gboolean zenity_misc_about;
|
||||||
static gboolean zenity_misc_version;
|
static gboolean zenity_misc_version;
|
||||||
@ -818,6 +823,39 @@ static GOptionEntry scale_options[] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static GOptionEntry color_selection_options[] = {
|
||||||
|
{
|
||||||
|
"color-selection",
|
||||||
|
'\0',
|
||||||
|
G_OPTION_FLAG_IN_MAIN,
|
||||||
|
G_OPTION_ARG_NONE,
|
||||||
|
&zenity_colorsel_active,
|
||||||
|
N_("Display color selection dialog"),
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color",
|
||||||
|
'\0',
|
||||||
|
0,
|
||||||
|
G_OPTION_ARG_STRING,
|
||||||
|
&zenity_colorsel_color,
|
||||||
|
N_("Set the color"),
|
||||||
|
N_("VALUE")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"show-palette",
|
||||||
|
'\0',
|
||||||
|
0,
|
||||||
|
G_OPTION_ARG_NONE,
|
||||||
|
&zenity_colorsel_show_palette,
|
||||||
|
N_("Show the palette"),
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
NULL
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static GOptionEntry miscellaneous_options[] = {
|
static GOptionEntry miscellaneous_options[] = {
|
||||||
{
|
{
|
||||||
"about",
|
"about",
|
||||||
@ -862,6 +900,7 @@ zenity_option_init (void) {
|
|||||||
results->text_data = g_new0 (ZenityTextData, 1);
|
results->text_data = g_new0 (ZenityTextData, 1);
|
||||||
results->tree_data = g_new0 (ZenityTreeData, 1);
|
results->tree_data = g_new0 (ZenityTreeData, 1);
|
||||||
results->notification_data = g_new0 (ZenityNotificationData, 1);
|
results->notification_data = g_new0 (ZenityNotificationData, 1);
|
||||||
|
results->color_data = g_new0 (ZenityColorData, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -897,6 +936,9 @@ zenity_option_free (void) {
|
|||||||
if (zenity_question_cancel_button)
|
if (zenity_question_cancel_button)
|
||||||
g_free (zenity_question_cancel_button);
|
g_free (zenity_question_cancel_button);
|
||||||
|
|
||||||
|
if (zenity_colorsel_color)
|
||||||
|
g_free (zenity_colorsel_color);
|
||||||
|
|
||||||
g_option_context_free (ctx);
|
g_option_context_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1115,6 +1157,19 @@ zenity_scale_pre_callback (GOptionContext *context,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
zenity_color_pre_callback (GOptionContext *context,
|
||||||
|
GOptionGroup *group,
|
||||||
|
gpointer data,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
zenity_colorsel_active = FALSE;
|
||||||
|
zenity_colorsel_color = NULL;
|
||||||
|
zenity_colorsel_show_palette = FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_misc_pre_callback (GOptionContext *context,
|
zenity_misc_pre_callback (GOptionContext *context,
|
||||||
GOptionGroup *group,
|
GOptionGroup *group,
|
||||||
@ -1480,6 +1535,30 @@ zenity_scale_post_callback (GOptionContext *context,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
zenity_color_post_callback (GOptionContext *context,
|
||||||
|
GOptionGroup *group,
|
||||||
|
gpointer data,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
zenity_option_set_dialog_mode (zenity_colorsel_active, MODE_COLOR);
|
||||||
|
|
||||||
|
if (results->mode == MODE_COLOR) {
|
||||||
|
results->color_data->color = zenity_colorsel_color;
|
||||||
|
results->color_data->show_palette = zenity_colorsel_show_palette;
|
||||||
|
} else {
|
||||||
|
if (zenity_colorsel_color)
|
||||||
|
zenity_option_error (zenity_option_get_name(color_selection_options, &zenity_colorsel_color),
|
||||||
|
ERROR_SUPPORT);
|
||||||
|
|
||||||
|
if (zenity_colorsel_show_palette)
|
||||||
|
zenity_option_error (zenity_option_get_name(color_selection_options, &zenity_colorsel_show_palette),
|
||||||
|
ERROR_SUPPORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_misc_post_callback (GOptionContext *context,
|
zenity_misc_post_callback (GOptionContext *context,
|
||||||
GOptionGroup *group,
|
GOptionGroup *group,
|
||||||
@ -1643,6 +1722,17 @@ zenity_create_context (void)
|
|||||||
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
|
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
|
||||||
g_option_context_add_group(tmp_ctx, a_group);
|
g_option_context_add_group(tmp_ctx, a_group);
|
||||||
|
|
||||||
|
/* Adds color selection option entries */
|
||||||
|
a_group = g_option_group_new("color-selection",
|
||||||
|
N_("Color selection options"),
|
||||||
|
N_("Show color selection options"), NULL, NULL);
|
||||||
|
g_option_group_add_entries(a_group, color_selection_options);
|
||||||
|
g_option_group_set_parse_hooks (a_group,
|
||||||
|
zenity_color_pre_callback, zenity_color_post_callback);
|
||||||
|
g_option_group_set_error_hook (a_group, zenity_option_error_callback);
|
||||||
|
g_option_group_set_translation_domain (a_group, GETTEXT_PACKAGE);
|
||||||
|
g_option_context_add_group(tmp_ctx, a_group);
|
||||||
|
|
||||||
/* Adds misc option entries */
|
/* Adds misc option entries */
|
||||||
a_group = g_option_group_new("misc",
|
a_group = g_option_group_new("misc",
|
||||||
N_("Miscellaneous options"),
|
N_("Miscellaneous options"),
|
||||||
|
@ -45,6 +45,7 @@ typedef enum {
|
|||||||
MODE_SCALE,
|
MODE_SCALE,
|
||||||
MODE_INFO,
|
MODE_INFO,
|
||||||
MODE_NOTIFICATION,
|
MODE_NOTIFICATION,
|
||||||
|
MODE_COLOR,
|
||||||
MODE_ABOUT,
|
MODE_ABOUT,
|
||||||
MODE_VERSION,
|
MODE_VERSION,
|
||||||
MODE_LAST
|
MODE_LAST
|
||||||
@ -70,6 +71,7 @@ typedef struct {
|
|||||||
ZenityTextData *text_data;
|
ZenityTextData *text_data;
|
||||||
ZenityTreeData *tree_data;
|
ZenityTreeData *tree_data;
|
||||||
ZenityNotificationData *notification_data;
|
ZenityNotificationData *notification_data;
|
||||||
|
ZenityColorData *color_data;
|
||||||
} ZenityParsingOptions;
|
} ZenityParsingOptions;
|
||||||
|
|
||||||
void zenity_option_error (gchar *string,
|
void zenity_option_error (gchar *string,
|
||||||
|
@ -126,6 +126,11 @@ typedef struct {
|
|||||||
gboolean listen;
|
gboolean listen;
|
||||||
} ZenityNotificationData;
|
} ZenityNotificationData;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
gchar *color;
|
||||||
|
gboolean show_palette;
|
||||||
|
} ZenityColorData;
|
||||||
|
|
||||||
void zenity_calendar (ZenityData *data,
|
void zenity_calendar (ZenityData *data,
|
||||||
ZenityCalendarData *calendar_data);
|
ZenityCalendarData *calendar_data);
|
||||||
void zenity_msg (ZenityData *data,
|
void zenity_msg (ZenityData *data,
|
||||||
@ -142,6 +147,8 @@ void zenity_tree (ZenityData *data,
|
|||||||
ZenityTreeData *tree_data);
|
ZenityTreeData *tree_data);
|
||||||
void zenity_notification (ZenityData *data,
|
void zenity_notification (ZenityData *data,
|
||||||
ZenityNotificationData *notification_data);
|
ZenityNotificationData *notification_data);
|
||||||
|
void zenity_colorselection (ZenityData *data,
|
||||||
|
ZenityColorData *notification_data);
|
||||||
void zenity_scale (ZenityData *data,
|
void zenity_scale (ZenityData *data,
|
||||||
ZenityScaleData *scale_data);
|
ZenityScaleData *scale_data);
|
||||||
void zenity_about (ZenityData *data);
|
void zenity_about (ZenityData *data);
|
||||||
|
Reference in New Issue
Block a user