[easytag/wip/application-window: 107/112] Move browse directory dialog to GtkBuilder



commit 431912f777cf88e3edc28b8586e8b9a1ae2fef06
Author: David King <amigadave amigadave com>
Date:   Thu Aug 21 08:36:40 2014 +0100

    Move browse directory dialog to GtkBuilder

 data/browser.ui |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/browser.c   |   77 ++++++++++++++++++++++++++---------------------------
 2 files changed, 116 insertions(+), 39 deletions(-)
---
diff --git a/data/browser.ui b/data/browser.ui
index b1dd913..2922a3d 100644
--- a/data/browser.ui
+++ b/data/browser.ui
@@ -1,5 +1,83 @@
 <interface domain="easytag">
     <requires lib="gtk+" version="3.4"/>
+    <object class="GtkDialog" id="open_directory_dialog">
+        <property name="border-width">12</property>
+        <property name="destroy-with-parent">True</property>
+        <property name="title" translatable="yes">Browse Directory With</property>
+        <child internal-child="vbox">
+            <object class="GtkBox" id="open_directory_vbox">
+                <child>
+                    <object class="GtkGrid" id="open_directory_grid">
+                        <property name="column-spacing">12</property>
+                        <property name="row-spacing">6</property>
+                        <property name="visible">True</property>
+                        <child>
+                            <object class="GtkLabel" id="open_directory_label">
+                                <property name="halign">start</property>
+                                <property name="label" translatable="yes">Run Program</property>
+                                <property name="visible">True</property>
+                                <attributes>
+                                    <attribute name="weight" value="bold"/>
+                                </attributes>
+                            </object>
+                            <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">0</property>
+                                <property name="width">2</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkComboBox" id="open_directory_combo">
+                                <property name="has-entry">True</property>
+                                <property name="entry-text-column">0</property>
+                                <property name="margin-left">12</property>
+                                <property name="tooltip-text" translatable="yes">Enter the program to run. 
It will receive the current directory as parameter</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">1</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkButton" id="open_directory_button">
+                                <property name="label" translatable="yes">_Open</property>
+                                <property name="use-underline">True</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">1</property>
+                                <property name="top-attach">1</property>
+                            </packing>
+                        </child>
+                    </object>
+                </child>
+                <child internal-child="action_area">
+                    <object class="GtkButtonBox" id="open_directory_button_box">
+                        <child>
+                            <object class="GtkButton" id="open_directory_cancel_button">
+                                <property name="label" translatable="yes">_Cancel</property>
+                                <property name="use-underline">True</property>
+                                <property name="visible">True</property>
+                            </object>
+                        </child>
+                        <child>
+                            <object class="GtkButton" id="open_directory_execute_button">
+                                <property name="can-default">True</property>
+                                <property name="label" translatable="yes">_Execute</property>
+                                <property name="use-underline">True</property>
+                                <property name="visible">True</property>
+                            </object>
+                        </child>
+                    </object>
+                </child>
+            </object>
+        </child>
+        <action-widgets>
+            <action-widget response="-5">open_directory_execute_button</action-widget>
+            <action-widget response="-6">open_directory_cancel_button</action-widget>
+        </action-widgets>
+    </object>
     <object class="GtkDialog" id="rename_directory_dialog">
         <property name="border-width">12</property>
         <property name="destroy-with-parent">True</property>
diff --git a/src/browser.c b/src/browser.c
index a25b25b..04c7ca2 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -4746,10 +4746,9 @@ void
 et_browser_show_open_directory_with_dialog (EtBrowser *self)
 {
     EtBrowserPrivate *priv;
-    GtkWidget *VBox;
-    GtkWidget *HBox;
-    GtkWidget *Label;
-    GtkWidget *Button;
+    GtkBuilder *builder;
+    GError *error = NULL;
+    GtkWidget *button;
     gchar *current_directory = NULL;
 
     g_return_if_fail (ET_BROWSER (self));
@@ -4768,67 +4767,67 @@ et_browser_show_open_directory_with_dialog (EtBrowser *self)
     if (!current_directory || strlen(current_directory)==0)
         return;
 
-    priv->open_directory_with_dialog = gtk_dialog_new_with_buttons (_("Browse Directory With"),
-                                                        GTK_WINDOW (MainWindow),
-                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                        _("_Cancel"),
-                                                        GTK_RESPONSE_CANCEL,
-                                                        _("_Execute"),
-                                                        GTK_RESPONSE_OK, NULL);
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_resource (builder,
+                                   "/org/gnome/EasyTAG/browser.ui",
+                                   &error);
 
+    if (error != NULL)
+    {
+        g_error ("Unable to get open directory with dialog from resource: %s",
+                 error->message);
+    }
+
+    priv->open_directory_with_dialog = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                                           "open_directory_dialog"));
+
+    gtk_window_set_transient_for (GTK_WINDOW (priv->open_directory_with_dialog),
+                                  GTK_WINDOW (MainWindow));
     gtk_dialog_set_default_response (GTK_DIALOG (priv->open_directory_with_dialog),
                                      GTK_RESPONSE_OK);
     g_signal_connect (priv->open_directory_with_dialog, "response",
                       G_CALLBACK (et_run_program_tree_on_response), self);
