app chooser: Use headerbar
Use a GtkHeaderBar in the app chooser dialog when desired. https://bugzilla.gnome.org/show_bug.cgi?id=720059
This commit is contained in:
committed by
Matthias Clasen
parent
9c443b4a3c
commit
dfaa4857f5
@ -46,10 +46,13 @@
|
|||||||
#include "gtkappchooserprivate.h"
|
#include "gtkappchooserprivate.h"
|
||||||
|
|
||||||
#include "gtkmessagedialog.h"
|
#include "gtkmessagedialog.h"
|
||||||
|
#include "gtksettings.h"
|
||||||
#include "gtklabel.h"
|
#include "gtklabel.h"
|
||||||
#include "gtkbbox.h"
|
#include "gtkbbox.h"
|
||||||
#include "gtkbutton.h"
|
#include "gtkbutton.h"
|
||||||
#include "gtkmenuitem.h"
|
#include "gtkmenuitem.h"
|
||||||
|
#include "gtkheaderbar.h"
|
||||||
|
#include "gtkdialogprivate.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <glib/gi18n-lib.h>
|
#include <glib/gi18n-lib.h>
|
||||||
@ -63,7 +66,6 @@ struct _GtkAppChooserDialogPrivate {
|
|||||||
char *heading;
|
char *heading;
|
||||||
|
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *button;
|
|
||||||
GtkWidget *software_button;
|
GtkWidget *software_button;
|
||||||
GtkWidget *inner_box;
|
GtkWidget *inner_box;
|
||||||
|
|
||||||
@ -132,9 +134,9 @@ widget_application_selected_cb (GtkAppChooserWidget *widget,
|
|||||||
GAppInfo *app_info,
|
GAppInfo *app_info,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkAppChooserDialog *self = user_data;
|
GtkDialog *self = user_data;
|
||||||
|
|
||||||
gtk_widget_set_sensitive (self->priv->button, TRUE);
|
gtk_dialog_set_response_sensitive (self, GTK_RESPONSE_OK, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -340,7 +342,7 @@ construct_appchooser_widget (GtkAppChooserDialog *self)
|
|||||||
self->priv->show_more_button, FALSE, FALSE, 6);
|
self->priv->show_more_button, FALSE, FALSE, 6);
|
||||||
|
|
||||||
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
|
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
|
||||||
gtk_widget_set_sensitive (self->priv->button, info != NULL);
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, info != NULL);
|
||||||
if (info)
|
if (info)
|
||||||
g_object_unref (info);
|
g_object_unref (info);
|
||||||
}
|
}
|
||||||
@ -433,23 +435,32 @@ ensure_software_button (GtkAppChooserDialog *self)
|
|||||||
{
|
{
|
||||||
if (g_find_program_in_path ("gnome-software"))
|
if (g_find_program_in_path ("gnome-software"))
|
||||||
{
|
{
|
||||||
GtkWidget *action_area;
|
GtkWidget *parent;
|
||||||
|
gboolean use_header;
|
||||||
|
|
||||||
|
self->priv->software_button = gtk_button_new_with_label (_("Software"));
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
||||||
action_area = gtk_dialog_get_action_area (GTK_DIALOG (self));
|
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
||||||
self->priv->software_button = gtk_button_new_with_mnemonic (_("Software"));
|
|
||||||
gtk_button_set_always_show_image (GTK_BUTTON (self->priv->software_button), TRUE);
|
gtk_button_set_always_show_image (GTK_BUTTON (self->priv->software_button), TRUE);
|
||||||
gtk_button_set_image (GTK_BUTTON (self->priv->software_button), gtk_image_new_from_icon_name ("gnome-software", GTK_ICON_SIZE_BUTTON));
|
gtk_button_set_image (GTK_BUTTON (self->priv->software_button), gtk_image_new_from_icon_name ("gnome-software", GTK_ICON_SIZE_BUTTON));
|
||||||
|
gtk_widget_set_valign (self->priv->software_button, GTK_ALIGN_CENTER);
|
||||||
gtk_box_pack_start (GTK_BOX (action_area), self->priv->software_button,
|
|
||||||
FALSE, FALSE, 0);
|
|
||||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), self->priv->software_button,
|
|
||||||
TRUE);
|
|
||||||
g_signal_connect (self->priv->software_button, "clicked",
|
g_signal_connect (self->priv->software_button, "clicked",
|
||||||
G_CALLBACK (software_button_clicked_cb), self);
|
G_CALLBACK (software_button_clicked_cb), self);
|
||||||
|
|
||||||
gtk_widget_show (self->priv->software_button);
|
gtk_widget_show (self->priv->software_button);
|
||||||
|
|
||||||
|
g_object_get (self, "use-header-bar", &use_header, NULL);
|
||||||
|
if (use_header)
|
||||||
|
{
|
||||||
|
parent = gtk_dialog_get_header_bar (GTK_DIALOG (self));
|
||||||
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (parent), self->priv->software_button);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
|
parent = gtk_dialog_get_action_area (GTK_DIALOG (self));
|
||||||
|
gtk_container_add (GTK_CONTAINER (parent), self->priv->software_button);
|
||||||
|
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (parent), self->priv->software_button, TRUE);
|
||||||
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,10 +606,10 @@ gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
|
|||||||
/* Bind class to template
|
/* Bind class to template
|
||||||
*/
|
*/
|
||||||
widget_class = GTK_WIDGET_CLASS (klass);
|
widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
gtk_widget_class_set_template_from_resource (widget_class,
|
gtk_widget_class_set_template_from_resource (widget_class,
|
||||||
"/org/gtk/libgtk/gtkappchooserdialog.ui");
|
"/org/gtk/libgtk/gtkappchooserdialog.ui");
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserDialog, label);
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserDialog, label);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserDialog, button);
|
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserDialog, show_more_button);
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserDialog, show_more_button);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserDialog, inner_box);
|
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserDialog, inner_box);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, show_more_button_clicked_cb);
|
gtk_widget_class_bind_template_callback (widget_class, show_more_button_clicked_cb);
|
||||||
@ -610,15 +621,25 @@ gtk_app_chooser_dialog_init (GtkAppChooserDialog *self)
|
|||||||
self->priv = gtk_app_chooser_dialog_get_instance_private (self);
|
self->priv = gtk_app_chooser_dialog_get_instance_private (self);
|
||||||
|
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
|
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (self));
|
||||||
|
gtk_dialog_add_buttons (GTK_DIALOG (self),
|
||||||
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||||
|
_("_Select"), GTK_RESPONSE_OK,
|
||||||
|
NULL);
|
||||||
|
gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
|
||||||
|
|
||||||
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (self),
|
||||||
|
GTK_RESPONSE_OK,
|
||||||
|
GTK_RESPONSE_CANCEL,
|
||||||
|
-1);
|
||||||
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
|
|
||||||
/* we can't override the class signal handler here, as it's a RUN_LAST;
|
/* we can't override the class signal handler here, as it's a RUN_LAST;
|
||||||
* we want our signal handler instead to be executed before any user code.
|
* we want our signal handler instead to be executed before any user code.
|
||||||
*/
|
*/
|
||||||
g_signal_connect (self, "response",
|
g_signal_connect (self, "response",
|
||||||
G_CALLBACK (gtk_app_chooser_dialog_response), NULL);
|
G_CALLBACK (gtk_app_chooser_dialog_response), NULL);
|
||||||
|
|
||||||
gtk_dialog_set_default_response (GTK_DIALOG (self),
|
|
||||||
GTK_RESPONSE_OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
<template class="GtkAppChooserDialog" parent="GtkDialog">
|
<template class="GtkAppChooserDialog" parent="GtkDialog">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="border_width">5</property>
|
<property name="border_width">5</property>
|
||||||
|
<property name="title" translatable="yes">Select Application</property>
|
||||||
<property name="type_hint">dialog</property>
|
<property name="type_hint">dialog</property>
|
||||||
<child internal-child="vbox">
|
<child internal-child="vbox">
|
||||||
<object class="GtkBox" id="dialog-vbox1">
|
<object class="GtkBox" id="dialog-vbox1">
|
||||||
@ -14,36 +15,6 @@
|
|||||||
<object class="GtkButtonBox" id="dialog-action_area1">
|
<object class="GtkButtonBox" id="dialog-action_area1">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="layout_style">end</property>
|
<property name="layout_style">end</property>
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="cancel">
|
|
||||||
<property name="label" translatable="yes">_Cancel</property>
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="can_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">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="button">
|
|
||||||
<property name="label" translatable="yes">_Select</property>
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="can_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">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@ -102,10 +73,6 @@
|
|||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<action-widgets>
|
|
||||||
<action-widget response="-6">cancel</action-widget>
|
|
||||||
<action-widget response="-5">button</action-widget>
|
|
||||||
</action-widgets>
|
|
||||||
</template>
|
</template>
|
||||||
<object class="GtkImage" id="show_more_image">
|
<object class="GtkImage" id="show_more_image">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
N_("_Cancel");
|
N_("Select Application");
|
||||||
N_("_Select");
|
|
||||||
N_("label");
|
N_("label");
|
||||||
N_("Show Other Applications");
|
N_("Show Other Applications");
|
||||||
|
|||||||
Reference in New Issue
Block a user