Rewrite using the new gtk_dialog_run function.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gnucash-gnome2-dev@9602 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton
2003-10-21 04:00:51 +00:00
parent ac6666b2a8
commit 94439c1d80
4 changed files with 30 additions and 117 deletions

View File

@@ -24,8 +24,8 @@
#include "config.h"
/** PROTOTYPES ******************************************************/
const char * gnc_file_dialog (const char * title,
const char * filter,
const char * default_name);
char * gnc_file_dialog (const char * title,
const char * filter,
const char * default_name);
#endif

View File

@@ -27,9 +27,9 @@ void gnc_file_init (void);
typedef void (*GNCHistoryAddFileFunc) (const char *filename);
typedef const char * (*GNCHistoryGetLastFunc) (void);
typedef const char * (*GNCFileDialogFunc) (const char * title,
const char * filter,
const char * default_name);
typedef char * (*GNCFileDialogFunc) (const char * title,
const char * filter,
const char * default_name);
void gnc_file_set_handlers (GNCHistoryAddFileFunc history_add_file_func,
GNCHistoryGetLastFunc history_get_last_func,

View File

@@ -28,30 +28,13 @@
#include "gnc-engine-util.h"
#include "gnc-file-dialog.h"
#include "gnc-file-history.h"
#include "gnc-ui.h"
#include "messages.h"
typedef struct
{
GtkFileSelection *file_box;
char *file_name;
} FileBoxInfo;
/* Global filebox information */
static FileBoxInfo fb_info = {NULL, NULL};
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_GUI;
/** PROTOTYPES ******************************************************/
static void store_filename(GtkWidget *w, gpointer data);
static void gnc_file_box_close_cb(GtkWidget *w, gpointer data);
static gboolean gnc_file_box_delete_cb(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
/********************************************************************\
* gnc_file_dialog *
* Pops up a file selection dialog (either a "Save As" or an *
@@ -65,108 +48,49 @@ static gboolean gnc_file_box_delete_cb(GtkWidget *widget, GdkEvent *event,
* Return: containing the name of the file the user selected *
\********************************************************************/
const char *
char *
gnc_file_dialog (const char * title,
const char * filter,
const char *default_name)
{
GtkFileSelection *file_box;
const char *internal_name;
char *file_name = NULL;
gint response;
ENTER("\n");
/* Set a default title if nothing was passed in */
if (title == NULL)
title = _("Open");
if (fb_info.file_name != NULL)
g_free(fb_info.file_name);
fb_info.file_box = GTK_FILE_SELECTION(gtk_file_selection_new(title));
fb_info.file_name = NULL;
file_box = GTK_FILE_SELECTION(gtk_file_selection_new(title));
if (default_name)
gtk_file_selection_set_filename(fb_info.file_box, default_name);
gtk_file_selection_set_filename(file_box, default_name);
/* hack alert - this was filtering directory names as well as file
* names, so I think we should not do this by default (rgmerk) */
#if 0
if (filter != NULL)
gtk_file_selection_complete(fb_info.file_box, filter);
gtk_file_selection_complete(file_box, filter);
#endif
gtk_window_set_modal(GTK_WINDOW(fb_info.file_box), TRUE);
gtk_window_set_transient_for(GTK_WINDOW(fb_info.file_box),
gtk_window_set_modal(GTK_WINDOW(file_box), TRUE);
gtk_window_set_transient_for(GTK_WINDOW(file_box),
GTK_WINDOW(gnc_ui_get_toplevel()));
response = gtk_dialog_run(GTK_DIALOG(file_box));
gtk_signal_connect(GTK_OBJECT(fb_info.file_box->ok_button),
"clicked", GTK_SIGNAL_FUNC(store_filename),
(gpointer) &fb_info);
/* Ensure that the dialog box is destroyed when the user clicks a button. */
gtk_signal_connect(GTK_OBJECT(fb_info.file_box->ok_button),
"clicked", GTK_SIGNAL_FUNC(gnc_file_box_close_cb),
(gpointer) &fb_info);
gtk_signal_connect(GTK_OBJECT(fb_info.file_box->cancel_button),
"clicked", GTK_SIGNAL_FUNC(gnc_file_box_close_cb),
(gpointer) &fb_info);
gtk_signal_connect(GTK_OBJECT(fb_info.file_box), "delete_event",
GTK_SIGNAL_FUNC(gnc_file_box_delete_cb), NULL);
gtk_signal_connect(GTK_OBJECT(fb_info.file_box), "destroy_event",
GTK_SIGNAL_FUNC(gnc_file_box_delete_cb), NULL);
gtk_widget_show(GTK_WIDGET(fb_info.file_box));
gtk_main();
gtk_widget_destroy(GTK_WIDGET(fb_info.file_box));
LEAVE("\n");
return fb_info.file_name;
}
/********************************************************************\
* store_filename *
* callback that saves the name of the file *
* *
* Args: w - the widget that called us *
* data - pointer to filebox info structure *
* Return: none *
\********************************************************************/
static void
store_filename (GtkWidget *w, gpointer data)
{
FileBoxInfo *fb_info = data;
GtkFileSelection *fs;
const char *file_name;
fs = GTK_FILE_SELECTION (fb_info->file_box);
file_name = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
if (!strstr (file_name, "://"))
file_name = gtk_file_selection_get_filename (fb_info->file_box);
fb_info->file_name = g_strdup (file_name);
}
static void
gnc_file_box_close_cb(GtkWidget *w, gpointer data)
{
gtk_widget_hide(GTK_WIDGET(fb_info.file_box));
gtk_main_quit();
}
static gboolean
gnc_file_box_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
gtk_widget_hide(GTK_WIDGET(fb_info.file_box));
gtk_main_quit();
/* Don't delete the window, we'll handle things ourselves. */
return TRUE;
if (response == GTK_RESPONSE_OK) {
/* look for constructs like postgres://foo */
internal_name = gtk_entry_get_text(GTK_ENTRY(file_box->selection_entry));
if (strstr (internal_name, "://") == 0) {
/* nope, a local file name */
internal_name = gtk_file_selection_get_filename(file_box);
}
file_name = g_strdup(internal_name);
}
gtk_widget_destroy(GTK_WIDGET(file_box));
LEAVE("%s", file_name);
return file_name;
}

View File

@@ -59,15 +59,4 @@ if they say 'Yes'. The return is false if the user says 'Cancel'.")
'()
"Get the last file opened by the user.")
(gw:wrap-function
ws
'gnc:file-selection-dialog
'(<gw:mchars> callee-owned const)
"gnc_file_dialog"
'(((<gw:mchars> caller-owned const) title)
((<gw:mchars> caller-owned const) filter)
((<gw:mchars> caller-owned const) default))
"Lets the user select a file. Dialog has given title, filter,
or default name. Either filter, default, or both should be NULL.")
)