about dialog: Use headerbar

Use a GtkHeaderBar for the credits and about buttons.

It makes less sense here than in other places to go back to
the buttons on the bottom, considering we only have a close
button, so we always use a header bar.

https://bugzilla.gnome.org/show_bug.cgi?id=720059
This commit is contained in:
William Jon McCann 2013-12-08 13:40:50 +01:00 committed by Matthias Clasen
parent 54b1419952
commit a70f8f44b4
3 changed files with 91 additions and 189 deletions

View File

@ -50,6 +50,10 @@
#include "gtkmessagedialog.h"
#include "gtktogglebutton.h"
#include "gtktypebuiltins.h"
#include "gtkstack.h"
#include "gtkstackswitcher.h"
#include "gtksettings.h"
#include "gtkheaderbar.h"
#include "gtkprivate.h"
#include "gtkintl.h"
@ -149,6 +153,7 @@ struct _GtkAboutDialogPrivate
gboolean license_page_initialized;
GtkWidget *stack;
GtkWidget *stack_switcher;
GtkWidget *logo_image;
GtkWidget *name_label;
GtkWidget *version_label;
@ -157,8 +162,8 @@ struct _GtkAboutDialogPrivate
GtkWidget *license_label;
GtkWidget *website_label;
GtkWidget *credits_button;
GtkWidget *license_button;
GtkWidget *credits_page;
GtkWidget *license_page;
GtkWidget *credits_grid;
GtkWidget *license_view;
@ -214,17 +219,11 @@ static void set_cursor_if_appropriate (GtkAboutDialog
GdkDevice *device,
gint x,
gint y);
static void display_credits_page (GtkWidget *button,
gpointer data);
static void display_license_page (GtkWidget *button,
gpointer data);
static void populate_credits_page (GtkAboutDialog *about);
static void populate_license_page (GtkAboutDialog *about);
static void close_cb (GtkAboutDialog *about);
static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
const gchar *uri);
static void credits_button_clicked (GtkButton *button,
gpointer data);
static void license_button_clicked (GtkButton *button,
gpointer data);
static gboolean emit_activate_link (GtkAboutDialog *about,
const gchar *uri);
static gboolean text_view_key_press_event (GtkWidget *text_view,
@ -250,6 +249,34 @@ static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE_WITH_PRIVATE (GtkAboutDialog, gtk_about_dialog, GTK_TYPE_DIALOG)
static gboolean
stack_visible_child_notify (GtkStack *stack,
GParamSpec *pspec,
GtkAboutDialog *about)
{
GtkAboutDialogPrivate *priv = about->priv;
GtkWidget *child;
child = gtk_stack_get_visible_child (stack);
if (child == priv->credits_page)
{
if (!priv->credits_page_initialized)
{
populate_credits_page (about);
priv->credits_page_initialized = TRUE;
}
}
else if (child == priv->license_page)
{
if (!priv->license_page_initialized)
{
populate_license_page (about);
priv->license_page_initialized = TRUE;
}
}
return FALSE;
}
static void
gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
@ -559,6 +586,7 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
"/org/gtk/libgtk/gtkaboutdialog.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, stack);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, stack_switcher);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, logo_image);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, name_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, version_label);
@ -566,18 +594,17 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, copyright_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, license_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, website_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, credits_button);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, license_button);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, credits_page);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, license_page);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, credits_grid);
gtk_widget_class_bind_template_child_private (widget_class, GtkAboutDialog, license_view);
gtk_widget_class_bind_template_callback (widget_class, credits_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, license_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, emit_activate_link);
gtk_widget_class_bind_template_callback (widget_class, text_view_event_after);
gtk_widget_class_bind_template_callback (widget_class, text_view_key_press_event);
gtk_widget_class_bind_template_callback (widget_class, text_view_visibility_notify_event);
gtk_widget_class_bind_template_callback (widget_class, text_view_motion_notify_event);
gtk_widget_class_bind_template_callback (widget_class, stack_visible_child_notify);
}
static gboolean
@ -591,15 +618,29 @@ emit_activate_link (GtkAboutDialog *about,
return TRUE;
}
static void
update_stack_switcher_visibility (GtkAboutDialog *about)
{
GtkAboutDialogPrivate *priv = about->priv;
if (gtk_widget_get_visible (priv->credits_page) ||
gtk_widget_get_visible (priv->license_page))
gtk_widget_show (priv->stack_switcher);
else
gtk_widget_hide (priv->stack_switcher);
}
static void
update_license_button_visibility (GtkAboutDialog *about)
{
GtkAboutDialogPrivate *priv = about->priv;
if (priv->license_type == GTK_LICENSE_CUSTOM && priv->license != NULL)
gtk_widget_show (priv->license_button);
gtk_widget_show (priv->license_page);
else
gtk_widget_hide (priv->license_button);
gtk_widget_hide (priv->license_page);
update_stack_switcher_visibility (about);
}
static void
@ -616,9 +657,11 @@ update_credits_button_visibility (GtkAboutDialog *about)
strcmp (priv->translator_credits, "translator_credits") &&
strcmp (priv->translator_credits, "translator-credits")));
if (show)
gtk_widget_show (priv->credits_button);
gtk_widget_show (priv->credits_page);
else
gtk_widget_hide (priv->credits_button);
gtk_widget_hide (priv->credits_page);
update_stack_switcher_visibility (about);
}
static void
@ -630,66 +673,6 @@ switch_page (GtkAboutDialog *about,
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), name);
}
static void
display_main_page (GtkButton *button,
gpointer data)
{
GtkAboutDialog *about = (GtkAboutDialog *)data;
switch_page (about, "main");
}
static void
credits_button_clicked (GtkButton *button,
gpointer data)
{
GtkAboutDialog *about = (GtkAboutDialog *)data;
GtkAboutDialogPrivate *priv = about->priv;
gboolean active;
if (priv->in_child_changed)
return;
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
if (active)
{
priv->in_child_changed = TRUE;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
priv->in_child_changed = FALSE;
display_credits_page (NULL, data);
}
else
{
display_main_page (NULL, data);
}
}
static void
license_button_clicked (GtkButton *button,
gpointer data)
{
GtkAboutDialog *about = (GtkAboutDialog *)data;
GtkAboutDialogPrivate *priv = about->priv;
gboolean active;
if (priv->in_child_changed)
return;
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
if (active)
{
priv->in_child_changed = TRUE;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
priv->in_child_changed = FALSE;
display_license_page (NULL, data);
}
else
{
display_main_page (NULL, data);
}
}
static void
gtk_about_dialog_init (GtkAboutDialog *about)
{
@ -723,6 +706,7 @@ gtk_about_dialog_init (GtkAboutDialog *about)
gtk_widget_init_template (GTK_WIDGET (about));
switch_page (about, "main");
update_stack_switcher_visibility (about);
/* force defaults */
gtk_about_dialog_set_program_name (about, NULL);
@ -2317,22 +2301,6 @@ populate_credits_page (GtkAboutDialog *about)
}
}
static void
display_credits_page (GtkWidget *button,
gpointer data)
{
GtkAboutDialog *about = (GtkAboutDialog *)data;
GtkAboutDialogPrivate *priv = about->priv;
if (!priv->credits_page_initialized)
{
populate_credits_page (about);
priv->credits_page_initialized = TRUE;
}
switch_page (about, "credits");
}
static void
populate_license_page (GtkAboutDialog *about)
{
@ -2349,22 +2317,6 @@ populate_license_page (GtkAboutDialog *about)
g_object_unref (buffer);
}
static void
display_license_page (GtkWidget *button,
gpointer data)
{
GtkAboutDialog *about = (GtkAboutDialog *)data;
GtkAboutDialogPrivate *priv = about->priv;
if (!priv->license_page_initialized)
{
populate_license_page (about);
priv->license_page_initialized = TRUE;
}
switch_page (about, "license");
}
/**
* gtk_about_dialog_new:
*
@ -2377,7 +2329,11 @@ display_license_page (GtkWidget *button,
GtkWidget *
gtk_about_dialog_new (void)
{
GtkAboutDialog *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, NULL);
GtkAboutDialog *dialog;
dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
"use-header-bar", TRUE,
NULL);
return GTK_WIDGET (dialog);
}
@ -2385,11 +2341,8 @@ gtk_about_dialog_new (void)
static void
close_cb (GtkAboutDialog *about)
{
GtkAboutDialogPrivate *priv = about->priv;
switch_page (about, "main");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->credits_button), FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->license_button), FALSE);
gtk_widget_hide (GTK_WIDGET (about));
}

View File

@ -11,77 +11,25 @@
<property name="border_width">5</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<child internal-child="headerbar">
<object class="GtkHeaderBar" id="headerbar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show-close-button">True</property>
<child type="title">
<object class="GtkStackSwitcher" id="stack_switcher">
<property name="visible">False</property>
<property name="stack">stack</property>
<property name="no-show-all">True</property>
</object>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkToggleButton" id="credits_button">
<property name="label" translatable="yes">C_redits</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="no_show_all">True</property>
<property name="image">image1</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="credits_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
<property name="secondary">True</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="license_button">
<property name="label" translatable="yes">_License</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="no_show_all">True</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="license_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
<property name="secondary">True</property>
</packing>
</child>
<child>
<object class="GtkButton" id="close_button">
<property name="label" translatable="yes">_Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="is_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box">
<property name="visible">True</property>
@ -124,6 +72,7 @@
<property name="homogeneous">True</property>
<property name="transition-type">over-up-down</property>
<property name="transition-duration">600</property>
<signal name="notify::visible-child" handler="stack_visible_child_notify" swapped="no"/>
<child>
<object class="GtkBox" id="page_vbox">
<property name="visible">True</property>
@ -224,11 +173,12 @@
</object>
<packing>
<property name="name">main</property>
<property name="title" translatable="yes">About</property>
</packing>
</child>
<child>
<object class="GtkBox" id="credits_page">
<property name="visible">True</property>
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">8</property>
@ -296,11 +246,12 @@
</object>
<packing>
<property name="name">credits</property>
<property name="title" translatable="yes">Credits</property>
</packing>
</child>
<child>
<object class="GtkBox" id="license_page">
<property name="visible">True</property>
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">8</property>
@ -334,6 +285,7 @@
</object>
<packing>
<property name="name">license</property>
<property name="title" translatable="yes">License</property>
</packing>
</child>
</object>
@ -352,8 +304,5 @@
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">close_button</action-widget>
</action-widgets>
</template>
</interface>

View File

@ -1,3 +1,3 @@
N_("C_redits");
N_("_License");
N_("_Close");
N_("About");
N_("Credits");
N_("License");