[ghex] prefs: Port to AdwPreferencesWindow



commit ee30d13b6ec9419cffee7ae2cf737773c2a681df
Author: Logan Rathbone <poprocks gmail com>
Date:   Tue Jun 21 21:17:26 2022 -0400

    prefs: Port to AdwPreferencesWindow

 src/preferences.c  |  61 +---------
 src/preferences.ui | 351 +++++++++++++++++++++--------------------------------
 2 files changed, 139 insertions(+), 273 deletions(-)
---
diff --git a/src/preferences.c b/src/preferences.c
index 7e4a4ef..f314eab 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -79,56 +79,12 @@ static GtkWidget *long_chkbtn;
 static GtkWidget *quad_chkbtn;
 static GtkWidget *shaded_box_chkbtn;
 static GtkWidget *shaded_box_spinbtn;
-static GtkWidget *shaded_box_box;
+static GtkWidget *shaded_box_row;
 static GtkWidget *dark_mode_switch;
 static GtkWidget *system_default_chkbtn;
-static GtkWidget *close_button;
-static GtkWidget *help_button;
 
 /* PRIVATE FUNCTIONS */
 
-static void
-do_css_stuff(void)
-{
-       GtkCssProvider *box_provider, *frame_provider;
-
-       /* Grab layout-oriented widgets and set CSS styling. */
-       GET_WIDGET (content_area_box);
-       GET_WIDGET (font_frame);
-       GET_WIDGET (group_type_frame);
-       GET_WIDGET (print_font_frame);
-       
-       /* overall padding for content area: */
-       box_provider = gtk_css_provider_new ();
-       gtk_css_provider_load_from_data (box_provider,
-                                                                               "* {\n"
-                                                                               "  padding-left: 24px;\n"
-                                                                               "  padding-right: 24px;\n"
-                                                                               "}\n", -1);
-
-       APPLY_PROVIDER_TO (box_provider, content_area_box);
-
-       /* padding for our frames (they look god-awful without a bit) */
-       frame_provider = gtk_css_provider_new ();
-       gtk_css_provider_load_from_data (frame_provider,
-                                                                               "* {\n"
-                                                                               "  padding: 12px;\n"
-                                                                               "}\n",  -1);
-
-       APPLY_PROVIDER_TO (frame_provider, font_frame);
-       APPLY_PROVIDER_TO (frame_provider, group_type_frame);
-       APPLY_PROVIDER_TO (frame_provider, print_font_frame);
-}
-
-static void
-help_clicked_cb (GtkButton *button,
-               gpointer user_data)
-{
-       g_return_if_fail (GTK_IS_WINDOW (prefs_dialog));
-
-       common_help_cb (GTK_WINDOW(prefs_dialog));
-}
-
 /* wee helper */
 static void
 sync_shaded_box_size_with_spinbtn (void)
