Unverified Commit db22428d authored by Victor Ananjevsky's avatar Victor Ananjevsky Committed by GitHub

Merge pull request #168 from Misko-2083/master

Add switch form field (by Misko <mpsrbija@gmail.com>)
parents 1e2379aa 6b32bb4f
...@@ -538,6 +538,8 @@ Add field to form. Type may be \fIH\fP, \fIRO\fP, \fINUM\fP, \fICHK\fP, \fICB\fP ...@@ -538,6 +538,8 @@ Add field to form. Type may be \fIH\fP, \fIRO\fP, \fINUM\fP, \fICHK\fP, \fICB\fP
.br .br
\fBSCL\fP - scale field. Value of this field in a range 0..100. \fBSCL\fP - scale field. Value of this field in a range 0..100.
.br .br
\fBSW\fP - switch field. Initial value is a case insensitive boolean constant (\fITRUE\fP or \fIFALSE\fP).
.br
\fBAPP\fP - application selection button. Input value for this field is mime-type. Output value - executable for selected application. \fBAPP\fP - application selection button. Input value for this field is mime-type. Output value - executable for selected application.
.br .br
\fBICON\fP - icon field. Like average entry field but has two icons. Left shows current icon and right is clickable and calls \fIyad-con-browser\fP for choosing icon. \fBICON\fP - icon field. Like average entry field but has two icons. Left shows current icon and right is clickable and calls \fIyad-con-browser\fP for choosing icon.
......
...@@ -93,6 +93,9 @@ expand_action (gchar * cmd) ...@@ -93,6 +93,9 @@ expand_action (gchar * cmd)
arg = g_shell_quote (buf ? buf : ""); arg = g_shell_quote (buf ? buf : "");
g_free (buf); g_free (buf);
break; break;
case YAD_FIELD_SWITCH:
arg = g_strdup (print_bool_val (gtk_switch_get_state (GTK_SWITCH (g_slist_nth_data (fields, num)))));
break;
case YAD_FIELD_SCALE: case YAD_FIELD_SCALE:
arg = g_strdup_printf ("%d", (gint) gtk_range_get_value (GTK_RANGE (g_slist_nth_data (fields, num)))); arg = g_strdup_printf ("%d", (gint) gtk_range_get_value (GTK_RANGE (g_slist_nth_data (fields, num))));
break; break;
...@@ -243,6 +246,10 @@ set_field_value (guint num, gchar *value) ...@@ -243,6 +246,10 @@ set_field_value (guint num, gchar *value)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), get_bool_val (value)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), get_bool_val (value));
break; break;
case YAD_FIELD_SWITCH:
gtk_switch_set_state (GTK_SWITCH (w), get_bool_val (value));
break;
case YAD_FIELD_COMPLETE: case YAD_FIELD_COMPLETE:
{ {
GtkEntryCompletion *c; GtkEntryCompletion *c;
...@@ -959,6 +966,24 @@ form_create_widget (GtkWidget * dlg) ...@@ -959,6 +966,24 @@ form_create_widget (GtkWidget * dlg)
} }
break; break;
case YAD_FIELD_SWITCH:
{
e = gtk_switch_new ();
gtk_widget_set_name (e, "yad-form-switch");
if (fld->tip)
{
if (!options.data.no_markup)
gtk_widget_set_tooltip_markup (e, fld->tip);
else
gtk_widget_set_tooltip_text (e, fld->tip);
}
gtk_grid_attach (GTK_GRID (tbl), e, 1 + col * 2, row, 1, 1);
gtk_widget_set_hexpand (e, TRUE);
gtk_label_set_mnemonic_widget (GTK_LABEL (l), e);
fields = g_slist_append (fields, e);
}
break;
case YAD_FIELD_COMBO: case YAD_FIELD_COMBO:
e = gtk_combo_box_text_new (); e = gtk_combo_box_text_new ();
gtk_widget_set_name (e, "yad-form-combo"); gtk_widget_set_name (e, "yad-form-combo");
...@@ -1383,6 +1408,14 @@ form_print_field (guint fn) ...@@ -1383,6 +1408,14 @@ form_print_field (guint fn)
g_printf ("%s%s", print_bool_val (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn)))), g_printf ("%s%s", print_bool_val (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (fields, fn)))),
options.common_data.separator); options.common_data.separator);
break; break;
case YAD_FIELD_SWITCH:
if (options.common_data.quoted_output)
g_printf ("'%s'%s", print_bool_val (gtk_switch_get_state (GTK_SWITCH (g_slist_nth_data (fields, fn)))),
options.common_data.separator);
else
g_printf ("%s%s", print_bool_val (gtk_switch_get_state (GTK_SWITCH (g_slist_nth_data (fields, fn)))),
options.common_data.separator);
break;
case YAD_FIELD_COMBO: case YAD_FIELD_COMBO:
case YAD_FIELD_COMBO_ENTRY: case YAD_FIELD_COMBO_ENTRY:
if (options.common_data.num_output && fld->type == YAD_FIELD_COMBO) if (options.common_data.num_output && fld->type == YAD_FIELD_COMBO)
......
...@@ -876,6 +876,8 @@ add_field (const gchar * option_name, const gchar * value, gpointer data, GError ...@@ -876,6 +876,8 @@ add_field (const gchar * option_name, const gchar * value, gpointer data, GError
fld->type = YAD_FIELD_DATE; fld->type = YAD_FIELD_DATE;
else if (strcasecmp (fstr[1], "SCL") == 0) else if (strcasecmp (fstr[1], "SCL") == 0)
fld->type = YAD_FIELD_SCALE; fld->type = YAD_FIELD_SCALE;
else if (strcasecmp (fstr[1], "SW") == 0)
fld->type = YAD_FIELD_SWITCH;
else if (strcasecmp (fstr[1], "BTN") == 0) else if (strcasecmp (fstr[1], "BTN") == 0)
fld->type = YAD_FIELD_BUTTON; fld->type = YAD_FIELD_BUTTON;
else if (strcasecmp (fstr[1], "FBTN") == 0) else if (strcasecmp (fstr[1], "FBTN") == 0)
......
...@@ -128,7 +128,8 @@ typedef enum { ...@@ -128,7 +128,8 @@ typedef enum {
YAD_FIELD_FULL_BUTTON, YAD_FIELD_FULL_BUTTON,
YAD_FIELD_LINK, YAD_FIELD_LINK,
YAD_FIELD_LABEL, YAD_FIELD_LABEL,
YAD_FIELD_TEXT YAD_FIELD_TEXT,
YAD_FIELD_SWITCH
} YadFieldType; } YadFieldType;
typedef enum { typedef enum {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment