[gnome-control-center/gbsneto/applications-panel-cleanups: 12/16] applications: Move handlers section into a dialog




commit 28212c77a74afdffd64843423d58deb9b34dad7a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jan 20 15:11:48 2022 -0300

    applications: Move handlers section into a dialog
    
    Add a new row in the usage section, like Built-in and Disk
    Usage. Move the file handler widgetry into this new dialog.

 panels/applications/cc-applications-panel.c  | 55 +++++++++++++----
 panels/applications/cc-applications-panel.ui | 88 ++++++++++++++++++++--------
 2 files changed, 110 insertions(+), 33 deletions(-)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index e11166424..94830fc8a 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -116,9 +116,11 @@ struct _CcApplicationsPanel
   CcToggleRow     *search;
   CcInfoRow       *no_search;
 
-  GtkWidget       *handler_section;
   GtkButton       *handler_reset;
+  GtkDialog       *handler_dialog;
   GtkListBox      *handler_list;
+  CcInfoRow       *handler_row;
+  GtkLabel        *handler_title_label;
   CcInfoRow       *hypertext;
   CcInfoRow       *text;
   CcInfoRow       *images;
@@ -1326,7 +1328,7 @@ static void
 add_handler_row (CcApplicationsPanel *self,
                  const gchar         *type)
 {
-  gtk_widget_show (self->handler_section);
+  gtk_widget_show (GTK_WIDGET (self->handler_row));
 
   if (g_content_type_is_a (type, "x-scheme-handler/*"))
     add_link_type (self, type);
@@ -1425,11 +1427,13 @@ handler_reset_cb (CcApplicationsPanel *self)
 }
 
 static void
-update_handler_sections (CcApplicationsPanel *self,
-                         GAppInfo            *info)
+update_handler_dialog (CcApplicationsPanel *self,
+                       GAppInfo            *info)
 {
+  g_autofree gchar *header_title = NULL;
   g_autoptr(GHashTable) hash = NULL;
   const gchar **types;
+  guint n_associations = 0;
   gint i;
 
   listbox_remove_all (self->handler_list);
@@ -1445,8 +1449,7 @@ update_handler_sections (CcApplicationsPanel *self,
   self->other = NULL;
   self->link = NULL;
 
-  gtk_widget_hide (self->handler_section);
-
+  gtk_widget_hide (GTK_WIDGET (self->handler_row));
   types = g_app_info_get_supported_types (info);
   if (types == NULL || types[0] == NULL)
     return;
@@ -1469,7 +1472,25 @@ update_handler_sections (CcApplicationsPanel *self,
 
       add_handler_row (self, ctype);
       g_hash_table_add (hash, g_steal_pointer (&ctype));
+
+      n_associations++;
     }
+
+  if (n_associations > 0)
+    {
+      g_autofree gchar *subtitle = NULL;
+
+      subtitle = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
+                                               "%u file and link type that is opened by the app",
+                                               "%u file and link types that are opened by the app",
+                                               n_associations),
+                                  n_associations);
+      adw_action_row_set_subtitle (ADW_ACTION_ROW (self->handler_row), subtitle);
+    }
+
+  header_title = g_strdup_printf (_("<b>%s</b> is used to open the following types of files and links."),
+                                  g_app_info_get_display_name (info));
+  gtk_label_set_markup (self->handler_title_label, header_title);
 }
 
 /* --- usage section --- */
@@ -1485,6 +1506,17 @@ on_builtin_row_activated_cb (GtkListBoxRow       *row,
   gtk_window_present (GTK_WINDOW (self->builtin_dialog));
 }
 
+static void
+on_handler_row_activated_cb (GtkListBoxRow       *row,
+                             CcApplicationsPanel *self)
+{
+  CcShell *shell = cc_panel_get_shell (CC_PANEL (self));
+
+  gtk_window_set_transient_for (GTK_WINDOW (self->handler_dialog),
+                                GTK_WINDOW (cc_shell_get_toplevel (shell)));
+  gtk_window_present (GTK_WINDOW (self->handler_dialog));
+}
+
 static void
 on_storage_row_activated_cb (GtkListBoxRow       *row,
                              CcApplicationsPanel *self)
@@ -1690,7 +1722,7 @@ update_panel (CcApplicationsPanel *self,
   update_header_section (self, info);
   update_permission_section (self, info);
   update_integration_section (self, info);
-  update_handler_sections (self, info);
+  update_handler_dialog (self, info);
   update_usage_section (self, info);
 
   g_set_object (&self->current_app_info, info);
@@ -2019,9 +2051,11 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, clear_cache_button);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, data);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, empty_box);
-  gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, handler_section);
+  gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, handler_dialog);
+  gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, handler_row);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, handler_reset);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, handler_list);
+  gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, handler_title_label);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, header_title);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, install_button);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, integration_section);
@@ -2068,12 +2102,13 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, open_software_cb);
   gtk_widget_class_bind_template_callback (widget_class, handler_reset_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_builtin_row_activated_cb);
