mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 14:30:15 +00:00
Improve PICKONE_* handling in GtkPrinterOptionWidget (bug #543520)
This patch modifies GtkPrinterOptionWidget to support loading them again. It also allows the user to enter values from the dropdown list to select the item.
This commit is contained in:
parent
6fa6576dda
commit
b3e352f489
@ -366,8 +366,8 @@ combo_box_set (GtkWidget *combo,
|
|||||||
gtk_tree_model_foreach (model, set_cb, &set_data);
|
gtk_tree_model_foreach (model, set_cb, &set_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static gchar *
|
||||||
combo_box_get (GtkWidget *combo)
|
combo_box_get (GtkWidget *combo, gboolean *custom)
|
||||||
{
|
{
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
gchar *value;
|
gchar *value;
|
||||||
@ -377,7 +377,41 @@ combo_box_get (GtkWidget *combo)
|
|||||||
|
|
||||||
value = NULL;
|
value = NULL;
|
||||||
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
|
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
|
||||||
|
{
|
||||||
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
|
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
|
||||||
|
*custom = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo)))
|
||||||
|
{
|
||||||
|
value = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)))));
|
||||||
|
*custom = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!value || !gtk_tree_model_get_iter_first (model, &iter))
|
||||||
|
return value;
|
||||||
|
|
||||||
|
/* If the user entered an item from the dropdown list manually, return
|
||||||
|
* the non-custom option instead. */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
gchar *val, *name;
|
||||||
|
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &val,
|
||||||
|
NAME_COLUMN, &name, -1);
|
||||||
|
if (g_str_equal (value, name))
|
||||||
|
{
|
||||||
|
*custom = FALSE;
|
||||||
|
g_free (name);
|
||||||
|
g_free (value);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (val);
|
||||||
|
g_free (name);
|
||||||
|
}
|
||||||
|
while (gtk_tree_model_iter_next (model, &iter));
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -558,12 +592,15 @@ combo_changed_cb (GtkWidget *combo,
|
|||||||
gchar *value;
|
gchar *value;
|
||||||
gchar *filtered_val = NULL;
|
gchar *filtered_val = NULL;
|
||||||
gboolean changed;
|
gboolean changed;
|
||||||
|
gboolean custom = TRUE;
|
||||||
|
|
||||||
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
g_signal_handler_block (priv->source, priv->source_changed_handler);
|
||||||
|
|
||||||
value = combo_box_get (combo);
|
value = combo_box_get (combo, &custom);
|
||||||
|
|
||||||
/* handle some constraints */
|
/* Handle constraints if the user entered a custom value. */
|
||||||
|
if (custom)
|
||||||
|
{
|
||||||
switch (priv->source->type)
|
switch (priv->source->type)
|
||||||
{
|
{
|
||||||
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
|
||||||
@ -578,6 +615,7 @@ combo_changed_cb (GtkWidget *combo,
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (filtered_val)
|
if (filtered_val)
|
||||||
{
|
{
|
||||||
@ -873,6 +911,22 @@ update_widgets (GtkPrinterOptionWidget *widget)
|
|||||||
case GTK_PRINTER_OPTION_TYPE_STRING:
|
case GTK_PRINTER_OPTION_TYPE_STRING:
|
||||||
gtk_entry_set_text (GTK_ENTRY (priv->entry), source->value);
|
gtk_entry_set_text (GTK_ENTRY (priv->entry), source->value);
|
||||||
break;
|
break;
|
||||||
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD:
|
||||||
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
|
||||||
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
|
||||||
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
|
||||||
|
case GTK_PRINTER_OPTION_TYPE_PICKONE_STRING:
|
||||||
|
{
|
||||||
|
GtkEntry *entry;
|
||||||
|
|
||||||
|
entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->combo)));
|
||||||
|
if (gtk_printer_option_has_choice (source, source->value))
|
||||||
|
combo_box_set (priv->combo, source->value);
|
||||||
|
else
|
||||||
|
gtk_entry_set_text (entry, source->value);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GTK_PRINTER_OPTION_TYPE_FILESAVE:
|
case GTK_PRINTER_OPTION_TYPE_FILESAVE:
|
||||||
{
|
{
|
||||||
gchar *filename = g_filename_from_uri (source->value, NULL, NULL);
|
gchar *filename = g_filename_from_uri (source->value, NULL, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user