diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-11-11 01:14:07 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-11-11 07:18:11 +0800 |
commit | 3dfdf087fc7657905fc7804b59414ecd3d74028e (patch) | |
tree | 45a5bb547ca73ebaea9c3276860f93df6d417006 /shell | |
parent | f70ecb0406903e0fdc09bbf1c9a3367c7ba55ec2 (diff) | |
download | gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar.gz gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.tar.zst gsoc2013-evolution-3dfdf087fc7657905fc7804b59414ecd3d74028e.zip |
Kill more redundant save dialogs and related utilities.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/e-shell-utils.c | 88 | ||||
-rw-r--r-- | shell/e-shell-utils.h | 6 |
2 files changed, 91 insertions, 3 deletions
diff --git a/shell/e-shell-utils.c b/shell/e-shell-utils.c index 9d3d6f5fb4..4d4f0fd2ea 100644 --- a/shell/e-shell-utils.c +++ b/shell/e-shell-utils.c @@ -24,9 +24,86 @@ #include <glib/gi18n-lib.h> /** + * 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. It automatically remembers the selected + * folder. 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) +{ + EShellSettings *shell_settings; + GtkFileChooser *file_chooser; + GFile *chosen_file = NULL; + GtkWidget *dialog; + GtkWindow *parent; + const gchar *property_name; + gchar *uri; + + g_return_val_if_fail (E_IS_SHELL (shell), NULL); + + property_name = "file-chooser-folder"; + shell_settings = e_shell_get_shell_settings (shell); + + parent = e_shell_get_active_window (shell); + + dialog = gtk_file_chooser_dialog_new ( + title, parent, + 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 = e_shell_settings_get_string (shell_settings, property_name); + if (uri != NULL) + gtk_file_chooser_set_current_folder_uri (file_chooser, uri); + g_free (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); + e_shell_settings_set_string (shell_settings, property_name, uri); + g_free (uri); + +exit: + 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 * @customize_func: optional dialog customization function * @customize_data: optional data to pass to @customize_func * @@ -42,6 +119,7 @@ GFile * e_shell_run_save_dialog (EShell *shell, const gchar *title, + const gchar *suggestion, GtkCallback customize_func, gpointer customize_data) { @@ -64,11 +142,12 @@ e_shell_run_save_dialog (EShell *shell, title, parent, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); file_chooser = GTK_FILE_CHOOSER (dialog); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + 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); @@ -79,11 +158,14 @@ e_shell_run_save_dialog (EShell *shell, gtk_file_chooser_set_current_folder_uri (file_chooser, uri); g_free (uri); + if (suggestion != NULL) + gtk_file_chooser_set_current_name (file_chooser, suggestion); + /* 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_OK) + if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT) goto exit; chosen_file = gtk_file_chooser_get_file (file_chooser); diff --git a/shell/e-shell-utils.h b/shell/e-shell-utils.h index 6fedca8a4a..24ca617369 100644 --- a/shell/e-shell-utils.h +++ b/shell/e-shell-utils.h @@ -32,8 +32,14 @@ G_BEGIN_DECLS +GFile * e_shell_run_open_dialog (EShell *shell, + const gchar *title, + GtkCallback customize_func, + gpointer customize_data); + GFile * e_shell_run_save_dialog (EShell *shell, const gchar *title, + const gchar *suggestion, GtkCallback customize_func, gpointer customize_data); |