[file-roller] delete: Use gtk-dialogs-use-header GtkSetting



commit e07caf4e9ca7f9de80d12d9e9c0a8200bbc9280a
Author: Iain Lane <iain orangesquash org uk>
Date:   Fri Dec 19 18:40:55 2014 +0000

    delete: Use gtk-dialogs-use-header GtkSetting
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741925

 src/dlg-delete.c |  115 ++++++++++++++++++++--------------
 src/ui/delete.ui |  183 ++++++++++++++++++------------------------------------
 2 files changed, 130 insertions(+), 168 deletions(-)
---
diff --git a/src/dlg-delete.c b/src/dlg-delete.c
index 5a5b47a..c5e6d4b 100644
--- a/src/dlg-delete.c
+++ b/src/dlg-delete.c
@@ -39,22 +39,21 @@ typedef struct {
        GtkWidget *d_files_entry;
 } DialogData;
 
-
 /* called when the main dialog is closed. */
 static void
 destroy_cb (GtkWidget  *widget,
-           DialogData *data)
+           DialogData *data)
 {
-       _g_string_list_free (data->selected_files);
-       g_object_unref (G_OBJECT (data->builder));
-       g_free (data);
+       _g_string_list_free (data->selected_files);
+       g_object_unref (G_OBJECT (data->builder));
+       g_free (data);
 }
 
-
-/* called when the "ok" button is pressed. */
+/* called when the dialog is dismissed. */
 static void
-ok_clicked_cb (GtkWidget  *widget,
-              DialogData *data)
+response_cb (GtkWidget  *widget,
+                       int         response_id,
+                       DialogData *data)
 {
        gboolean  selected_files;
        gboolean  pattern_files;
@@ -62,34 +61,37 @@ ok_clicked_cb (GtkWidget  *widget,
        GList    *file_list = NULL;
        gboolean  do_not_remove_if_null = FALSE;
 
-       selected_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->d_selected_files_radio));
-       pattern_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->d_files_radio));
+       switch (response_id) {
+       case GTK_RESPONSE_OK:
+               selected_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON 
(data->d_selected_files_radio));
+               pattern_files = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->d_files_radio));
 
-       /* create the file list. */
+               /* create the file list. */
 
-       if (selected_files) {
-               file_list = data->selected_files;
-               data->selected_files = NULL;       /* do not free the list when destroying the dialog. */
-       }
-       else if (pattern_files) {
-               const char *pattern;
+               if (selected_files) {
+                       file_list = data->selected_files;
+                       data->selected_files = NULL;       /* do not free the list when destroying the 
dialog. */
+               }
+               else if (pattern_files) {
+                       const char *pattern;
 
-               pattern = gtk_entry_get_text (GTK_ENTRY (data->d_files_entry));
-               file_list = fr_window_get_file_list_pattern (window, pattern);
-               if (file_list == NULL)
-                       do_not_remove_if_null = TRUE;
-       }
+                       pattern = gtk_entry_get_text (GTK_ENTRY (data->d_files_entry));
+                       file_list = fr_window_get_file_list_pattern (window, pattern);
+                       if (file_list == NULL)
+                               do_not_remove_if_null = TRUE;
+               }
 
-       /* close the dialog. */
+               /* remove ! */
 
-       gtk_widget_destroy (data->dialog);
-
-       /* remove ! */
+               if (! do_not_remove_if_null || (file_list != NULL))
+                       fr_window_archive_remove (window, file_list);
 
-       if (! do_not_remove_if_null || (file_list != NULL))
-               fr_window_archive_remove (window, file_list);
+               _g_string_list_free (file_list);
+               break;
+       }
 
-       _g_string_list_free (file_list);
+       /* close the dialog. */
+       gtk_widget_destroy (data->dialog);
 }
 
 
