[nautilus/wip/oholy/encrypted-archives: 2/6] compress-dialog: Use GtkListBox for archive formats




commit 6fa9ec38f49d94279e3dfca3001dfaf9f635bc68
Author: Ondrej Holy <oholy redhat com>
Date:   Mon Jun 21 11:48:11 2021 +0200

    compress-dialog: Use GtkListBox for archive formats
    
    Use GtkListBox for archive formats and their descriptions as per
    the mockup for the encrypted archives support.
    
    https://gitlab.gnome.org/GNOME/nautilus/-/issues/822

 src/nautilus-compress-dialog-controller.c    |  24 +--
 src/resources/ui/nautilus-compress-dialog.ui | 226 +++++++++++++++++----------
 2 files changed, 155 insertions(+), 95 deletions(-)
---
diff --git a/src/nautilus-compress-dialog-controller.c b/src/nautilus-compress-dialog-controller.c
index d8aa792ee..280739129 100644
--- a/src/nautilus-compress-dialog-controller.c
+++ b/src/nautilus-compress-dialog-controller.c
@@ -31,7 +31,6 @@ struct _NautilusCompressDialogController
     NautilusFileNameWidgetController parent_instance;
 
     GtkWidget *compress_dialog;
-    GtkWidget *description_stack;
     GtkWidget *name_entry;
     GtkWidget *zip_radio_button;
     GtkWidget *tar_xz_radio_button;
@@ -135,7 +134,6 @@ update_selected_format (NautilusCompressDialogController *self,
                         NautilusCompressionFormat         format)
 {
     const char *extension;
-    const char *description_label_name;
     GtkWidget *active_button;
 
     switch (format)
@@ -143,7 +141,6 @@ update_selected_format (NautilusCompressDialogController *self,
         case NAUTILUS_COMPRESSION_ZIP:
         {
             extension = ".zip";
-            description_label_name = "zip-description-label";
             active_button = self->zip_radio_button;
         }
         break;
@@ -151,7 +148,6 @@ update_selected_format (NautilusCompressDialogController *self,
         case NAUTILUS_COMPRESSION_TAR_XZ:
         {
             extension = ".tar.xz";
-            description_label_name = "tar-xz-description-label";
             active_button = self->tar_xz_radio_button;
         }
         break;
@@ -159,7 +155,6 @@ update_selected_format (NautilusCompressDialogController *self,
         case NAUTILUS_COMPRESSION_7ZIP:
         {
             extension = ".7z";
-            description_label_name = "seven-zip-description-label";
             active_button = self->seven_zip_radio_button;
         }
         break;
@@ -173,9 +168,6 @@ update_selected_format (NautilusCompressDialogController *self,
 
     self->extension = extension;
 
-    gtk_stack_set_visible_child_name (GTK_STACK (self->description_stack),
-                                      description_label_name);
-
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (active_button),
                                   TRUE);
 
@@ -188,6 +180,17 @@ update_selected_format (NautilusCompressDialogController *self,
     g_signal_emit_by_name (self->name_entry, "changed");
 }
 
+static void
+on_row_activated (GtkListBox    *box,
+                  GtkListBoxRow *row,
+                  gpointer       user_data)
+{
+    GtkWidget *radio_button;
+
+    radio_button = gtk_bin_get_child (GTK_BIN (row));
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), TRUE);
+}
+
 static void
 zip_radio_button_on_toggled (GtkToggleButton *toggle_button,
                              gpointer         user_data)
@@ -251,7 +254,6 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
     GtkWidget *error_label;
     GtkWidget *name_entry;
     GtkWidget *activate_button;
-    GtkWidget *description_stack;
     GtkWidget *zip_radio_button;
     GtkWidget *tar_xz_radio_button;
     GtkWidget *seven_zip_radio_button;
@@ -266,7 +268,6 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
     zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "zip_radio_button"));
     tar_xz_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "tar_xz_radio_button"));
     seven_zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "seven_zip_radio_button"));
-    description_stack = GTK_WIDGET (gtk_builder_get_object (builder, "description_stack"));
 
     gtk_window_set_transient_for (GTK_WINDOW (compress_dialog),
                                   parent_window);
@@ -282,7 +283,6 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
     self->zip_radio_button = zip_radio_button;
     self->tar_xz_radio_button = tar_xz_radio_button;
     self->seven_zip_radio_button = seven_zip_radio_button;