+  gtk_widget_class_bind_template_callback (widget_class, on_handler_row_activated_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_launch_button_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_sidebar_search_entry_activated_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_sidebar_search_entry_search_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_sidebar_search_entry_search_stopped_cb);
-  gtk_widget_class_bind_template_callback (widget_class, on_storage_row_activated_cb);
-}
+
+  gtk_widget_class_bind_template_callback (widget_class, on_storage_row_activated_cb);}
 
 static void
 cc_applications_panel_init (CcApplicationsPanel *self)
diff --git a/panels/applications/cc-applications-panel.ui b/panels/applications/cc-applications-panel.ui
index 8015bca47..40e55fcf1 100644
--- a/panels/applications/cc-applications-panel.ui
+++ b/panels/applications/cc-applications-panel.ui
@@ -221,29 +221,6 @@
               </object>
             </child>
 
-            <child>
-              <object class="AdwPreferencesGroup" id="handler_section">
-                <child>
-                  <object class="GtkListBox" id="handler_list">
-                    <property name="selection-mode">none</property>
-                    <signal name="row-activated" handler="handler_row_activated_cb" 
object="CcApplicationsPanel" swapped="yes"/>
-                    <style>
-                      <class name="boxed-list"/>
-                    </style>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkButton" id="handler_reset">
-                    <property name="halign">end</property>
-                    <property name="valign">center</property>
-                    <property name="margin-top">12</property>
-                    <property name="label" translatable="yes">Reset</property>
-                    <signal name="clicked" handler="handler_reset_cb" object="CcApplicationsPanel" 
swapped="yes"/>
-                  </object>
-                </child>
-              </object>
-            </child>
-
             <child>
               <object class="AdwPreferencesGroup" id="usage_section">
                 <child>
@@ -255,6 +232,14 @@
                     <signal name="activated" handler="on_builtin_row_activated_cb" 
object="CcApplicationsPanel" swapped="no" />
                   </object>
                 </child>
+                <child>
+                  <object class="CcInfoRow" id="handler_row">
+                    <property name="title" translatable="yes">File &amp;amp; Link Associations</property>
+                    <property name="has-expander">True</property>
+                    <property name="is-link">True</property>
+                    <signal name="activated" handler="on_handler_row_activated_cb" 
object="CcApplicationsPanel" swapped="no" />
+                  </object>
+                </child>
                 <child>
                   <object class="CcInfoRow" id="storage">
                     <property name="title" translatable="yes">Storage</property>
@@ -377,6 +362,63 @@
     </child>
   </object>
 
+  <!-- File & Link handlers dialog -->
+  <object class="GtkDialog" id="handler_dialog">
+    <property name="title" translatable="yes">File &amp; Link Associations</property>
+    <property name="modal">1</property>
+    <property name="use-header-bar">1</property>
+    <property name="resizable">0</property>
+    <property name="hide-on-close">True</property>
+    <property name="default-width">500</property>
+    <property name="default-height">400</property>
+    <child>
+      <object class="AdwPreferencesPage">
+
+        <child>
+          <object class="AdwPreferencesGroup">
+            <child>
+              <object class="GtkLabel" id="handler_title_label">
+                <property name="wrap">True</property>
+                <property name="xalign">0.0</property>
+              </object>
+            </child>
+          </object>
+        </child>
+
+        <child>
+          <object class="AdwPreferencesGroup" id="handler_section">
+            <child>
+              <object class="GtkListBox" id="handler_list">
+                <property name="selection-mode">none</property>
+                <signal name="row-activated" handler="handler_row_activated_cb" object="CcApplicationsPanel" 
swapped="yes"/>
+                <style>
+                  <class name="boxed-list"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+
+        <child>
+          <object class="AdwPreferencesGroup">
+            <child>
+              <object class="GtkButton" id="handler_reset">
+                <property name="valign">center</property>
+                <property name="margin-top">12</property>
+                <property name="label" translatable="yes">Reset</property>
+                <signal name="clicked" handler="handler_reset_cb" object="CcApplicationsPanel" 
swapped="yes"/>
+                <style>
+                  <class name="destructive-action" />
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+
+      </object>
+    </child>
+  </object>
+
   <!-- Storage dialog -->
   <object class="GtkDialog" id="storage_dialog">
     <property name="title" translatable="yes">Storage</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]