-    VBox = gtk_dialog_get_content_area (GTK_DIALOG (priv->open_directory_with_dialog));
-    gtk_container_set_border_width (GTK_CONTAINER (priv->open_directory_with_dialog),
-                                    BOX_SPACING);
-
-    Label = gtk_label_new(_("Program to run:"));
-    gtk_box_pack_start(GTK_BOX(VBox),Label,TRUE,FALSE,0);
-    gtk_label_set_line_wrap(GTK_LABEL(Label),TRUE);
-
-    HBox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BOX_SPACING);
-    gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,2);
 
     /* The combobox to enter the program to run */
-    priv->open_directory_with_combobox = 
gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(priv->run_program_model));
-    gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(priv->open_directory_with_combobox), MISC_COMBO_TEXT);
-    gtk_box_pack_start(GTK_BOX(HBox),priv->open_directory_with_combobox,TRUE,TRUE,0);
-    gtk_widget_set_size_request(GTK_WIDGET(priv->open_directory_with_combobox),250,-1);
-    
gtk_widget_set_tooltip_text(GTK_WIDGET(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->open_directory_with_combobox)))),_("Enter
 the program to run. "
-        "It will receive the current directory as parameter."));
+    priv->open_directory_with_combobox = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                                             "open_directory_combo"));
+    gtk_combo_box_set_model (GTK_COMBO_BOX (priv->open_directory_with_combobox),
+                             GTK_TREE_MODEL (priv->run_program_model));
 
     /* History list */
-    gtk_list_store_clear(priv->run_program_model);
-    Load_Run_Program_With_Directory_List(priv->run_program_model, MISC_COMBO_TEXT);
+    gtk_list_store_clear (priv->run_program_model);
+    Load_Run_Program_With_Directory_List (priv->run_program_model,
+                                          MISC_COMBO_TEXT);
     g_signal_connect_swapped (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->open_directory_with_combobox))),
                               "activate",
                               G_CALLBACK (Run_Program_With_Directory),
                               self);
 
     /* The button to Browse */
-    Button = gtk_button_new_with_mnemonic (_("_Open"));
-    gtk_box_pack_start(GTK_BOX(HBox),Button,FALSE,FALSE,0);
-    g_signal_connect_swapped(G_OBJECT(Button),"clicked",
-                             
G_CALLBACK(File_Selection_Window_For_File),G_OBJECT(gtk_bin_get_child(GTK_BIN(priv->open_directory_with_combobox))));
+    button = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                 "open_directory_button"));
+    g_signal_connect_swapped (button, "clicked",
+                              G_CALLBACK (File_Selection_Window_For_File),
+                              G_OBJECT (gtk_bin_get_child (GTK_BIN (priv->open_directory_with_combobox))));
 
     /* We attach useful data to the combobox (into Run_Program_With_Directory) */
-    g_object_set_data(G_OBJECT(priv->open_directory_with_combobox), "Current_Directory", current_directory);
+    g_object_set_data (G_OBJECT (priv->open_directory_with_combobox),
+                       "Current_Directory", current_directory);
 
     /* Button to execute */
-    Button = gtk_dialog_get_widget_for_response (GTK_DIALOG (priv->open_directory_with_dialog),
+    button = gtk_dialog_get_widget_for_response (GTK_DIALOG (priv->open_directory_with_dialog),
                                                  GTK_RESPONSE_OK);
-    g_signal_connect_swapped (Button, "clicked",
+    g_signal_connect_swapped (button, "clicked",
                               G_CALLBACK (Run_Program_With_Directory),
                               self);
     g_signal_connect_swapped (gtk_bin_get_child (GTK_BIN (priv->open_directory_with_combobox)),
                               "changed",
                               G_CALLBACK (empty_entry_disable_widget),
-                              G_OBJECT (Button));
-    
g_signal_emit_by_name(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->open_directory_with_combobox)))),"changed",NULL);
+                              G_OBJECT (button));
+    g_signal_emit_by_name (G_OBJECT (GTK_ENTRY (gtk_bin_get_child (GTK_BIN 
(priv->open_directory_with_combobox)))),
+                           "changed", NULL);
 
-    gtk_widget_show_all(priv->open_directory_with_dialog);
+    gtk_widget_show_all (priv->open_directory_with_dialog);
 }
 
 static void


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