comic-open-dialog divided in various functions
authorDario Villar <dario.villar.v@gmail.com>
Tue, 31 Aug 2010 16:58:38 +0000 (18:58 +0200)
committerdanigm <dani@danigm.net>
Tue, 31 Aug 2010 16:58:38 +0000 (18:58 +0200)
src/comic-open-dialog.c

index f5a778b..c88e0e1 100644 (file)
 #include "tbo-window.h"
 #include "comic.h"
 
+
+static GtkFileFilter * AddFilters (GtkWidget *filechooser);
+static GtkWidget * FileChooserWidget (TboWindow *window);
+
+
 gboolean
 tbo_comic_open_dialog (GtkWidget *widget, TboWindow *window)
 {
@@ -34,6 +39,30 @@ tbo_comic_open_dialog (GtkWidget *widget, TboWindow *window)
     char *filename;
     char buffer[255];
 
+    filechooser = FileChooserWidget (window);
+    filter = AddFilters (filechooser);
+
+    response = gtk_dialog_run (GTK_DIALOG (filechooser));
+
+    if (response == GTK_RESPONSE_ACCEPT)
+    {
+        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
+        tbo_comic_open (window, filename);
+        tbo_window_set_path (window, filename);
+        tbo_drawing_update (TBO_DRAWING (window->drawing));
+        tbo_window_update_status (window, 0, 0);
+    }
+
+    gtk_widget_destroy ((GtkWidget *) filechooser);
+
+    return FALSE;
+}
+
+//Return the widget to choose file
+static GtkWidget *
+FileChooserWidget (TboWindow *window)
+{
+    GtkWidget *filechooser;
     filechooser = gtk_file_chooser_dialog_new (_("Open"),
                                                GTK_WINDOW (window->window),
                                                GTK_FILE_CHOOSER_ACTION_OPEN,
@@ -42,7 +71,14 @@ tbo_comic_open_dialog (GtkWidget *widget, TboWindow *window)
                                                GTK_STOCK_OPEN,
                                                GTK_RESPONSE_ACCEPT,
                                                NULL);
+    return filechooser;
+}
 
+//Return the files' filters
+static GtkFileFilter *
+AddFilters (GtkWidget *filechooser)
+{
+    GtkFileFilter *filter;
     filter = gtk_file_filter_new ();
     gtk_file_filter_set_name (filter, _("TBO files"));
     gtk_file_filter_add_pattern (filter, "*.tbo");
@@ -51,19 +87,5 @@ tbo_comic_open_dialog (GtkWidget *widget, TboWindow *window)
     gtk_file_filter_set_name (filter, _("All files"));
     gtk_file_filter_add_pattern (filter, "*");
     gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (filechooser), filter);
-
-    response = gtk_dialog_run (GTK_DIALOG (filechooser));
-
-    if (response == GTK_RESPONSE_ACCEPT)
-    {
-        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
-        tbo_comic_open (window, filename);
-        tbo_window_set_path (window, filename);
-        tbo_drawing_update (TBO_DRAWING (window->drawing));
-        tbo_window_update_status (window, 0, 0);
-    }
-
-    gtk_widget_destroy ((GtkWidget *) filechooser);
-
-    return FALSE;
+    return filter;
 }