Strange file selection behaviour




I have a problem with the file selection dialog. When I click
the cancel button, the dialog doesn't close, but instead the cancel
button disappears. The code is as follows:


  GtkWidget *dia_file = NULL;

  void file_open(void) {

    /* Create file dialog */
    dia_file = gtk_file_selection_new("Select file");

    /* Make dialog modal */
    gtk_window_set_modal(GTK_WINDOW(dia_file), TRUE);

    /* Register selection event */
    gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(dia_file)->ok_button),
                       "clicked",
		       GTK_SIGNAL_FUNC(file_selected),
                       NULL);

    /* Register cancellation event */
    gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(dia_file)->cancel_button),
                       "clicked",
		       GTK_SIGNAL_FUNC(gtk_widget_destroy),
                       GTK_OBJECT(dia_file));

    /* Show dialog */
    gtk_widget_show(dia_file);
  }

  void file_selected(GtkWidget *widget, gpointer *data) {

    /* Get name of selected file */
    char *filename = strdup(gtk_file_selection_get_filename(
                              GTK_FILE_SELECTION(dia_file)));

    /* Destroy file selection dialog */
    gtk_widget_destroy(dia_file); dia_file = NULL;

    /* Ouput name of selected file */
    printf("File selected: '%s'\n", filename);
  }


Any help would be appreciated.

-- 
Lars Haugseth



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]