-    self->description_stack = description_stack;
     self->name_entry = name_entry;
 
     self->response_handler_id = g_signal_connect (compress_dialog,
@@ -291,6 +291,8 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
                                                   self);
 
     gtk_builder_add_callback_symbols (builder,
+                                      "on_row_activated",
+                                      G_CALLBACK (on_row_activated),
                                       "zip_radio_button_on_toggled",
                                       G_CALLBACK (zip_radio_button_on_toggled),
                                       "tar_xz_radio_button_on_toggled",
diff --git a/src/resources/ui/nautilus-compress-dialog.ui b/src/resources/ui/nautilus-compress-dialog.ui
index ba7ce4e29..c96a488c5 100644
--- a/src/resources/ui/nautilus-compress-dialog.ui
+++ b/src/resources/ui/nautilus-compress-dialog.ui
@@ -61,48 +61,157 @@
           </packing>
         </child>
         <child>
-          <object class="GtkBox" id="hbox">
-            <property name="orientation">horizontal</property>
-            <property name="homogeneous">True</property>
-            <property name="spacing">0</property>
+          <object class="GtkListBox">
+            <property name="margin-top">12</property>
+            <property name="margin-bottom">12</property>
+            <property name="selection-mode">GTK_SELECTION_NONE</property>
+            <signal name="row-activated" handler="on_row_activated"/>
             <child>
-              <object class="GtkRadioButton" id="zip_radio_button">
-                <property name="label" translatable="no">.zip</property>
-                <property name="draw_indicator">True</property>
-                <signal name="toggled" handler="zip_radio_button_on_toggled"/>
+              <object class="GtkListBoxRow">
+                <child>
+                  <object class="GtkRadioButton" id="zip_radio_button">
+                    <property name="margin-start">12</property>
+                    <property name="margin-end">12</property>
+                    <property name="draw-indicator">True</property>
+                    <signal name="toggled" handler="zip_radio_button_on_toggled"/>
+                    <property name="can-focus">False</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="margin-start">12</property>
+                        <property name="margin-top">6</property>
+                        <property name="margin-bottom">6</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">3</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="label" translatable="no">.zip</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="label" translatable="yes">Compatible with all operating 
systems.</property>
+                            <property name="xalign">0</property>
+                            <style>
+                              <class name="dim-label"/>
+                            </style>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkRadioButton" id="tar_xz_radio_button">
-                <property name="label" translatable="no">.tar.xz</property>
-                <property name="group">zip_radio_button</property>
-                <property name="draw_indicator">True</property>
-                <signal name="toggled" handler="tar_xz_radio_button_on_toggled"/>
+              <object class="GtkListBoxRow">
+                <child>
+                  <object class="GtkRadioButton" id="tar_xz_radio_button">
+                    <property name="margin-start">12</property>
+                    <property name="margin-end">12</property>
+                    <property name="draw-indicator">True</property>
+                    <property name="group">zip_radio_button</property>
+                    <signal name="toggled" handler="tar_xz_radio_button_on_toggled"/>
+                    <property name="can-focus">False</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="margin-start">12</property>
+                        <property name="margin-top">6</property>
+                        <property name="margin-bottom">6</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">3</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="label" translatable="no">.tar.xz</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="label" translatable="yes">Smaller archives but Linux and Mac 
only.</property>
+                            <property name="xalign">0</property>
+                            <style>
+                              <class name="dim-label"/>
+                            </style>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkRadioButton" id="seven_zip_radio_button">
-                <property name="label" translatable="no">.7z</property>
-                <property name="group">zip_radio_button</property>
-                <property name="draw_indicator">True</property>
-                <signal name="toggled" handler="seven_zip_radio_button_on_toggled"/>
+              <object class="GtkListBoxRow">
+                <child>
+                  <object class="GtkRadioButton" id="seven_zip_radio_button">
+                    <property name="margin-start">12</property>
+                    <property name="margin-end">12</property>
+                    <property name="draw-indicator">True</property>
+                    <property name="group">zip_radio_button</property>
+                    <signal name="toggled" handler="seven_zip_radio_button_on_toggled"/>
+                    <property name="can-focus">False</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="margin-start">12</property>
+                        <property name="margin-top">6</property>
+                        <property name="margin-bottom">6</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">3</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="label" translatable="no">.7z</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="label" translatable="yes">Smaller archives but must be installed 
on Windows and Mac.</property>
+                            <property name="xalign">0</property>
+                            <style>
+                              <class name="dim-label"/>
+                            </style>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
             </child>
+            <style>
+              <class name="content"/>
+            </style>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -110,57 +219,6 @@
             <property name="position">4</property>
           </packing>
         </child>
-        <child>
-          <object class="GtkStack" id="description_stack">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="homogeneous">True</property>
-            <child>
-              <object class="GtkLabel" id="zip_description_label">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Compatible with all operating systems.</property>
-                <property name="xalign">0</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-              <packing>
-                <property name="name">zip-description-label</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="tar_xz_description_label">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Smaller archives but Linux and Mac only.</property>
-                <property name="xalign">0</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-              <packing>
-                <property name="name">tar-xz-description-label</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="seven_zip_description_label">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Smaller archives but must be installed on Windows 
and Mac.</property>
-                <property name="xalign">0</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-              <packing>
-                <property name="name">seven-zip-description-label</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">5</property>
-          </packing>
-        </child>
       </object>
     </child>
     <child type="action">


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