GFile * gtkhtml_editor_run_open_dialog (GtkhtmlEditor *editor, const gchar *title, GtkCallback customize_func, gpointer customize_data) { GtkFileChooser *file_chooser; GFile *chosen_file = NULL; GtkWidget *dialog; gchar *uri; g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), NULL); dialog = gtk_file_chooser_dialog_new ( title, GTK_WINDOW (editor), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); file_chooser = GTK_FILE_CHOOSER (dialog); gtk_dialog_set_default_response ( GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); gtk_file_chooser_set_local_only (file_chooser, FALSE); /* Restore the current folder from the previous file chooser. */ uri = (gchar *) gtkhtml_editor_get_current_folder (editor); if (uri != NULL) gtk_file_chooser_set_current_folder_uri (file_chooser, uri); /* Allow further customizations before running the dialog. */ if (customize_func != NULL) customize_func (dialog, customize_data); if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT) goto exit; chosen_file = gtk_file_chooser_get_file (file_chooser); /* Save the current folder for subsequent file choosers. */ uri = gtk_file_chooser_get_current_folder_uri (file_chooser); gtkhtml_editor_set_current_folder (editor, uri); g_free (uri); exit: gtk_widget_destroy (dialog); return chosen_file; }
/** * e_shell_run_open_dialog: * @shell: an #EShell * @title: file chooser dialog title * @customize_func: optional dialog customization function * @customize_data: optional data to pass to @customize_func * * Runs a #GtkFileChooserDialog in open mode with the given title and * returns the selected #GFile. If @customize_func is provided, the * function is called just prior to running the dialog (the file chooser * is the first argument, @customize data is the second). If the user * cancels the dialog the function will return %NULL. * * Returns: the #GFile to open, or %NULL **/ GFile * e_shell_run_open_dialog (EShell *shell, const gchar *title, GtkCallback customize_func, gpointer customize_data) { GtkFileChooser *file_chooser; GFile *chosen_file = NULL; GtkWidget *dialog; GtkWindow *parent; g_return_val_if_fail (E_IS_SHELL (shell), NULL); parent = e_shell_get_active_window (shell); dialog = gtk_file_chooser_dialog_new ( title, parent, GTK_FILE_CHOOSER_ACTION_OPEN, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Open"), GTK_RESPONSE_ACCEPT, NULL); file_chooser = GTK_FILE_CHOOSER (dialog); gtk_dialog_set_default_response ( GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); gtk_file_chooser_set_local_only (file_chooser, FALSE); /* Allow further customizations before running the dialog. */ if (customize_func != NULL) customize_func (dialog, customize_data); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) chosen_file = gtk_file_chooser_get_file (file_chooser); gtk_widget_destroy (dialog); return chosen_file; }
/** * e_shell_run_save_dialog: * @shell: an #EShell * @title: file chooser dialog title * @suggestion: file name suggestion, or %NULL * @filters: Possible filters for dialog, or %NULL * @customize_func: optional dialog customization function * @customize_data: optional data to pass to @customize_func * * Runs a #GtkFileChooserDialog in save mode with the given title and * returns the selected #GFile. If @customize_func is provided, the * function is called just prior to running the dialog (the file chooser * is the first argument, @customize_data is the second). If the user * cancels the dialog the function will return %NULL. * * With non-%NULL @filters will be added also file filters to the dialog. * The string format is "pat1:mt1;pat2:mt2:...", where 'pat' is a pattern * and 'mt' is a MIME type for the pattern to be used. There can be more * than one MIME type, those are separated by comma. * * Returns: the #GFile to save to, or %NULL **/ GFile * e_shell_run_save_dialog (EShell *shell, const gchar *title, const gchar *suggestion, const gchar *filters, GtkCallback customize_func, gpointer customize_data) { GtkFileChooser *file_chooser; GFile *chosen_file = NULL; GtkWidget *dialog; GtkWindow *parent; g_return_val_if_fail (E_IS_SHELL (shell), NULL); parent = e_shell_get_active_window (shell); dialog = gtk_file_chooser_dialog_new ( title, parent, GTK_FILE_CHOOSER_ACTION_SAVE, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Save"), GTK_RESPONSE_ACCEPT, NULL); file_chooser = GTK_FILE_CHOOSER (dialog); gtk_dialog_set_default_response ( GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); gtk_file_chooser_set_local_only (file_chooser, FALSE); gtk_file_chooser_set_do_overwrite_confirmation (file_chooser, TRUE); if (suggestion != NULL) { gchar *current_name; current_name = g_strdup (suggestion); e_filename_make_safe (current_name); gtk_file_chooser_set_current_name (file_chooser, current_name); g_free (current_name); } if (filters != NULL) { gchar **flts = g_strsplit (filters, ";", -1); gint i; for (i = 0; flts && flts[i]; i++) { GtkFileFilter *filter = gtk_file_filter_new (); gchar *flt = flts[i]; gchar *delim = strchr (flt, ':'), *next = NULL; if (delim) { *delim = 0; next = strchr (delim + 1, ','); } gtk_file_filter_add_pattern (filter, flt); if (g_ascii_strcasecmp (flt, "*.mbox") == 0) gtk_file_filter_set_name ( filter, _("Berkeley Mailbox (mbox)")); else if (g_ascii_strcasecmp (flt, "*.vcf") == 0) gtk_file_filter_set_name ( filter, _("vCard (.vcf)")); else if (g_ascii_strcasecmp (flt, "*.ics") == 0) gtk_file_filter_set_name ( filter, _("iCalendar (.ics)")); else gtk_file_filter_set_name (filter, flt); while (delim) { delim++; if (next) *next = 0; gtk_file_filter_add_mime_type (filter, delim); delim = next; if (next) next = strchr (next + 1, ','); } gtk_file_chooser_add_filter (file_chooser, filter); } if (flts && flts[0]) { GtkFileFilter *filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, "*"); gtk_file_filter_set_name (filter, _("All Files (*)")); gtk_file_chooser_add_filter (file_chooser, filter); } g_strfreev (flts); } /* Allow further customizations before running the dialog. */ if (customize_func != NULL) customize_func (dialog, customize_data); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) chosen_file = gtk_file_chooser_get_file (file_chooser); gtk_widget_destroy (dialog); return chosen_file; }