[easytag] Move file selection dialogs to application window



commit 6456cdfc6bad7e48670bb380cdb42c905d48a4ed
Author: David King <amigadave amigadave com>
Date:   Thu Nov 20 23:36:03 2014 +0000

    Move file selection dialogs to application window

 src/browser.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/misc.c    |   83 ---------------------------------------------------------
 src/misc.h    |    3 --
 3 files changed, 70 insertions(+), 86 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 4d61776..b7b4f7e 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -3747,6 +3747,76 @@ on_sort_mode_changed (EtBrowser *self, gchar *key, GSettings *settings)
 }
 
 /*
+ * Open the file selection window and saves the selected file path into entry
+ */
+static void
+open_file_selection_dialog (GtkWidget *entry,
+                            const gchar *title,
+                            GtkFileChooserAction action)
+{
+    const gchar *tmp;
+    gchar *filename, *filename_utf8;
+    GtkWidget *dialog;
+    GtkWindow *parent_window = NULL;
+    gint response;
+
+    parent_window = (GtkWindow*) gtk_widget_get_toplevel (entry);
+    if (!gtk_widget_is_toplevel (GTK_WIDGET (parent_window)))
+    {
+        g_warning ("%s", "Could not get parent window");
+        return;
+    }
+
+    dialog = gtk_file_chooser_dialog_new (title, parent_window, action,
+                                          _("_Cancel"), GTK_RESPONSE_CANCEL,
+                                          _("_Open"), GTK_RESPONSE_ACCEPT,
+                                          NULL);
+
+    /* Set initial directory. */
+    tmp = gtk_entry_get_text (GTK_ENTRY (entry));
+
+    if (tmp && *tmp)
+    {
+        if (!gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), tmp))
+        {
+            gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+                                                 tmp);
+        }
+    }
+
+    response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+    if (response == GTK_RESPONSE_ACCEPT)
+    {
+        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+        filename_utf8 = filename_to_display (filename);
+        gtk_entry_set_text (GTK_ENTRY (entry), filename_utf8);
+        g_free (filename);
+        g_free (filename_utf8);
+        /* Useful for the button on the main window. */
+        gtk_widget_grab_focus (GTK_WIDGET (entry));
+        g_signal_emit_by_name (entry, "activate");
+    }
+
+    gtk_widget_destroy (dialog);
+}
+
+/* File selection window */
+static void
+File_Selection_Window_For_File (GtkWidget *entry)
+{
+    open_file_selection_dialog (entry, _("Select File"),
+                                GTK_FILE_CHOOSER_ACTION_OPEN);
+}
+
+static void
+File_Selection_Window_For_Directory (GtkWidget *entry)
+{
+    open_file_selection_dialog (entry, _("Select Directory"),
+                                GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+}
+
+/*
  * Create item of the browser (Entry + Tree + List).
  */
 static void
diff --git a/src/misc.c b/src/misc.c
index b35d511..8e13b20 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -32,7 +32,6 @@
 #include "browser.h"
 #include "setting.h"
 #include "preferences_dialog.h"
-#include "charset.h"
 
 #ifdef G_OS_WIN32
 #include <windows.h>
@@ -46,23 +45,6 @@ static const guint BOX_SPACING = 6;
 
 static GdkCursor *MouseCursor;
 
-/**************
- * Prototypes *
- **************/
-/* Browser */
-static void Open_File_Selection_Window (GtkWidget *entry, gchar *title, GtkFileChooserAction action);
-void        File_Selection_Window_For_File      (GtkWidget *entry);
-void        File_Selection_Window_For_Directory (GtkWidget *entry);
-
-
-/*************
- * Functions *
- *************/
-
-/******************************
- * Functions managing pixmaps *
- ******************************/
-
 /*
  * Add the 'string' passed in parameter to the list store
  * If this string already exists in the list store, it doesn't add it.
@@ -342,71 +324,6 @@ et_run_program (const gchar *program_name,
     return res;
 }
 
-/*************************
- * File selection window *
- *************************/
-void File_Selection_Window_For_File (GtkWidget *entry)
-{
-    Open_File_Selection_Window (entry, _("Select File"),
-                                GTK_FILE_CHOOSER_ACTION_OPEN);
-}
-
-void File_Selection_Window_For_Directory (GtkWidget *entry)
-{
-    Open_File_Selection_Window (entry, _("Select Directory"),
-                                GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
-}
-
-/*
- * Open the file selection window and saves the selected file path into entry
- */
-static void Open_File_Selection_Window (GtkWidget *entry, gchar *title, GtkFileChooserAction action)
-{
-    const gchar *tmp;
-    gchar *filename, *filename_utf8;
-    GtkWidget *FileSelectionWindow;
-    GtkWindow *parent_window = NULL;
-    gint response;
-
-    parent_window = (GtkWindow*) gtk_widget_get_toplevel(entry);
-    if (!gtk_widget_is_toplevel(GTK_WIDGET(parent_window)))
-    {
-        g_warning("Could not get parent window\n");
-        return;
-    }
-
-    FileSelectionWindow = gtk_file_chooser_dialog_new (title, parent_window,
-                                                       action,
-                                                       _("_Cancel"),
-                                                       GTK_RESPONSE_CANCEL,
-                                                       _("_Open"),
-                                                       GTK_RESPONSE_ACCEPT,
-                                                       NULL);
-
-    /* Set initial directory. */
-    tmp = gtk_entry_get_text(GTK_ENTRY(entry));
-    if (tmp && *tmp)
-    {
-        if (!gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(FileSelectionWindow),tmp))
-            gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow),tmp);
-    }
-
-    response = gtk_dialog_run(GTK_DIALOG(FileSelectionWindow));
-    if (response == GTK_RESPONSE_ACCEPT)
-    {
-        filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(FileSelectionWindow));
-        filename_utf8 = filename_to_display(filename);
-        gtk_entry_set_text(GTK_ENTRY(entry),filename_utf8);
-        g_free (filename);
-        g_free(filename_utf8);
-        /* Useful for the button on the main window. */
-        gtk_widget_grab_focus (GTK_WIDGET (entry));
-       g_signal_emit_by_name (entry, "activate");
-    }
-       
-    gtk_widget_destroy(FileSelectionWindow);
-}
-
 gboolean
 et_run_audio_player (GList *files,
                      GError **error)
diff --git a/src/misc.h b/src/misc.h
index 2291a38..60f64b0 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -51,9 +51,6 @@ gint Combo_Alphabetic_Sort (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
 gboolean et_run_audio_player (GList *files, GError **error);
 gboolean et_run_program (const gchar *program_name, GList *args_list, GError **error);
 
-void File_Selection_Window_For_File      (GtkWidget *entry);
-void File_Selection_Window_For_Directory (GtkWidget *entry);
-
 gchar * et_disc_number_to_string (const guint disc_number);
 gchar * et_track_number_to_string (const guint track_number);
 


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