@@ -107,8 +109,10 @@ dlg_delete__common (FrWindow *window,
                    GList    *selected_files)
 {
        DialogData *data;
-       GtkWidget  *cancel_button;
+       GtkWidget  *content_area;
+       GtkWidget  *delete_box;
        GtkWidget  *ok_button;
+       gboolean   use_header;
 
        data = g_new (DialogData, 1);
        data->window = window;
@@ -121,15 +125,35 @@ dlg_delete__common (FrWindow *window,
        }
 
        /* Get the widgets. */
+       g_object_get (gtk_settings_get_default (),
+                                 "gtk-dialogs-use-header", &use_header,
+                                 NULL);
+
+       data->dialog = g_object_new (GTK_TYPE_DIALOG,
+                                                  "transient-for", GTK_WINDOW (window),
+                                                  "modal", TRUE,
+                                                  "use-header-bar", use_header,
+                                                  NULL);
+
+       gtk_dialog_add_buttons (GTK_DIALOG (data->dialog),
+                                                       _("_Cancel"), GTK_RESPONSE_CANCEL,
+                                                       _("_Delete"), GTK_RESPONSE_OK,
+                                                       NULL);
+
+       ok_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog),
+                       GTK_RESPONSE_OK);
+       gtk_style_context_add_class (gtk_widget_get_style_context (ok_button),
+                       "destructive-action");
+
+       delete_box = _gtk_builder_get_widget (data->builder, "delete_box");
 
-       data->dialog = _gtk_builder_get_widget (data->builder, "delete_dialog");
        data->d_all_files_radio = _gtk_builder_get_widget (data->builder, "d_all_files_radio");
        data->d_selected_files_radio = _gtk_builder_get_widget (data->builder, "d_selected_files_radio");
        data->d_files_radio = _gtk_builder_get_widget (data->builder, "d_files_radio");
        data->d_files_entry = _gtk_builder_get_widget (data->builder, "d_files_entry");
 
-       ok_button = _gtk_builder_get_widget (data->builder, "d_ok_button");
-       cancel_button = _gtk_builder_get_widget (data->builder, "d_cancel_button");
+       content_area = gtk_dialog_get_content_area (GTK_DIALOG (data->dialog));
+       gtk_container_add (GTK_CONTAINER (content_area), delete_box);
 
        /* Set widgets data. */
 
@@ -146,25 +170,24 @@ dlg_delete__common (FrWindow *window,
                          "destroy",
                          G_CALLBACK (destroy_cb),
                          data);
-       g_signal_connect_swapped (G_OBJECT (cancel_button),
-                                 "clicked",
-                                 G_CALLBACK (gtk_widget_destroy),
-                                 G_OBJECT (data->dialog));
-       g_signal_connect (G_OBJECT (ok_button),
-                         "clicked",
-                         G_CALLBACK (ok_clicked_cb),
+       g_signal_connect (G_OBJECT (data->dialog),
+                         "response",
+                         G_CALLBACK (response_cb),
                          data);
+//     g_signal_connect_swapped (G_OBJECT (cancel_button),
+//                               "clicked",
+//                               G_CALLBACK (gtk_widget_destroy),
+//                               G_OBJECT (data->dialog));
+//     g_signal_connect (G_OBJECT (ok_button),
+//                       "clicked",
+//                       G_CALLBACK (ok_clicked_cb),
+//                       data);
        g_signal_connect (G_OBJECT (data->d_files_entry),
                          "changed",
                          G_CALLBACK (entry_changed_cb),
                          data);
 
        /* Run dialog. */
-
-       gtk_window_set_transient_for (GTK_WINDOW (data->dialog),
-                                     GTK_WINDOW (window));
-       gtk_window_set_modal         (GTK_WINDOW (data->dialog), TRUE);
-
        gtk_widget_show (data->dialog);
 }
 
