Sunday, August 11, 2002, 11:31:23 AM, you wrote:
> I found that GtkFileSelection is some difficult to use. I mean, I
> want to force it to pickup a file name, not a directory name, but
> even when there's no file selected, the OK button still can be
> clicked. I did add some signals to the button to prevent it, but
> there's always some problems with the code. So can anybody give me
> some suggestions (or codes) to do it?
If your dialog run with gtk_dialog_run(). Then you must not to hide
your dialog if no file selected. My code for this:

const gchar *path;
// Create GtkFileSelection and set all properties
GtkWidget *OpenDlg = create_FileSelectionDialog();
do {
        // Wait for dialog close
        if (gtk_dialog_run(GTK_DIALOG(OpenDlg)) != GTK_RESPONSE_OK) {
                // Exit if Cancel or so pressed
                gtk_widget_destroy(GTK_WIDGET(OpenDlg));
                return;
        }
        // Retrieve the path
        path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (OpenDlg));
// Test is returned filename a regular file
} while (!(g_file_test(path,G_FILE_TEST_EXISTS) && 
g_file_test(path,G_FILE_TEST_IS_REGULAR)));
// Get filename from full path
gchar *filename = g_path_get_basename(path);

...

g_free(filename);
// !!!!!!!!!!!!!!!!!!!! Destroy dialog only here !!!!!!!!!!!!!!!!!!!!!!!!!!
gtk_widget_destroy(GTK_WIDGET(OpenDlg));


Alexander Chemeris

_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to