gtr-file-dialogs.c 3.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*
 * Copyright (C) 2007  Ignacio Casal Quinteiro <nacho.resa@gmail.com>
 * 
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include "gtr-file-dialogs.h"
#include "gtr-tab.h"
#include "gtr-po.h"
#include "gtr-window.h"

/*
 * File chooser dialog
 */
GtkWidget *
gtr_file_chooser_new (GtkWindow * parent,
                      FileselMode mode,
                      const gchar * title, const gchar * dir)
{
  GtkWidget *dialog;
  GtkFileFilter *filter;

  dialog = gtk_file_chooser_dialog_new (title,
                                        parent,
                                        (mode ==
                                         FILESEL_SAVE) ?
                                        GTK_FILE_CHOOSER_ACTION_SAVE :
                                        GTK_FILE_CHOOSER_ACTION_OPEN,
45
                                        _("_Cancel"), GTK_RESPONSE_CANCEL,
46
                                        (mode ==
47 48
                                         FILESEL_SAVE) ? _("_Save") :
                                        _("_Open"), GTK_RESPONSE_ACCEPT,
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
                                        NULL);
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

  if (dir)
    gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), dir);

  if (mode != FILESEL_SAVE)
    {
      /* We set a multi selection dialog */
      gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);

      /* Now we set the filters */
      filter = gtk_file_filter_new ();
      gtk_file_filter_set_name (filter, _("Gettext translation"));
#ifndef G_OS_WIN32
      gtk_file_filter_add_mime_type (filter, "text/x-gettext-translation");
#else
      gtk_file_filter_add_pattern (filter, "*.po");
#endif
      gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);

      filter = gtk_file_filter_new ();
      gtk_file_filter_set_name (filter, _("Gettext translation template"));
      gtk_file_filter_add_pattern (filter, "*.pot");
      gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);

      filter = gtk_file_filter_new ();
      gtk_file_filter_set_name (filter, _("All files"));
      gtk_file_filter_add_pattern (filter, "*");
      gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
    }

  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));

  return dialog;
}