Problems with File Dialogs




I'm working on a file conversion program with a gtk graphical interface.

I've been trying to get file dialogs to work, and been having some
problems.

When the user clicks on the load or save buttons, a file dialog pops up.
However originally, clicking on cancel would kill the entire program,
while clicking ok would perform the proper functions, but the file dialog
would stay open.

After purchasing "Developing Linux Applications with GTK+ and GDK" by
Eric Harlow, I managed to get the cancel button to work properly, ie
killing the dialog box but leaving the rest of the program running.
However the OK button now has the same problem, clicking on it kills the
entire program, not just the dialog, and i'm not quite sure how to fix it.

Below are the relevant functions (In order used, not order in program. =) 
I would greatly appreciate any help.

/**********************Data Type****************/

typedef struct
{
  void (*func) (gchar *);
  GtkWidget *filesel;
}
typFileSelectionData;


/**********************File Dialog****************/

void load_file (GtkWidget *w, void (*callback) (char*))
{
  GtkWidget *filew;
  typFileSelectionData *data;

  filew=gtk_file_selection_new ("File Selection");
  data=g_malloc(sizeof(typFileSelectionData));
  data->func=callback;
  data->filesel=filew;

  gtk_signal_connect (GTK_OBJECT (filew), "destroy",
		      (GtkSignalFunc) destroy_dialog, data);
    /* Connect the ok_button to file_ok_sel function */
  gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
		      "clicked", (GtkSignalFunc) file_ok_sel_load, filew);
    /* Connect the cancel_button to destroy the widget */
  gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
			     (filew)->cancel_button),
			     "clicked", (GtkSignalFunc) gtk_widget_destroy,
			     GTK_OBJECT (filew));
  gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew), 
				   "a.tif");
  gtk_widget_show(filew);
  gtk_grab_add(filew);
}

/**************Loading Function (Ok button)****************/

void file_ok_sel_load (GtkWidget *w, gpointer data)
{
  GtkWidget *filew;
  typFileSelectionData *localdata;
  localdata=(typFileSelectionData *) data;
  filew=localdata->filesel;

  gopen=gtk_file_selection_get_filename (GTK_FILE_SELECTION (filew));

gtk_entry_set_text(GTK_ENTRY(in_entry),gtk_file_selection_get_filename(GTK_FILE_SELECTION
(filew)));

  //gtk_grab_remove(filew);
  gtk_widget_destroy(filew);
  //destroy_dialog(filew,data);

/*
Eric Harlow used gtk_widget_destroy in his book, i also tried the other
two functions as alternate methods, and both gave the same result, the
entire program termianted instead of just the file dialog.
*/

  
}

/*****************Destructor Functions****************/


void destroy(GtkWidget *widget, gpointer data)
{
  gtk_main_quit();
}
void destroy_dialog(GtkWidget *widget, gpointer data)
{
  gtk_grab_remove(widget);
  g_free(data);
}



Thanks again



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