diff --git a/src/ui/delete.ui b/src/ui/delete.ui
index a392e9e..d8b8207 100644
--- a/src/ui/delete.ui
+++ b/src/ui/delete.ui
@@ -1,160 +1,99 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkDialog" id="delete_dialog">
+  <object class="GtkBox" id="delete_box">
+    <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">Delete</property>
-    <property name="resizable">False</property>
-    <property name="window_position">center-on-parent</property>
-    <property name="type_hint">dialog</property>
-    <property name="use_header_bar">1</property>
-    <child internal-child="headerbar">
-      <object class="GtkHeaderBar" id="dialog-header_bar">
+    <property name="orientation">vertical</property>
+    <property name="spacing">2</property>
+    <child>
+      <object class="GtkTable" id="table2">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="show_close_button">False</property>
+        <property name="border_width">5</property>
+        <property name="n_rows">3</property>
+        <property name="n_columns">2</property>
+        <property name="column_spacing">12</property>
+        <property name="row_spacing">6</property>
         <child>
-          <object class="GtkButton" id="d_cancel_button">
-            <property name="label" translatable="yes">_Cancel</property>
+          <object class="GtkRadioButton" id="d_files_radio">
+            <property name="label" translatable="yes">_Files:</property>
             <property name="use_action_appearance">False</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">False</property>
             <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
-            <property name="valign">center</property>
-            <style>
-              <class name="text-button"/>
-            </style>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
           </object>
           <packing>
-            <property name="pack_type">start</property>
+            <property name="top_attach">2</property>
+            <property name="bottom_attach">3</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
           </packing>
         </child>
         <child>
-          <object class="GtkButton" id="d_ok_button">
-            <property name="label" translatable="yes">_Delete</property>
+          <object class="GtkEntry" id="d_files_entry">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="tooltip_text" translatable="yes">example: *.txt; *.doc</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">2</property>
+            <property name="bottom_attach">3</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkRadioButton" id="d_all_files_radio">
+            <property name="label" translatable="yes">_All files</property>
             <property name="use_action_appearance">False</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="can_default">True</property>
-            <property name="has_default">True</property>
             <property name="receives_default">False</property>
             <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
-            <property name="valign">center</property>
-            <style>
-              <class name="text-button"/>
-              <class name="destructive-action"/>
-            </style>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
+            <property name="group">d_files_radio</property>
           </object>
           <packing>
-            <property name="pack_type">end</property>
+            <property name="right_attach">2</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
           </packing>
         </child>
-      </object>
-    </child>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox14">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
         <child>
-          <object class="GtkTable" id="table2">
+          <object class="GtkRadioButton" id="d_selected_files_radio">
+            <property name="label" translatable="yes">_Selected files</property>
+            <property name="use_action_appearance">False</property>
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="border_width">5</property>
-            <property name="n_rows">3</property>
-            <property name="n_columns">2</property>
-            <property name="column_spacing">12</property>
-            <property name="row_spacing">6</property>
-            <child>
-              <object class="GtkRadioButton" id="d_files_radio">
-                <property name="label" translatable="yes">_Files:</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_underline">True</property>
-                <property name="xalign">0</property>
-                <property name="draw_indicator">True</property>
-              </object>
-              <packing>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options"></property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkEntry" id="d_files_entry">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="tooltip_text" translatable="yes">example: *.txt; *.doc</property>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-                <property name="y_options"></property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="d_all_files_radio">
-                <property name="label" translatable="yes">_All files</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_underline">True</property>
-                <property name="xalign">0</property>
-                <property name="draw_indicator">True</property>
-                <property name="group">d_files_radio</property>
-              </object>
-              <packing>
-                <property name="right_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options"></property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="d_selected_files_radio">
-                <property name="label" translatable="yes">_Selected files</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_underline">True</property>
-                <property name="xalign">0</property>
-                <property name="draw_indicator">True</property>
-                <property name="group">d_files_radio</property>
-              </object>
-              <packing>
-                <property name="right_attach">2</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-                <property name="y_options"></property>
-              </packing>
-            </child>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="use_action_appearance">False</property>
+            <property name="use_underline">True</property>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
+            <property name="group">d_files_radio</property>
           </object>
           <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">1</property>
+            <property name="bottom_attach">2</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
           </packing>
         </child>
       </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
     </child>
-    <action-widgets>
-      <action-widget response="0">d_cancel_button</action-widget>
-      <action-widget response="0">d_ok_button</action-widget>
-    </action-widgets>
   </object>
 </interface>


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