Make comment field editable
This commit is contained in:
parent
a56bb9073a
commit
d2790f7f7e
@ -59,6 +59,8 @@
|
|||||||
<object class="GtkLabel" id="label_title">
|
<object class="GtkLabel" id="label_title">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">2</property>
|
||||||
|
<property name="margin_bottom">1</property>
|
||||||
<property name="label" translatable="yes">Title</property>
|
<property name="label" translatable="yes">Title</property>
|
||||||
<property name="wrap">True</property>
|
<property name="wrap">True</property>
|
||||||
<attributes>
|
<attributes>
|
||||||
@ -102,6 +104,8 @@
|
|||||||
<object class="GtkLabel" id="label_description">
|
<object class="GtkLabel" id="label_description">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">2</property>
|
||||||
|
<property name="margin_top">1</property>
|
||||||
<property name="label" translatable="yes">Description</property>
|
<property name="label" translatable="yes">Description</property>
|
||||||
<property name="wrap">True</property>
|
<property name="wrap">True</property>
|
||||||
</object>
|
</object>
|
||||||
@ -123,16 +127,22 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="label_comment">
|
<object class="GtkEntry" id="entry_comment">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="label" translatable="yes">Comment</property>
|
<property name="tooltip_text" translatable="yes">Click here to add a comment.</property>
|
||||||
<attributes>
|
<property name="editable">False</property>
|
||||||
<attribute name="style" value="italic"/>
|
<property name="max_length">128</property>
|
||||||
</attributes>
|
<property name="has_frame">False</property>
|
||||||
|
<property name="placeholder_text" translatable="yes">Click here to add a comment.</property>
|
||||||
|
<property name="input_hints">GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_NONE</property>
|
||||||
|
<property name="enable_emoji_completion">True</property>
|
||||||
|
<style>
|
||||||
|
<class name="entry_comment"/>
|
||||||
|
</style>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
@ -181,6 +191,7 @@
|
|||||||
<object class="GtkButton" id="button_properties">
|
<object class="GtkButton" id="button_properties">
|
||||||
<property name="label">gtk-properties</property>
|
<property name="label">gtk-properties</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="margin_left">4</property>
|
<property name="margin_left">4</property>
|
||||||
|
@ -6,7 +6,7 @@ typedef struct _YacosCartItemPriv {
|
|||||||
|
|
||||||
GtkWidget *label_title;
|
GtkWidget *label_title;
|
||||||
GtkWidget *label_description;
|
GtkWidget *label_description;
|
||||||
GtkWidget *label_comment;
|
GtkWidget *entry_comment;
|
||||||
GtkWidget *label_id;
|
GtkWidget *label_id;
|
||||||
|
|
||||||
GtkWidget *button_properties;
|
GtkWidget *button_properties;
|
||||||
@ -66,7 +66,7 @@ static void yacos_cart_item_class_init(YacosCartItemClass *klass)
|
|||||||
oclass->finalize = yacos_cart_item_finalize;
|
oclass->finalize = yacos_cart_item_finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void yacos_ceart_item_button_delete_cb(GtkWidget *widget, gpointer user_data)
|
static void yacos_cart_item_button_delete_cb(GtkWidget *widget, gpointer user_data)
|
||||||
{
|
{
|
||||||
YacosCartItem *self = (YacosCartItem *)user_data;
|
YacosCartItem *self = (YacosCartItem *)user_data;
|
||||||
|
|
||||||
@ -75,6 +75,18 @@ static void yacos_ceart_item_button_delete_cb(GtkWidget *widget, gpointer user_d
|
|||||||
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(list_box_row)), list_box_row);
|
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(list_box_row)), list_box_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void yacos_cart_item_button_properties_cb(GtkWidget *widget, gpointer user_data)
|
||||||
|
{
|
||||||
|
YacosCartItem *self = (YacosCartItem *)user_data;
|
||||||
|
|
||||||
|
if (self->priv.status != YACOS_CART_ITEM_STATUS_VALID) {
|
||||||
|
g_warning("Comments can only be set on valid entries.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void yacos_cart_item_init(YacosCartItem *self)
|
static void yacos_cart_item_init(YacosCartItem *self)
|
||||||
{
|
{
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
@ -84,7 +96,7 @@ static void yacos_cart_item_init(YacosCartItem *self)
|
|||||||
|
|
||||||
self->priv.label_id = GTK_WIDGET(gtk_builder_get_object(builder, "label_id"));
|
self->priv.label_id = GTK_WIDGET(gtk_builder_get_object(builder, "label_id"));
|
||||||
self->priv.label_title = GTK_WIDGET(gtk_builder_get_object(builder, "label_title"));
|
self->priv.label_title = GTK_WIDGET(gtk_builder_get_object(builder, "label_title"));
|
||||||
self->priv.label_comment = GTK_WIDGET(gtk_builder_get_object(builder, "label_comment"));
|
self->priv.entry_comment = GTK_WIDGET(gtk_builder_get_object(builder, "entry_comment"));
|
||||||
self->priv.label_description = GTK_WIDGET(gtk_builder_get_object(builder, "label_description"));
|
self->priv.label_description = GTK_WIDGET(gtk_builder_get_object(builder, "label_description"));
|
||||||
|
|
||||||
self->priv.button_delete = GTK_WIDGET(gtk_builder_get_object(builder, "button_delete"));
|
self->priv.button_delete = GTK_WIDGET(gtk_builder_get_object(builder, "button_delete"));
|
||||||
@ -101,13 +113,30 @@ static void yacos_cart_item_init(YacosCartItem *self)
|
|||||||
|
|
||||||
g_signal_connect(self->priv.button_delete,
|
g_signal_connect(self->priv.button_delete,
|
||||||
"clicked",
|
"clicked",
|
||||||
(GCallback) yacos_ceart_item_button_delete_cb,
|
(GCallback) yacos_cart_item_button_delete_cb,
|
||||||
|
self);
|
||||||
|
g_signal_connect(self->priv.button_properties,
|
||||||
|
"clicked",
|
||||||
|
(GCallback) yacos_cart_item_button_properties_cb,
|
||||||
self);
|
self);
|
||||||
|
|
||||||
|
|
||||||
gtk_container_add(GTK_CONTAINER(self), self->priv.box);
|
gtk_container_add(GTK_CONTAINER(self), self->priv.box);
|
||||||
|
|
||||||
g_object_unref(builder);
|
g_object_unref(builder);
|
||||||
|
|
||||||
|
GtkStyleContext *context;
|
||||||
|
GtkCssProvider *provider;
|
||||||
|
|
||||||
|
context = gtk_widget_get_style_context (self->priv.entry_comment);
|
||||||
|
provider = gtk_css_provider_new ();
|
||||||
|
gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
|
||||||
|
".entry_comment {\n"
|
||||||
|
" font-style: italic;\n"
|
||||||
|
"}\n", -1, NULL);
|
||||||
|
gtk_style_context_add_provider (context,
|
||||||
|
GTK_STYLE_PROVIDER (provider),
|
||||||
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
|
g_object_unref (provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *yacos_cart_item_new(void)
|
GtkWidget *yacos_cart_item_new(void)
|
||||||
@ -144,7 +173,7 @@ static void yacos_cart_item_fetch_meta_cb (SoupSession *session, SoupMessage *ms
|
|||||||
gtk_label_set_text(GTK_LABEL(self->priv.label_title), "Unknown article");
|
gtk_label_set_text(GTK_LABEL(self->priv.label_title), "Unknown article");
|
||||||
gtk_widget_override_color(self->priv.label_title, GTK_STATE_FLAG_NORMAL, &color_error);
|
gtk_widget_override_color(self->priv.label_title, GTK_STATE_FLAG_NORMAL, &color_error);
|
||||||
gtk_label_set_text(GTK_LABEL(self->priv.label_description), "This article will be ignored on checkout.");
|
gtk_label_set_text(GTK_LABEL(self->priv.label_description), "This article will be ignored on checkout.");
|
||||||
gtk_label_set_text(GTK_LABEL(self->priv.label_comment), "If you think this is an error, please contact a member of staff.");
|
gtk_entry_set_text(GTK_ENTRY(self->priv.entry_comment), "If you think this is an error, please contact a member of staff.");
|
||||||
self->priv.status = YACOS_CART_ITEM_STATUS_INVALID;
|
self->priv.status = YACOS_CART_ITEM_STATUS_INVALID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -169,12 +198,14 @@ static void yacos_cart_item_fetch_meta_cb (SoupSession *session, SoupMessage *ms
|
|||||||
|
|
||||||
json_reader_read_member (reader, "comment");
|
json_reader_read_member (reader, "comment");
|
||||||
temp = json_reader_get_string_value (reader);
|
temp = json_reader_get_string_value (reader);
|
||||||
gtk_label_set_text(GTK_LABEL(self->priv.label_comment), temp);
|
gtk_entry_set_text(GTK_ENTRY(self->priv.entry_comment), temp);
|
||||||
json_reader_end_member (reader);
|
json_reader_end_member (reader);
|
||||||
|
|
||||||
g_object_unref (reader);
|
g_object_unref (reader);
|
||||||
g_object_unref (parser);
|
g_object_unref (parser);
|
||||||
|
|
||||||
|
gtk_editable_set_editable(GTK_EDITABLE(self->priv.entry_comment), TRUE);
|
||||||
|
gtk_widget_set_sensitive(self->priv.button_properties, TRUE);
|
||||||
self->priv.status = YACOS_CART_ITEM_STATUS_VALID;
|
self->priv.status = YACOS_CART_ITEM_STATUS_VALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,8 +217,7 @@ void yacos_cart_item_fetch_meta(YacosCartItem *self)
|
|||||||
|
|
||||||
gtk_label_set_text(GTK_LABEL(self->priv.label_title), "Loading ...");
|
gtk_label_set_text(GTK_LABEL(self->priv.label_title), "Loading ...");
|
||||||
gtk_label_set_text(GTK_LABEL(self->priv.label_description), "");
|
gtk_label_set_text(GTK_LABEL(self->priv.label_description), "");
|
||||||
gtk_label_set_text(GTK_LABEL(self->priv.label_comment), "");
|
gtk_entry_set_text(GTK_LABEL(self->priv.entry_comment), " ");
|
||||||
|
|
||||||
|
|
||||||
id_str = yacos_tag_id_to_str(self->priv.tag_id);
|
id_str = yacos_tag_id_to_str(self->priv.tag_id);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user