[nautilus/wip/coreyberla/app-picker-followups: 1/4] app-chooser: Replace Reset and Set as Default buttons with a Switch
- From: Corey Berla <coreyberla src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/coreyberla/app-picker-followups: 1/4] app-chooser: Replace Reset and Set as Default buttons with a Switch
- Date: Sat, 6 Aug 2022 15:06:44 +0000 (UTC)
commit e382d092b5305ba87f0490e52120519e69426d4c
Author: Corey Berla <corey berla me>
Date: Fri Aug 5 12:48:59 2022 -0700
app-chooser: Replace Reset and Set as Default buttons with a Switch
Set the switch to active when the association is set as default
and inactive when it is not set as default (also a way to remove
the default association). Add a label for the switch with a
subtitle indicating the content description.
src/nautilus-app-chooser.c | 69 ++++++++++++++++++--------------
src/resources/ui/nautilus-app-chooser.ui | 65 ++++++++++++++++++------------
2 files changed, 78 insertions(+), 56 deletions(-)
---
diff --git a/src/nautilus-app-chooser.c b/src/nautilus-app-chooser.c
index 599e1c38d..c55b55864 100644
--- a/src/nautilus-app-chooser.c
+++ b/src/nautilus-app-chooser.c
@@ -20,8 +20,9 @@ struct _NautilusAppChooser
gboolean single_content_type;
GtkWidget *app_chooser_widget_box;
- GtkWidget *reset_button;
- GtkWidget *set_as_default_button;
+ GtkWidget *label_content_type_description;
+ GtkWidget *set_as_default_switch;
+ GtkWidget *set_default_box;
GtkWidget *app_chooser_widget;
};
@@ -36,31 +37,26 @@ enum
LAST_PROP
};
-static void
-reset_clicked_cb (GtkButton *button,
- gpointer user_data)
-{
- NautilusAppChooser *self = NAUTILUS_APP_CHOOSER (user_data);
-
- g_app_info_reset_type_associations (self->content_type);
- gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->app_chooser_widget));
- gtk_widget_set_sensitive (self->reset_button, FALSE);
-
- g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
-}
-
-static void
-set_as_default_clicked_cb (GtkButton *button,
- gpointer user_data)
+static gboolean
+set_as_default_state_set_cb (GtkSwitch *default_switch,
+ gboolean state,
+ gpointer user_data)
{
NautilusAppChooser *self = NAUTILUS_APP_CHOOSER (user_data);
g_autoptr (GAppInfo) info = NULL;
g_autoptr (GError) error = NULL;
- info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->app_chooser_widget));
-
- g_app_info_set_as_default_for_type (info, self->content_type,
- &error);
+ if (state)
+ {
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->app_chooser_widget));
+ g_app_info_set_as_default_for_type (info, self->content_type,
+ &error);
+ }
+ else
+ {
+ g_app_info_reset_type_associations (self->content_type);
+ gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->app_chooser_widget));
+ }
if (error != NULL)
{
@@ -77,8 +73,8 @@ set_as_default_clicked_cb (GtkButton *button,
}
gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->app_chooser_widget));
- gtk_widget_set_sensitive (self->reset_button, TRUE);
g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
+ return FALSE;
}
static void
@@ -95,7 +91,9 @@ on_application_selected (GtkAppChooserWidget *widget,
default_app = g_app_info_get_default_for_type (self->content_type, FALSE);
is_default = default_app != NULL && g_app_info_equal (info, default_app);
- gtk_widget_set_sensitive (self->set_as_default_button, !is_default);
+ g_signal_handlers_block_by_func (self->set_as_default_switch, G_CALLBACK (set_as_default_state_set_cb),
self);
+ gtk_switch_set_state (GTK_SWITCH (self->set_as_default_switch), is_default);
+ g_signal_handlers_unblock_by_func (self->set_as_default_switch, G_CALLBACK
(set_as_default_state_set_cb), self);
}
static void
@@ -141,6 +139,7 @@ nautilus_app_chooser_constructed (GObject *object)
{
NautilusAppChooser *self = NAUTILUS_APP_CHOOSER (object);
g_autoptr (GAppInfo) info = NULL;
+ g_autofree gchar *content_type_description = NULL;
G_OBJECT_CLASS (nautilus_app_chooser_parent_class)->constructed (object);
@@ -152,11 +151,8 @@ nautilus_app_chooser_constructed (GObject *object)
gtk_app_chooser_widget_set_show_default (GTK_APP_CHOOSER_WIDGET (self->app_chooser_widget), TRUE);
gtk_app_chooser_widget_set_show_fallback (GTK_APP_CHOOSER_WIDGET (self->app_chooser_widget), TRUE);
gtk_app_chooser_widget_set_show_other (GTK_APP_CHOOSER_WIDGET (self->app_chooser_widget), TRUE);
- g_signal_connect (self->reset_button, "clicked",
- G_CALLBACK (reset_clicked_cb),
- self);
- g_signal_connect (self->set_as_default_button, "clicked",
- G_CALLBACK (set_as_default_clicked_cb),
+ g_signal_connect (self->set_as_default_switch, "state-set",
+ G_CALLBACK (set_as_default_state_set_cb),
self);
/* initialize sensitivity */
@@ -175,6 +171,16 @@ nautilus_app_chooser_constructed (GObject *object)
gtk_header_bar_set_title_widget (GTK_HEADER_BAR (gtk_dialog_get_header_bar (GTK_DIALOG (self))),
adw_window_title_new (gtk_window_get_title (GTK_WINDOW (self)),
self->content_type));
+
+ if (self->single_content_type)
+ {
+ content_type_description = g_content_type_get_description (self->content_type);
+ gtk_label_set_label (GTK_LABEL (self->label_content_type_description), content_type_description);
+ }
+ else
+ {
+ gtk_widget_set_visible (self->set_default_box, FALSE);
+ }
}
static void
@@ -200,8 +206,9 @@ nautilus_app_chooser_class_init (NautilusAppChooserClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/nautilus/ui/nautilus-app-chooser.ui");
gtk_widget_class_bind_template_child (widget_class, NautilusAppChooser, app_chooser_widget_box);
- gtk_widget_class_bind_template_child (widget_class, NautilusAppChooser, reset_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusAppChooser, set_as_default_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusAppChooser, set_as_default_switch);
+ gtk_widget_class_bind_template_child (widget_class, NautilusAppChooser, label_content_type_description);
+ gtk_widget_class_bind_template_child (widget_class, NautilusAppChooser, set_default_box);
g_object_class_install_property (object_class,
PROP_CONTENT_TYPE,
diff --git a/src/resources/ui/nautilus-app-chooser.ui b/src/resources/ui/nautilus-app-chooser.ui
index 5c2eb95f5..0d69ed994 100644
--- a/src/resources/ui/nautilus-app-chooser.ui
+++ b/src/resources/ui/nautilus-app-chooser.ui
@@ -19,14 +19,14 @@
<property name="name">list</property>
<property name="child">
<object class="GtkScrolledWindow">
+ <property name="margin-top">18</property>
+ <property name="margin-bottom">18</property>
+ <property name="margin-start">18</property>
+ <property name="margin-end">18</property>
<property name="hscrollbar-policy">never</property>
<property name="vexpand">true</property>
<property name="child">
<object class="AdwClamp">
- <property name="margin-top">12</property>
- <property name="margin-bottom">12</property>
- <property name="margin-start">12</property>
- <property name="margin-end">12</property>
<style>
<class name="background"/>
</style>
@@ -36,31 +36,12 @@
<property name="spacing">12</property>
<child>
<object class="GtkBox" id="app_chooser_widget_box">
+ <property name="margin-start">18</property>
+ <property name="margin-end">18</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
</object>
</child>
- <child>
- <object class="GtkBox">
- <property name="spacing">6</property>
- <child>
- <object class="GtkButton" id="reset_button">
- <property name="label" translatable="yes">_Reset</property>
- <property name="use-underline">True</property>
- <property name="focusable">True</property>
- <property name="receives_default">True</property>
- <property name="hexpand">True</property>
- <property name="halign">start</property>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="set_as_default_button">
- <property name="label" translatable="yes">Set as _Default</property>
- <property name="use-underline">True</property>
- </object>
- </child>
- </object>
- </child>
</object>
</property>
</object>
@@ -71,6 +52,40 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkBox" id="set_default_box">
+ <property name="margin-bottom">18</property>
+ <property name="margin-start">18</property>
+ <property name="margin-end">18</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="label" translatable="yes">Always use for this file type</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_content_type_description">
+ <property name="halign">start</property>
+ <style>
+ <class name="dim-label"/>
+ <class name="caption"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="set_as_default_switch">
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
<child type="action">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]