Commit 88771f7b authored by William Jon McCann's avatar William Jon McCann

Add an optional close button to the info bar

This adds gtk_info_bar_{get,set}_show_close_button.
Similar to the one for the search bar. This can replace Cancel
buttons.

https://bugzilla.gnome.org/show_bug.cgi?id=704274
parent 16e43733
......@@ -2381,6 +2381,8 @@ gtk_info_bar_set_message_type
gtk_info_bar_get_message_type
gtk_info_bar_get_action_area
gtk_info_bar_get_content_area
gtk_info_bar_get_show_close_button
gtk_info_bar_set_show_close_button
<SUBSECTION Standard>
GTK_TYPE_INFO_BAR
......
......@@ -118,14 +118,17 @@
enum
{
PROP_0,
PROP_MESSAGE_TYPE
PROP_MESSAGE_TYPE,
PROP_SHOW_CLOSE_BUTTON
};
struct _GtkInfoBarPrivate
{
GtkWidget *content_area;
GtkWidget *action_area;
GtkWidget *close_button;
gboolean show_close_button;
GtkMessageType message_type;
};
......@@ -198,6 +201,9 @@ gtk_info_bar_set_property (GObject *object,
case PROP_MESSAGE_TYPE:
gtk_info_bar_set_message_type (info_bar, g_value_get_enum (value));
break;
case PROP_SHOW_CLOSE_BUTTON:
gtk_info_bar_set_show_close_button (info_bar, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -217,6 +223,9 @@ gtk_info_bar_get_property (GObject *object,
case PROP_MESSAGE_TYPE:
g_value_set_enum (value, gtk_info_bar_get_message_type (info_bar));
break;
case PROP_SHOW_CLOSE_BUTTON:
g_value_set_boolean (value, gtk_info_bar_get_show_close_button (info_bar));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -283,7 +292,8 @@ find_button (GtkInfoBar *info_bar,
static void
gtk_info_bar_close (GtkInfoBar *info_bar)
{
if (!find_button (info_bar, GTK_RESPONSE_CANCEL))
if (!gtk_widget_get_visible (info_bar->priv->close_button)
&& !find_button (info_bar, GTK_RESPONSE_CANCEL))
return;
gtk_info_bar_response (GTK_INFO_BAR (info_bar),
......@@ -404,6 +414,21 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
GTK_TYPE_MESSAGE_TYPE,
GTK_MESSAGE_INFO,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* GtkInfoBar:show-close-button:
*
* Whether to include a standard close button.
*
* Since: 3.10
*/
g_object_class_install_property (object_class,
PROP_SHOW_CLOSE_BUTTON,
g_param_spec_boolean ("show-close-button",
P_("Show Close Button"),
P_("Whether to include a standard close button"),
FALSE,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* GtkInfoBar::response:
* @info_bar: the object on which the signal is emitted
......@@ -523,6 +548,15 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkinfobar.ui");
gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, content_area);
gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, action_area);
gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, close_button);
}
static void
close_button_clicked_cb (GtkWidget *button,
GtkInfoBar *info_bar)
{
gtk_info_bar_response (GTK_INFO_BAR (info_bar),
GTK_RESPONSE_CLOSE);
}
static void
......@@ -540,6 +574,10 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
info_bar->priv->message_type = GTK_MESSAGE_OTHER;
gtk_widget_init_template (GTK_WIDGET (info_bar));
gtk_widget_set_no_show_all (info_bar->priv->close_button, TRUE);
g_signal_connect (info_bar->priv->close_button, "clicked",
G_CALLBACK (close_button_clicked_cb), info_bar);
}
static GtkBuildableIface *parent_buildable_iface;
......@@ -1169,3 +1207,46 @@ gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
return info_bar->priv->message_type;
}
/**
* gtk_info_bar_set_show_close_button:
* @info_bar: a #GtkInfoBar
* @setting: %TRUE to include a close button
*
* If true, a standard close button is shown. When clicked it emits
* the response %GTK_RESPONSE_CLOSE.
*
* Since: 3.10
*/
void
gtk_info_bar_set_show_close_button (GtkInfoBar *info_bar,
gboolean setting)
{
g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
if (setting != info_bar->priv->show_close_button)
{
info_bar->priv->show_close_button = setting;
gtk_widget_set_visible (info_bar->priv->close_button, setting);
g_object_notify (G_OBJECT (info_bar), "show-close-button");
}
}
/**
* gtk_info_bar_get_show_close_button:
* @info_bar: a #GtkInfoBar
*
* Returns whether the widget will display a standard close button.
*
* Returns: %TRUE if the widget displays standard close button
*
* Since: 3.10
*/
gboolean
gtk_info_bar_get_show_close_button (GtkInfoBar *info_bar)
{
g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), FALSE);
return info_bar->priv->show_close_button;
}
......@@ -124,6 +124,12 @@ void gtk_info_bar_set_message_type (GtkInfoBar *info_bar,
GDK_AVAILABLE_IN_ALL
GtkMessageType gtk_info_bar_get_message_type (GtkInfoBar *info_bar);
GDK_AVAILABLE_IN_3_10
void gtk_info_bar_set_show_close_button (GtkInfoBar *info_bar,
gboolean setting);
GDK_AVAILABLE_IN_3_10
gboolean gtk_info_bar_get_show_close_button (GtkInfoBar *info_bar);
G_END_DECLS
#endif /* __GTK_INFO_BAR_H__ */
......@@ -38,5 +38,29 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="close_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">6</property>
<property name="relief">none</property>
<style>
<class name="raised"/>
<class name="close"/>
</style>
<child>
<object class="GtkImage" id="close_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">window-close-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</template>
</interface>
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