@@ -159,7 +115,7 @@ shaded_box_chkbtn_toggled_cb (GtkCheckButton *checkbutton,
 
        checked = gtk_check_button_get_active (checkbutton);
 
-       gtk_widget_set_sensitive (shaded_box_box,
+       gtk_widget_set_sensitive (shaded_box_row,
                        checked ? TRUE : FALSE);
 
        if (checked) {
@@ -360,14 +316,6 @@ setup_signals (void)
 
        g_signal_connect (shaded_box_spinbtn, "value-changed",
                        G_CALLBACK(shaded_box_spinbtn_value_changed_cb), NULL);
-
-       /* close and help */
-
-       g_signal_connect_swapped (close_button, "clicked",
-                       G_CALLBACK(gtk_window_destroy), prefs_dialog);
-
-       g_signal_connect (help_button, "clicked",
-                       G_CALLBACK(help_clicked_cb), NULL);
 }
 
 static void
@@ -466,11 +414,9 @@ init_widgets (void)
        GET_WIDGET (quad_chkbtn);
        GET_WIDGET (shaded_box_chkbtn);
        GET_WIDGET (shaded_box_spinbtn);
-       GET_WIDGET (shaded_box_box);
+       GET_WIDGET (shaded_box_row);
        GET_WIDGET (dark_mode_switch);
        GET_WIDGET (system_default_chkbtn);
-       GET_WIDGET (close_button);
-       GET_WIDGET (help_button);
 
        /* Make certain font choosers only allow monospace fonts. */
        monospace_only (font_button);
@@ -494,7 +440,6 @@ create_preferences_dialog (GtkWindow *parent)
 {
        builder = gtk_builder_new_from_resource (PREFS_RESOURCE);
 
-       do_css_stuff ();
        init_widgets ();
        grab_widget_values_from_settings ();
        setup_signals ();
diff --git a/src/preferences.ui b/src/preferences.ui
index 48359e0..f36c1be 100644
--- a/src/preferences.ui
+++ b/src/preferences.ui
@@ -24,248 +24,169 @@
 -->
 
 <interface>
-
-       <object class="GtkDialog" id="prefs_dialog"> <!-- prefs_dialog -->
+       <object class="AdwPreferencesWindow" id="prefs_dialog">
                <property name="title" translatable="yes">Preferences</property>
-               <property name="default-width">400</property>
-               <property name="default-height">400</property>
-
-               <child internal-child="content_area"> <!-- box -->
-                       <object class="GtkBox" id="content_area_box">
-                               <property name="orientation">vertical</property>
 
-                               <child> <!-- stackswitcher -->
-                                       <object class="GtkStackSwitcher">
-                                               <property name="stack">stack</property>
-                                               <property name="halign">center</property>
-                                       </object>
-                               </child> <!-- /stackswitcher -->
+               <child>
+                       <object class="AdwPreferencesPage">
+                               <property name="name">page1</property>
+                               <property name="title" translatable="yes">Display</property>
+                               <property name="icon-name">preferences-desktop-display-symbolic</property>
+                               <child>
+                                       <object class="AdwPreferencesGroup">
+                                               <property name="title" 
translatable="yes">Appearance</property>
+
+                                               <child>
+                                                       <object class="AdwActionRow">
+                                                               <property name="title" 
translatable="yes">Font</property>
+                                                               <child>
+                                                                       <object class="GtkFontButton" 
id="font_button">
+                                                                               <property 
name="halign">start</property>
+                                                                       </object>
+                                                               </child>
+                                                       </object>
+                                               </child>
 
-                               <child> <!-- stack -->
-                                       <object class="GtkStack" id="stack">
-                                               <property name="transition-type">crossfade</property>
-                                               <property name="vexpand">true</property>
+                                               <child>
+                                                       <object class="AdwActionRow">
+                                                               <property name="title" 
translatable="yes">Dark mode</property>
 
-                                               <child> <!-- stackPage1 -->
-                                                       <object class="GtkStackPage">
-                                                               <property name="name">page1</property>
-                                                               <property name="title" 
translatable="yes">Display</property>
-                                                               <property name="child"> <!-- page1 child -->
-                                                                       <object class="GtkBox"> <!-- box -->
-                                                                               <property 
name="orientation">vertical</property>
+                                                               <child> <!-- dark mode hbox -->
+                                                                       <object class="GtkBox">
+                                                                               <property 
name="orientation">horizontal</property>
                                                                                <property 
name="spacing">18</property>
 
-                                                                               <child> <!-- font_frame -->
-                                                                                       <object 
class="GtkFrame" id="font_frame">
-
-                                                                                               <child 
type="label">
-                                                                                                       
<object class="GtkLabel" id="font_frame_label">
-                                                                                                             
  <property name="label" translatable="yes">Font</property>
-                                                                                                       
</object>
-                                                                                               </child>
-
-                                                                                               <child>
-                                                                                                       
<object class="GtkFontButton" id="font_button">
-                                                                                                             
  <property name="halign">start</property>
-                                                                                                       
</object>
-                                                                                               </child>
+                                                                               <child>
+                                                                                       <object 
class="GtkSwitch" id="dark_mode_switch">
+                                                                                               <property 
name="active">false</property>
+                                                                                               <property 
name="valign">center</property>
+                                                                                       </object>
+                                                                               </child>
 
+                                                                               <child>
+                                                                                       <object 
class="GtkCheckButton" id="system_default_chkbtn">
+                                                                                               <property 
name="label" translatable="yes">Use system default</property>
                                                                                        </object>
-                                                                               </child> <!-- /font_frame -->
+                                                                               </child>
 
-                                                                               <child> <!-- dark mode hbox 
-->
-                                                                                       <object 
class="GtkBox">
-                                                                                               <property 
name="orientation">horizontal</property>
-                                                                                               <property 
name="spacing">18</property>
+                                                                       </object> <!-- /dark mode hbox -->
+                                                               </child>
+                                                       </object> <!-- /action row -->
+                                               </child>
 
-                                                                                               <child>
-                                                                                                       
<object class="GtkLabel" id="dark_mode_label">
-                                                                                                             
  <property name="label" translatable="yes">Dark Mode</property>
-                                                                                                       
</object>
-                                                                                               </child>
-                                                                                               <child>
-                                                                                                       
<object class="GtkSwitch" id="dark_mode_switch">
-                                                                                                             
  <property name="active">false</property>
-                                                                                                       
</object>
-                                                                                               </child>
-                                                                                               <child>
-                                                                                                       
<object class="GtkCheckButton" id="system_default_chkbtn">
-                                                                                                             
  <property name="label" translatable="yes">Use system default</property>
-                                                                                                       
</object>
-                                                                                               </child>
+                                       </object> <!-- /prefsGroup -->
+                               </child>
 
-                                                                                       </object>
-                                                                               </child> <!-- /dark mode hbox 
-->
+                               <child>
+                                       <object class="AdwPreferencesGroup">
+                                               <property name="title" translatable="yes">Hex 
Display</property>
 
-                                                                               <child> <!-- group_type_frame 
-->
-                                                                                       <object 
class="GtkFrame" id="group_type_frame">
-                                                                                               <property 
name="label" translatable="yes">Hex Group Type</property>
-                                                                                               <child>
-                                                                                                       
<object class="GtkBox">
-                                                                                                             
  <property name="orientation">vertical</property>
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkCheckButton" id="bytes_chkbtn">
-                                                                                                             
                  <property name="label" translatable="yes">Bytes (8-bit)</property>
-                                                                                                             
                          <!-- note: don't put group="bytes_checkbtn" here. -->
-                                                                                                             
          </object>
-                                                                                                             
  </child>
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkCheckButton" id="words_chkbtn">
-                                                                                                             
                  <property name="label" translatable="yes">Words (16-bit)</property>
-                                                                                                             
                  <property name="group">bytes_chkbtn</property>
-                                                                                                             
          </object>
-                                                                                                             
  </child>
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkCheckButton" id="long_chkbtn">
-                                                                                                             
                  <property name="label" translatable="yes">Longwords (32-bit)</property>
-                                                                                                             
                  <property name="group">bytes_chkbtn</property>
-                                                                                                             
          </object>
-                                                                                                             
  </child>
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkCheckButton" id="quad_chkbtn">
-                                                                                                             
                  <property name="label" translatable="yes">Quadwords (64-bit)</property>
-                                                                                                             
                  <property name="group">bytes_chkbtn</property>
-                                                                                                             
          </object>
-                                                                                                             
  </child>
-                                                                                                       
</object>
-                                                                                               </child>
+                                               <child>
+                                                       <object class="AdwExpanderRow">
+                                                               <property name="title" 
translatable="yes">Group data as</property>
 
+                                                               <child>
+                                                                       <object class="GtkBox">
+                                                                               <property 
name="orientation">vertical</property>
+                                                                               <child>
+                                                                                       <object 
class="GtkCheckButton" id="bytes_chkbtn">
+                                                                                               <property 
name="label" translatable="yes">Bytes (8-bit)</property>
+                                                                                               <!-- note: 
don't put group="bytes_checkbtn" here. -->
                                                                                        </object>
-                                                                               </child> <!-- 
/group_type_frame -->
-
-                                                                               <child> <!-- 
show_offsets_chkbtn -->
-                                                                                       <object 
class="GtkCheckButton" id="show_offsets_chkbtn">
-                                                                                               <property 
name="label" translatable="yes">Show offsets column</property>
+                                                                               </child>
+                                                                               <child>
+                                                                                       <object 
class="GtkCheckButton" id="words_chkbtn">
+                                                                                               <property 
name="label" translatable="yes">Words (16-bit)</property>
+                                                                                               <property 
name="group">bytes_chkbtn</property>
+                                                                                       </object>
+                                                                               </child>
+                                                                               <child>
+                                                                                       <object 
class="GtkCheckButton" id="long_chkbtn">
+                                                                                               <property 
name="label" translatable="yes">Longwords (32-bit)</property>
+                                                                                               <property 
name="group">bytes_chkbtn</property>
+                                                                                       </object>
+                                                                               </child>
+                                                                               <child>
+                                                                                       <object 
class="GtkCheckButton" id="quad_chkbtn">
+                                                                                               <property 
name="label" translatable="yes">Quadwords (64-bit)</property>
+                                                                                               <property 
name="group">bytes_chkbtn</property>
                                                                                        </object>
-                                                                               </child> <!-- 
/show_offsets_chkbtn -->
+                                                                               </child>
                                                                        </object> <!-- /box -->
-                                                               </property>     <!-- /page1 child -->
-                                                       </object>
-                                               </child> <!-- /stackPage1 -->
-
-                                               <child> <!-- stackPage2 -->
-                                                       <object class="GtkStackPage">
-                                                               <property name="name">page2</property>
-                                                               <property name="title" 
translatable="yes">Printing</property>
-                                                               <property name="child"> <!-- page2 child -->
-                                                                       <object class="GtkBox"> <!-- vbox -->
-                                                                               <property 
name="orientation">vertical</property>
-                                                                               <property 
name="spacing">18</property>
+                                                               </child>
+                                                       </object> <!-- /row -->
+                                               </child>
+                                               <child>
+                                                       <object class="AdwActionRow">
+                                                               <property name="title" 
translatable="yes">Show offsets column</property>
+                                                               <child>
+                                                                       <object class="GtkCheckButton" 
id="show_offsets_chkbtn" />
+                                                               </child>
+                                                       </object> <!-- /row -->
+                                               </child>
+
+                                       </object> <!-- /group -->
+                               </child>
+                       </object> <!-- /page1 -->
+               </child>
 
-                                                                               <child> <!-- print_font_frame 
-->
-                                                                                       <object 
class="GtkFrame" id="print_font_frame">
-                                                                                               <child 
type="label">
-                                                                                                       
<object class="GtkLabel" id="print_font_frame_label">
-                                                                                                             
  <property name="label" translatable="yes">Fonts</property>
-                                                                                                       
</object>
-                                                                                               </child>
+               <child>
+                       <object class="AdwPreferencesPage">
+                               <property name="name">page2</property>
+                               <property name="title" translatable="yes">Printing</property>
+                               <property name="icon-name">document-print-symbolic</property>
+                               <child>
+                                       <object class="AdwPreferencesGroup">
+                                               <property name="title" translatable="yes">Fonts</property>
+
+                                               <child>
+                                                       <object class="AdwActionRow">
+                                                               <property name="title" 
translatable="yes">Data font</property>
+                                                               <child>
+                                                                       <object class="GtkFontButton" 
id="data_font_button" />
+                                                               </child>
+                                                       </object>
+                                               </child>
+
+                                               <child>
+                                                       <object class="AdwActionRow">
+                                                               <property name="title" 
translatable="yes">Header font</property>
+                                                               <child>
+                                                                       <object class="GtkFontButton" 
id="header_font_button" />
+                                                               </child>
+                                                       </object>
+                                               </child>
 
-                                                                                               <child> <!-- 
print font grid -->
-                                                                                                       
<object class="GtkGrid">
-                                                                                                             
  <property name="margin-top">12</property>
-                                                                                                             
  <property name="margin-bottom">12</property>
-                                                                                                             
  <property name="row-spacing">12</property>
-                                                                                                             
  <property name="column-spacing">18</property>
+                                       </object> <!-- /group -->
+                               </child>
 
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkLabel">
-                                                                                                             
                  <property name="label" translatable="yes">Data font:</property>
-                                                                                                             
                  <property name="halign">start</property>
-                                                                                                             
                  <layout>
-                                                                                                             
                          <property name="row">0</property>
-                                                                                                             
                          <property name="column">0</property>
-                                                                                                             
                  </layout>
-                                                                                                             
          </object>
-                                                                                                             
  </child>
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkLabel">
-                                                                                                             
                  <property name="label" translatable="yes">Header font:</property>
-                                                                                                             
                  <property name="halign">start</property>
-                                                                                                             
                  <layout>
-                                                                                                             
                          <property name="row">1</property>
-                                                                                                             
                          <property name="column">0</property>
-                                                                                                             
                  </layout>
-                                                                                                             
          </object>
-                                                                                                             
  </child>
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkFontButton" id="data_font_button">
-                                                                                                             
                  <property name="halign">start</property>
-                                                                                                             
                  <layout>
-                                                                                                             
                          <property name="row">0</property>
-                                                                                                             
                          <property name="column">1</property>
-                                                                                                             
                  </layout>
-                                                                                                             
          </object>
-                                                                                                             
  </child>
-                                                                                                             
  <child>
-                                                                                                             
          <object class="GtkFontButton" id="header_font_button">
-                                                                                                             
                  <property name="halign">start</property>
-                                                                                                             
                  <layout>
-                                                                                                             
                          <property name="row">1</property>
-                                                                                                             
                          <property name="column">1</property>
-                                                                                                             
                  </layout>
-                                                                                                             
          </object>
-                                                                                                             
  </child>
+                               <child>
+                                       <object class="AdwPreferencesGroup">
+                                               <property name="title" translatable="yes">Shaded 
rows</property>
 
-                                                                                                       
</object>
-                                                                                               </child> <!-- 
/print font grid -->
+                                               <child>
+                                                       <object class="AdwExpanderRow">
+                                                               <property name="title" 
translatable="yes">Print alternating shaded rows</property>
 
-                                                                                       </object>
-                                                                               </child> <!-- 
/print_font_frame -->
+                                                               <child type="action">
+                                                                       <object class="GtkCheckButton" 
id="shaded_box_chkbtn" />
+                                                               </child>
 
+                                                               <child>
+                                                                       <object class="AdwActionRow" 
id="shaded_box_row">
+                                                                               <property name="title" 
translatable="yes">Span across lines:</property>
                                                                                <child>
-                                                                                       <object 
class="GtkBox"> <!-- print shaded check hbox -->
-                                                                                               <property 
name="orientation">horizontal</property>
-                                                                                               <property 
name="spacing">12</property>
-                                                                                               <child>
-                                                                                                       
<object class="GtkCheckButton" id="shaded_box_chkbtn">
-                                                                                                             
  <property name="label" translatable="yes">Print alternating shaded rows</property>
-                                                                                                       
</object>
-                                                                                               </child>
-                                                                                       </object> <!-- /print 
shaded hbox -->
+                                                                                       <object 
class="GtkSpinButton" id="shaded_box_spinbtn" />
                                                                                </child>
+                                                                       </object>
+                                                               </child>
 
-                                                                               <child>
-                                                                                       <object 
class="GtkBox" id="shaded_box_box"> <!-- shaded_box hbox -->
-                                                                                               <property 
name="orientation">horizontal</property>
-                                                                                               <property 
name="spacing">12</property>
-                                                                                               <child>
-                                                                                                       
<object class="GtkLabel" id="shaded_box_label">
-                                                                                                             
  <property name="label" translatable="yes">Span across lines:</property>
-                                                                                                       
</object>
-                                                                                               </child>
-                                                                                               <child>
-                                                                                                       
<object class="GtkSpinButton" id="shaded_box_spinbtn" />
-                                                                                               </child>
-                                                                                       </object> <!-- 
/shaded_box hbox -->
-                                                                               </child>
+                                                       </object> <!-- /expanderRow -->
+                                               </child>
 
-                                                                       </object> <!-- /vbox -->
-                                                               </property> <!-- /page2 child -->
-                                                       </object>
-                                               </child> <!-- /stackPage2 -->
                                        </object>
-                               </child> <!-- /stack -->
-
-                       </object>
-               </child> <!-- /box -->
-
-               <child type="action">
-                       <object class="GtkButton" id="help_button">
-                               <property name="use-underline">true</property>
-                               <property name="label" translatable="yes">_Help</property>
+                               </child> <!-- /group-->
                        </object>
-               </child>
-               <child type="action">
-                       <object class="GtkButton" id="close_button">
-                               <property name="use-underline">true</property>
-                               <property name="label" translatable="yes">_Close</property>
-                       </object>
-               </child>
-
-               <action-widgets>
-                       <action-widget response="help">help_button</action-widget>
-                       <action-widget response="close" default="true">close_button</action-widget>
-               </action-widgets>
+               </child> <!-- /page2 -->
        </object> <!-- /prefs_dialog -->
-
 </interface>


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